From 6ab1a052713d9ab252a7a4cf5c36030e7c5bb288 Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Mon, 8 Nov 2021 23:28:40 +0100 Subject: [PATCH] Loggin works, as well as adding services --- app.py | 35 ++++++++++++++++++++++++++-- sqlite.db | Bin 24576 -> 24576 bytes static/script.js | 51 ++++++++++++++++++++++++++++++++++++----- static/style.css | 33 ++++++++++++++++++++++---- templates/admin.html | 6 +++-- templates/login.html | 14 +++++++---- templates/results.html | 17 ++++++++++---- 7 files changed, 132 insertions(+), 24 deletions(-) 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 14c7bf65ad408f514ea5fafabb560ecd1e40bc1c..b6f1ca21a1db4bf7a3af6376a8b5bd9f6bc22b34 100644 GIT binary patch delta 266 zcmZoTz}Rqrae_2s@kAMC#^Q|$^Ys}sHW{!8Fw1iBO=fp6=HOb*Rm^40#kaBX3}?M| z1`C6+sgZ$^p{}8!u7RO~fu)tPft7)Qp_P%9v6YFHsg;?Pxs`>LrIn$9SvpX$Hx|Xw zhB^vHIts=*3MM)VraB5{Itu1G3KlvFmO2WC2C-&oxb%e)(3px#BYu6GAA8A)0s#ER BI2`~0 delta 42 ycmZoTz}Rqrae_2s{zMsP#{7*5^Ys~1HW{!8FiUbhp3LrGys>d5*XGAwvZ4Spwhl!A 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