diff --git a/app/assets/javascripts/repositories/import/records_importer.js b/app/assets/javascripts/repositories/import/records_importer.js index d4d42a142..8ccbab01e 100644 --- a/app/assets/javascripts/repositories/import/records_importer.js +++ b/app/assets/javascripts/repositories/import/records_importer.js @@ -47,6 +47,7 @@ // Populate the errors container $('#import-errors-container').html(data.responseJSON.html); + animateSpinner(null, false); } }); } diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 80ad95773..ca41b2ed4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/views/shared/_flash_errors.html.erb b/app/views/shared/_flash_errors.html.erb new file mode 100644 index 000000000..cf0b290ca --- /dev/null +++ b/app/views/shared/_flash_errors.html.erb @@ -0,0 +1,7 @@ +<% if error.present? %> +