From 7032f2ad77d8a2e77fba175cb781e30531b45dcf Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Mon, 30 Mar 2015 23:02:05 +0200 Subject: [PATCH] `The Final Countdown --- app/create_database.py | 1 + app/static/js/timer.js | 36 ++++++++++++++++++++++++++++++++++++ app/templates/layout.html | 1 + app/templates/order.html | 4 ++-- app/templates/utils.html | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/static/js/timer.js diff --git a/app/create_database.py b/app/create_database.py index ba2814a..a4af0de 100644 --- a/app/create_database.py +++ b/app/create_database.py @@ -42,6 +42,7 @@ specials = ["Kippenbolletjes zoetzuur", "varkenbolletjes zoetzuur", "Nazi Babi P chinees = Location() chinees.configure("Oceans's Garden", "Top-4-straat Keknet-city", "http://oceangarden.byethost3.com/studentenmenus.html") +db.session.add(chinees) def chinees_create_entry(zetmeel, vlees="", saus=""): entry = Product() diff --git a/app/static/js/timer.js b/app/static/js/timer.js new file mode 100644 index 0000000..f0872ee --- /dev/null +++ b/app/static/js/timer.js @@ -0,0 +1,36 @@ +/** + * Created by feliciaan on 30/03/15. + */ +$.ready(function(){ + $('.time').each(function() { + var timeEl = $( this ); + var time = timeEl.text().split(' ').slice(-1)[0].split(':'); + + if (timeEl.text().indexOf('closed') < 0) { + window.setInterval(function () { + time = my_tick(time); + if (time !== "closed") { + timeS = "closes in " + ("0" + time[0]).slice(-2) + ":" + ("0" + time[1]).slice(-2) + ":" + ("0" + time[2]).slice(-2); + } else { + timeS = "closed" + } + timeEl.html(timeS); + }, 1000); + } + }); + + function my_tick(time) { + if (time[2] > 0) { + time[2] = time[2] - 1; + } else if(time[1] > 0) { + time[2] = 59; + time[1] = time[1] - 1; + } else if(time[0] > 0) { + time[1] = 59; + time[0] = time[0] - 1; + } else { + return "closed"; + } + return time; + } +}()); \ No newline at end of file diff --git a/app/templates/layout.html b/app/templates/layout.html index 050c0e8..7c0473e 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -23,6 +23,7 @@ {% block scripts %} {{ super() }} + {% endblock %} diff --git a/app/templates/order.html b/app/templates/order.html index 1141d98..b95c8fa 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -8,7 +8,7 @@

Order {{ order.id }} {% if order.can_close(current_user.id) -%} - Close
+ Close
{%- endif %}

courrier: {{ order.courrier.username }} {% if order.courrier == None and not current_user.is_anonymous() %} @@ -16,7 +16,7 @@ {% endif %}
location: {{ order.location.name }}
- status: {% if order.stoptime %}{{ order.stoptime|countdown }}{% else %}open{% endif %}
+ status: {% if order.stoptime %}{{ order.stoptime|countdown }}{% else %}open{% endif %}
total price: {{ total_price|euro }}
{% if form -%} diff --git a/app/templates/utils.html b/app/templates/utils.html index bdb0e31..f45bb4f 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -2,7 +2,7 @@
{{ order.location.name }}
-

Status: {{ order.stoptime|countdown }}
+

Status: {{ order.stoptime|countdown }}
Orders: {{ order.items.count() }}