diff --git a/app.py b/app.py index 998d086..8675c1c 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,11 @@ -from flask import Flask, render_template, request, jsonify, abort, redirect, url_for +from flask import * from flask_login import LoginManager , login_required , UserMixin , login_user, current_user, logout_user from forms import LoginForm from services import Services, UserManager from models import User import sqlite3 import re +import datetime #Setup app = Flask("Project Fish") @@ -35,6 +36,9 @@ def index(): @app.route("/GetServices", methods=['GET', 'POST']) def GetServices(): nummer = (request.json)["nummer"] + if(nummer == "-1"): + ser=services.GetAllServices() + return jsonify(render_template("results.html", services=ser),) if(not is_string_sanitized(nummer)): return abort(401) if(nummer != None and nummer != ""): @@ -72,5 +76,32 @@ def login(): else: return render_template("login.html") +@app.route("/AddService", methods=["POST"]) +@login_required +def AddService(): + datum = (request.json)["datum"] + tijd = (request.json)["tijd"] + van = (request.json)["van"] + tot = (request.json)["tot"] + try: + van = int(van) + tot = int(tot) + groepen = "" + if(van < tot): + for i in range(van, tot, 1): + groepen += str(i) + groepen += ":" + else: + return "Invalid groups" + groepen += str(tot) + 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" + def RunWeb(): - app.run(debug=True) \ No newline at end of file + app.run(debug=True) + \ No newline at end of file diff --git a/sqlite.db b/sqlite.db index 14c7bf6..b6f1ca2 100644 Binary files a/sqlite.db and b/sqlite.db differ diff --git a/static/script.js b/static/script.js index 2cf4f90..afe0fed 100644 --- a/static/script.js +++ b/static/script.js @@ -13,10 +13,49 @@ function GetServices(){ error: function(error){ console.log(error); } - // success: function(result) { - // console.log("aa"); - // console.log(results); - // - // } }); -} \ No newline at end of file +} + +function GetAllServices(){ + console.log("aa") + $.ajax({ + type: "POST", + url: "/GetServices", + data: JSON.stringify({ + "nummer": "-1", + }), + contentType: "application/json", + dataType: 'text json', + success: function(response) { + document.getElementById('resultblock').innerHTML = response + }, + error: function(error){ + console.log(error); + } + }); +} + +function AddService(){ + $.ajax({ + type: "POST", + url: "/AddService", + data: JSON.stringify({ + "datum": document.getElementById('datum_input').value, + "tijd": document.getElementById('tijd_input').value, + "van": document.getElementById('van_input').value, + "tot": document.getElementById('tot_input').value, + }), + contentType: "application/json", + dataType: 'text json', + success: function(response) { + document.getElementById('resultblock').innerHTML = response + }, + error: function(error){ + console.log(error); + } + }); +} + +$(document).ready( function () { + GetAllServices(); +}) \ No newline at end of file diff --git a/static/style.css b/static/style.css index 6c1f33e..dce5f66 100644 --- a/static/style.css +++ b/static/style.css @@ -58,10 +58,6 @@ margin-top: 0%; } -.resultitem{ - padding: .5%; -} - .klanten_logo:active{ /* -webkit-animation:spin 4s linear infinite; -moz-animation:spin 4s linear infinite; @@ -119,7 +115,7 @@ .resultitem{ margin: 1%; - padding: 1; + padding: 1%; text-align: center; } @@ -169,4 +165,31 @@ .add_service_btn:hover{ background-color: blue; cursor: pointer; +} + +.loginbutton{ + background-color: green; + font-size: 20px; + margin: 1%; + width: 10%; + text-align: center; + padding: 1%;; +} +.loginbutton:hover{ + background-color: lightgreen; + cursor: pointer; +} + +.deletebutton{ + position: absolute; + background-color: red; + right: 0; + font-size: medium; + padding: .5%; + margin-bottom: .5%; + right: 3%; +} +.deletebutton:hover{ + background-color: orangered; + cursor: pointer; } \ No newline at end of file diff --git a/templates/admin.html b/templates/admin.html index 47750df..7684a21 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -4,15 +4,17 @@

Administratie

+ - {% block content %}

Voeg dienst toe:

+ Tijd +
@@ -23,7 +25,7 @@
Toevoegen
-
+
{% endblock %} diff --git a/templates/login.html b/templates/login.html index 75ac2fc..5918710 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,9 +1,13 @@ {% extends "base.html" %} {% block content %} -
-

-

-

-

+
+
+

+

+ + +

+
+ {% endblock %} \ No newline at end of file diff --git a/templates/results.html b/templates/results.html index 3bbf90c..c92e531 100644 --- a/templates/results.html +++ b/templates/results.html @@ -2,13 +2,22 @@ {% for key, value in services.items() %} {% if(loop.index % 2 == 0) %}
- Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur. + {% 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 %}
- Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur. + {% if current_user.is_authenticated %} +
+ Verwijderen +
+ {% endif %} + Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}}:{{value[0].time().minute}} uur. +
{% endif %} - - {% endfor %} \ No newline at end of file