mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-01 04:32:16 +08:00
Error is displayed and import is prevented in case repository name column is not mapped, when importing repository items from file. [SCI-1402]
This commit is contained in:
parent
d726c121bc
commit
f847b44067
4 changed files with 35 additions and 10 deletions
|
@ -47,6 +47,7 @@
|
|||
|
||||
// Populate the errors container
|
||||
$('#import-errors-container').html(data.responseJSON.html);
|
||||
animateSpinner(null, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -226,18 +226,33 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def import_records
|
||||
import_records = repostiory_import_actions
|
||||
status = import_records.import!
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if status[:status] == :ok
|
||||
flash[:success] = t('repositories.import_records.success_flash',
|
||||
number_of_rows: status[:nr_of_added])
|
||||
render json: {}, status: :ok
|
||||
# Check if there exist mapping for repository record (it's mandatory)
|
||||
if params[:mappings].value?('-1')
|
||||
import_records = repostiory_import_actions
|
||||
status = import_records.import!
|
||||
|
||||
if status[:status] == :ok
|
||||
flash[:success] = t('repositories.import_records.success_flash',
|
||||
number_of_rows: status[:nr_of_added])
|
||||
render json: {}, status: :ok
|
||||
else
|
||||
flash[:alert] = t('repositories.import_records.error_flash',
|
||||
message: status[:errors])
|
||||
render json: {}, status: :unprocessable_entity
|
||||
end
|
||||
else
|
||||
flash[:alert] = t('repositories.import_records.error_flash',
|
||||
message: status[:errors])
|
||||
render json: {}, status: :unprocessable_entity
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'shared/flash_errors.html.erb',
|
||||
locals: { error_title: t('repositories.import_records'\
|
||||
'.error_message.errors_list_title'),
|
||||
error: t('repositories.import_records.error_message'\
|
||||
'.no_repository_name') }
|
||||
)
|
||||
},
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
app/views/shared/_flash_errors.html.erb
Normal file
7
app/views/shared/_flash_errors.html.erb
Normal file
|
@ -0,0 +1,7 @@
|
|||
<% if error.present? %>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<div><%= error_title %></div>
|
||||
<br>
|
||||
<%= error %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -899,6 +899,8 @@ en:
|
|||
no_data_to_parse: "There's nothing to be parsed."
|
||||
no_column_name: "Name column is required!"
|
||||
duplicated_values: "Two or more columns have the same mapping."
|
||||
errors_list_title: "Items were not imported because one or more errors were found:"
|
||||
no_repository_name: "Item name is required!"
|
||||
edit_record: "Edit"
|
||||
delete_record: "Delete"
|
||||
save_record: "Save"
|
||||
|
@ -1083,7 +1085,7 @@ en:
|
|||
empty_file: "You've selected empty file. There's not much to import."
|
||||
temp_file_failure: "We couldn't create temporary file. Please contact administrator."
|
||||
no_file_selected: "You didn't select any file."
|
||||
errors_list_title: "Samples were not imported because one or more errors was found:"
|
||||
errors_list_title: "Samples were not imported because one or more errors were found:"
|
||||
list_row: "Row %{row}"
|
||||
list_error: "%{key}: %{val}"
|
||||
import_samples:
|
||||
|
|
Loading…
Reference in a new issue