-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adjust service to handle blob * broadcast completion * add loading spinnder * i18n and clean up * wording * turbo frame not needed * fix broadcast / minor tweaks * change change to current user get current org in service * set org with actsastenant * update service tests * test index and create * clean up * assert errors instance variable * proper order * standard
- Loading branch information
Showing
11 changed files
with
205 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CsvImportJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(blob_signed_id, current_user_id) | ||
blob = ActiveStorage::Blob.find_signed(blob_signed_id) | ||
|
||
Organizations::Importers::CsvImportService.new(blob, current_user_id).call | ||
ensure | ||
blob.purge_later | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/views/organizations/staff/external_form_upload/_upload_in_progress.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div id="results" class="d-flex justify-content-center"> | ||
<div class="spinner-border text-primary" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</div> | ||
</div> |
42 changes: 21 additions & 21 deletions
42
app/views/organizations/staff/external_form_upload/_upload_results.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<turbo-frame id="results"> | ||
<% if import.success? %> | ||
<div class="alert alert-success"> | ||
<h5 class="alert-heading" role="alert"><%= t('.success_heading') %></h5> | ||
<p><%= t('.submissions_added', count: import.count) %></p> | ||
</div> | ||
<% else %> | ||
<div class="alert alert-danger"> | ||
<h5 class="alert-heading" role="alert"><%= t('.error_heading', count: import.errors.count) %></h5> | ||
<p><%= t('.submissions_added', count: import.count) %></p> | ||
<%= t('.review_errors', count: import.count) %> | ||
<ul> | ||
<% import.errors.each do |error| %> | ||
<li> | ||
<%= t('.row', number: error[0], message: error[1].message) %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
</turbo-frame> | ||
<%= tag.div id: "results" do %> | ||
<% if import.success? %> | ||
<div class="alert alert-success"> | ||
<h5 class="alert-heading" role="alert"><%= t(".success_heading") %></h5> | ||
<p><%= t(".submissions_added", count: import.count) %></p> | ||
</div> | ||
<% else %> | ||
<div class="alert alert-danger"> | ||
<h5 class="alert-heading" role="alert"><%= t(".error_heading", count: import.errors.count) %></h5> | ||
<p><%= t(".submissions_added", count: import.count) %></p> | ||
<%= t(".review_errors", count: import.count) %> | ||
<ul> | ||
<% import.errors.each do |error| %> | ||
<li> | ||
<%= t(".row", number: error[0], message: error[1].message) %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<% end %> |
3 changes: 3 additions & 0 deletions
3
app/views/organizations/staff/external_form_upload/create.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_stream.replace("flash", partial: "layouts/shared/flash_messages") %> | ||
|
||
<%= turbo_stream.replace("results", partial: "upload_in_progress") %> |
17 changes: 12 additions & 5 deletions
17
app/views/organizations/staff/external_form_upload/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
<%= render DashboardPageComponent.new(crumb: :external_form) do |c| %> | ||
<% c.with_header_title { t('.header') } %> | ||
<% c.with_header_title { t(".header") } %> | ||
<% c.with_body do %> | ||
<section> | ||
<div> | ||
<div> | ||
<p><%= t('.description') %></p> | ||
<p class="fw-bold"><%= t('.csv_header_requirements') %></p> | ||
<%= render "organizations/staff/shared/attachment_form", instance: nil, title: 'Files', url: staff_external_form_upload_index_path, multiple: false, attachment_type: 'files' %> | ||
<p><%= t(".description") %></p> | ||
<p class="fw-bold"><%= t(".csv_header_requirements") %></p> | ||
<%= render "organizations/staff/shared/attachment_form", | ||
instance: nil, | ||
title: "Files", | ||
url: staff_external_form_upload_index_path, | ||
multiple: false, | ||
attachment_type: "files" %> | ||
</div> | ||
</div> | ||
</section> | ||
<%= turbo_stream_from ["csv_import", current_user] %> | ||
<%= tag.div id: "results" %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,55 +3,25 @@ | |
module Organizations | ||
module Staff | ||
class ExternalFormUploadControllerTest < ActionDispatch::IntegrationTest | ||
context "success" do | ||
setup do | ||
file = fixture_file_upload("google_form_sample.csv", "text/csv") | ||
@params = {files: file} | ||
admin = create(:admin) | ||
@adopter = create(:adopter, email: "[email protected]") | ||
@adopter2 = create(:adopter, email: "[email protected]") | ||
sign_in admin | ||
end | ||
|
||
should "Creates new form submission" do | ||
assert_difference "@adopter.person.form_submissions.count" do | ||
post staff_external_form_upload_index_path, params: @params | ||
end | ||
end | ||
|
||
should "It does not create form answers for adopter2" do | ||
assert_no_difference "@adopter2.person.form_submissions.count" do | ||
post staff_external_form_upload_index_path, params: @params | ||
end | ||
end | ||
|
||
should "shows success feedback" do | ||
post staff_external_form_upload_index_path, params: @params, as: :turbo_stream | ||
|
||
assert_response :success | ||
assert_turbo_stream(action: "replace", count: 1) do | ||
assert_select "h5", text: "File successfully scanned" | ||
end | ||
end | ||
setup do | ||
file = fixture_file_upload("google_form_sample.csv", "text/csv") | ||
@params = {files: file} | ||
admin = create(:admin) | ||
sign_in admin | ||
end | ||
|
||
context "error" do | ||
setup do | ||
file = fixture_file_upload("google_form_error_sample.csv", "text/csv") | ||
@params = {files: file} | ||
admin = create(:admin) | ||
create(:adopter, email: "[email protected]") | ||
sign_in admin | ||
end | ||
should "get index" do | ||
get staff_external_form_upload_index_path | ||
assert_response :success | ||
end | ||
|
||
should "shows error feedback" do | ||
should "Creates new form submission" do | ||
assert_enqueued_with(job: CsvImportJob) do | ||
post staff_external_form_upload_index_path, params: @params, as: :turbo_stream | ||
|
||
assert_response :success | ||
assert_turbo_stream(action: "replace", count: 1) do | ||
assert_select "h5", text: "File scanned: 1 error(s) present" | ||
end | ||
end | ||
|
||
assert_response :success | ||
assert_equal "File uploaded for processing", flash[:notice] | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.