From ee45fdd4944ffe645a11300122f30403c5b3dd9b Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:59:40 +0100 Subject: [PATCH] Additional work on filters --- app/helpers/filters_helper.rb | 7 +++---- app/models/bulk_upload.rb | 3 ++- app/services/filter_manager.rb | 9 +++++---- app/views/bulk_upload_shared/_upload_filters.html.erb | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index b218c9243..7c5183b39 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -14,14 +14,13 @@ module FiltersHelper return true if (selected_filters["owning_organisation"].present? || selected_filters["owning_organisation_text_search"].present?) && filter == "owning_organisation_select" && value == :specific_org return true if (selected_filters["managing_organisation"].present? || selected_filters["managing_organisation_text_search"].present?) && filter == "managing_organisation_select" && value == :specific_org - return true if !selected_filters.key?("uploaded_by") && filter == "uploaded_by" && value == :all + return true if !selected_filters.key?("user") && filter == "uploaded_by" && value == :all return true if selected_filters["uploaded_by"] == "specific_user" && filter == "uploaded_by" && value == :specific_user return true if !selected_filters.key?("uploading_organisation") && filter == "uploading_organisation_select" && value == :all - return true if selected_filters["uploading_organisation"] == "specific_org" && filter == "uploading_organisation_select" && value == :specific_org + return true if (selected_filters["uploading_organisation"].present? || selected_filters["uploading_organisation_text_search"].present?) && filter == "uploading_organisation_select" && value == :specific_org return false if selected_filters[filter].blank? - selected_filters[filter].include?(value.to_s) end @@ -285,7 +284,7 @@ private filters.each.sum do |category, category_filters| if %w[years status needstypes bulk_upload_id].include?(category) category_filters.count(&:present?) - elsif %w[user owning_organisation managing_organisation user_text_search owning_organisation_text_search managing_organisation_text_search].include?(category) + elsif %w[user owning_organisation managing_organisation user_text_search owning_organisation_text_search managing_organisation_text_search uploading_organisation].include?(category) 1 else 0 diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index b17d6d289..e437fc2b6 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -43,7 +43,8 @@ class BulkUpload < ApplicationRecord } scope :filter_by_uploaded_by, ->(user_id, _user = nil) { where(user_id:) } scope :filter_by_user_text_search, ->(param, _user = nil) { where(user_id: User.search_by(param).select(:id)) } - scope :filter_by_user, ->(selected_user, _user = nil) { selected_user.present? ? where(user: selected_user) : all } + scope :filter_by_user, ->(user_id, _user = nil) { user_id.present? ? where(user_id:) : all } + scope :filter_by_uploading_organisation , ->(organisation_id, _user = nil) { where(user_id: User.where(organisation_id: organisation_id).select(:id)) } def completed? incomplete_logs = logs.where.not(status: "completed") diff --git a/app/services/filter_manager.rb b/app/services/filter_manager.rb index f5c7bd71b..ce141c6cf 100644 --- a/app/services/filter_manager.rb +++ b/app/services/filter_manager.rb @@ -83,7 +83,7 @@ class FilterManager next if Array(values).reject(&:empty?).blank? next if category == "uploading_organisation" && all_orgs next if category == "uploading_organisation_text_search" && all_orgs - # next if category == "uploaded_by" + next if category == "uploaded_by" next if category == "uploaded_by_text_search" && filters["uploaded_by"] != "specific_user" uploads = uploads.public_send("filter_by_#{category}", values, user) @@ -142,11 +142,12 @@ class FilterManager current_user.logs_filters(specific_org:).each do |filter| new_filters[filter] = params[filter] if params[filter].present? end + # binding.pry new_filters = new_filters.except("uploading_organisation") if params["uploading_organisation_select"] == "all" - new_filters = new_filters.except("uploaded_by") if params["uploaded_by"] == "all" - new_filters["uploaded_by"] = current_user.id.to_s if params["uploaded_by"] == "you" + new_filters = new_filters.except("user") if params["uploaded_by"] == "all" + new_filters["user"] = current_user.id.to_s if params["uploaded_by"] == "you" end - + # binding.pry new_filters end diff --git a/app/views/bulk_upload_shared/_upload_filters.html.erb b/app/views/bulk_upload_shared/_upload_filters.html.erb index 754e62cbf..af54ec827 100644 --- a/app/views/bulk_upload_shared/_upload_filters.html.erb +++ b/app/views/bulk_upload_shared/_upload_filters.html.erb @@ -36,7 +36,7 @@ conditional_filter: { type: "text_select", label: "User", - category: "uploaded_by", + category: "user", options: uploaded_by_filter_options, caption_text: "User's name or email", }, @@ -54,7 +54,7 @@ "specific_org": { label: "Specific uploading organisation", conditional_filter: { - type: "text_select", + type: "select", label: "Uploading Organisation", category: "uploading_organisation", options: all_owning_organisation_filter_options(current_user),