diff --git a/README.md b/README.md index 4b77a35..0427bcb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The exam client is made with accessibility in mind, and has been designed to be ## Set Up and Installation -The clien is designed to work on a server. +The app is designed to be hosted on a server. ### Pre-Requisites diff --git a/nginx/conf.d/ref-test-app.conf b/nginx/conf.d/ref-test-app.conf index 36c1247..24c2694 100644 --- a/nginx/conf.d/ref-test-app.conf +++ b/nginx/conf.d/ref-test-app.conf @@ -19,6 +19,7 @@ server { include /etc/nginx/ssl.conf; include /etc/nginx/certbot-challenge.conf; + # Define locations for static files to be served by Nginx location ^~ /quiz/static/ { include /etc/nginx/mime.types; alias /usr/share/nginx/html/quiz/static/; @@ -34,6 +35,12 @@ server { alias /usr/share/nginx/html/admin/editor/static/; } + location ^~ /admin/view/static/ { + include /etc/nginx/mime.types; + alias /usr/share/nginx/html/admin/view/static/; + } + + # Proxy to the main app for all other requests location / { include /etc/nginx/conf.d/proxy_headers.conf; proxy_pass http://reftest; diff --git a/ref-test/app/__init__.py b/ref-test/app/__init__.py index 4122f2c..66dfc25 100644 --- a/ref-test/app/__init__.py +++ b/ref-test/app/__init__.py @@ -46,11 +46,13 @@ def create_app(): from .quiz.views import quiz from .views import views from .editor.views import editor + from .view.views import view app.register_blueprint(admin, url_prefix='/admin') app.register_blueprint(api, url_prefix='/api') app.register_blueprint(views) app.register_blueprint(quiz) app.register_blueprint(editor, url_prefix='/admin/editor') + app.register_blueprint(view, url_prefix='/admin/view') return app \ No newline at end of file diff --git a/ref-test/app/admin/static/js/script.js b/ref-test/app/admin/static/js/script.js index 1fd1391..caaee59 100644 --- a/ref-test/app/admin/static/js/script.js +++ b/ref-test/app/admin/static/js/script.js @@ -1,25 +1,25 @@ // Menu Highlight Scripts -const menuItems = document.getElementsByClassName('nav-link'); +const menuItems = document.getElementsByClassName('nav-link') for(let i = 0; i < menuItems.length; i++) { if(menuItems[i].pathname == window.location.pathname) { - menuItems[i].classList.add('active'); + menuItems[i].classList.add('active') } } -const dropdownItems = document.getElementsByClassName('dropdown-item'); +const dropdownItems = document.getElementsByClassName('dropdown-item') for(let i = 0; i< dropdownItems.length; i++) { if(dropdownItems[i].pathname == window.location.pathname) { - dropdownItems[i].classList.add('active'); - $( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active'); + dropdownItems[i].classList.add('active') + $( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active') } } // General Post Method Form Processing Script $('form.form-post').submit(function(event) { - var $form = $(this); - var data = $form.serialize(); - var url = $(this).prop('action'); - var rel_success = $(this).data('rel-success'); + var $form = $(this) + var data = $form.serialize() + var url = $(this).prop('action') + var rel_success = $(this).data('rel-success') $.ajax({ url: url, @@ -28,25 +28,25 @@ $('form.form-post').submit(function(event) { dataType: 'json', success: function(response) { if (response.redirect_to) { - window.location.href = response.redirect_to; + window.location.href = response.redirect_to } else { - window.location.href = rel_success; + window.location.href = rel_success } }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) // Form Upload Questions - Special case, needs to handle files. $('form[name=form-upload-questions]').submit(function(event) { - var $form = $(this); - var data = new FormData($form[0]); + var $form = $(this) + var data = new FormData($form[0]) var file = $('input[name=data_file]')[0].files[0] data.append('file', file) @@ -57,21 +57,21 @@ $('form[name=form-upload-questions]').submit(function(event) { processData: false, contentType: false, success: function(response) { - window.location.reload(); + window.location.reload() }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) // Edit and Delete Test Button Handlers $('.test-action').click(function(event) { - let id = $(this).data('id'); - let action = $(this).data('action'); + let id = $(this).data('id') + let action = $(this).data('action') if (action == 'delete' || action == 'start' || action == 'end') { $.ajax({ @@ -80,25 +80,25 @@ $('.test-action').click(function(event) { data: JSON.stringify({'id': id, 'action': action}), contentType: 'application/json', success: function(response) { - window.location.href = '/admin/tests/'; + window.location.href = '/admin/tests/' }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } else if (action == 'edit') { window.location.href = `/admin/test/${id}/` } - event.preventDefault(); -}); + event.preventDefault() +}) // Edit Dataset Button Handlers $('.edit-question-dataset').click(function(event) { - var id = $(this).data('id'); - var action = $(this).data('action'); - var disabled = $(this).hasClass('disabled'); + var id = $(this).data('id') + var action = $(this).data('action') + var disabled = $(this).hasClass('disabled') if ( !disabled ) { if (action == 'delete') { @@ -111,25 +111,27 @@ $('.edit-question-dataset').click(function(event) { }), contentType: 'application/json', success: function(response) { - window.location.reload(); + window.location.reload() }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } else if (action == 'edit') { window.location.href = `/admin/editor/${id}/` + } else if (action == 'view') { + window.location.href = `/admin/view/${id}` } else if (action == 'download') { window.location.href = `/admin/settings/questions/download/${id}/` } - }; - event.preventDefault(); -}); + } + event.preventDefault() +}) function error_response(response) { - const $alert = $("#alert-box"); - $alert.html(''); + const $alert = $("#alert-box") + $alert.html('') if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { $alert.html(` @@ -138,18 +140,18 @@ function error_response(response) { ${response.responseJSON.error} - `); + `) } else if (response.responseJSON.error instanceof Array) { var output = '' - for (var i = 0; i < response.responseJSON.error.length; i ++) { + for (let i = 0; i < response.responseJSON.error.length; i ++) { output += `
- {{ question }} + {{ question|int + 1 }} | {{ answers[question|int][answer|int] }} diff --git a/ref-test/app/admin/templates/admin/settings/questions.html b/ref-test/app/admin/templates/admin/settings/questions.html index eed4611..d9e941a 100644 --- a/ref-test/app/admin/templates/admin/settings/questions.html +++ b/ref-test/app/admin/templates/admin/settings/questions.html @@ -57,28 +57,37 @@ class="btn btn-primary edit-question-dataset" data-id="{{ element.id }}" data-action="download" - title="Download Dataset" + title="Download Questions" > - + + + + - - + + - + |