diff --git a/app/javascript/vue/storage_locations/modals/new_edit.vue b/app/javascript/vue/storage_locations/modals/new_edit.vue index 795acbeca..e94a83065 100644 --- a/app/javascript/vue/storage_locations/modals/new_edit.vue +++ b/app/javascript/vue/storage_locations/modals/new_edit.vue @@ -186,8 +186,23 @@ export default { // Smart annotation fix this.object.description = $(this.$refs.description).val(); + const params = { + name: this.object.name, + description: this.object.description, + signed_blob_id: this.object.signed_blob_id, + container: this.object.container + }; + + if (this.object.container) { + params.metadata = this.object.metadata; + + if (params.metadata.display_type === 'no_grid') { + delete params.metadata.dimensions; + } + } + if (this.object.code) { - axios.put(this.object.urls.update, this.object) + axios.put(this.object.urls.update, params) .then(() => { this.$emit('tableReloaded'); HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.edit_${this.editModalMode}`, { name: this.object.name }), 'success'); @@ -196,7 +211,7 @@ export default { HelperModule.flashAlertMsg(error.response.data.error, 'danger'); }); } else { - axios.post(this.createUrl, this.object) + axios.post(this.createUrl, params) .then(() => { this.$emit('tableReloaded'); HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.create_${this.editModalMode}`, { name: this.object.name }), 'success'); diff --git a/app/models/storage_location.rb b/app/models/storage_location.rb index 41fce90fc..e4c3366ed 100644 --- a/app/models/storage_location.rb +++ b/app/models/storage_location.rb @@ -21,6 +21,8 @@ class StorageLocation < ApplicationRecord validates :name, length: { maximum: Constants::NAME_MAX_LENGTH } validate :parent_validation, if: -> { parent.present? } + validate :no_grid_options, if: -> { !container } + validate :no_dimensions, if: -> { !with_grid? } scope :readable_by_user, (lambda do |user, team = user.current_team| next StorageLocation.none unless team.permission_granted?(user, TeamPermissions::STORAGE_LOCATIONS_READ) @@ -193,4 +195,12 @@ class StorageLocation < ApplicationRecord errors.add(:parent, I18n.t('activerecord.errors.models.project_folder.attributes.parent_storage_location_child')) end end + + def no_grid_options + errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if metadata['display_type'] || metadata['dimensions'] + end + + def no_dimensions + errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if !with_grid? && metadata['dimensions'] + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 5b5ec225a..2b7d0a83f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -268,6 +268,8 @@ en: attributes: parent_storage_location: "Storage location cannot be parent to itself" parent_storage_location_child: "Storage location cannot be moved to it's child" + metadata: + invalid: 'Invalid metadata' storage: limit_reached: "Storage limit has been reached." helpers: