From f07b4a80651d23a4a8e1531305b569c1d892c5f3 Mon Sep 17 00:00:00 2001 From: Gregor Lasnibat Date: Tue, 9 Apr 2024 14:18:41 +0200 Subject: [PATCH] (dev) Create 'update inventory' modal first step [SCI-10578] --- app/controllers/repositories_controller.rb | 42 +++-- .../packs/vue/design_system/modals.js | 4 +- .../vue/repositories/modals/import.vue | 82 +++++++- .../repositories/modals/import/first_step.vue | 175 ++++++++++++++++++ .../vue/shared/drag_and_drop_upload.vue | 125 +++++++++++++ app/javascript/vue/shared/info_component.vue | 8 +- app/javascript/vue/shared/info_modal.vue | 18 +- app/javascript/vue/shared/modal_mixin.js | 4 +- app/serializers/repository_serializer.rb | 13 ++ app/views/design_elements/_modals.html.erb | 9 +- config/locales/en.yml | 28 +++ 11 files changed, 462 insertions(+), 46 deletions(-) create mode 100644 app/javascript/vue/repositories/modals/import/first_step.vue create mode 100644 app/javascript/vue/shared/drag_and_drop_upload.vue create mode 100644 app/serializers/repository_serializer.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5c216e4cc..059767942 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -53,13 +53,21 @@ class RepositoriesController < ApplicationController end def show - current_team_switch(@repository.team) unless @repository.shared_with?(current_team) - @display_edit_button = can_create_repository_rows?(@repository) - @display_delete_button = can_delete_repository_rows?(@repository) - @display_duplicate_button = can_create_repository_rows?(@repository) - @snapshot_provisioning = @repository.repository_snapshots.provisioning.any? + respond_to do |format| + format.html do + current_team_switch(@repository.team) unless @repository.shared_with?(current_team) + @display_edit_button = can_create_repository_rows?(@repository) + @display_delete_button = can_delete_repository_rows?(@repository) + @display_duplicate_button = can_create_repository_rows?(@repository) + @snapshot_provisioning = @repository.repository_snapshots.provisioning.any? - @busy_printer = LabelPrinter.where.not(current_print_job_ids: []).first + @busy_printer = LabelPrinter.where.not(current_print_job_ids: []).first + end + format.json do + # render serialized repository json + render json: @repository, serializer: RepositorySerializer + end + end end def table_toolbar @@ -281,13 +289,9 @@ class RepositoriesController < ApplicationController session: session ) if parsed_file.too_large? - repository_response(t('general.file.size_exceeded', - file_size: Rails.configuration.x.file_max_size_mb)) + return render json: { error: t('general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb) }, status: :unprocessable_entity elsif parsed_file.has_too_many_rows? - repository_response( - t('repositories.import_records.error_message.items_limit', - items_size: Constants::IMPORT_REPOSITORY_ITEMS_LIMIT) - ) + return render json: { error: t('repositories.import_records.error_message.items_limit', items_size: Constants::IMPORT_REPOSITORY_ITEMS_LIMIT) }, status: :unprocessable_entity else sheet = SpreadsheetParser.open_spreadsheet(import_params[:file]) duplicate_ids = SpreadsheetParser.duplicate_ids(sheet) @@ -298,22 +302,22 @@ class RepositoriesController < ApplicationController @import_data = parsed_file.data if @import_data.header.blank? || @import_data.columns.blank? - return repository_response(t('repositories.parse_sheet.errors.empty_file')) + return render json: { error: t('repositories.parse_sheet.errors.empty_file') }, status: :unprocessable_entity end if (@temp_file = parsed_file.generate_temp_file) render json: { - html: render_to_string(partial: 'repositories/parse_records_modal', formats: :html) + import_data: @import_data, + temp_file: @temp_file } else - repository_response(t('repositories.parse_sheet.errors.temp_file_failure')) + return render json: { error: t('repositories.parse_sheet.errors.temp_file_failure') }, status: :unprocessable_entity end end rescue ArgumentError, CSV::MalformedCSVError - repository_response(t('repositories.parse_sheet.errors.invalid_file', - encoding: ''.encoding)) + return render json: { error: t('repositories.parse_sheet.errors.invalid_file', encoding: ''.encoding) }, status: :unprocessable_entity rescue TypeError - repository_response(t('repositories.parse_sheet.errors.invalid_extension')) + return render json: { error: t('repositories.parse_sheet.errors.invalid_extension') }, status: :unprocessable_entity end end @@ -326,7 +330,7 @@ class RepositoriesController < ApplicationController should_overwrite_with_empty_cells = params[:overwrite_with_empty_cells] # Check if there exist mapping for repository record (it's mandatory) - if import_params[:mappings].value?('-1') + if import_params[:mappings].present? && import_params[:mappings].value?('-1') import_records = repostiory_import_actions status = import_records.import!(can_edit_existing_items, should_overwrite_with_empty_cells) diff --git a/app/javascript/packs/vue/design_system/modals.js b/app/javascript/packs/vue/design_system/modals.js index 8baabddf7..7c98aba1f 100644 --- a/app/javascript/packs/vue/design_system/modals.js +++ b/app/javascript/packs/vue/design_system/modals.js @@ -54,9 +54,7 @@ const app = createApp({ // Info modal infoParams: { title: 'Guide for updating the inventory', - modalTitle: 'Update inventory', - helpText: 'Help', - steps: [ + elements: [ { id: 'el1', icon: 'sn-icon-export', diff --git a/app/javascript/vue/repositories/modals/import.vue b/app/javascript/vue/repositories/modals/import.vue index c52cb71d6..794e627ad 100644 --- a/app/javascript/vue/repositories/modals/import.vue +++ b/app/javascript/vue/repositories/modals/import.vue @@ -1,26 +1,91 @@ diff --git a/app/javascript/vue/shared/drag_and_drop_upload.vue b/app/javascript/vue/shared/drag_and_drop_upload.vue new file mode 100644 index 000000000..299eac2e5 --- /dev/null +++ b/app/javascript/vue/shared/drag_and_drop_upload.vue @@ -0,0 +1,125 @@ + + + diff --git a/app/javascript/vue/shared/info_component.vue b/app/javascript/vue/shared/info_component.vue index 771f63ff8..4a6199307 100644 --- a/app/javascript/vue/shared/info_component.vue +++ b/app/javascript/vue/shared/info_component.vue @@ -1,13 +1,13 @@