From ba1162c4539e9e18963cca6fc288236def1ce5a4 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Oct 2024 11:02:18 +0200 Subject: [PATCH 01/28] Improve storage locations search [SCI-11129] --- app/models/storage_location.rb | 1 + .../lists/storage_locations_service.rb | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/models/storage_location.rb b/app/models/storage_location.rb index e4c3366ed..03fb0a0b3 100644 --- a/app/models/storage_location.rb +++ b/app/models/storage_location.rb @@ -6,6 +6,7 @@ class StorageLocation < ApplicationRecord ID_PREFIX = 'SL' include PrefixedIdModel include Shareable + include SearchableModel default_scope -> { kept } diff --git a/app/services/lists/storage_locations_service.rb b/app/services/lists/storage_locations_service.rb index ca1c6b77b..fb79c91ef 100644 --- a/app/services/lists/storage_locations_service.rb +++ b/app/services/lists/storage_locations_service.rb @@ -44,8 +44,25 @@ module Lists @records = @records.where(parent_id: @parent_id) end - @records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@filters[:query].downcase}%") if @filters[:query].present? - @records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@params[:search].downcase}%") if @params[:search].present? + if @filters[:query].present? + @records = @records.where_attributes_like( + [ + 'storage_locations.name', + 'storage_locations.description', + StorageLocation::PREFIXED_ID_SQL + ], @filters[:query] + ) + end + + if @params[:search].present? + @records = @records.where_attributes_like( + [ + 'storage_locations.name', + 'storage_locations.description', + StorageLocation::PREFIXED_ID_SQL + ], @params[:search] + ) + end end private From f03f22fd8a37a56fa051f371c1d92d464ffe6348 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Oct 2024 11:48:25 +0200 Subject: [PATCH 02/28] Hide archived rows and repositories in storage locations assignment modal [SCI-11131] --- app/controllers/repositories_controller.rb | 9 ++++++--- .../vue/storage_locations/modals/assign/row_selector.vue | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 65a831092..5f41d3a0a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -44,11 +44,12 @@ class RepositoriesController < ApplicationController end def list - results = @repositories + results = @repositories.select(:id, :name, 'LOWER(repositories.name)') results = results.name_like(params[:query]) if params[:query].present? results = results.joins(:repository_rows).distinct if params[:non_empty].present? + results = results.active if params[:active].present? - render json: { data: results.map { |r| [r.id, r.name] } } + render json: { data: results.order('LOWER(repositories.name) asc').map { |r| [r.id, r.name] } } end def rows_list @@ -59,7 +60,9 @@ class RepositoriesController < ApplicationController params[:query] ) end - render json: { data: results.map { |r| [r.id, r.name] } } + results = results.active if params[:active].present? + + render json: { data: results.order('LOWER(repository_rows.name) asc').map { |r| [r.id, r.name] } } end def sidebar diff --git a/app/javascript/vue/storage_locations/modals/assign/row_selector.vue b/app/javascript/vue/storage_locations/modals/assign/row_selector.vue index ac26f07ea..2ae417099 100644 --- a/app/javascript/vue/storage_locations/modals/assign/row_selector.vue +++ b/app/javascript/vue/storage_locations/modals/assign/row_selector.vue @@ -48,14 +48,14 @@ export default { }, computed: { repositoriesUrl() { - return list_team_repositories_path(this.teamId, { non_empty: true }); + return list_team_repositories_path(this.teamId, { non_empty: true, active: true }); }, rowsUrl() { if (!this.selectedRepository) { return null; } - return rows_list_team_repositories_path(this.teamId); + return rows_list_team_repositories_path(this.teamId, { active: true }); } }, data() { From c760b215deeaa447ea00a55fedfed136eb07b61d Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Oct 2024 12:14:18 +0200 Subject: [PATCH 03/28] Storage locations fix name ordering and move modal ordering [SCI-11133] --- app/controllers/storage_locations_controller.rb | 2 +- app/services/lists/storage_locations_service.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 965d766a0..d9f81cba5 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -253,7 +253,7 @@ class StorageLocationsController < ApplicationController end def storage_locations_recursive_builder(storage_locations) - storage_locations.map do |storage_location| + storage_locations.order('LOWER(storage_locations.name) ASC').map do |storage_location| { storage_location: storage_location, can_manage: (can_manage_storage_location?(storage_location) unless storage_location.parent_id), diff --git a/app/services/lists/storage_locations_service.rb b/app/services/lists/storage_locations_service.rb index ca1c6b77b..a1300ee09 100644 --- a/app/services/lists/storage_locations_service.rb +++ b/app/services/lists/storage_locations_service.rb @@ -60,9 +60,9 @@ module Lists @records = @records.order(id: :asc) when 'code_DESC' @records = @records.order(id: :desc) - when 'name_ASC' + when 'name_hash_ASC' @records = @records.order(name: :asc) - when 'name_DESC' + when 'name_hash_DESC' @records = @records.order(name: :desc) when 'sub_location_count_ASC' @records = @records.order(sub_location_count: :asc) From 714b7e85ea17a64084b1f65e776f2604acc89188 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Oct 2024 12:43:47 +0200 Subject: [PATCH 04/28] Change create by on location duplicate [SCI-11136] --- app/controllers/storage_locations_controller.rb | 2 +- app/models/storage_location.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 965d766a0..0af0e74bf 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -86,7 +86,7 @@ class StorageLocationsController < ApplicationController def duplicate ActiveRecord::Base.transaction do - new_storage_location = @storage_location.duplicate! + new_storage_location = @storage_location.duplicate!(current_user) if new_storage_location @storage_location = new_storage_location log_activity('storage_location_created') diff --git a/app/models/storage_location.rb b/app/models/storage_location.rb index e4c3366ed..0538d39a6 100644 --- a/app/models/storage_location.rb +++ b/app/models/storage_location.rb @@ -59,13 +59,14 @@ class StorageLocation < ApplicationRecord storage_location_repository_rows.count.zero? end - def duplicate! + def duplicate!(user) ActiveRecord::Base.transaction do new_storage_location = dup new_storage_location.name = next_clone_name + new_storage_location.created_by = user new_storage_location.save! copy_image(self, new_storage_location) - recursive_duplicate(id, new_storage_location.id) + recursive_duplicate(id, new_storage_location.id, user) new_storage_location rescue ActiveRecord::RecordInvalid false @@ -141,13 +142,14 @@ class StorageLocation < ApplicationRecord private - def recursive_duplicate(old_parent_id = nil, new_parent_id = nil) + def recursive_duplicate(old_parent_id = nil, new_parent_id = nil, user = nil) StorageLocation.where(parent_id: old_parent_id).find_each do |child| new_child = child.dup new_child.parent_id = new_parent_id + new_child.created_by = user new_child.save! copy_image(child, new_child) - recursive_duplicate(child.id, new_child.id) + recursive_duplicate(child.id, new_child.id, user) end end From 94c478ab25271c7969b3a9eeefd6d156170674e6 Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 3 Oct 2024 07:58:53 +0200 Subject: [PATCH 05/28] Add counter cache for counting repository row on repository [SCI-11114] --- app/models/repository_row.rb | 2 +- app/serializers/lists/repository_serializer.rb | 2 +- app/services/lists/repositories_service.rb | 4 +--- ...241001163211_add_counter_cache_repository_row.rb | 13 +++++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20241001163211_add_counter_cache_repository_row.rb diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index f0c4c72a9..076bc9c28 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -10,7 +10,7 @@ class RepositoryRow < ApplicationRecord ID_PREFIX = 'IT' include PrefixedIdModel - belongs_to :repository, class_name: 'RepositoryBase' + belongs_to :repository, class_name: 'RepositoryBase', counter_cache: :repository_rows_count delegate :team, to: :repository belongs_to :parent, class_name: 'RepositoryRow', optional: true belongs_to :created_by, class_name: 'User' diff --git a/app/serializers/lists/repository_serializer.rb b/app/serializers/lists/repository_serializer.rb index d0db9e299..f05b01c9c 100644 --- a/app/serializers/lists/repository_serializer.rb +++ b/app/serializers/lists/repository_serializer.rb @@ -9,7 +9,7 @@ module Lists attributes :name, :code, :nr_of_rows, :team, :created_at, :created_by, :archived_on, :archived_by, :urls def nr_of_rows - object[:row_count] + object[:repository_rows_count] end def team diff --git a/app/services/lists/repositories_service.rb b/app/services/lists/repositories_service.rb index 20062cb1c..6c66c057f 100644 --- a/app/services/lists/repositories_service.rb +++ b/app/services/lists/repositories_service.rb @@ -9,11 +9,9 @@ module Lists 'ON repositories.created_by_id = creators.id') .joins('LEFT OUTER JOIN users AS archivers ' \ 'ON repositories.archived_by_id = archivers.id') - .left_outer_joins(:repository_rows) .joins(:team) .select('repositories.*') .select('MAX(teams.name) AS team_name') - .select('COUNT(DISTINCT(repository_rows.*)) AS row_count') .select('MAX(creators.full_name) AS created_by_user') .select('MAX(archivers.full_name) AS archived_by_user') .select(shared_sql_select) @@ -47,7 +45,7 @@ module Lists created_at: 'repositories.created_at', archived_on: 'repositories.archived_on', archived_by: 'archived_by_user', - nr_of_rows: 'row_count', + nr_of_rows: 'repository_rows_count', code: 'repositories.id', shared_label: 'shared' } diff --git a/db/migrate/20241001163211_add_counter_cache_repository_row.rb b/db/migrate/20241001163211_add_counter_cache_repository_row.rb new file mode 100644 index 000000000..1b91e4ffa --- /dev/null +++ b/db/migrate/20241001163211_add_counter_cache_repository_row.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddCounterCacheRepositoryRow < ActiveRecord::Migration[7.0] + def change + change_table :repositories, bulk: true do |t| + t.integer :repository_rows_count, default: 0, null: false + end + + Repository.find_each do |repository| + Repository.reset_counters(repository.id, :repository_rows) + end + end +end From 533985b8c096f8bb98971153fef2269d9baf9677 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 3 Oct 2024 11:21:24 +0200 Subject: [PATCH 06/28] Add loading spinner for import export [SCI-11130] --- .../vue/storage_locations/modals/import.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/javascript/vue/storage_locations/modals/import.vue b/app/javascript/vue/storage_locations/modals/import.vue index f8a8a5e67..1a9abfc6e 100644 --- a/app/javascript/vue/storage_locations/modals/import.vue +++ b/app/javascript/vue/storage_locations/modals/import.vue @@ -49,6 +49,10 @@ {{ i18n.t('general.cancel') }} +
+
+ Loading +
@@ -78,7 +82,8 @@ export default { }, data() { return { - error: null + error: null, + loading: false }; }, computed: { @@ -99,7 +104,7 @@ export default { }, uploadFile(file) { const formData = new FormData(); - + this.loading = true; // required payload formData.append('file', file); @@ -108,9 +113,11 @@ export default { }) .then(() => { this.$emit('reloadTable'); + this.loading = false; this.close(); }).catch((error) => { this.handleError(error.response.data.message); + this.loading = false; }); } } From cf22bc946a2169fca539176677a721bf10d5afa9 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 3 Oct 2024 12:03:26 +0200 Subject: [PATCH 07/28] Fix split table state for storage containers [SCI-11138] --- app/javascript/vue/storage_locations/container.vue | 6 ++++-- config/initializers/extends.rb | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/javascript/vue/storage_locations/container.vue b/app/javascript/vue/storage_locations/container.vue index b4e88c92e..8272dd5bc 100644 --- a/app/javascript/vue/storage_locations/container.vue +++ b/app/javascript/vue/storage_locations/container.vue @@ -11,7 +11,7 @@
Date: Thu, 3 Oct 2024 12:24:50 +0200 Subject: [PATCH 08/28] Fix moving during locations filtering [SCI-11137] --- .../vue/storage_locations/modals/move_tree_mixin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/vue/storage_locations/modals/move_tree_mixin.js b/app/javascript/vue/storage_locations/modals/move_tree_mixin.js index ec7a86e30..656d6f03a 100644 --- a/app/javascript/vue/storage_locations/modals/move_tree_mixin.js +++ b/app/javascript/vue/storage_locations/modals/move_tree_mixin.js @@ -34,13 +34,13 @@ export default { }, methods: { filteredStorageLocationsTreeHelper(storageLocationsTree) { - return storageLocationsTree.map(({ storage_location, children }) => { + return storageLocationsTree.map(({ storage_location, children, can_manage }) => { if (storage_location.name.toLowerCase().includes(this.query.toLowerCase())) { - return { storage_location, children }; + return { storage_location, children, can_manage }; } const filteredChildren = this.filteredStorageLocationsTreeHelper(children); - return filteredChildren.length ? { storage_location, children: filteredChildren } : null; + return filteredChildren.length ? { storage_location, can_manage, children: filteredChildren } : null; }).filter(Boolean); }, selectStorageLocation(storageLocationId) { From e1898d6fc8908717f12a12240c91addc2ccfbbcf Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 3 Oct 2024 12:45:24 +0200 Subject: [PATCH 09/28] Fix position emit in row selection [SCI-11139] --- .../vue/storage_locations/modals/assign/position_selector.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/app/javascript/vue/storage_locations/modals/assign/position_selector.vue b/app/javascript/vue/storage_locations/modals/assign/position_selector.vue index 1385c8978..401fbd066 100644 --- a/app/javascript/vue/storage_locations/modals/assign/position_selector.vue +++ b/app/javascript/vue/storage_locations/modals/assign/position_selector.vue @@ -52,6 +52,7 @@ export default { watch: { selectedRow() { [[this.selectedColumn]] = this.availableColumns; + this.$emit('change', [this.selectedRow, this.selectedColumn]); }, selectedColumn() { this.$emit('change', [this.selectedRow, this.selectedColumn]); From 49d88b66c4a3f16a302cfc21d832543f0eea3532 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 3 Oct 2024 13:01:21 +0200 Subject: [PATCH 10/28] Add storage refresh on item assignment [SCI-11140] --- .../vue/repository_item_sidebar/locations.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/javascript/vue/repository_item_sidebar/locations.vue b/app/javascript/vue/repository_item_sidebar/locations.vue index d496fd4ad..9f6dd9a5e 100644 --- a/app/javascript/vue/repository_item_sidebar/locations.vue +++ b/app/javascript/vue/repository_item_sidebar/locations.vue @@ -38,7 +38,7 @@ v-if="openAssignModal" assignMode="assign" :selectedRow="repositoryRow.id" - @close="openAssignModal = false; $emit('reloadRow')" + @close="openAssignModal = false; $emit('reloadRow'); reloadStorageLocations()" > { this.$emit('reloadRow'); - if (window.StorageLocationsContainer) { - window.StorageLocationsContainer.$refs.container.reloadingTable = true; - } + this.reloadStorageLocations(); }); } } From f2aa3842fdc4c082096c83fd47b59fed3c266d04 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 3 Oct 2024 14:11:18 +0200 Subject: [PATCH 11/28] Fix assign modal storage locations item card interactions [SCI-11141] --- app/helpers/storage_locations_helper.rb | 2 + .../vue/repository_item_sidebar/locations.vue | 9 ++-- .../vue/storage_locations/modals/assign.vue | 9 +++- .../modals/assign/container_selector.vue | 50 ++++++++++--------- .../modals/assign/position_selector.vue | 10 +++- .../modals/move_tree_mixin.js | 4 +- config/locales/en.yml | 3 ++ 7 files changed, 57 insertions(+), 30 deletions(-) diff --git a/app/helpers/storage_locations_helper.rb b/app/helpers/storage_locations_helper.rb index 1e0b6d651..8754ad523 100644 --- a/app/helpers/storage_locations_helper.rb +++ b/app/helpers/storage_locations_helper.rb @@ -1,5 +1,7 @@ module StorageLocationsHelper def storage_locations_placeholder + return if StorageLocation.storage_locations_enabled? + "
#{I18n.t('storage_locations.storage_locations_disabled')}
" diff --git a/app/javascript/vue/repository_item_sidebar/locations.vue b/app/javascript/vue/repository_item_sidebar/locations.vue index 9f6dd9a5e..88cd3e30a 100644 --- a/app/javascript/vue/repository_item_sidebar/locations.vue +++ b/app/javascript/vue/repository_item_sidebar/locations.vue @@ -7,7 +7,10 @@ {{ i18n.t('repositories.locations.assign') }}
- @@ -70,7 +70,7 @@ {{ i18n.t('general.select_all') }} - +