diff --git a/slaeforms/app.py b/slaeforms/app.py index e92ecf1..d445af4 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -53,6 +53,7 @@ class User(db.Model): device_id = db.Column("device_id",db.UUID(as_uuid=True), nullable=False) question_order = db.Column("question_order",db.String(60)) date_created = db.Column("date_created",db.DateTime, default=datetime.today()) # todo test if this default works + form_completed = db.Column("form_completed",db.Boolean, default=False) def __repr__(self) -> str: return "" % self.user_id @@ -131,7 +132,7 @@ except SQLAlchemyError as e: #------------------------------------------------------------------------------ #actual page logic with start, form and send -@app.route("/popuptest", methods=["GET"]) +#@app.route("/popuptest", methods=["GET"]) def popuptest(): return render_template( @@ -147,6 +148,7 @@ def startpage(): new_device_id = uuid.uuid4() session["slaeform_device_id"] = new_device_id session["agreed_to_tos"] = False + if request.method == "POST": @@ -213,11 +215,12 @@ def startpage(): user_id = new_user_id question_order = str(session["block_order"]) date = datetime.today() - new_user = User(user_id=user_id, device_id=device_id,question_order=question_order,date_created = date) #,question_order=question_order + new_user = User(user_id=user_id, device_id=device_id,question_order=question_order,date_created = date,form_completed=False) #,question_order=question_order db.session.add(new_user) db.session.commit() + print("block order: {order}".format(order=session["block_order"])) try: db.session.add(new_user) @@ -231,6 +234,11 @@ def startpage(): "teststartpage.html" ) +@app.route("/endpage") +def endpage(): + print("Form is done, sent to endpage") + return render_template("endpage.html") + @app.route("/form") def form(): @@ -248,10 +256,14 @@ def form(): #print("current Blockname: {blockname}, current block index: {blockindex}, current stim index: {stimulusindex}".format(blockname=session["current_block_name"], # blockindex=session["current_block_index"], # stimulusindex=session["current_stimulus_index"] ) ) + infovideo = None + if "infovideo" in current_block: + infovideo = current_block["infovideo"] # erster Fall: SinglePage if current_block["type"] == "SinglePage": return render_template(current_block["template"]) + #zweiter Fall, empty TaskTemplate if current_block["type"] == "TaskTemplate" and current_block["stimuli"]["type"] == "empty": @@ -264,7 +276,8 @@ def form(): stimuli=current_block_stimuli, stimulus_type=stimulus_type, current_stimulus=current_stimulus, - questions=current_block["questions"] + questions=current_block["questions"], + infovideo=infovideo ) @@ -293,7 +306,8 @@ def form(): stimulus_type=stimulus_type, current_stimulus=current_stimulus, stimulus_configuration=stimulus_configuration, - questions=current_block["questions"] + questions=current_block["questions"], + infovideo=infovideo ) @@ -369,23 +383,39 @@ def sendpage(): os.makedirs(UPLOAD_FOLDER, exist_ok=True) video.save(path) - + if (session["current_block_index"] == session["number_of_blocks"]-1) and (session["current_stimulus_index"] >= session["number_of_stimuli"]-1): + #update the database entry, the form is completed + user = db.session.query(User).filter_by(user_id=session["slaeform_user_id"]).one() + user.form_completed = True + print("updated db entry for form_completed") + # This user is done, so we can remove it from the session + session.pop("slaeform_user_id") + try: + db.session.commit() + except Exception as e: + print("Error occurred: {e}".format(e=str(e))) + return "There was a problem while updating the user" + return redirect("/endpage") + # Now move to the next stimulus or block update_session() print("now redirect and reload the page") return redirect("/form") def update_session(): + print("update session") if "stimuli" in config[session["current_block_name"]]: # if there are stimuli in this block if session["current_stimulus_index"] < session["number_of_stimuli"]-1: - + print("there are still stimuli left") # if there are still stimuli left, keep going through them session["current_stimulus_index"] += 1 # set the name of the current stimulus session["current_stimulus_name"] = session["block_order"][session["current_block_name"]][session["current_stimulus_index"]] else: + print("here are no stimuli left") + session["number_of_stimuli"] = 0 # if there are no stimuli left.. if(session["current_block_index"] < session["number_of_blocks"]-1): # go to next block if possible @@ -406,15 +436,27 @@ def update_session(): if "stimuli" in config[session["current_block_name"]]: # set the name of the current stimulus session["current_stimulus_name"] = session["block_order"][session["current_block_name"]][session["current_stimulus_index"]] - - if (session["current_block_index"] == session["number_of_blocks"]-1) and (session["current_stimulus_index"] >= session["number_of_stimuli"]-1): - session.pop("slaeform_user_id") - print("---Session updated---") + + print("---Session updated-----------------------------------------------") print("current_block_index / number_of_blocks: {current_block_index} / {number_of_blocks}".format(current_block_index=session["current_block_index"],number_of_blocks=session["number_of_blocks"])) print("current_block_name: ", session["current_block_name"]) print("current_stimulus_index: ", session["current_stimulus_index"]) print("Current number_of_stimuli: ", session["number_of_stimuli"]) +#@app.route("/update") +def update(): + + print("Current Session: ",session) + try: + user = db.session.query(User).filter_by(user_id=session["slaeform_user_id"]).one() + user.form_completed = True + db.session.commit() + except Exception as e: + print("Error occurred: {e}".format(e=str(e))) + return "There was a problem while updating the user" + + return "db entry updated!" + # Database stuff------------------------------------------------------------------------------ @@ -494,19 +536,6 @@ def table_contents(): tables = meta.tables.keys() table_contents = {} - #Testing querys for exporting etc - print("tables: ",tables) - print("testquerys:") - qtable = meta.tables["default_demographic_test"] - query1 = select(qtable).where(qtable.c.alter == 78) - print("Query 1: ", query1) - print("Query 1 result: ") - result = db.session.execute(query1) - print("Columns: ", result.columns) - for row in result: - print(row) - #Test End - for table_name in tables: table = meta.tables[table_name] columns = table.columns.keys() @@ -537,19 +566,6 @@ def show_tables(): tables = meta.tables return render_template('show_tables.html', tables=tables) -# Control Panel --------------------------------------------------------- - -@app.route("/upload_configs") -def upload_configs(): - links = [] - for rule in app.url_map.iter_rules(): - # Filter out rules we can't navigate to in a browser - # and rules that require parameters - if "GET" in rule.methods and has_no_empty_params(rule): - url = url_for(rule.endpoint, **(rule.defaults or {})) - links.append((url, rule.endpoint)) - return render_template("all_links.html", links=links) - # Root page ----------------------------- @@ -572,7 +588,7 @@ def all_links(): # delete all tables as last link -------------------------- # Route to delete all entries -@app.route('/delete_json_tables', methods=['GET']) +#@app.route('/delete_json_tables', methods=['GET']) def delete_json_tables(): try: meta = db.metadata diff --git a/slaeforms/default.json b/slaeforms/default.json index e059e4e..c4b3349 100644 --- a/slaeforms/default.json +++ b/slaeforms/default.json @@ -1,64 +1,71 @@ { - "Block 0":{ + "Block 0": { "type": "TaskTemplate", "tempalte": "standard_template.html", - "stimuli":{ - "type":"double_video", - "list_1":{ - "video_1":"https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522", - "video_2":"https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-" + "stimuli": { + "type": "double_video", + "list_1": { + "video_1": "https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522", + "video_2": "https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-" }, - "list_2":{ - "video_2":"https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-", - "video_1":"https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522" + "list_2": { + "video_2": "https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-", + "video_1": "https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522" }, - "configuration":{ - "embed":"yt" + "configuration": { + "embed": "yt" } }, - "questions":{ - "question1":{ + "questions": { + "question1": { "type": "likert", "name": "likertscale", "text": "How would you rate this video?", "required": "true", - "points":{ - "p1":{ - "value":"1", - "text":"I dont like it at all" + "points": { + "p1": { + "value": "1", + "text": "I dont like it at all" }, - "p2":{ - "value":"2", - "text":"I am indifferent" + "p2": { + "value": "2", + "text": "I am indifferent" }, - "p3":{ - "value":"3", - "text":"I like it a lot" + "p3": { + "value": "3", + "text": "I like it a lot" } } } }, - "database_table" :{ + "infovideo": { + "videourl": "https://www.youtube-nocookie.com/embed/F_w50c5Us3Y?si=-H07MmQ4lYOC2Bwh", + "infotext": "Hier wird in Zukunft ein Erklärtext stehen, in dem die Fragestellungen erklärt werden. Dazu werden alle Fragen der Seite einzeln durchgegangen und einfach erklärt. Zum Beispiel wird hier erklärt, dass man um Feedback zu geben, ein Video aufnehmen kann. Dazu drückt man auf den Knopf mit dem Videokamera Symbol. Danach muss man oben links am Browser bestätigen, dass der Browser auf die Kamera zugreifen darf.", + "configuration": { + "embed": "yt" + } + }, + "database_table": { "table_name": "double_video_responses", "fields": { - "likertscale":{ + "likertscale": { "type": "integer", "nullable": "false" } } } }, - "Block 1":{ + "Block 1": { "type": "TaskTemplate", "tempalte": "standard_template.html", - "stimuli":{ - "type":"empty", - "list":{ - "empty_stimulus":"" + "stimuli": { + "type": "empty", + "list": { + "empty_stimulus": "" } }, - "questions":{ - "question1_alter":{ + "questions": { + "question1_alter": { "type": "numberinput", "name": "alter", "text": "Alter:", @@ -66,74 +73,74 @@ "min": "1", "max": "120" }, - "question2_geschlecht":{ + "question2_geschlecht": { "type": "dropdowninput", "name": "geschlecht", "text": "Geschlecht:", "required": "true", "defaulttext": "", - "points":{ - "männlich":{ - "value":"Männlich", - "text":"Männlich" + "points": { + "männlich": { + "value": "Männlich", + "text": "Männlich" }, - "weiblich":{ - "value":"Weiblich", - "text":"Weiblich" + "weiblich": { + "value": "Weiblich", + "text": "Weiblich" }, - "divers":{ - "value":"Divers", - "text":"Divers" + "divers": { + "value": "Divers", + "text": "Divers" }, - "keine_angabe":{ - "value":"keine_angabe", - "text":"Keine Angabe" + "keine_angabe": { + "value": "keine_angabe", + "text": "Keine Angabe" } } }, - "question3_hoerstatus":{ + "question3_hoerstatus": { "type": "dropdowninput", "name": "hoerstatus", "text": "Hörstatus:", "required": "true", "defaulttext": "", - "points":{ - "hörend":{ - "value":"Hörend", - "text":"Hörend" + "points": { + "hörend": { + "value": "Hörend", + "text": "Hörend" }, - "schwerhörig":{ - "value":"Schwerhörig", - "text":"Schwerhörig" + "schwerhörig": { + "value": "Schwerhörig", + "text": "Schwerhörig" }, - "gehörlos":{ - "value":"Gehörlos", - "text":"Gehörlos" + "gehörlos": { + "value": "Gehörlos", + "text": "Gehörlos" } } }, - "question4_bevorzugte_kommunikation":{ + "question4_bevorzugte_kommunikation": { "type": "dropdowninput", "name": "bevorzugte_kommunikation", "text": "Bevorzugte Kommunikationsform:", "required": "true", "defaulttext": "", - "points":{ - "gesprochen":{ - "value":"Gesprochene Sprache", - "text":"Gesprochene Sprache" + "points": { + "gesprochen": { + "value": "Gesprochene Sprache", + "text": "Gesprochene Sprache" }, - "text":{ - "value":"Text", - "text":"Text" + "text": { + "value": "Text", + "text": "Text" }, - "gebärdensprache":{ - "value":"Gebärdensprache", - "text":"Gebärdensprache" + "gebärdensprache": { + "value": "Gebärdensprache", + "text": "Gebärdensprache" } } }, - "question5_gebeardenzeitraum":{ + "question5_gebeardenzeitraum": { "type": "numberinput", "name": "gebärdenzeitraum", "text": "Wie viele Jahre verwenden sie schon Gebärdensprache:", @@ -142,7 +149,7 @@ "max": "100", "step": "0.5" }, - "question6_sprachkompetenz":{ + "question6_sprachkompetenz": { "type": "numberinput", "name": "gebärdensprachkompetenz", "text": "Wie schätzen sie ihre Gebärdensprachkompetenz ein (1-10):", @@ -151,118 +158,128 @@ "max": "10" } }, - "database_table" :{ + "infovideo": { + "videourl": "https://www.youtube-nocookie.com/embed/F_w50c5Us3Y?si=-H07MmQ4lYOC2Bwh", + "infotext": "Hier wird in Zukunft ein Erklärtext stehen, in dem die Fragestellungen erklärt werden. \n Dazu werden alle Fragen der Seite einzeln durchgegangen und einfach erklärt. Zum Beispiel wird hier erklärt, dass man um Feedback zu geben, ein Video aufnehmen kann. Dazu drückt man auf den Knopf mit dem Videokamera Symbol. Danach muss man oben links am Browser bestätigen, dass der Browser auf die Kamera zugreifen darf.", + "configuration": { + "embed": "yt" + } + }, + "database_table": { "table_name": "demographic_data", "fields": { - "alter":{ + "alter": { "type": "integer", "nullable": "false" }, - "geschlecht":{ + "geschlecht": { "type": "string", "size": "14", "nullable": "false" }, - "hoerstatus":{ + "hoerstatus": { "type": "string", "size": "14", "nullable": "false" }, - "bevorzugte_kommunikation":{ + "bevorzugte_kommunikation": { "type": "string", "size": "22", "nullable": "false" }, - "gebärdenzeitraum":{ + "gebärdenzeitraum": { "type": "float", "nullable": "false" }, - "gebärdensprachkompetenz":{ + "gebärdensprachkompetenz": { "type": "integer", "nullable": "false" } } } }, - "Block 2":{ + "Block 2": { "type": "TaskTemplate", "tempalte": "standard_template.html", - "stimuli":{ - "type":"single_video", + "stimuli": { + "type": "single_video", "order": "random", - "list":{ - "video_1":"https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522", - "video_2":"https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-" + "list": { + "video_1": "https://www.youtube-nocookie.com/embed/IqGVT1q1PtM?si=kel7ZWEQl3h-h522", + "video_2": "https://www.youtube-nocookie.com/embed/g9KA72jN5SM?si=O7dfqTXdFCCAScJ-" }, - "configuration":{ - "embed":"yt" + "configuration": { + "embed": "yt" } }, - "questions":{ - "question1":{ + "questions": { + "question1": { "type": "likert", "name": "likertscale", "text": "How would you rate this video?", "required": "true", - "points":{ - "p1":{ - "value":"1", - "text":"I dont like it at all" + "points": { + "p1": { + "value": "1", + "text": "I dont like it at all" }, - "p2":{ - "value":"2", - "text":"I dont like it" + "p2": { + "value": "2", + "text": "I dont like it" }, - "p3":{ - "value":"3", - "text":"I am indifferent" + "p3": { + "value": "3", + "text": "I am indifferent" }, - "p4":{ - "value":"4", - "text":"I like it" + "p4": { + "value": "4", + "text": "I like it" }, - "p5":{ - "value":"5", - "text":"I like it a lot" + "p5": { + "value": "5", + "text": "I like it a lot" } } }, - "question2":{ + "question2": { "type": "textinput", "name": "text_feedback", "text": "Here you can give us Feedback", "required": "false", "size": "250" }, - "question3":{ + "question3": { "type": "videoinput", "text": "Here you can give us Feedback as video", "name": "video_feedback", "required": "false" } }, - "database_table" :{ + "infovideo": { + "videourl": "https://www.youtube-nocookie.com/embed/F_w50c5Us3Y?si=-H07MmQ4lYOC2Bwh", + "infotext": "Hier wird in Zukunft ein Erklärtext stehen, in dem die Fragestellungen erklärt werden.\\n Dazu werden alle Fragen der Seite einzeln durchgegangen und einfach erklärt.\\n Zum Beispiel wird hier erklärt, dass man um Feedback zu geben, ein Video aufnehmen kann. Dazu drückt man auf den Knopf mit dem Videokamera Symbol. Danach muss man oben links am Browser bestätigen, dass der Browser auf die Kamera zugreifen darf.", + "configuration": { + "embed": "yt" + } + }, + "database_table": { "table_name": "single_video_responses", "fields": { - "likertscale":{ + "likertscale": { "type": "integer", "nullable": "false" }, - "text_feedback":{ + "text_feedback": { "type": "string", "size": "250", "nullable": "true" }, - "video_upload":{ + "video_upload": { "type": "string", "size": "100", "nullable": "true" } } } - }, - "Block_3":{ - "type": "SinglePage", - "template": "endpage.html" } } \ No newline at end of file diff --git a/slaeforms/static/infoDialogScript.js b/slaeforms/static/infoDialogScript.js new file mode 100644 index 0000000..897a04d --- /dev/null +++ b/slaeforms/static/infoDialogScript.js @@ -0,0 +1,13 @@ +const dialog = document.querySelector("dialog"); + const showButton = document.querySelector("dialog + button"); + const closeButton = document.querySelector("dialog button"); + + // "Show the dialog" button opens the dialog modally + showButton.addEventListener("click", () => { + dialog.showModal(); + }); + + // "Close" button closes the dialog + closeButton.addEventListener("click", () => { + dialog.close(); + }); \ No newline at end of file diff --git a/slaeforms/static/styles.css b/slaeforms/static/styles.css index efd9133..a480233 100644 --- a/slaeforms/static/styles.css +++ b/slaeforms/static/styles.css @@ -40,8 +40,8 @@ dialog .iframe-container{ height: 90px; padding: 8px; position: fixed; - top: 20px; - left: 80vw; + top: 30px; + left: min(calc(66vw + 30px + 34vw / 2),calc(1720px + calc(100vw - 1690px) / 2)); /*first is the normal case, second if 66vw is more than 1690 */ } .infoButtonIcon { @@ -56,8 +56,8 @@ dialog .iframe-container{ .container { margin: 0 auto; /* height: 100vh;*/ - width: 60vw; /* You can adjust this width as needed */ - max-width: 1200px; /* Maximum width to keep it from getting too wide on large screens */ + width: 66vw; /* You can adjust this width as needed */ + max-width: 1690px; /* Maximum width to keep it from getting too wide on large screens */ padding: 20px; background-color: #7b8cdb; /* Just for visual differentiation */ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); diff --git a/slaeforms/templates/popuptest.html b/slaeforms/templates/popuptest.html index 62c4ba0..11920b0 100644 --- a/slaeforms/templates/popuptest.html +++ b/slaeforms/templates/popuptest.html @@ -15,7 +15,7 @@
-
diff --git a/slaeforms/templates/standard_template.html b/slaeforms/templates/standard_template.html index 0a88141..de8c0d3 100644 --- a/slaeforms/templates/standard_template.html +++ b/slaeforms/templates/standard_template.html @@ -92,6 +92,27 @@ step={{question["step"]}}
+ + {% if (infovideo) %} + + + +
+ +
+
+

{{ infovideo["infotext"] }}

+
+
+ + + {% endif %} + + {% if (stimulus_type == "single_video") %} {{ single_video(**stimulus_configuration) }} {% elif (stimulus_type == "double_video") %} @@ -120,7 +141,6 @@ step={{question["step"]}} {% endfor %}
- {% elif (questions[question]["type"] == "textinput") %}