From d0c07d6a3dae692bfbb74bc9fd0f14b87a9767ab Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 19 Jul 2024 13:24:23 +0200 Subject: [PATCH] Add create/edit modal for storage locations [SCI-10860]/ --- .../storage_locations_controller.rb | 13 +- .../vue/shared/drag_and_drop_upload.vue | 2 +- .../vue/storage_locations/modals/new_edit.vue | 223 ++++++++++++++++++ .../vue/storage_locations/table.vue | 53 ++++- .../lists/storage_location_serializer.rb | 22 +- app/views/storage_locations/index.html.erb | 3 +- config/locales/en.yml | 27 +++ 7 files changed, 323 insertions(+), 20 deletions(-) create mode 100644 app/javascript/vue/storage_locations/modals/new_edit.vue diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 9d3521058..849b16348 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -18,13 +18,14 @@ class StorageLocationsController < ApplicationController end def update - @storage_location.image.attach(storage_location_params[:signed_blob_id]) if storage_location_params[:signed_blob_id] + @storage_location.image.purge if params[:file_name].blank? + @storage_location.image.attach(params[:signed_blob_id]) if params[:signed_blob_id] @storage_location.update(storage_location_params) if @storage_location.save render json: @storage_location, serializer: Lists::StorageLocationSerializer else - render json: @storage_location.errors, status: :unprocessable_entity + render json: { error: @storage_location.errors.full_messages }, status: :unprocessable_entity end end @@ -33,12 +34,12 @@ class StorageLocationsController < ApplicationController storage_location_params.merge({ team: current_team, created_by: current_user }) ) - @storage_location.image.attach(storage_location_params[:signed_blob_id]) if storage_location_params[:signed_blob_id] + @storage_location.image.attach(params[:signed_blob_id]) if params[:signed_blob_id] if @storage_location.save render json: @storage_location, serializer: Lists::StorageLocationSerializer else - render json: @storage_location.errors, status: :unprocessable_entity + render json: { error: @storage_location.errors.full_messages }, status: :unprocessable_entity end end @@ -63,8 +64,8 @@ class StorageLocationsController < ApplicationController private def storage_location_params - params.permit(:id, :parent_id, :name, :container, :signed_blob_id, :description, - metadata: { dimensions: [], parent_coordinations: [], display_type: :string }) + params.permit(:id, :parent_id, :name, :container, :description, + metadata: [:display_type, dimensions: [], parent_coordinations: []]) end def load_storage_location diff --git a/app/javascript/vue/shared/drag_and_drop_upload.vue b/app/javascript/vue/shared/drag_and_drop_upload.vue index dd2c313bf..2796acb48 100644 --- a/app/javascript/vue/shared/drag_and_drop_upload.vue +++ b/app/javascript/vue/shared/drag_and_drop_upload.vue @@ -19,7 +19,7 @@ {{ i18n.t('repositories.import_records.dragAndDropUpload.importText.firstPart') }} {{ i18n.t('repositories.import_records.dragAndDropUpload.importText.secondPart') }} -
+
{{ supportingText }}
diff --git a/app/javascript/vue/storage_locations/modals/new_edit.vue b/app/javascript/vue/storage_locations/modals/new_edit.vue new file mode 100644 index 000000000..73a376d57 --- /dev/null +++ b/app/javascript/vue/storage_locations/modals/new_edit.vue @@ -0,0 +1,223 @@ + + + diff --git a/app/javascript/vue/storage_locations/table.vue b/app/javascript/vue/storage_locations/table.vue index 53991400e..6a176db8f 100644 --- a/app/javascript/vue/storage_locations/table.vue +++ b/app/javascript/vue/storage_locations/table.vue @@ -6,16 +6,21 @@ :reloadingTable="reloadingTable" :toolbarActions="toolbarActions" :actionsUrl="actionsUrl" - @archive="archive" - @restore="restore" - @delete="deleteRepository" - @update="update" - @duplicate="duplicate" - @export="exportRepositories" - @share="share" - @create="newRepository = true" + @create_location="openCreateLocationModal" + @create_box="openCreateBoxModal" + @edit="edit" @tableReloaded="reloadingTable = false" /> + + + @@ -23,11 +28,13 @@ /* global */ import DataTable from '../shared/datatable/table.vue'; +import EditModal from './modals/new_edit.vue'; export default { name: 'RepositoriesTable', components: { - DataTable + DataTable, + EditModal }, props: { dataSource: { @@ -40,11 +47,17 @@ export default { }, createUrl: { type: String + }, + directUploadUrl: { + type: String } }, data() { return { - reloadingTable: false + reloadingTable: false, + openEditModal: false, + editModalMode: null, + editStorageLocation: null }; }, computed: { @@ -126,14 +139,34 @@ export default { } }, methods: { + openCreateLocationModal() { + this.openEditModal = true; + this.editModalMode = 'location'; + this.editStorageLocation = null; + }, + openCreateBoxModal() { + this.openEditModal = true; + this.editModalMode = 'box'; + this.editStorageLocation = null; + }, + edit(action, params) { + this.openEditModal = true; + this.editModalMode = params[0].container ? 'box' : 'location'; + [this.editStorageLocation] = params; + }, // Renderers nameRenderer(params) { const { name, urls } = params.data; + let boxIcon = ''; + if (params.data.container) { + boxIcon = ''; + } return ` + ${boxIcon} ${name} `; } diff --git a/app/serializers/lists/storage_location_serializer.rb b/app/serializers/lists/storage_location_serializer.rb index ff69c971b..e29d31a02 100644 --- a/app/serializers/lists/storage_location_serializer.rb +++ b/app/serializers/lists/storage_location_serializer.rb @@ -4,12 +4,24 @@ module Lists class StorageLocationSerializer < ActiveModel::Serializer include Rails.application.routes.url_helpers - attributes :id, :code, :name, :container, :description, :owned_by, :created_by, :created_on, :urls + attributes :id, :code, :name, :container, :description, :owned_by, :created_by, + :created_on, :urls, :metadata, :file_name def owned_by object.team.name end + def metadata + { + display_type: object.metadata['display_type'], + dimensions: object.metadata['dimensions'] || [] + } + end + + def file_name + object.image.filename if object.image.attached? + end + def created_by object.created_by.full_name end @@ -19,8 +31,14 @@ module Lists end def urls + show_url = if @object.container + storage_location_path(@object) + else + storage_locations_path(parent_id: object.id) + end { - show: storage_locations_path(parent_id: object.id), + show: show_url, + update: storage_location_path(@object) } end end diff --git a/app/views/storage_locations/index.html.erb b/app/views/storage_locations/index.html.erb index 44b755642..564b05a72 100644 --- a/app/views/storage_locations/index.html.erb +++ b/app/views/storage_locations/index.html.erb @@ -13,7 +13,8 @@ diff --git a/config/locales/en.yml b/config/locales/en.yml index 957a35541..7605be074 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2687,6 +2687,33 @@ en: owned_by: "Owned by" created_on: "Created on" description: "Description" + edit_modal: + title_create_location: "Create new location" + title_create_box: "Create new box" + title_edit_location: "Edit location" + title_edit_box: "Edit box" + description_create_location: "Fill in the fields and create a new location." + description_create_box: "Fill in the fields to create a new box. Defining the box dimensions allows you to control the number of available spaces for placing inventory items." + name_label_location: "Location name" + image_label_location: "Image of location" + name_label_box: "Box name" + image_label_box: "Image of box" + drag_and_drop_supporting_text: ".png or .jpg file" + description_label: "Description" + name_placeholder: "Big freezer" + description_placeholder: "Keep everyone on the same page. You can also use smart annotations." + dimensions_label: "Dimensions (rows x columns)" + no_grid: "No grid" + grid: "Grid" + no_grid_tooltip: "You can assign unlimited items to the “No-grid” box but they do not have assigned position." + success_message: + create_location: "Location %{name} was successfully created." + create_box: "Box %{name} was successfully created." + edit_location: "Location %{name} was successfully updated." + edit_box: "Box %{name} was successfully updated." + errors: + max_length: "is too long (maximum is %{max_length} characters)" + libraries: manange_modal_column_index: title: "Manage columns"