diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2b0a7..d6bb1c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Matemat Changelog + +## Version 0.2.7 + +Feature release + +### Changes + + +- Feature: More touch-friendly deposit interface + + + + + +## Version 0.2.6 + +Bugfix release + +### Changes + + +- Fix: Improve support for stock providers + + + + ## Version 0.2.5 diff --git a/matemat/__init__.py b/matemat/__init__.py index 6c0a1ad..e98cbf8 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.2.5' +__version__ = '0.2.7' diff --git a/matemat/webserver/pagelets/buy.py b/matemat/webserver/pagelets/buy.py index bd64b2e..350b20e 100644 --- a/matemat/webserver/pagelets/buy.py +++ b/matemat/webserver/pagelets/buy.py @@ -25,11 +25,11 @@ def buy(): if 'pid' in request.params: pid = int(str(request.params.pid)) product = db.get_product(pid) - # Create a consumption entry for the (user, product) combination - db.increment_consumption(user, product) - stock_provider = c.get_stock_provider() - if stock_provider.needs_update(): - stock_provider.update_stock(product, -1) - c.get_dispenser().dispense(product, 1) + if c.get_dispenser().dispense(product, 1): + # Create a consumption entry for the (user, product) combination + db.increment_consumption(user, product) + stock_provider = c.get_stock_provider() + if stock_provider.needs_update(): + stock_provider.update_stock(product, -1) # Redirect to the main page (where this request should have come from) redirect('/') diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index 43e9faa..b1f8a77 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -1,5 +1,5 @@ Package: matemat -Version: 0.2.4 +Version: 0.2.7 Maintainer: s3lph Section: web Priority: optional diff --git a/static/css/matemat.css b/static/css/matemat.css index a554c6d..708dea5 100644 --- a/static/css/matemat.css +++ b/static/css/matemat.css @@ -49,4 +49,127 @@ display: inline-block; margin-right: 40px; } -} \ No newline at end of file +} + +#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; +} diff --git a/static/js/depositlist.js b/static/js/depositlist.js new file mode 100644 index 0000000..e6b4a1f --- /dev/null +++ b/static/js/depositlist.js @@ -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); diff --git a/templates/productlist.html b/templates/productlist.html index 51ae56f..f79ecef 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -11,13 +11,28 @@ {# Show the users current balance #} Your balance: {{ authuser.balance|chf }}
+ {# Logout link #} +
+ Logout +
{# Links to deposit two common amounts of cash. TODO: Will be replaced by a nicer UI later (#20) #} -
- Deposit CHF 1 + -
- Deposit CHF 10 +
+
+ 0.00 + {% 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', '✓')] %} +
{{ i.1 }}
+ {% endfor %} +
+
{% for product in products %} @@ -34,16 +49,15 @@
Picture of {{ product.name }} - {% if product.stockable %} - {{ stock.get_stock(product) }} + {% set pstock = stock.get_stock(product) %} + {% if pstock is not none %} + {{ pstock }} {% endif %}
{% endfor %}
- {# Logout link #} - Logout {{ super() }}