diff --git a/slaeforms/app.py b/slaeforms/app.py index 391a62f..1011057 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -5,7 +5,7 @@ import base64 from flask import Flask, redirect, url_for, request, session, make_response, jsonify, send_from_directory from flask import render_template from flask_sqlalchemy import SQLAlchemy -from sqlalchemy import Integer, String, Column +from sqlalchemy import Integer, String, Column, Float from datetime import datetime import uuid from sqlalchemy.exc import SQLAlchemyError @@ -41,7 +41,7 @@ UPLOAD_FOLDER = 'uploads' #---------testing JSON Stuff #open the json file with the config -testconfigfile = open("singleformconfig.json") +testconfigfile = open("singleformconfig.json", encoding='utf-8') #convert it to dict testconfig = json.load(testconfigfile) testconfigfile.close() @@ -93,7 +93,7 @@ except SQLAlchemyError as e: #open the json file with the config -configfile = open("default.json") #todo replace with other name +configfile = open("default.json", encoding='utf-8') #todo replace with other name #convert it to dict config = json.load(configfile) configfile.close() @@ -132,6 +132,8 @@ def create_model_class(schema): column_type = Integer elif column_info["type"] == "string": column_type = String(int(column_info["size"])) + if column_info["type"] == "float": + column_type = Float attributes[column_name] = Column(column_name,column_type, nullable=column_info["nullable"]) @@ -186,7 +188,7 @@ def teststartpage(): print(session["block_names"]) for name in block_names: - if config[name]["type"] == "TaskTemplate": + if config[name]["type"] == "TaskTemplate" and ("stimuli" in current_block): match config[name]["stimuli"]["type"]: case "single_video": order = list(config[name]["stimuli"]["list"]) # order = list of simuli keys @@ -194,6 +196,11 @@ def teststartpage(): if config[name]["stimuli"]["order"] == "random": random.shuffle(order) #in random order session["block_order"][name] = order + case "empty": + order = list(config[name]["stimuli"]["list"]) # order = list of simuli keys + print("order: ",order) + session["block_order"][name] = order + if "stimuli" in current_block: #get the name of the current stimulus @@ -245,8 +252,21 @@ def jsonform(): # 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": + current_block_order = session["block_order"][session["current_block_name"]] + current_block_stimuli = current_block["stimuli"] + current_stimulus = current_block_order[session["current_stimulus_index"]] + stimulus_type=current_block["stimuli"]["type"] + return render_template( + "standard_template.html", + stimuli=current_block_stimuli, + stimulus_type=stimulus_type, + current_stimulus=current_stimulus, + questions=current_block["questions"] + ) # ansonsten, templates: @@ -318,14 +338,15 @@ def sendpage_json(): return "There was a problem while adding the response to the Database" # handle possible Video that was send - formatted_date = date.strftime("%Y.%m.%d %H-%M-%S") - print("date: ", date) - video = request.files['recordedVideo'] - video_name = str(session_user_id) + "_" + session["current_block_name"] + "_" + session["current_stimulus_name"] + "_" + str(formatted_date) + ".webm" - path = os.path.join(UPLOAD_FOLDER, video_name) - print("path: ",path) - os.makedirs(UPLOAD_FOLDER, exist_ok=True) - video.save(path) + if 'recordedVideo' in request.files: + video = request.files['recordedVideo'] + formatted_date = date.strftime("%Y.%m.%d %H-%M-%S") + print("date: ", date) + video_name = str(session_user_id) + "_" + session["current_block_name"] + "_" + session["current_stimulus_name"] + "_" + str(formatted_date) + ".webm" + path = os.path.join(UPLOAD_FOLDER, video_name) + print("path: ",path) + os.makedirs(UPLOAD_FOLDER, exist_ok=True) + video.save(path) # Now move to the next stimulus or block diff --git a/slaeforms/default.json b/slaeforms/default.json index 481cb8a..1a4db5f 100644 --- a/slaeforms/default.json +++ b/slaeforms/default.json @@ -1,5 +1,141 @@ { "Block 3":{ + "type": "TaskTemplate", + "tempalte": "standard_template.html", + "stimuli":{ + "type":"empty", + "list":{ + "empty_stimulus":"" + } + }, + "questions":{ + "question1_alter":{ + "type": "numberinput", + "name": "alter", + "text": "Alter:", + "required": "true", + "min": "1", + "max": "120" + }, + "question2_geschlecht":{ + "type": "dropdowninput", + "name": "geschlecht", + "text": "Geschlecht:", + "required": "true", + "defaulttext": "", + "points":{ + "männlich":{ + "value":"Männlich", + "text":"Männlich" + }, + "weiblich":{ + "value":"Weiblich", + "text":"Weiblich" + }, + "divers":{ + "value":"Divers", + "text":"Divers" + }, + "keine_angabe":{ + "value":"keine_angabe", + "text":"Keine Angabe" + } + } + }, + "question3_hoerstatus":{ + "type": "dropdowninput", + "name": "hoerstatus", + "text": "Hörstatus:", + "required": "true", + "defaulttext": "", + "points":{ + "hörend":{ + "value":"Hörend", + "text":"Hörend" + }, + "schwerhörig":{ + "value":"Schwerhörig", + "text":"Schwerhörig" + }, + "gehörlos":{ + "value":"Gehörlos", + "text":"Gehörlos" + } + } + }, + "question4_bevorzugte_kommunikation":{ + "type": "dropdowninput", + "name": "bevorzugte_kommunikation", + "text": "Bevorzugte Kommunikationsform:", + "required": "true", + "defaulttext": "", + "points":{ + "gesprochen":{ + "value":"Gesprochene Sprache", + "text":"Gesprochene Sprache" + }, + "text":{ + "value":"Text", + "text":"Text" + }, + "gebärdensprache":{ + "value":"Gebärdensprache", + "text":"Gebärdensprache" + } + } + }, + "question5_gebeardenzeitraum":{ + "type": "numberinput", + "name": "gebärdenzeitraum", + "text": "Wie viele Jahre verwenden sie schon Gebärdensprache:", + "required": "true", + "min": "0", + "max": "100", + "step": "0.5" + }, + "question6_sprachkompetenz":{ + "type": "numberinput", + "name": "gebärdensprachkompetenz", + "text": "Wie schätzen sie ihre Gebärdensprachkompetenz ein (1-10):", + "required": "true", + "min": "1", + "max": "10" + } + }, + "database_table" :{ + "table_name": "default_demographic_test", + "fields": { + "alter":{ + "type": "integer", + "nullable": "false" + }, + "geschlecht":{ + "type": "string", + "size": "14", + "nullable": "false" + }, + "hoerstatus":{ + "type": "string", + "size": "14", + "nullable": "false" + }, + "bevorzugte_kommunikation":{ + "type": "string", + "size": "22", + "nullable": "false" + }, + "gebärdenzeitraum":{ + "type": "float", + "nullable": "false" + }, + "gebärdensprachkompetenz":{ + "type": "integer", + "nullable": "false" + } + } + } + }, + "Block 4":{ "type": "TaskTemplate", "tempalte": "standard_template.html", "number_of_pages":"3", @@ -19,6 +155,7 @@ "question1":{ "type": "likert", "name": "likertscale", + "text": "How would you rate this video?", "required": "true", "points":{ "p1":{ @@ -46,11 +183,13 @@ "question2":{ "type": "textinput", "name": "text_feedback", + "text": "Here you can give us Feedback", "required": "false", "size": "250" }, "question3":{ "type": "videoinput", + "text": "Here you can give us Feedback as video", "name": "video_feedback", "required": "false" } diff --git a/slaeforms/static/styles.css b/slaeforms/static/styles.css index 22952f9..acc8973 100644 --- a/slaeforms/static/styles.css +++ b/slaeforms/static/styles.css @@ -1,15 +1,34 @@ +html { + height: 100%; +} + body { width: 100%; height: 100%; margin: 0; - display: flex; - justify-content: center; /*align-items: center; this will make the content a square, with edges up and bottom*/ background-color: #a4b5ff; color: #000000; font-family: Tahoma; font-size: 16px; - } +} + +.centercontent { + height: 100%; + display: flex; + justify-content: center; +} +.container { + height: 100%; + + width: 80%; /* You can adjust this width as needed */ + max-width: 1200px; /* 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); +} + + .spacer { clear: both; @@ -44,13 +63,7 @@ body { .textarea-label{ align-self: flex-start; /* Aligns the label to the start of the container */ } -.container { - width: 80%; /* You can adjust this width as needed */ - max-width: 1200px; /* 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); -} + video { max-width: 100%; @@ -127,6 +140,10 @@ iframe { form { text-align: center; + display: flex; + flex-direction: column; + align-items: center; + } .centertext { diff --git a/slaeforms/templates/standard_template.html b/slaeforms/templates/standard_template.html index 86498e8..4c31468 100644 --- a/slaeforms/templates/standard_template.html +++ b/slaeforms/templates/standard_template.html @@ -25,6 +25,18 @@ required {% endif %} {%- endmacro %} +{% macro inputconfig(question) -%} +{% if ("min" in question) %} +min={{question["min"]}} +{% endif %} +{% if ("max" in question) %} +max={{question["max"]}} +{% endif %} +{% if ("step" in question) %} +step={{question["step"]}} +{% endif %} +{%- endmacro %} + {% macro input(name, value='', type='text', size=20) -%} @@ -45,11 +57,12 @@ required
+Error: Block {{ stimulus["type"] }} could not be loaded!
@@ -63,26 +76,65 @@ required {% if (questions[question]["type"] == "likert") %}