[PATCH coffee-flask v3] Add function for add events to callendar

A replaced of paper calendar with operations related to the maintenance of a coffee shop --- .gitmodules | 15 ++++++ app.py | 51 +++++++++++++++++- coffee_db.py | 22 ++++++++ coffee_db.sql | 18 +++++++ templates/bower_components/bootstrap | 1 + templates/bower_components/bootstrap3-dialog | 1 + templates/bower_components/fullcalendar | 1 + templates/bower_components/jquery | 1 + templates/bower_components/moment | 1 + templates/calendar.html | 80 ++++++++++++++++++++++++++++ templates/calendar.svg | 51 ++++++++++++++++++ templates/events/box.svg | 68 +++++++++++++++++++++++ templates/events/machine.svg | 67 +++++++++++++++++++++++ templates/events/milk.svg | 68 +++++++++++++++++++++++ templates/events/milk_container.svg | 47 ++++++++++++++++ templates/main.js | 22 ++++++++ templates/user.html | 8 ++- 17 files changed, 519 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 templates/bower_components/bootstrap create mode 160000 templates/bower_components/bootstrap3-dialog create mode 160000 templates/bower_components/fullcalendar create mode 160000 templates/bower_components/jquery create mode 160000 templates/bower_components/moment create mode 100644 templates/calendar.html create mode 100644 templates/calendar.svg create mode 100644 templates/events/box.svg create mode 100644 templates/events/machine.svg create mode 100644 templates/events/milk.svg create mode 100644 templates/events/milk_container.svg diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3175491 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "templates/bower_components/jquery"] + path = templates/bower_components/jquery + url = https://github.com/jquery/jquery-dist.git +[submodule "templates/bower_components/bootstrap"] + path = templates/bower_components/bootstrap + url = https://github.com/twbs/bootstrap.git +[submodule "templates/bower_components/bootstrap3-dialog"] + path = templates/bower_components/bootstrap3-dialog + url = https://github.com/nakupanda/bootstrap3-dialog.git +[submodule "templates/bower_components/moment"] + path = templates/bower_components/moment + url = https://github.com/moment/moment +[submodule "templates/bower_components/fullcalendar"] + path = templates/bower_components/fullcalendar + url = https://github.com/fullcalendar/fullcalendar diff --git a/app.py b/app.py index 5481624..05a1994 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, send_file, request, session, redirect, url_for, make_response +from flask import Flask, render_template, send_file, request, session, redirect, url_for, make_response, jsonify from flask_cors import CORS import numpy as np @@ -13,7 +13,7 @@ import time from datetime import date, timedelta db.init_db() -app = Flask(__name__) +app = Flask(__name__, static_url_path="", static_folder="templates") CORS(app, supports_credentials=True) app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' @@ -163,6 +163,53 @@ def js(): response.headers['Content-Type'] = "text/javascript" return response +@app.route('/jquery.min.js') +def jquery_min_js(): + response = make_response(render_template("bower_components/jquery/dist/jquery.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route('/bootstrap.min.js') +def bootstrap_min_js(): + response = make_response(render_template("bower_components/bootstrap/dist/js/bootstrap.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route('/bootstrap-dialog.min.js') +def bootstrap_dialog_min_js(): + response = make_response(render_template("bower_components/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route("/events/<image>") +def event_icon(image): + print(image) + svg = open('templates/events/'+image).read() + response = make_response(svg) + response.content_type = 'image/svg+xml' + return response + +@app.route("/event/add", methods=["POST"]) +def event_add(): + if request.method == "POST": + json = request.json + db.add_event(json["time"], json["event"], json["uid"]) + return redirect(url_for('user')) + +@app.route("/event_list") +def event_list(): + return jsonify(db.list_event()) + +@app.route("/calendar.svg") +def calender_icon(): + svg = open('templates/calendar.svg').read() + response = make_response(svg) + response.content_type = 'image/svg+xml' + return response + +@app.route('/calendar') +def calendar(): + return render_template('calendar.html',events=db.events()) @app.route("/log", methods=["POST"]) def log(): diff --git a/coffee_db.py b/coffee_db.py index 0abb5a4..03bc15e 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -54,6 +54,28 @@ def add_coffee(uid, flavor, time=None): c.execute("insert into coffees (id, flavor, time) values (?,?,?)", (uid, flavor, time)) close_db(conn) +def add_event(time, title, uid): + conn, c = open_db() + c.execute("insert into events (time,title,id) values (?,?,?)", (time,title,uid)) + close_db(conn) + +def list_event(): + conn, c = open_db() + result=c.execute("select e.time, e.title, l.image from events e left join (select * from list_events) l on e.title=l.title") + items=[] + for row in result: + items.append({'start': row[0], 'color': '#FFFFFF', 'imageurl':row[2]}) + close_db(conn) + return items + +def events(): #various events that can be created + conn, c = open_db() + result=c.execute("select title, image from list_events") + items=[] + for row in result: + items.append({'title': row[0],'image': row[1]}) + close_db(conn) + return items def list_coffees(uid=None): c = conn.cursor() diff --git a/coffee_db.sql b/coffee_db.sql index d9f7d8e..63367d8 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -28,6 +28,24 @@ create table if not exists days ( num integer primary key not null ); +create table if not exists events ( + time datetime, + title varchar(255), + id varchar(24) references users(id) +); + +create table if not exists list_events ( + title varchar(255) primary key not null, + image varchar(255) +); + +insert or ignore into list_events values + ("Milk container cleaned", "milk_container.svg"), + ("Coffee machine cleaned", "machine.svg"), + ("Milk washed wipill","milk.svg"), + ("New coffee opened","box.svg") +; + insert or ignore into days values (0),(1),(2),(3),(4),(5),(6) ; diff --git a/templates/bower_components/bootstrap b/templates/bower_components/bootstrap new file mode 160000 index 0000000..0b9c4a4 --- /dev/null +++ b/templates/bower_components/bootstrap @@ -0,0 +1 @@ +Subproject commit 0b9c4a4007c44201dce9a6cc1a38407005c26c86 diff --git a/templates/bower_components/bootstrap3-dialog b/templates/bower_components/bootstrap3-dialog new file mode 160000 index 0000000..5304d56 --- /dev/null +++ b/templates/bower_components/bootstrap3-dialog @@ -0,0 +1 @@ +Subproject commit 5304d56cd33da77b8c8e6e250e8f39211d191a0e diff --git a/templates/bower_components/fullcalendar b/templates/bower_components/fullcalendar new file mode 160000 index 0000000..3ddb3c8 --- /dev/null +++ b/templates/bower_components/fullcalendar @@ -0,0 +1 @@ +Subproject commit 3ddb3c8d1461c6b841aed3487ba07d8ba338adb6 diff --git a/templates/bower_components/jquery b/templates/bower_components/jquery new file mode 160000 index 0000000..9e8ec3d --- /dev/null +++ b/templates/bower_components/jquery @@ -0,0 +1 @@ +Subproject commit 9e8ec3d10fad04748176144f108d7355662ae75e diff --git a/templates/bower_components/moment b/templates/bower_components/moment new file mode 160000 index 0000000..db71a65 --- /dev/null +++ b/templates/bower_components/moment @@ -0,0 +1 @@ +Subproject commit db71a655fc51fe58009675608a400d0d4cd0ca87 diff --git a/templates/calendar.html b/templates/calendar.html new file mode 100644 index 0000000..6951163 --- /dev/null +++ b/templates/calendar.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> + +<head> + <meta charset='utf-8' /> + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/fullcalendar/dist/fullcalendar.min.css', _external=True, stamp=stamp) }}"> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/moment/min/moment.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/jquery/dist/jquery.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/fullcalendar/dist/fullcalendar.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript> + var calendar; + $(document).ready(function() { + calendar = $('#calendar').fullCalendar({ + header: { + left: 'prev,next today', + center: 'title', + right: '' + }, + selectable: true, + selectHelper: true, + selectConstraint: { + start: '00:00', + end: '24:00' + }, + events: { + url: "{{ url_for('event_list', _external=True, stamp=stamp) }}" + }, + eventRender: function(event, eventElement) { + if (event.imageurl) { + var variable1 = event.imageurl; + eventElement.find(".fc-title").html("<center> <img src={{ url_for('event_icon', image='var1', _external=True, stamp=stamp) }} width='20' height='20' /> </center>".replace("var1", variable1)); + } + } + }); + }); + </script> + <style> + body { + margin: 20px 10px; + padding: 0; + font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif; + font-size: 14px; + } + #calendar { + max-width: 800px; + margin: 0 auto; + } + fieldset { + font-size: 15px; + padding: 10px; + width: 450px; + margin: 0 auto; + text-align: center; + line-height: 1.8; + } + </style> + +</head> + +<body> + <center> + <h2> <b>Coffee machine cleaning </b></h2> + <h3> Write the operation performed by pressing the button in this dialog window in the lower part.</h3> + <form> + <b>Operations: </b> + {% for event in events %} + <img style="vertical-align:middle" src="{{ url_for('event_icon', image=event.image, _external=True, stamp=stamp )}}" width="40" height="40"> + <span style="">{{ event.title }}</span> + {% endfor %} + </form> + <div id='calendar'></div> + <form> + {% for event in events %} + <input type="button" value="{{ event.title }}" onclick="addEvent(this.value)"> + {% endfor %} + </form> + </center> +</body> + +</html> diff --git a/templates/calendar.svg b/templates/calendar.svg new file mode 100644 index 0000000..4d781eb --- /dev/null +++ b/templates/calendar.svg @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 64 64" style="enable-background:new 0 0 64 64;" xml:space="preserve"> +<style type="text/css"> + .st0{fill:#77B3D4;} + .st1{opacity:0.2;} + .st2{fill:#231F20;} + .st3{fill:#FFFFFF;} + .st4{fill:#C75C5C;} + .st5{fill:#4F5D73;} + .st6{fill:#E0E0D1;} +</style> +<g id="Layer_1"> + <g> + <circle class="st0" cx="32" cy="32" r="32"/> + </g> + <g> + <g class="st1"> + <path class="st2" d="M12,25v25c0,2.2,1.8,4,4,4h32c2.2,0,4-1.8,4-4V25H12z"/> + </g> + <g> + <path class="st3" d="M12,23v25c0,2.2,1.8,4,4,4h32c2.2,0,4-1.8,4-4V23H12z"/> + </g> + <g class="st1"> + <path class="st2" d="M48,14H16c-2.2,0-4,1.8-4,4v7h40v-7C52,15.8,50.2,14,48,14z"/> + </g> + <g> + <path class="st4" d="M48,12H16c-2.2,0-4,1.8-4,4v7h40v-7C52,13.8,50.2,12,48,12z"/> + </g> + <g> + <path class="st5" d="M32,48c-1.1,0-2-0.9-2-2c0-5.5,1.8-9.5,3.5-12H27c-1.1,0-2-0.9-2-2s0.9-2,2-2h11c0.9,0,1.6,0.6,1.9,1.4 + s0,1.7-0.7,2.2C39,33.8,34,37.5,34,46C34,47.1,33.1,48,32,48z"/> + </g> + <g class="st1"> + <path class="st2" d="M20,21c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C22,20.1,21.1,21,20,21L20,21z"/> + </g> + <g class="st1"> + <path class="st2" d="M45,21c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C47,20.1,46.1,21,45,21L45,21z"/> + </g> + <g> + <path class="st6" d="M20,19c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C22,18.1,21.1,19,20,19L20,19z"/> + </g> + <g> + <path class="st6" d="M45,19c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C47,18.1,46.1,19,45,19L45,19z"/> + </g> + </g> +</g> +<g id="Layer_2"> +</g> +</svg> diff --git a/templates/events/box.svg b/templates/events/box.svg new file mode 100644 index 0000000..2bcbbf1 --- /dev/null +++ b/templates/events/box.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="box.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="-44.841946" + inkscape:cy="65.020819" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#c49347;fill-opacity:1;stroke:none;stroke-width:0.26458332;" + x="7.6817751" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="7.6817751" + y="25.313768" + style="font-size:22.57777786px;fill:#c49347;fill-opacity:1;stroke-width:0.26458332;">N</tspan></text> + <rect + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#c49347;stroke-width:2.39791874;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4505" + width="32.602345" + height="32.602345" + x="1.1988993" + y="1.198831" /> +</svg> diff --git a/templates/events/machine.svg b/templates/events/machine.svg new file mode 100644 index 0000000..2d2e606 --- /dev/null +++ b/templates/events/machine.svg @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="machine.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="-47.084043" + inkscape:cy="66.141869" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#47c779;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="8.9252768" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="8.9252768" + y="25.313768" + style="font-size:22.57777786px;fill:#47c779;fill-opacity:1;stroke-width:0.26458332">C</tspan></text> + <circle + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#47c779;stroke-width:2.04399991;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="path4489" + cx="17.500038" + cy="17.500036" + r="16.478037" /> +</svg> diff --git a/templates/events/milk.svg b/templates/events/milk.svg new file mode 100644 index 0000000..eb7c51e --- /dev/null +++ b/templates/events/milk.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="milk.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="67.262918" + inkscape:cy="66.141869" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000c8;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="7.6817751" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="7.6817751" + y="25.313768" + style="font-size:22.57777786px;fill:#0000c8;fill-opacity:1;stroke-width:0.26458332">M</tspan></text> + <rect + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#0000c8;stroke-width:2.39779854;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4505" + width="32.602345" + height="32.602345" + x="1.1988993" + y="1.198831" /> +</svg> diff --git a/templates/events/milk_container.svg b/templates/events/milk_container.svg new file mode 100644 index 0000000..b31f75e --- /dev/null +++ b/templates/events/milk_container.svg @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm"> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + transform="translate(-23.989663,-42.769872)" + id="layer1"> + <text + id="text4487" + y="68.083641" + x="31.671438" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332" + xml:space="preserve"><tspan + style="font-size:22.57777786px;fill:#ff0000;stroke-width:0.26458332" + y="68.083641" + x="31.671438" + id="tspan4485">M</tspan></text> + <circle + r="16.478037" + cy="60.269909" + cx="41.4897" + id="path4489" + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#ff0000;stroke-width:2.04399991;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </g> +</svg> diff --git a/templates/main.js b/templates/main.js index 8135983..c3ea61e 100644 --- a/templates/main.js +++ b/templates/main.js @@ -7,6 +7,7 @@ var timeToLogout = undefined; // defined during logout countdown var logoutTimer; var reloadTimer = undefined; var id_user; // ID of the user who is to be accounted for the next coffee +var dialog; console.log("hello from flask"); //sendJSON("{\"type\":\"empty\"}"); @@ -155,8 +156,17 @@ function login(id) { countingTimeLogout(120); } +function show_calendar(){ + var url="{{ url_for('calendar', _external=True, stamp=stamp) }}"; + dialog=BootstrapDialog.show({ + title: 'Calendar', + message: $('<div></div>').load(url) + }); +} + function logout() { sendReset(); + dialog.close(); ajax("GET", "logout", "", "user"); id_user = undefined; timeToLogout = undefined; @@ -202,6 +212,18 @@ function addCoffee(flavor, time = new Date()) { } } +function addEvent(event, time = new Date()) { + var data = JSON.stringify({ + time: time.toISOString().split("T")[0], + event: event, + uid: id_user + }); + if (id_user) { + ajax("POST", "event/add", data, ""); + dialog.close(); + } +} + function sendLog(json) { ajax("POST", "log", json, "log"); } diff --git a/templates/user.html b/templates/user.html index 95ee95e..4b31077 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,4 +1,10 @@ {% if name %} + + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/bootstrap/dist/css/bootstrap.min.css', _external=True, stamp=stamp) }}"> + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css', _external=True, stamp=stamp) }}"> + + <img src="{{ url_for('calender_icon', _external=True, stamp=stamp) }}" width="100" height="100" onclick="show_calendar()" align="left"> + <form style="position: absolute; right: 15%; width: 15%; height: 15%;"> <button type="button" id="logout_button" onclick="logout()" style="width: 100%; height: 100%;">logout</button> </form> @@ -28,7 +34,7 @@ <input id="username" type="text" name="name"> <input type="button" value="rename" onclick="renameUser()"> </form> - </p + </p> {% else %} Use your card/token to log in... {% endif %} -- 2.11.0

