diff --git a/_sqlite.db b/_sqlite.db new file mode 100644 index 0000000..b6f1ca2 Binary files /dev/null and b/_sqlite.db differ diff --git a/app.py b/app.py index 8675c1c..0c85fbf 100644 --- a/app.py +++ b/app.py @@ -97,11 +97,24 @@ def AddService(): tijd = datetime.datetime.strptime(f"{datum}|{tijd}" , "%d-%m-%Y|%H:%M") if(tijd != None): services.AddService(tijd, str(groepen)) - except: return "500" return "200" +@app.route("/DelService", methods=["POST"]) +@login_required +def DelService(): + datum = (request.json)["datum"] + tijd = (request.json)["tijd"] + try: + tijd = datetime.datetime.strptime(f"{datum}|{tijd}" , "%Y-%m-%d|%H:%M:%S") + if(tijd != None): + services.RemoveService(tijd) + except: + return "Invalid date/time" + return "200" + + def RunWeb(): app.run(debug=True) \ No newline at end of file diff --git a/services.py b/services.py index 8ae9bc1..d0e485c 100644 --- a/services.py +++ b/services.py @@ -44,7 +44,7 @@ class Services: query = f"""CREATE TABLE IF NOT EXISTS services ( id INTEGER PRIMARY KEY AUTOINCREMENT, - date STRING, + date STRING UNIQUE, groups STRING ); """ @@ -55,6 +55,18 @@ class Services: INSERT INTO services (date, groups) VALUES('{date}', '{groups}'); """ + try: + self.cursor.execute(query) + self.db.commit() + return "Success" + except: + return "Service already exists?" + + def RemoveService(self, service): + query = f""" + DELETE FROM services + WHERE date == '{service}' + """ self.cursor.execute(query) self.db.commit() @@ -71,7 +83,7 @@ class UserManager(): query = f"""CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, - name STRING, + name STRING UNIQUE, password STRING, salt STRING ); @@ -114,7 +126,7 @@ if __name__ == "__main__": ser = Services(db) us = UserManager(db) - # us.AddUser("Eljakim", "Kunnenwe?") + us.AddUser("Eljakim", "Kunnenwe?") us.Authenticate("Eljakim", "Kunnenwe?") us.Authenticate("Eljakim", "Kunnenwe2?") # for i in range(100): diff --git a/sqlite.db b/sqlite.db index b6f1ca2..9caeaeb 100644 Binary files a/sqlite.db and b/sqlite.db differ diff --git a/static/script.js b/static/script.js index afe0fed..eb24968 100644 --- a/static/script.js +++ b/static/script.js @@ -17,7 +17,6 @@ function GetServices(){ } function GetAllServices(){ - console.log("aa") $.ajax({ type: "POST", url: "/GetServices", @@ -56,6 +55,23 @@ function AddService(){ }); } -$(document).ready( function () { - GetAllServices(); -}) \ No newline at end of file +function DeleteService(date){ + d = $(date).parent()[0].getAttribute("data"); + $.ajax({ + type: "POST", + url: "/DelService", + data: JSON.stringify({ + "datum": d.split(" ")[0], + "tijd": d.split(" ")[1], + }), + contentType: "application/json", + dataType: 'text json', + success: function(response) { + document.getElementById('resultblock').innerHTML = response + }, + error: function(error){ + console.log(error); + } + }); +} + diff --git a/static/style.css b/static/style.css index dce5f66..a119553 100644 --- a/static/style.css +++ b/static/style.css @@ -1,6 +1,6 @@ .headerblock{ width: 100%; - height: 5%; + /* height: 5%; */ /* background-color: #FFFFFF; */ } @@ -133,35 +133,53 @@ } .a_datum_input{ - padding: 1%; + background-color:white; position: relative; - margin:1%; -} -.a_datum_block{ - width: 100%; + padding: 2%; + margin: 1%; + width: 39.5%; + left: 10%; + font-size: 20px; + text-align: center; + font-size: 26px; } .a_van_input{ - padding: 1%; - margin:1%; -} - -.a_tot_input{ - padding: 1%; - margin:1%; -} - -.add_service_btn{ + background-color:white; position: relative; - background-color: lightblue; padding: 2%; margin: 1%; - width: 20%; - left: 20%; + width: 39.5%; + left: 10%; + font-size: 20px; text-align: center; font-size: 26px; } +/* .a_tot_input{ + background-color:white; + position: relative; + padding: 2%; + margin: 1%; + width: 39.5%; + left: 14%; + font-size: 20px; + text-align: center; + font-size: 26px; +} */ + +.add_service_btn{ +position: relative; + background-color: rgb(35, 34, 126); + padding: 2%; + margin: 1%; + width: 40%; + left: 30%; + text-align: center; + font-size: 26px; + color: white; +} + .add_service_btn:hover{ background-color: blue; cursor: pointer; diff --git a/templates/admin.html b/templates/admin.html index 7684a21..23b9253 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -1,28 +1,54 @@ + + + {% extends 'base.html' %} +
-

Administratie

- + Administratie - {% block content %}
-

Voeg dienst toe:

-
- - Tijd - -
-
- - t/m - -
+
+

Voeg dienst toe

+

Vul de datum en groepen in om toe te voegen

-
Toevoegen
+ +
+ + Tijd + +
+
+ + t/m + +
+ +
Toevoegen
+
diff --git a/templates/base.html b/templates/base.html index dc06b04..215fcf8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,6 +6,7 @@ +
diff --git a/templates/index.html b/templates/index.html index 31db5bf..f106007 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,6 @@
-

Mag ik naar de kapel?

diff --git a/templates/results.html b/templates/results.html index c92e531..b089837 100644 --- a/templates/results.html +++ b/templates/results.html @@ -3,16 +3,16 @@ {% if(loop.index % 2 == 0) %}
{% if current_user.is_authenticated %} -
+
Verwijderen
{% endif %} Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}}:{{value[0].time().minute}} uur.
{% else %} -
+
{% if current_user.is_authenticated %} -
+
Verwijderen
{% endif %}