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

Tomas Prochazka tomas.prochazka at cvut.cz
Thu Sep 6 01:07:58 CEST 2018


A replaced of paper calendar with operations related to the maintenance of a coffee shop
---
 .gitmodules                               | 15 ++++++
 app.py                                    | 41 +++++++++++++++-
 coffee_db.py                              | 22 +++++++++
 coffee_db.sql                             | 18 ++++++++
 static/bower_components/bootstrap         |  1 +
 static/bower_components/bootstrap3-dialog |  1 +
 static/bower_components/fullcalendar      |  1 +
 static/bower_components/jquery            |  1 +
 static/bower_components/moment            |  1 +
 templates/calendar.html                   | 77 +++++++++++++++++++++++++++++++
 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                         | 27 +++++++++++
 templates/user.html                       |  8 +++-
 17 files changed, 512 insertions(+), 2 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 static/bower_components/bootstrap
 create mode 160000 static/bower_components/bootstrap3-dialog
 create mode 160000 static/bower_components/fullcalendar
 create mode 160000 static/bower_components/jquery
 create mode 160000 static/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..5d289cc
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,15 @@
+[submodule "static/bower_components/jquery"]
+	path = static/bower_components/jquery
+	url = https://github.com/jquery/jquery-dist.git
+[submodule "static/bower_components/bootstrap"]
+	path = static/bower_components/bootstrap
+	url = https://github.com/twbs/bootstrap.git
+[submodule "static/bower_components/bootstrap3-dialog"]
+	path = static/bower_components/bootstrap3-dialog
+	url = https://github.com/nakupanda/bootstrap3-dialog.git
+[submodule "static/bower_components/moment"]
+	path = static/bower_components/moment
+	url = https://github.com/moment/moment
+[submodule "static/bower_components/fullcalendar"]
+	path = static/bower_components/fullcalendar
+	url = https://github.com/fullcalendar/fullcalendar
diff --git a/app.py b/app.py
index 807f614..76f4963 100644
--- a/app.py
+++ b/app.py
@@ -1,6 +1,9 @@
-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, abort, send_from_directory
 from flask_cors import CORS
 
+import os
+import os.path
+
 import numpy as np
 import matplotlib
 matplotlib.use('Agg')
@@ -163,6 +166,42 @@ def js():
     response.headers['Content-Type'] = "text/javascript"
     return response
 
+ at 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
+    
+ at 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'))
+
+ at app.route("/event_list")
+def event_list():
+    return jsonify(db.list_event())
+
+ at 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
+
+ at app.route('/calendar')
+def calendar():
+    return render_template('calendar.html',events=db.events())
+
+ at app.route('/bower_components/<path:filename>')
+def download_file(filename):
+    if os.path.exists('static/bower_components/' + filename):
+        return send_from_directory('static/bower_components/', filename, as_attachment=True)
+    else:
+        abort(404)
 
 @app.route("/log", methods=["POST"])
 def log():
diff --git a/coffee_db.py b/coffee_db.py
index 8c18e63..ce0d1b5 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/static/bower_components/bootstrap b/static/bower_components/bootstrap
new file mode 160000
index 0000000..0b9c4a4
--- /dev/null
+++ b/static/bower_components/bootstrap
@@ -0,0 +1 @@
+Subproject commit 0b9c4a4007c44201dce9a6cc1a38407005c26c86
diff --git a/static/bower_components/bootstrap3-dialog b/static/bower_components/bootstrap3-dialog
new file mode 160000
index 0000000..5304d56
--- /dev/null
+++ b/static/bower_components/bootstrap3-dialog
@@ -0,0 +1 @@
+Subproject commit 5304d56cd33da77b8c8e6e250e8f39211d191a0e
diff --git a/static/bower_components/fullcalendar b/static/bower_components/fullcalendar
new file mode 160000
index 0000000..3ddb3c8
--- /dev/null
+++ b/static/bower_components/fullcalendar
@@ -0,0 +1 @@
+Subproject commit 3ddb3c8d1461c6b841aed3487ba07d8ba338adb6
diff --git a/static/bower_components/jquery b/static/bower_components/jquery
new file mode 160000
index 0000000..9e8ec3d
--- /dev/null
+++ b/static/bower_components/jquery
@@ -0,0 +1 @@
+Subproject commit 9e8ec3d10fad04748176144f108d7355662ae75e
diff --git a/static/bower_components/moment b/static/bower_components/moment
new file mode 160000
index 0000000..0e67426
--- /dev/null
+++ b/static/bower_components/moment
@@ -0,0 +1 @@
+Subproject commit 0e67426b8e8d200a3ca7dab046040717110e87e6
diff --git a/templates/calendar.html b/templates/calendar.html
new file mode 100644
index 0000000..d192fd4
--- /dev/null
+++ b/templates/calendar.html
@@ -0,0 +1,77 @@
+<!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>
+        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 %}
+            <button type="button" onclick="addEvent(this.value)" value="{{ event.title }}"> <img style="vertical-align:middle" src="{{ url_for('event_icon', image=event.image, _external=True, stamp=stamp )}}" width="30" height="30"> </button>
+            {% 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..fd16b87 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,23 @@ 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();
+        dialog=BootstrapDialog.show({
+            title: 'Information',
+            message: 'Event('+event+') add to calendar (this dialog will automatically close in 5 seconds)'
+        });
+        setTimeout(function(){ dialog.close(); }, 5000);
+    }
+}
+
 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




More information about the Coffee mailing list