Skip to content

Commit b31174d

Browse files
Added confirmation when uploading scans for a template with no divisions (#7993)
1 parent ac8c9da commit b31174d

6 files changed

Lines changed: 55 additions & 3 deletions

File tree

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### 🚨 Breaking changes
88

99
### ✨ New features and improvements
10+
- Added a confirm dialog to the Upload Scans form that appears when no template divisions are assigned to the selected exam template (#7993)
1011
- Migrated `MarkingSchemesTable` component to React Table V8 (#7985)
1112
- Removed Graders Subcomponent and added a Graders column in the Assignment Grades tab (#7967)
1213
- Added GET and PATCH /overall_comment API routes (#7963)

app/views/exam_templates/_boot.js.erb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,32 @@ function set_crop_selection(crop_target, form, id, jcrop_api) {
246246
function _round_down_to_nearest_hundred(num) {
247247
return Math.floor(num / 100) * 100;
248248
}
249+
250+
/**
251+
* Adds a submit event listener to the upload scans form.
252+
* The event listener checks the template divisions count of the template that was selected from the form dropdown
253+
* and shows a confirmation dialog on submission of the form if the selected template has no divisions assigned to it.
254+
* This function runs after the form is injected in view_logs.js.erb.
255+
* @param {Array} examTemplateData contains exam template ids and matching template division counts.
256+
* @returns {void}
257+
*/
258+
function init_upload_scans_form(examTemplateData) {
259+
const uploadScansForm = document.getElementById('upload_scans_form');
260+
const dropdown = document.getElementById('exam_template_dropdown');
261+
262+
if (!uploadScansForm || !dropdown) {
263+
return;
264+
}
265+
266+
uploadScansForm.addEventListener('submit', (e) => {
267+
const selectedExamTemplate = examTemplateData.find(template => String(template.exam_template_id) === dropdown.value);
268+
269+
if (selectedExamTemplate && selectedExamTemplate.template_division_count === 0) {
270+
const proceed = confirm(I18n.t('exam_templates.upload_scans.confirmation_dialog'));
271+
if (!proceed) {
272+
e.preventDefault();
273+
e.stopPropagation();
274+
}
275+
}
276+
}, true);
277+
}

app/views/exam_templates/_split_form.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<%= form_with url: split_course_assignment_exam_templates_path(@current_course),
1+
<%= form_with id: 'upload_scans_form',
2+
url: split_course_assignment_exam_templates_path(@current_course),
23
method: :patch,
34
authenticity_token: true,
45
multipart: true do |f| %>
56
<div class="inline-labels">
67
<%= f.label :exam_template_id, ExamTemplate.model_name.human %>
78
<%= f.select :exam_template_id,
89
options_from_collection_for_select(@exam_templates, 'id', 'name'),
9-
required: true %>
10+
{required: true},
11+
{id: 'exam_template_dropdown'} %>
1012
<%= f.label :pdf_to_split, t('exam_templates.upload_scans.instruction') %>
1113
<%= f.file_field :pdf_to_split, required: true, accept: 'application/pdf' %>
1214
</div>

app/views/exam_templates/view_logs.js.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ document.getElementById('editing_pane_menu').innerHTML =
33

44
makeExamScanLogTable(document.getElementById('exam_scan_log_table'),
55
{course_id: <%= @current_course.id %>, assignment_id: <%= @assignment.id %>});
6+
7+
<% exam_template_data = @exam_templates.map{
8+
|exam_template|
9+
{ exam_template_id: exam_template.id, template_division_count: exam_template.template_divisions.size }
10+
} %>
11+
12+
let examTemplateData = <%= exam_template_data.to_json.html_safe %>;
13+
14+
init_upload_scans_form(examTemplateData);

config/locales/views/exam_templates/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ en:
9898
instruction: Replace template file
9999
success: Exam Template has been successfully updated
100100
upload_scans:
101+
confirmation_dialog: The selected exam template has no template divisions assigned to it. Are you sure you would like to proceed?
101102
failure: Scans failed to upload
102103
instruction: Papers to upload (.pdf)
103104
invalid: Invalid file type

spec/controllers/exam_templates_controller_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,19 @@
342342
end
343343

344344
describe '#view_logs' do
345-
before { get_as user, :view_logs, params: { assignment_id: exam_template.assignment.id, course_id: course.id } }
345+
render_views
346+
before do
347+
get_as user, :view_logs, format: 'js', params: { assignment_id: exam_template.assignment.id, course_id: course.id }
348+
end
346349

347350
it('should respond with 200') { expect(response).to have_http_status :ok }
351+
352+
it 'passes template division data to init_upload_scans_form' do
353+
expect(response.body).to include('upload_scans_form')
354+
expect(response.body).to include('template_division_count')
355+
expect(response.body).to include('init_upload_scans_form(examTemplateData)')
356+
expect(response.body).to include(exam_template.id.to_s)
357+
end
348358
end
349359

350360
describe '#download_generate' do

0 commit comments

Comments
 (0)