From 1c3cc71174b4a8f7029b0423ad2ea628505e8d54 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 22 Jul 2024 12:12:47 +0200 Subject: [PATCH] Add duplicate action to locations [SCI-10862] --- .../storage_locations_controller.rb | 11 ++++- .../vue/storage_locations/table.vue | 14 ++++++- app/models/concerns/cloneable.rb | 18 +++++--- app/models/storage_location.rb | 41 +++++++++++++++++++ .../toolbars/storage_locations_service.rb | 2 +- config/locales/en.yml | 2 + config/routes.rb | 2 +- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 849b16348..8440ed866 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StorageLocationsController < ApplicationController - before_action :load_storage_location, only: %i(update destroy) + before_action :load_storage_location, only: %i(update destroy duplicate) before_action :check_read_permissions, only: :index before_action :check_manage_permissions, except: :index before_action :set_breadcrumbs_items, only: :index @@ -51,6 +51,15 @@ class StorageLocationsController < ApplicationController end end + def duplicate + new_storage_location = @storage_location.duplicate! + if new_storage_location + render json: new_storage_location, serializer: Lists::StorageLocationSerializer + else + render json: { errors: :failed }, status: :unprocessable_entity + end + end + def actions_toolbar render json: { actions: diff --git a/app/javascript/vue/storage_locations/table.vue b/app/javascript/vue/storage_locations/table.vue index 6a176db8f..13b6310ab 100644 --- a/app/javascript/vue/storage_locations/table.vue +++ b/app/javascript/vue/storage_locations/table.vue @@ -9,6 +9,7 @@ @create_location="openCreateLocationModal" @create_box="openCreateBoxModal" @edit="edit" + @duplicate="duplicate" @tableReloaded="reloadingTable = false" /> @@ -25,8 +26,9 @@