From 52908a548cea6c81a728cdc76ca36ee93d5fd5fd Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Sat, 4 Dec 2021 15:41:47 +0000 Subject: [PATCH] Added server and admin-side time limit adjustments --- ref-test/admin/models/tests.py | 9 +- ref-test/admin/static/css/style.css | 6 +- ref-test/admin/static/js/script.js | 76 ++++++-- .../admin/components/client-alerts.html | 2 +- ref-test/admin/templates/admin/test.html | 180 ++++++++++++++++++ ref-test/admin/templates/admin/tests.html | 6 +- ref-test/admin/views.py | 24 ++- 7 files changed, 270 insertions(+), 33 deletions(-) create mode 100644 ref-test/admin/templates/admin/test.html diff --git a/ref-test/admin/models/tests.py b/ref-test/admin/models/tests.py index 656c424..a1b3397 100644 --- a/ref-test/admin/models/tests.py +++ b/ref-test/admin/models/tests.py @@ -41,13 +41,14 @@ class Test: return jsonify({'error': f'Could not create exam. An error occurred.'}), 400 def add_time_adjustment(self, time_adjustment): - code = { + adjustment = { '_id': uuid4().hex, - 'user_code': secrets.token_hex(2).upper(), + 'user_code': secrets.token_hex(3).upper(), 'time_adjustment': time_adjustment } - if db.tests.find_one_and_update({'_id': self._id}, {'$push': {'time_adjustments': code}},upsert=False): - return jsonify({'success': code}) + if db.tests.find_one_and_update({'_id': self._id}, {'$push': {'time_adjustments': adjustment}},upsert=False): + flash(f'Time adjustment for {adjustment["time_adjustment"]} minutes has been added. This can be enabled using the user code {adjustment["user_code"]}.') + return jsonify({'success': adjustment}) return jsonify({'error': 'Failed to add the time adjustment. An error occurred.'}), 400 def remove_time_adjustment(self, _id): diff --git a/ref-test/admin/static/css/style.css b/ref-test/admin/static/css/style.css index 8107688..137d546 100644 --- a/ref-test/admin/static/css/style.css +++ b/ref-test/admin/static/css/style.css @@ -214,11 +214,15 @@ table.dataTable { font-size: 14pt; } -.result-action-buttons { +.result-action-buttons, .test-action { margin: 5px auto; width: fit-content; } +.accordion-item { + background-color: unset; +} + /* Fallback for Edge -------------------------------------------------- */ @supports (-ms-ime-align: auto) { diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js index d3362b5..184374a 100644 --- a/ref-test/admin/static/js/script.js +++ b/ref-test/admin/static/js/script.js @@ -63,22 +63,27 @@ $('form[name=form-upload-questions]').submit(function(event) { }); // Edit and Delete Test Button Handlers -$('.delete-test').click(function(event) { +$('.test-action').click(function(event) { - let _id = $(this).data('_id') + let _id = $(this).data('_id'); + let action = $(this).data('action'); - $.ajax({ - url: `/admin/tests/delete/`, - type: 'POST', - data: JSON.stringify({'_id': _id}), - contentType: 'application/json', - success: function(response) { - window.location.href = '/admin/tests/'; - }, - error: function(response){ - error_response(response); - }, - }); + if (action == 'delete') { + $.ajax({ + url: `/admin/tests/delete/`, + type: 'POST', + data: JSON.stringify({'_id': _id}), + contentType: 'application/json', + success: function(response) { + window.location.href = '/admin/tests/'; + }, + error: function(response){ + error_response(response); + }, + }); + } else if (action == 'edit') { + window.location.href = `/admin/test/${_id}/` + } event.preventDefault(); }); @@ -109,11 +114,11 @@ $('.edit-question-dataset').click(function(event) { function error_response(response) { - var alert = $("#alert-box"); - alert.html(''); + const $alert = $("#alert-box"); + $alert.html(''); if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { - alert.html(` + $alert.html(`