Skip to content

Commit

Permalink
Add button to bulk import assessments from file system (#1931)
Browse files Browse the repository at this point in the history
* Update old-style path to use path helper

* Add install all button

* Rename install -> import

* Improve logic

* Add alert

* Rephrase message

* Rename btn variable
  • Loading branch information
damianhxy authored Jul 17, 2023
1 parent d850ad9 commit e885c67
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def importAssessment
redirect_to(install_assessment_course_assessments_path(@course)) && return
end
flash[:success] = "Successfully imported #{@assessment.name}"
redirect_to([@course, @assessment])
redirect_to course_assessment_path(@course, @assessment)
end

# create - Creates an assessment from an assessment directory
Expand Down
33 changes: 28 additions & 5 deletions app/views/assessments/install_assessment.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<% @title = "Install Assessment" %>
<% content_for :javascripts do %>
<script>
$(function() {
$("#importAll").click(function(e) {
const msg = "Are you sure you want to import all assessments?";
if (!window.confirm(msg))
return false;

const $btn = $(e.target);
$btn.text("Importing...");
$btn.addClass("disabled");

Promise.all(
$(".import").map((i, e) => $.post(e.href))
)
.then(() => {
alert("Finished import of all assessments.\nIf any assessments remain, errors occurred while importing them.");
location.reload();
});
});
});
</script>
<% end %>

Choose one of the following methods to install an assessment
<div class="section">
<h4>1. Create from scratch</h4>
Expand Down Expand Up @@ -30,13 +54,12 @@ Choose one of the following methods to install an assessment
</em>
</li>
<% else %>
<ul>
<div class="collection">
<% @unused_config_files.each do |ass_file| %>
<li>
<%= link_to ass_file, {action: :importAssessment, assessment_name: ass_file}, method: :post %>
</li>
<%= link_to ass_file, {action: :importAssessment, assessment_name: ass_file}, method: :post, class: "collection-item import" %>
<% end %>
</ul>
</div>
<a id="importAll" class="btn">Import all</a>
<% end %>
</ul>
</div>
Expand Down

0 comments on commit e885c67

Please sign in to comment.