mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-12 16:14:58 +08:00
Merge pull request #7931 from aignatov-bio/ai-sci-11149-fix-moving-for-shared-locations
Fix moving action for shared locations [SCI-11149]
This commit is contained in:
commit
122f389629
6 changed files with 39 additions and 8 deletions
|
@ -123,8 +123,17 @@ class StorageLocationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tree
|
def tree
|
||||||
records = StorageLocation.viewable_by_user(current_user, current_team).where(parent: nil, container: [false, params[:container] == 'true'])
|
records = StorageLocation.viewable_by_user(current_user, current_team)
|
||||||
render json: storage_locations_recursive_builder(records)
|
.where(
|
||||||
|
parent: nil,
|
||||||
|
container: [false, params[:container] == 'true']
|
||||||
|
)
|
||||||
|
records = records.where(team_id: params[:team_id]) if params[:team_id]
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
locations: storage_locations_recursive_builder(records),
|
||||||
|
movable_to_root: params[:team_id] && current_team.id == params[:team_id].to_i
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_positions
|
def available_positions
|
||||||
|
|
|
@ -25,9 +25,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="max-h-80 overflow-y-auto">
|
<div class="max-h-80 overflow-y-auto">
|
||||||
<div class="p-2 flex items-center gap-2 cursor-pointer text-sn-blue hover:bg-sn-super-light-grey"
|
<div class="p-2 flex items-center gap-2 "
|
||||||
@click="selectStorageLocation(null)"
|
@click="selectStorageLocation(null)"
|
||||||
:class="{'!bg-sn-super-light-blue': selectedStorageLocationId == null}">
|
:class="{
|
||||||
|
'!bg-sn-super-light-blue': selectedStorageLocationId == null,
|
||||||
|
'cursor-pointer text-sn-blue hover:bg-sn-super-light-grey': movableToRoot
|
||||||
|
}">
|
||||||
<i class="sn-icon sn-icon-projects"></i>
|
<i class="sn-icon sn-icon-projects"></i>
|
||||||
{{ i18n.t('storage_locations.index.move_modal.search_header') }}
|
{{ i18n.t('storage_locations.index.move_modal.search_header') }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,11 +66,15 @@ export default {
|
||||||
selectedObject: Array,
|
selectedObject: Array,
|
||||||
moveToUrl: String
|
moveToUrl: String
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.teamId = this.selectedObject.team_id;
|
||||||
|
},
|
||||||
mixins: [modalMixin, MoveTreeMixin],
|
mixins: [modalMixin, MoveTreeMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedStorageLocationId: null,
|
selectedStorageLocationId: null,
|
||||||
storageLocationsTree: [],
|
storageLocationsTree: [],
|
||||||
|
teamId: null,
|
||||||
query: '',
|
query: '',
|
||||||
moveMode: 'locations'
|
moveMode: 'locations'
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,14 +6,19 @@ import {
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
axios.get(this.storageLocationsTreeUrl).then((response) => {
|
axios.get(this.storageLocationsTreeUrl, { params: { team_id: this.teamId } }).then((response) => {
|
||||||
this.storageLocationsTree = response.data;
|
this.storageLocationsTree = response.data.locations;
|
||||||
|
this.movableToRoot = response.data.movable_to_root;
|
||||||
|
if (!this.movableToRoot) {
|
||||||
|
this.selectedStorageLocationId = -1;
|
||||||
|
}
|
||||||
this.dataLoaded = true;
|
this.dataLoaded = true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedStorageLocationId: null,
|
selectedStorageLocationId: null,
|
||||||
|
movableToRoot: false,
|
||||||
storageLocationsTree: [],
|
storageLocationsTree: [],
|
||||||
query: '',
|
query: '',
|
||||||
dataLoaded: false
|
dataLoaded: false
|
||||||
|
@ -46,6 +51,10 @@ export default {
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
},
|
},
|
||||||
selectStorageLocation(storageLocationId) {
|
selectStorageLocation(storageLocationId) {
|
||||||
|
if (!this.movableToRoot && storageLocationId === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selectedStorageLocationId = storageLocationId;
|
this.selectedStorageLocationId = storageLocationId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ class StorageLocation < ApplicationRecord
|
||||||
has_many :repository_rows, through: :storage_location_repository_rows
|
has_many :repository_rows, through: :storage_location_repository_rows
|
||||||
|
|
||||||
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
|
validate :parent_same_team, if: -> { parent.present? }
|
||||||
validate :parent_validation, if: -> { parent.present? }
|
validate :parent_validation, if: -> { parent.present? }
|
||||||
validate :no_grid_options, if: -> { !container }
|
validate :no_grid_options, if: -> { !container }
|
||||||
validate :no_dimensions, if: -> { !with_grid? }
|
validate :no_dimensions, if: -> { !with_grid? }
|
||||||
|
@ -203,6 +204,10 @@ class StorageLocation < ApplicationRecord
|
||||||
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if metadata['display_type'] || metadata['dimensions']
|
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if metadata['display_type'] || metadata['dimensions']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parent_same_team
|
||||||
|
errors.add(:parent, I18n.t('activerecord.errors.models.storage_location.attributes.parent_storage_location_team')) if parent.team != team
|
||||||
|
end
|
||||||
|
|
||||||
def no_dimensions
|
def no_dimensions
|
||||||
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if !with_grid? && metadata['dimensions']
|
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if !with_grid? && metadata['dimensions']
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Lists
|
||||||
|
|
||||||
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
|
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
|
||||||
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty,
|
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty,
|
||||||
:img_url, :sa_description, :name_hash
|
:img_url, :sa_description, :name_hash, :team_id
|
||||||
|
|
||||||
def owned_by
|
def owned_by
|
||||||
object['team_name']
|
object['team_name']
|
||||||
|
|
|
@ -265,6 +265,7 @@ en:
|
||||||
not_uniq_repository_row: 'Inventory item already exists'
|
not_uniq_repository_row: 'Inventory item already exists'
|
||||||
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_team: "Parent storage location and storage location should belongs to the same team"
|
||||||
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:
|
metadata:
|
||||||
invalid: 'Invalid metadata'
|
invalid: 'Invalid metadata'
|
||||||
|
|
Loading…
Add table
Reference in a new issue