From f50555dee49a4b1db8611b211205ca180d1645b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20Kr=C3=A4mer?= <dominicdaniel3107@gmail.com> Date: Fri, 21 Jun 2024 02:04:24 +0200 Subject: [PATCH] implement feedback feature --- app/app.py | 17 +++++++++++++++++ app/static/css/index.css | 2 +- app/static/javascript/frontend.js | 31 +++++++++++++++++++++++++++++++ app/templates/index.html | 8 +++++++- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/app.py b/app/app.py index c9cf6a5..e8ba072 100644 --- a/app/app.py +++ b/app/app.py @@ -5,6 +5,7 @@ from flask import jsonify import requests app = Flask(__name__) +feedback_file = "../data/feedback.txt" @app.route('/') def home(): @@ -32,5 +33,21 @@ def sendmessage(): return jsonify(responses) +@app.route('/feedback', methods=['POST']) +def feedback(): + timestamp = request.form['timestamp'] + name = request.form['name'] + feedback = request.form['feedback'] + + input = [ + 'timestamp:' + str(timestamp) + '\n', + 'name:' + str(name) + '\n', + 'feedback:' + str(feedback) + '\n\n' + ] + with open(feedback_file, 'a') as file: + file.writelines(input) + + return "feedback received" + if __name__ == '__main__': app.run(debug=True) diff --git a/app/static/css/index.css b/app/static/css/index.css index 22a1176..fd97cae 100644 --- a/app/static/css/index.css +++ b/app/static/css/index.css @@ -96,7 +96,7 @@ button { top: 0; right: 0; position: fixed; - padding-right: 150px; + padding-right: 50px; width: 500px; padding-top: 50px; } diff --git a/app/static/javascript/frontend.js b/app/static/javascript/frontend.js index 4e38dea..35d385e 100644 --- a/app/static/javascript/frontend.js +++ b/app/static/javascript/frontend.js @@ -49,6 +49,37 @@ function sendMessage() { } }; +function expandFeedback() { + let feedback = document.getElementById('feedback-expandable'); + if(feedback.style.display === "none") + feedback.style.display = "block" + else + feedback.style.display = "none" +} + +function saveFeedback() { + const name = document.getElementById("feedback-name").value; + const feedback = document.getElementById("feedback-content").value; + if(name!=="" && feedback!=="") { + document.getElementById("feedback-name").value = ""; + document.getElementById("feedback-content").value = ""; + } + const timestamp = new Date().toISOString(); + + const message = new URLSearchParams; + message.append("timestamp", timestamp); + message.append("name", name); + message.append("feedback", feedback); + + fetch("http://localhost:5000/feedback", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: message.toString() + }); +} + function checkKeyInput(event) { if(event.key === 'Enter') sendMessage(); diff --git a/app/templates/index.html b/app/templates/index.html index 8b44fe1..cbf829e 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -28,7 +28,13 @@ </div> <div class="feedback"> - <button>Feedback</button> + <button style="margin-right: 25%;" onclick="expandFeedback()">Feedback</button> + <br><br><br><br> + <div id="feedback-expandable" style="display: none;"> + <input id="feedback-name" type="text" placeholder="Your name" style="float:right"> + <input id="feedback-content" type="text" placeholder="Your feedback" style="float:right"> + <button style="float:right; margin-top: 10px; width: 74%;" onclick="saveFeedback()">Submit</button> + </div> </div> <script src="static/javascript/frontend.js" type="application/javascript"></script> -- GitLab