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(`