From c0875e4c2a77d940bff5c3a73364702b25f23a96 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Wed, 14 Jun 2023 17:44:50 +0200 Subject: [PATCH] :sparkles: Added Answer-Count to admin screen --- classquiz/db/models.py | 4 +-- classquiz/routers/storage.py | 4 +++ classquiz/socket_server/__init__.py | 1 + frontend/src/lib/admin.svelte | 38 ++++++++++++++++++--------- frontend/src/lib/i18n/locales/en.json | 10 ++++--- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/classquiz/db/models.py b/classquiz/db/models.py index 3352fa8..688f851 100644 --- a/classquiz/db/models.py +++ b/classquiz/db/models.py @@ -471,5 +471,5 @@ class PrivateStorageItem(PublicStorageItem): class UpdateStorageItem(BaseModel): - filename: str - alt_text: str + filename: str | None + alt_text: str | None diff --git a/classquiz/routers/storage.py b/classquiz/routers/storage.py index 40cf007..63a4bb8 100644 --- a/classquiz/routers/storage.py +++ b/classquiz/routers/storage.py @@ -197,6 +197,10 @@ async def update_image_data( file_data = await StorageItem.objects.get_or_none(id=file_id, user=user, deleted_at=None) if file_data is None: raise HTTPException(status_code=404, detail="File not found") + if data.alt_text == "": + data.alt_text = None + if data.filename == "": + data.filename = None file_data.filename = data.filename file_data.alt_text = data.alt_text await file_data.update() diff --git a/classquiz/socket_server/__init__.py b/classquiz/socket_server/__init__.py index ef72bd2..7b6c463 100644 --- a/classquiz/socket_server/__init__.py +++ b/classquiz/socket_server/__init__.py @@ -390,6 +390,7 @@ async def submit_answer(sid: str, data: dict): answers, game_pin=session["game_pin"], data=answer_data, q_index=int(float(data.question_index)) ) player_count = await redis.scard(f"game_session:{session['game_pin']}:players") + await sio.emit("player_answer", {}) if len(answers.__root__) == player_count: # await sio.emit( # "question_results", diff --git a/frontend/src/lib/admin.svelte b/frontend/src/lib/admin.svelte index 826e737..3936bf7 100644 --- a/frontend/src/lib/admin.svelte +++ b/frontend/src/lib/admin.svelte @@ -31,6 +31,7 @@ let shown_question_now: number; let final_results_clicked = false; let timer_interval; + let answer_count = 0; export let control_visible: boolean; export let player_scores; @@ -53,6 +54,7 @@ shown_question_now = data.question_index; timer_res = quiz_data.questions[data.question_index].time; selected_question = selected_question + 1; + answer_count = 0; timer(timer_res); }); const get_question_results = () => { @@ -95,6 +97,10 @@ } }); + socket.on('player_answer', (_) => { + answer_count += 1; + }); + const timer = (time: string) => { let seconds = Number(time); timer_interval = setInterval(() => { @@ -179,13 +185,13 @@ {/if} {:else} + on:click={() => { + set_question_number(selected_question + 1); + }} + class='admin-button' + >Next Question ({selected_question + 2} + ) + --> {/if} @@ -215,12 +221,18 @@ {@html quiz_data.questions[selected_question].question} -
- +
+ +
+ +
+

+ {$t('admin_page.answers_submitted', { answer_count: answer_count })} +

{#if quiz_data.questions[selected_question].image !== null} diff --git a/frontend/src/lib/i18n/locales/en.json b/frontend/src/lib/i18n/locales/en.json index 885a16c..6141f8e 100644 --- a/frontend/src/lib/i18n/locales/en.json +++ b/frontend/src/lib/i18n/locales/en.json @@ -181,7 +181,10 @@ "progress": "Progress", "speed": "Speed", "upload": "Upload", - "files_library": "Files Library" + "files_library": "Files Library", + "answer_plural": "Answers", + "yes": "Yes", + "no": "no" }, "editor": { "time_in_seconds": "Time in seconds", @@ -229,7 +232,8 @@ "next_question": "Next Question ({{question}})", "show_results": "Show results", "stop_time_and_solutions": "Stop time and show solutions", - "enter_answer_into_field": "Enter your answer into the input field!" + "enter_answer_into_field": "Enter your answer into the input field!", + "answers_submitted": "{{answer_count}} Answers submitted" }, "password_reset_page": { "reset_password": "Reset password" @@ -407,7 +411,7 @@ "caption": "Caption: {{caption}}", "filename": "Filename: {{filename}}", "uploaded": "Uploaded: {{date}}", - "Imported": "Imported: {{yes_or_no}}", + "imported": "Imported: {{yes_or_no}}", "edit_details": "Edit details", "delete_image": "Delete image", "edit_the_image": "Edit the image",