diff --git a/CHANGELOG.md b/CHANGELOG.md index 65aebfb..7d068b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Matemat Changelog + +## Version 0.3.4 + +Purchase confirmation overlay + +### Changes + + +- Show and fade an overlay after completing a purchase or deposit + + + + ## Version 0.3.3 diff --git a/matemat/__init__.py b/matemat/__init__.py index 2fd20b5..6d4c134 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.3.3' +__version__ = '0.3.4' diff --git a/matemat/webserver/pagelets/buy.py b/matemat/webserver/pagelets/buy.py index e8e6d51..796458d 100644 --- a/matemat/webserver/pagelets/buy.py +++ b/matemat/webserver/pagelets/buy.py @@ -26,7 +26,7 @@ def buy(): pid = int(str(request.params.pid)) product = db.get_product(pid) if c.get_dispenser().dispense(product, 1): - price = None + price = product.price_member if user.is_member else product.price_non_member if 'price' in request.params: price = int(str(request.params.price)) # Create a consumption entry for the (user, product) combination @@ -34,5 +34,6 @@ def buy(): 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 to the main page (where this request should have come from) + redirect(f'/?lastaction=buy&lastproduct={pid}&lastprice={price}') redirect('/') diff --git a/matemat/webserver/pagelets/deposit.py b/matemat/webserver/pagelets/deposit.py index 2da8ea2..291d0d2 100644 --- a/matemat/webserver/pagelets/deposit.py +++ b/matemat/webserver/pagelets/deposit.py @@ -26,5 +26,6 @@ def deposit(): n = int(str(request.params.n)) # Write the deposit to the database db.deposit(user, n) - # 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(f'/?lastaction=deposit&lastprice={n}') redirect('/') diff --git a/matemat/webserver/pagelets/main.py b/matemat/webserver/pagelets/main.py index 5b52be9..251ca03 100644 --- a/matemat/webserver/pagelets/main.py +++ b/matemat/webserver/pagelets/main.py @@ -1,6 +1,6 @@ from datetime import datetime -from bottle import route, redirect +from bottle import route, redirect, request from matemat.db import MatematDatabase from matemat.webserver import template, session @@ -26,9 +26,15 @@ def main_page(): user = db.get_user(uid) # Fetch the list of products to display products = db.list_products() + if request.params.lastproduct: + lastproduct = db.get_product(request.params.lastproduct) + else: + lastproduct = None + lastprice = int(request.params.lastprice) if request.params.lastprice else None # Prepare a response with a jinja2 template return template.render('productlist.html', authuser=user, users=users, products=products, authlevel=authlevel, + lastaction=request.params.lastaction, lastprice=lastprice, lastproduct=lastproduct, stock=get_stock_provider(), setupname=config['InstanceName'], now=now) else: # If there are no admin users registered, jump to the admin creation procedure diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index ad71767..b8847c9 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -1,5 +1,5 @@ Package: matemat -Version: 0.3.3 +Version: 0.3.4 Maintainer: s3lph <1375407-s3lph@users.noreply.gitlab.com> Section: web Priority: optional diff --git a/static/css/matemat.css b/static/css/matemat.css index e36f817..b5d9151 100644 --- a/static/css/matemat.css +++ b/static/css/matemat.css @@ -297,4 +297,37 @@ div.osk-button:active, div.osk-button.osk-locked { div.osk-button.osk-button-space { flex: 5 0 1px; color: #606060; +} + +aside#overlay { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + background: #88ff88; + text-align: center; + z-index: 1000; + padding: 5%; + font-family: sans-serif; + display: none; +} + +aside#overlay.fade { + opacity: 0; + transition: opacity 0.5s; +} + +aside#overlay > h2 { + font-size: 3em; +} + +aside#overlay > img { + width: 30%; + height: auto; +} + +aside#overlay > div.price { + padding-top: 30px; + font-size: 2em; } \ No newline at end of file diff --git a/static/js/overlay.js b/static/js/overlay.js new file mode 100644 index 0000000..57e60ba --- /dev/null +++ b/static/js/overlay.js @@ -0,0 +1,14 @@ + +setTimeout(() => { + let overlay = document.getElementById('overlay'); + if (overlay !== null) { + overlay.style.display = 'block'; + setTimeout(() => { + overlay.classList.add('fade'); + setTimeout(() => { + overlay.style.display = 'none'; + overlay.classList.remove('fade'); + }, 500); + }, 500); + } +}, 0); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 063d3ad..399ec5e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,6 +12,9 @@ +{% block overlay %} +{% endblock %} +
{% block header %} @@ -54,5 +57,6 @@ {% endblock %} + diff --git a/templates/productlist.html b/templates/productlist.html index 4080312..93e1227 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -6,6 +6,27 @@ {{ super() }} {% endblock %} +{% block overlay %} +{% if lastaction is not none %} +{% if lastaction == 'buy' %} + +{% elif lastaction == 'deposit' %} + +{% endif %} +{% endif %} +{% endblock %} + {% block main %} {# Show the users current balance #}