From 1f7566ae73c423b3636159a354333d2329ab599c Mon Sep 17 00:00:00 2001 From: wandji20 Date: Wed, 27 Mar 2024 11:44:52 +0100 Subject: [PATCH] Add project folders group to global search page [SCI-10470] --- .../javascripts/sitewide/constants.js.erb | 1 + app/controllers/search_controller.rb | 21 +++++++-- .../vue/global_search/groups/folders.vue | 45 ++++++++++++++++++- .../vue/global_search/groups/projects.vue | 2 +- .../vue/global_search/groups/search_mixin.js | 4 ++ .../project_folder_serializer.rb | 33 ++++++++++++++ config/initializers/constants.rb | 2 + 7 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 app/serializers/global_search/project_folder_serializer.rb diff --git a/app/assets/javascripts/sitewide/constants.js.erb b/app/assets/javascripts/sitewide/constants.js.erb index 6d3eeff90..b88b22bd5 100644 --- a/app/assets/javascripts/sitewide/constants.js.erb +++ b/app/assets/javascripts/sitewide/constants.js.erb @@ -18,4 +18,5 @@ const GLOBAL_CONSTANTS = { SLOW_STATUS_POLLING_INTERVAL: <%= Constants::SLOW_STATUS_POLLING_INTERVAL %>, ASSET_POLLING_INTERVAL: <%= Constants::ASSET_POLLING_INTERVAL %>, ASSET_SYNC_URL: '<%= Constants::ASSET_SYNC_URL %>', + GLOBAL_SEARCH_PREVIEW_LIMIT: <%= Constants::GLOBAL_SEARCH_PREVIEW_LIMIT %> }; diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 7ba3e1e47..a7d8c6cfb 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -21,12 +21,27 @@ class SearchController < ApplicationController results = @project_results.page(params[:page]).per(Constants::SEARCH_LIMIT) end - render json: results, + render json: results.includes(:team, :project_folder), each_serializer: GlobalSearch::ProjectSerializer, meta: { total: @search_count, next_page: (results.next_page if results.respond_to?(:next_page)), } + when 'project_folders' + @project_folder_search_count = fetch_cached_count ProjectFolder + search_project_folders + results = if params[:preview] == 'true' + @project_folder_results.limit(Constants::GLOBAL_SEARCH_PREVIEW_LIMIT) + else + @project_folder_results.page(params[:page]).per(Constants::SEARCH_LIMIT) + end + render json: results.includes(:team, :parent_folder), + each_serializer: GlobalSearch::ProjectFolderSerializer, + meta: { + total: @search_count, + next_page: results.try(:next_page) + } + else return when 'protocols' @protocol_search_count = fetch_cached_count(Protocol) @@ -267,13 +282,13 @@ class SearchController < ApplicationController end def search_projects - @project_results = [] + @project_results = Project.none @project_results = search_by_name(Project) if @project_search_count.positive? @search_count = @project_search_count end def search_project_folders - @project_folder_results = [] + @project_folder_results = ProjectFolder.none @project_folder_results = search_by_name(ProjectFolder) if @project_folder_search_count.positive? @search_count = @project_folder_search_count end diff --git a/app/javascript/vue/global_search/groups/folders.vue b/app/javascript/vue/global_search/groups/folders.vue index 15ea2f7f0..3b1a441c4 100644 --- a/app/javascript/vue/global_search/groups/folders.vue +++ b/app/javascript/vue/global_search/groups/folders.vue @@ -1,14 +1,55 @@ diff --git a/app/javascript/vue/global_search/groups/projects.vue b/app/javascript/vue/global_search/groups/projects.vue index f98dbf54a..e30786e65 100644 --- a/app/javascript/vue/global_search/groups/projects.vue +++ b/app/javascript/vue/global_search/groups/projects.vue @@ -1,5 +1,5 @@