mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-24 12:46:39 +08:00
Fix validation for storage locations metadata [SCI-11116]
This commit is contained in:
parent
8552cd9600
commit
55f9dd4964
3 changed files with 29 additions and 2 deletions
|
|
@ -186,8 +186,23 @@ export default {
|
||||||
// Smart annotation fix
|
// Smart annotation fix
|
||||||
this.object.description = $(this.$refs.description).val();
|
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) {
|
if (this.object.code) {
|
||||||
axios.put(this.object.urls.update, this.object)
|
axios.put(this.object.urls.update, params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$emit('tableReloaded');
|
this.$emit('tableReloaded');
|
||||||
HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.edit_${this.editModalMode}`, { name: this.object.name }), 'success');
|
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');
|
HelperModule.flashAlertMsg(error.response.data.error, 'danger');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
axios.post(this.createUrl, this.object)
|
axios.post(this.createUrl, params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$emit('tableReloaded');
|
this.$emit('tableReloaded');
|
||||||
HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.create_${this.editModalMode}`, { name: this.object.name }), 'success');
|
HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.create_${this.editModalMode}`, { name: this.object.name }), 'success');
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ class StorageLocation < ApplicationRecord
|
||||||
|
|
||||||
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
validate :parent_validation, if: -> { parent.present? }
|
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|
|
scope :readable_by_user, (lambda do |user, team = user.current_team|
|
||||||
next StorageLocation.none unless team.permission_granted?(user, TeamPermissions::STORAGE_LOCATIONS_READ)
|
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'))
|
errors.add(:parent, I18n.t('activerecord.errors.models.project_folder.attributes.parent_storage_location_child'))
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,8 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
parent_storage_location: "Storage location cannot be parent to itself"
|
parent_storage_location: "Storage location cannot be parent to itself"
|
||||||
parent_storage_location_child: "Storage location cannot be moved to it's child"
|
parent_storage_location_child: "Storage location cannot be moved to it's child"
|
||||||
|
metadata:
|
||||||
|
invalid: 'Invalid metadata'
|
||||||
storage:
|
storage:
|
||||||
limit_reached: "Storage limit has been reached."
|
limit_reached: "Storage limit has been reached."
|
||||||
helpers:
|
helpers:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue