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:
Martin Artnik 2024-10-07 11:54:18 +02:00 committed by GitHub
commit 122f389629
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 8 deletions

View file

@ -123,8 +123,17 @@ class StorageLocationsController < ApplicationController
end
def tree
records = StorageLocation.viewable_by_user(current_user, current_team).where(parent: nil, container: [false, params[:container] == 'true'])
render json: storage_locations_recursive_builder(records)
records = StorageLocation.viewable_by_user(current_user, current_team)
.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
def available_positions

View file

@ -25,9 +25,12 @@
</div>
</div>
<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"
@click="selectStorageLocation(null)"
:class="{'!bg-sn-super-light-blue': selectedStorageLocationId == null}">
<div class="p-2 flex items-center gap-2 "
@click="selectStorageLocation(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>
{{ i18n.t('storage_locations.index.move_modal.search_header') }}
</div>
@ -63,11 +66,15 @@ export default {
selectedObject: Array,
moveToUrl: String
},
created() {
this.teamId = this.selectedObject.team_id;
},
mixins: [modalMixin, MoveTreeMixin],
data() {
return {
selectedStorageLocationId: null,
storageLocationsTree: [],
teamId: null,
query: '',
moveMode: 'locations'
};

View file

@ -6,14 +6,19 @@ import {
export default {
mounted() {
axios.get(this.storageLocationsTreeUrl).then((response) => {
this.storageLocationsTree = response.data;
axios.get(this.storageLocationsTreeUrl, { params: { team_id: this.teamId } }).then((response) => {
this.storageLocationsTree = response.data.locations;
this.movableToRoot = response.data.movable_to_root;
if (!this.movableToRoot) {
this.selectedStorageLocationId = -1;
}
this.dataLoaded = true;
});
},
data() {
return {
selectedStorageLocationId: null,
movableToRoot: false,
storageLocationsTree: [],
query: '',
dataLoaded: false
@ -46,6 +51,10 @@ export default {
}).filter(Boolean);
},
selectStorageLocation(storageLocationId) {
if (!this.movableToRoot && storageLocationId === null) {
return;
}
this.selectedStorageLocationId = storageLocationId;
}
}

View file

@ -21,6 +21,7 @@ class StorageLocation < ApplicationRecord
has_many :repository_rows, through: :storage_location_repository_rows
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
validate :parent_same_team, if: -> { parent.present? }
validate :parent_validation, if: -> { parent.present? }
validate :no_grid_options, if: -> { !container }
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']
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
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if !with_grid? && metadata['dimensions']
end

View file

@ -9,7 +9,7 @@ module Lists
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
: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
object['team_name']

View file

@ -265,6 +265,7 @@ en:
not_uniq_repository_row: 'Inventory item already exists'
attributes:
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"
metadata:
invalid: 'Invalid metadata'