1
0
Fork 0
forked from s3lph/matemat

Merge branch 'staging' into 'master'

0.2.7

See merge request s3lph/matemat!76
This commit is contained in:
s3lph 2021-04-07 00:56:45 +00:00
commit 4e643799f2
7 changed files with 225 additions and 17 deletions

View file

@ -1,5 +1,31 @@
# Matemat Changelog # Matemat Changelog
<!-- BEGIN RELEASE v0.2.7 -->
## Version 0.2.7
Feature release
### Changes
<!-- BEGIN CHANGES 0.2.7 -->
- Feature: More touch-friendly deposit interface
<!-- END CHANGES 0.2.7 -->
<!-- END RELEASE v0.2.7 -->
<!-- BEGIN RELEASE v0.2.6 -->
## Version 0.2.6
Bugfix release
### Changes
<!-- BEGIN CHANGES 0.2.6 -->
- Fix: Improve support for stock providers
<!-- END CHANGES 0.2.6 -->
<!-- END RELEASE v0.2.6 -->
<!-- BEGIN RELEASE v0.2.5 --> <!-- BEGIN RELEASE v0.2.5 -->
## Version 0.2.5 ## Version 0.2.5

View file

@ -1,2 +1,2 @@
__version__ = '0.2.5' __version__ = '0.2.7'

View file

@ -25,11 +25,11 @@ def buy():
if 'pid' in request.params: if 'pid' in request.params:
pid = int(str(request.params.pid)) pid = int(str(request.params.pid))
product = db.get_product(pid) product = db.get_product(pid)
# Create a consumption entry for the (user, product) combination if c.get_dispenser().dispense(product, 1):
db.increment_consumption(user, product) # Create a consumption entry for the (user, product) combination
stock_provider = c.get_stock_provider() db.increment_consumption(user, product)
if stock_provider.needs_update(): stock_provider = c.get_stock_provider()
stock_provider.update_stock(product, -1) if stock_provider.needs_update():
c.get_dispenser().dispense(product, 1) stock_provider.update_stock(product, -1)
# Redirect to the main page (where this request should have come from) # Redirect to the main page (where this request should have come from)
redirect('/') redirect('/')

View file

@ -1,5 +1,5 @@
Package: matemat Package: matemat
Version: 0.2.4 Version: 0.2.7
Maintainer: s3lph <account-gitlab-ideynizv@kernelpanic.lol> Maintainer: s3lph <account-gitlab-ideynizv@kernelpanic.lol>
Section: web Section: web
Priority: optional Priority: optional

View file

@ -49,4 +49,127 @@
display: inline-block; display: inline-block;
margin-right: 40px; margin-right: 40px;
} }
} }
#depositlist {
display: inline;
}
#deposit-wrapper {
display: none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,0,0,.75);
z-index: 100;
}
#deposit-input {
display: grid;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 320px;
height: 540px;
grid-template-columns: 100px 100px 100px;
grid-template-rows: 100px 100px 100px 100px 100px;
column-gap: 10px;
row-gap: 10px;
}
#deposit-wrapper.show {
display: block;
}
.fakelink {
cursor: pointer;
color: blue;
}
#deposit-amount {
grid-column-start: 1;
grid-column-end: 4;
text-align: right;
grid-row: 1;
font-size: 50px;
line-heigt: 100px;
padding: 10px 0;
font-family: monospace;
background: #ffffff;
}
.numpad {
background: #f0f0f0;
text-decoration: none;
font-size: 50px;
font-family: sans-serif;
line-height: 100px;
text-align: center;
}
#numpad-1 {
grid-column: 1;
grid-row: 2;
}
#numpad-2 {
grid-column: 2;
grid-row: 2;
}
#numpad-3 {
grid-column: 3;
grid-row: 2;
}
#numpad-4 {
grid-column: 1;
grid-row: 3;
}
#numpad-5 {
grid-column: 2;
grid-row: 3;
}
#numpad-6 {
grid-column: 3;
grid-row: 3;
}
#numpad-7 {
grid-column: 1;
grid-row: 4;
}
#numpad-8 {
grid-column: 2;
grid-row: 4;
}
#numpad-9 {
grid-column: 3;
grid-row: 4;
}
#numpad-del {
grid-column: 1;
grid-row: 5;
background: #f06060;
}
#numpad-0 {
grid-column: 2;
grid-row: 5;
}
#numpad-ok {
grid-column: 3;
grid-row: 5;
background: #60f060;
}

45
static/js/depositlist.js Normal file
View file

@ -0,0 +1,45 @@
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
let deposit = '0';
let button = document.createElement('div');
let input = document.getElementById('deposit-wrapper');
let amount = document.getElementById('deposit-amount');
button.classList.add('thumblist-item');
button.classList.add('fakelink');
button.innerText = 'Deposit';
button.onclick = (ev) => {
deposit = '0';
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
input.classList.add('show');
};
deposit_key = (k) => {
if (k == 'ok') {
window.location.href = '/deposit?n=' + parseInt(deposit);
deposit = '0';
input.classList.remove('show');
} else if (k == 'del') {
if (deposit == '0') {
input.classList.remove('show');
}
deposit = deposit.substr(0, deposit.length - 1);
if (deposit.length == 0) {
deposit = '0';
}
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
} else {
if (deposit == '0') {
deposit = k;
} else {
deposit += k;
}
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
}
};
let list = document.getElementById('depositlist');
list.innerHTML = '';
list.appendChild(button);

View file

@ -11,13 +11,28 @@
{# Show the users current balance #} {# Show the users current balance #}
Your balance: {{ authuser.balance|chf }} Your balance: {{ authuser.balance|chf }}
<br/> <br/>
{# Logout link #}
<div class="thumblist-item">
<a href="/logout">Logout</a>
</div>
{# Links to deposit two common amounts of cash. TODO: Will be replaced by a nicer UI later (#20) #} {# Links to deposit two common amounts of cash. TODO: Will be replaced by a nicer UI later (#20) #}
<div class="thumblist-item"> <div id="depositlist">
<a href="/deposit?n=100">Deposit CHF 1</a> <div class="thumblist-item">
<a href="/deposit?n=100">Deposit CHF 1</a>
</div>
<div class="thumblist-item">
<a href="/deposit?n=1000">Deposit CHF 10</a>
</div>
</div> </div>
<div class="thumblist-item"> <div id="deposit-wrapper">
<a href="/deposit?n=1000">Deposit CHF 10</a> <div id="deposit-input">
<span id="deposit-amount">0.00</span>
{% for i in [('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('del', '✗'), ('0', '0'), ('ok', '✓')] %}
<div class="numpad" id="numpad-{{ i.0 }}" onclick="deposit_key('{{ i.0 }}');">{{ i.1 }}</div>
{% endfor %}
</div>
</div> </div>
<script src="/static/js/depositlist.js"></script>
<br/> <br/>
{% for product in products %} {% for product in products %}
@ -34,16 +49,15 @@
</span><br/> </span><br/>
<div class="imgcontainer"> <div class="imgcontainer">
<img src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}"/> <img src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}"/>
{% if product.stockable %} {% set pstock = stock.get_stock(product) %}
<span class="thumblist-stock">{{ stock.get_stock(product) }}</span> {% if pstock is not none %}
<span class="thumblist-stock">{{ pstock }}</span>
{% endif %} {% endif %}
</div> </div>
</a> </a>
</div> </div>
{% endfor %} {% endfor %}
<br/> <br/>
{# Logout link #}
<a href="/logout">Logout</a>
{{ super() }} {{ super() }}