On Wed, Sep 05 2018, Tomas Prochazka wrote:
A replaced of paper calendar with operations related to the maintenance of a coffee shop --- .gitmodules | 15 ++++++ app.py | 51 +++++++++++++++++- coffee_db.py | 22 ++++++++ coffee_db.sql | 18 +++++++ templates/bower_components/bootstrap | 1 + templates/bower_components/bootstrap3-dialog | 1 + templates/bower_components/fullcalendar | 1 + templates/bower_components/jquery | 1 + templates/bower_components/moment | 1 + templates/calendar.html | 80 ++++++++++++++++++++++++++++ templates/calendar.svg | 51 ++++++++++++++++++ templates/events/box.svg | 68 +++++++++++++++++++++++ templates/events/machine.svg | 67 +++++++++++++++++++++++ templates/events/milk.svg | 68 +++++++++++++++++++++++ templates/events/milk_container.svg | 47 ++++++++++++++++ templates/main.js | 22 ++++++++ templates/user.html | 8 ++- 17 files changed, 519 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 templates/bower_components/bootstrap create mode 160000 templates/bower_components/bootstrap3-dialog create mode 160000 templates/bower_components/fullcalendar create mode 160000 templates/bower_components/jquery create mode 160000 templates/bower_components/moment create mode 100644 templates/calendar.html create mode 100644 templates/calendar.svg create mode 100644 templates/events/box.svg create mode 100644 templates/events/machine.svg create mode 100644 templates/events/milk.svg create mode 100644 templates/events/milk_container.svg
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3175491 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "templates/bower_components/jquery"] + path = templates/bower_components/jquery + url = https://github.com/jquery/jquery-dist.git +[submodule "templates/bower_components/bootstrap"] + path = templates/bower_components/bootstrap + url = https://github.com/twbs/bootstrap.git +[submodule "templates/bower_components/bootstrap3-dialog"] + path = templates/bower_components/bootstrap3-dialog + url = https://github.com/nakupanda/bootstrap3-dialog.git +[submodule "templates/bower_components/moment"] + path = templates/bower_components/moment + url = https://github.com/moment/moment +[submodule "templates/bower_components/fullcalendar"] + path = templates/bower_components/fullcalendar + url = https://github.com/fullcalendar/fullcalendar diff --git a/app.py b/app.py index 5481624..05a1994 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, send_file, request, session, redirect, url_for, make_response +from flask import Flask, render_template, send_file, request, session, redirect, url_for, make_response, jsonify from flask_cors import CORS
import numpy as np @@ -13,7 +13,7 @@ import time from datetime import date, timedelta
db.init_db() -app = Flask(__name__) +app = Flask(__name__, static_url_path="", static_folder="templates") CORS(app, supports_credentials=True) app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@@ -163,6 +163,53 @@ def js(): response.headers['Content-Type'] = "text/javascript" return response
+@app.route('/jquery.min.js') +def jquery_min_js():
Je potřeba tam přidávat funkci pro každý soubor zvlášť? Očekával bych, že to stačí nasypat do nějakého adresáře a nastavit tab static_url_path (nebo něco takového). Tady je k tomu asi dokumentace: http://flask.pocoo.org/docs/1.0/tutorial/static/ -M.
+ response = make_response(render_template("bower_components/jquery/dist/jquery.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route('/bootstrap.min.js') +def bootstrap_min_js(): + response = make_response(render_template("bower_components/bootstrap/dist/js/bootstrap.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route('/bootstrap-dialog.min.js') +def bootstrap_dialog_min_js(): + response = make_response(render_template("bower_components/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js")) + response.headers['Content-Type'] = "text/javascript" + return response + +@app.route("/events/<image>") +def event_icon(image): + print(image) + svg = open('templates/events/'+image).read() + response = make_response(svg) + response.content_type = 'image/svg+xml' + return response + +@app.route("/event/add", methods=["POST"]) +def event_add(): + if request.method == "POST": + json = request.json + db.add_event(json["time"], json["event"], json["uid"]) + return redirect(url_for('user')) + +@app.route("/event_list") +def event_list(): + return jsonify(db.list_event()) + +@app.route("/calendar.svg") +def calender_icon(): + svg = open('templates/calendar.svg').read() + response = make_response(svg) + response.content_type = 'image/svg+xml' + return response + +@app.route('/calendar') +def calendar(): + return render_template('calendar.html',events=db.events())
@app.route("/log", methods=["POST"]) def log(): diff --git a/coffee_db.py b/coffee_db.py index 0abb5a4..03bc15e 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -54,6 +54,28 @@ def add_coffee(uid, flavor, time=None): c.execute("insert into coffees (id, flavor, time) values (?,?,?)", (uid, flavor, time)) close_db(conn)
+def add_event(time, title, uid): + conn, c = open_db() + c.execute("insert into events (time,title,id) values (?,?,?)", (time,title,uid)) + close_db(conn) + +def list_event(): + conn, c = open_db() + result=c.execute("select e.time, e.title, l.image from events e left join (select * from list_events) l on e.title=l.title") + items=[] + for row in result: + items.append({'start': row[0], 'color': '#FFFFFF', 'imageurl':row[2]}) + close_db(conn) + return items + +def events(): #various events that can be created + conn, c = open_db() + result=c.execute("select title, image from list_events") + items=[] + for row in result: + items.append({'title': row[0],'image': row[1]}) + close_db(conn) + return items
def list_coffees(uid=None): c = conn.cursor() diff --git a/coffee_db.sql b/coffee_db.sql index d9f7d8e..63367d8 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -28,6 +28,24 @@ create table if not exists days ( num integer primary key not null );
+create table if not exists events ( + time datetime, + title varchar(255), + id varchar(24) references users(id) +); + +create table if not exists list_events ( + title varchar(255) primary key not null, + image varchar(255) +); + +insert or ignore into list_events values + ("Milk container cleaned", "milk_container.svg"), + ("Coffee machine cleaned", "machine.svg"), + ("Milk washed wipill","milk.svg"), + ("New coffee opened","box.svg") +; + insert or ignore into days values (0),(1),(2),(3),(4),(5),(6) ; diff --git a/templates/bower_components/bootstrap b/templates/bower_components/bootstrap new file mode 160000 index 0000000..0b9c4a4 --- /dev/null +++ b/templates/bower_components/bootstrap @@ -0,0 +1 @@ +Subproject commit 0b9c4a4007c44201dce9a6cc1a38407005c26c86 diff --git a/templates/bower_components/bootstrap3-dialog b/templates/bower_components/bootstrap3-dialog new file mode 160000 index 0000000..5304d56 --- /dev/null +++ b/templates/bower_components/bootstrap3-dialog @@ -0,0 +1 @@ +Subproject commit 5304d56cd33da77b8c8e6e250e8f39211d191a0e diff --git a/templates/bower_components/fullcalendar b/templates/bower_components/fullcalendar new file mode 160000 index 0000000..3ddb3c8 --- /dev/null +++ b/templates/bower_components/fullcalendar @@ -0,0 +1 @@ +Subproject commit 3ddb3c8d1461c6b841aed3487ba07d8ba338adb6 diff --git a/templates/bower_components/jquery b/templates/bower_components/jquery new file mode 160000 index 0000000..9e8ec3d --- /dev/null +++ b/templates/bower_components/jquery @@ -0,0 +1 @@ +Subproject commit 9e8ec3d10fad04748176144f108d7355662ae75e diff --git a/templates/bower_components/moment b/templates/bower_components/moment new file mode 160000 index 0000000..db71a65 --- /dev/null +++ b/templates/bower_components/moment @@ -0,0 +1 @@ +Subproject commit db71a655fc51fe58009675608a400d0d4cd0ca87 diff --git a/templates/calendar.html b/templates/calendar.html new file mode 100644 index 0000000..6951163 --- /dev/null +++ b/templates/calendar.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> + +<head> + <meta charset='utf-8' /> + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/fullcalendar/dist/fullcalendar.min.css', _external=True, stamp=stamp) }}"> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/moment/min/moment.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/jquery/dist/jquery.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript src="{{ url_for('static', filename='bower_components/fullcalendar/dist/fullcalendar.min.js', _external=True, stamp=stamp) }}"></script> + <script type=text/javascript> + var calendar; + $(document).ready(function() { + calendar = $('#calendar').fullCalendar({ + header: { + left: 'prev,next today', + center: 'title', + right: '' + }, + selectable: true, + selectHelper: true, + selectConstraint: { + start: '00:00', + end: '24:00' + }, + events: { + url: "{{ url_for('event_list', _external=True, stamp=stamp) }}" + }, + eventRender: function(event, eventElement) { + if (event.imageurl) { + var variable1 = event.imageurl; + eventElement.find(".fc-title").html("<center> <img src={{ url_for('event_icon', image='var1', _external=True, stamp=stamp) }} width='20' height='20' /> </center>".replace("var1", variable1)); + } + } + }); + }); + </script> + <style> + body { + margin: 20px 10px; + padding: 0; + font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif; + font-size: 14px; + } + #calendar { + max-width: 800px; + margin: 0 auto; + } + fieldset { + font-size: 15px; + padding: 10px; + width: 450px; + margin: 0 auto; + text-align: center; + line-height: 1.8; + } + </style> + +</head> + +<body> + <center> + <h2> <b>Coffee machine cleaning </b></h2> + <h3> Write the operation performed by pressing the button in this dialog window in the lower part.</h3> + <form> + <b>Operations: </b> + {% for event in events %} + <img style="vertical-align:middle" src="{{ url_for('event_icon', image=event.image, _external=True, stamp=stamp )}}" width="40" height="40"> + <span style="">{{ event.title }}</span> + {% endfor %} + </form> + <div id='calendar'></div> + <form> + {% for event in events %} + <input type="button" value="{{ event.title }}" onclick="addEvent(this.value)"> + {% endfor %} + </form> + </center> +</body> + +</html> diff --git a/templates/calendar.svg b/templates/calendar.svg new file mode 100644 index 0000000..4d781eb --- /dev/null +++ b/templates/calendar.svg @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 64 64" style="enable-background:new 0 0 64 64;" xml:space="preserve"> +<style type="text/css"> + .st0{fill:#77B3D4;} + .st1{opacity:0.2;} + .st2{fill:#231F20;} + .st3{fill:#FFFFFF;} + .st4{fill:#C75C5C;} + .st5{fill:#4F5D73;} + .st6{fill:#E0E0D1;} +</style> +<g id="Layer_1"> + <g> + <circle class="st0" cx="32" cy="32" r="32"/> + </g> + <g> + <g class="st1"> + <path class="st2" d="M12,25v25c0,2.2,1.8,4,4,4h32c2.2,0,4-1.8,4-4V25H12z"/> + </g> + <g> + <path class="st3" d="M12,23v25c0,2.2,1.8,4,4,4h32c2.2,0,4-1.8,4-4V23H12z"/> + </g> + <g class="st1"> + <path class="st2" d="M48,14H16c-2.2,0-4,1.8-4,4v7h40v-7C52,15.8,50.2,14,48,14z"/> + </g> + <g> + <path class="st4" d="M48,12H16c-2.2,0-4,1.8-4,4v7h40v-7C52,13.8,50.2,12,48,12z"/> + </g> + <g> + <path class="st5" d="M32,48c-1.1,0-2-0.9-2-2c0-5.5,1.8-9.5,3.5-12H27c-1.1,0-2-0.9-2-2s0.9-2,2-2h11c0.9,0,1.6,0.6,1.9,1.4 + s0,1.7-0.7,2.2C39,33.8,34,37.5,34,46C34,47.1,33.1,48,32,48z"/> + </g> + <g class="st1"> + <path class="st2" d="M20,21c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C22,20.1,21.1,21,20,21L20,21z"/> + </g> + <g class="st1"> + <path class="st2" d="M45,21c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C47,20.1,46.1,21,45,21L45,21z"/> + </g> + <g> + <path class="st6" d="M20,19c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C22,18.1,21.1,19,20,19L20,19z"/> + </g> + <g> + <path class="st6" d="M45,19c-1.1,0-2-0.9-2-2v-7c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v7C47,18.1,46.1,19,45,19L45,19z"/> + </g> + </g> +</g> +<g id="Layer_2"> +</g> +</svg> diff --git a/templates/events/box.svg b/templates/events/box.svg new file mode 100644 index 0000000..2bcbbf1 --- /dev/null +++ b/templates/events/box.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="box.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="-44.841946" + inkscape:cy="65.020819" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#c49347;fill-opacity:1;stroke:none;stroke-width:0.26458332;" + x="7.6817751" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="7.6817751" + y="25.313768" + style="font-size:22.57777786px;fill:#c49347;fill-opacity:1;stroke-width:0.26458332;">N</tspan></text> + <rect + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#c49347;stroke-width:2.39791874;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4505" + width="32.602345" + height="32.602345" + x="1.1988993" + y="1.198831" /> +</svg> diff --git a/templates/events/machine.svg b/templates/events/machine.svg new file mode 100644 index 0000000..2d2e606 --- /dev/null +++ b/templates/events/machine.svg @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="machine.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="-47.084043" + inkscape:cy="66.141869" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#47c779;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="8.9252768" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="8.9252768" + y="25.313768" + style="font-size:22.57777786px;fill:#47c779;fill-opacity:1;stroke-width:0.26458332">C</tspan></text> + <circle + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#47c779;stroke-width:2.04399991;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="path4489" + cx="17.500038" + cy="17.500036" + r="16.478037" /> +</svg> diff --git a/templates/events/milk.svg b/templates/events/milk.svg new file mode 100644 index 0000000..eb7c51e --- /dev/null +++ b/templates/events/milk.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm" + sodipodi:docname="milk.svg" + inkscape:version="0.92.1 r15371"> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1016" + id="namedview9" + showgrid="false" + inkscape:zoom="1.7840439" + inkscape:cx="67.262918" + inkscape:cy="66.141869" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg8" /> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000c8;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="7.6817751" + y="25.313768" + id="text4487"><tspan + id="tspan4485" + x="7.6817751" + y="25.313768" + style="font-size:22.57777786px;fill:#0000c8;fill-opacity:1;stroke-width:0.26458332">M</tspan></text> + <rect + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#0000c8;stroke-width:2.39779854;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4505" + width="32.602345" + height="32.602345" + x="1.1988993" + y="1.198831" /> +</svg> diff --git a/templates/events/milk_container.svg b/templates/events/milk_container.svg new file mode 100644 index 0000000..b31f75e --- /dev/null +++ b/templates/events/milk_container.svg @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + id="svg8" + version="1.1" + viewBox="0 0 35.000072 35.000072" + height="35.000072mm" + width="35.000072mm"> + <defs + id="defs2" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + transform="translate(-23.989663,-42.769872)" + id="layer1"> + <text + id="text4487" + y="68.083641" + x="31.671438" + style="font-style:normal;font-weight:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332" + xml:space="preserve"><tspan + style="font-size:22.57777786px;fill:#ff0000;stroke-width:0.26458332" + y="68.083641" + x="31.671438" + id="tspan4485">M</tspan></text> + <circle + r="16.478037" + cy="60.269909" + cx="41.4897" + id="path4489" + style="opacity:0.98999999;fill:none;fill-opacity:1;stroke:#ff0000;stroke-width:2.04399991;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </g> +</svg> diff --git a/templates/main.js b/templates/main.js index 8135983..c3ea61e 100644 --- a/templates/main.js +++ b/templates/main.js @@ -7,6 +7,7 @@ var timeToLogout = undefined; // defined during logout countdown var logoutTimer; var reloadTimer = undefined; var id_user; // ID of the user who is to be accounted for the next coffee +var dialog;
console.log("hello from flask"); //sendJSON("{\"type\":\"empty\"}"); @@ -155,8 +156,17 @@ function login(id) { countingTimeLogout(120); }
+function show_calendar(){ + var url="{{ url_for('calendar', _external=True, stamp=stamp) }}"; + dialog=BootstrapDialog.show({ + title: 'Calendar', + message: $('<div></div>').load(url) + }); +} + function logout() { sendReset(); + dialog.close(); ajax("GET", "logout", "", "user"); id_user = undefined; timeToLogout = undefined; @@ -202,6 +212,18 @@ function addCoffee(flavor, time = new Date()) { } }
+function addEvent(event, time = new Date()) { + var data = JSON.stringify({ + time: time.toISOString().split("T")[0], + event: event, + uid: id_user + }); + if (id_user) { + ajax("POST", "event/add", data, ""); + dialog.close(); + } +} + function sendLog(json) { ajax("POST", "log", json, "log"); } diff --git a/templates/user.html b/templates/user.html index 95ee95e..4b31077 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,4 +1,10 @@ {% if name %} + + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/bootstrap/dist/css/bootstrap.min.css', _external=True, stamp=stamp) }}"> + <link rel="stylesheet" href="{{ url_for('static', filename='bower_components/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css', _external=True, stamp=stamp) }}"> + + <img src="{{ url_for('calender_icon', _external=True, stamp=stamp) }}" width="100" height="100" onclick="show_calendar()" align="left"> + <form style="position: absolute; right: 15%; width: 15%; height: 15%;"> <button type="button" id="logout_button" onclick="logout()" style="width: 100%; height: 100%;">logout</button> </form> @@ -28,7 +34,7 @@ <input id="username" type="text" name="name"> <input type="button" value="rename" onclick="renameUser()"> </form> - </p + </p> {% else %} Use your card/token to log in... {% endif %} -- 2.11.0
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
participants (2)
-
Michal Sojka
-
Tomas Prochazka