From 83d9c88546283f17a798c107a07d4fc2b5983f36 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 2 Aug 2024 13:59:01 +0200 Subject: [PATCH] Add filters to storage locations [SCI-10927] --- app/javascript/vue/storage_locations/table.vue | 16 ++++++++++++++++ app/services/lists/storage_locations_service.rb | 17 +++++++++++++++-- config/locales/en.yml | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/javascript/vue/storage_locations/table.vue b/app/javascript/vue/storage_locations/table.vue index 6cbc21ee4..ae5221de8 100644 --- a/app/javascript/vue/storage_locations/table.vue +++ b/app/javascript/vue/storage_locations/table.vue @@ -6,6 +6,7 @@ :reloadingTable="reloadingTable" :toolbarActions="toolbarActions" :actionsUrl="actionsUrl" + :filters="filters" @create_location="openCreateLocationModal" @create_container="openCreateContainerModal" @edit="edit" @@ -158,6 +159,21 @@ export default { left, 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: { diff --git a/app/services/lists/storage_locations_service.rb b/app/services/lists/storage_locations_service.rb index 57e4a773e..664688f32 100644 --- a/app/services/lists/storage_locations_service.rb +++ b/app/services/lists/storage_locations_service.rb @@ -5,13 +5,26 @@ module Lists def initialize(team, params) @team = team @parent_id = params[:parent_id] + @filters = params[:filters] || {} @params = params end def fetch_records - @records = @team.storage_locations.where(parent_id: @parent_id) + @records = @team.storage_locations 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index b7d90ed6e..484ad665e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2726,6 +2726,8 @@ en: owned_by: "Owned by" created_on: "Created on" description: "Description" + filters_modal: + search_tree: "Look inside locations" edit_modal: title_create_location: "Create new location" title_create_container: "Create new box"