Merge pull request #7776 from aignatov-bio/ai-sci-10927-add-storage-locations-filter-search

Add filters to storage locations [SCI-10927]
This commit is contained in:
aignatov-bio 2024-08-02 14:04:33 +02:00 committed by GitHub
commit 838bce9ac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 2 deletions

View file

@ -6,6 +6,7 @@
:reloadingTable="reloadingTable" :reloadingTable="reloadingTable"
:toolbarActions="toolbarActions" :toolbarActions="toolbarActions"
:actionsUrl="actionsUrl" :actionsUrl="actionsUrl"
:filters="filters"
@create_location="openCreateLocationModal" @create_location="openCreateLocationModal"
@create_container="openCreateContainerModal" @create_container="openCreateContainerModal"
@edit="edit" @edit="edit"
@ -158,6 +159,21 @@ export default {
left, left,
right: [] right: []
}; };
},
filters() {
const filters = [
{
key: 'query',
type: 'Text'
},
{
key: 'search_tree',
type: 'Checkbox',
label: this.i18n.t('storage_locations.index.filters_modal.search_tree')
}
];
return filters;
} }
}, },
methods: { methods: {

View file

@ -5,13 +5,26 @@ module Lists
def initialize(team, params) def initialize(team, params)
@team = team @team = team
@parent_id = params[:parent_id] @parent_id = params[:parent_id]
@filters = params[:filters] || {}
@params = params @params = params
end end
def fetch_records def fetch_records
@records = @team.storage_locations.where(parent_id: @parent_id) @records = @team.storage_locations
end end
def filter_records; end def filter_records
if @filters[:search_tree].present?
if @parent_id.present?
storage_location = @records.find_by(id: @parent_id)
@records = @records.where(id: StorageLocation.inner_storage_locations(@team, storage_location))
end
else
@records = @records.where(parent_id: @parent_id)
end
@records = @records.where('LOWER(name) ILIKE ?', "%#{@filters[:query].downcase}%") if @filters[:query].present?
@records = @records.where('LOWER(name) ILIKE ?', "%#{@params[:search].downcase}%") if @params[:search].present?
end
end end
end end

View file

@ -2726,6 +2726,8 @@ en:
owned_by: "Owned by" owned_by: "Owned by"
created_on: "Created on" created_on: "Created on"
description: "Description" description: "Description"
filters_modal:
search_tree: "Look inside locations"
edit_modal: edit_modal:
title_create_location: "Create new location" title_create_location: "Create new location"
title_create_container: "Create new box" title_create_container: "Create new box"