From 2387f8f211e1facd4bf0f84a9ab67f9ccc5b38bc Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Wed, 16 Oct 2024 17:30:42 -0600 Subject: [PATCH] Reorganize methods in BubblesController --- app/controllers/bubbles_controller.rb | 33 +++++++++++++++------------ app/helpers/filters_helper.rb | 4 ++++ app/views/bubbles/_filters.html.erb | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb index 3987ac5a5..937a4bbf9 100644 --- a/app/controllers/bubbles_controller.rb +++ b/app/controllers/bubbles_controller.rb @@ -2,7 +2,8 @@ class BubblesController < ApplicationController include BucketScoped before_action :set_bubble, only: %i[ show edit update ] - before_action :set_assignee_filters, :set_tag_filters, only: :index + before_action :clear_assignees_if_unassigned, only: :index + before_action :set_tag_filters, :set_assignee_filters, only: :index def index @bubbles = @bucket.bubbles @@ -38,21 +39,23 @@ class BubblesController < ApplicationController @bubble = @bucket.bubbles.find params[:id] end - def set_assignee_filters - params[:assignee_ids] = nil if status_filter_param.unassigned? - @assignee_filters = Current.account.users.where(id: params[:assignee_ids]) if params[:assignee_ids] - end - - def status_filter_param - params.fetch(:status, "")&.inquiry - end - helper_method :status_filter_param - - def set_tag_filters - @tag_filters = Current.account.tags.where(id: params[:tag_ids]) if params[:tag_ids] - end - def bubble_params params.require(:bubble).permit(:title, :color, :due_on, :image, tag_ids: []) end + + def clear_assignees_if_unassigned + params[:assignee_ids] = nil if helpers.querying_unassigned_status? + end + + def set_tag_filters + if params[:tag_ids] + @tag_filters = Current.account.tags.where id: params[:tag_ids] + end + end + + def set_assignee_filters + if params[:assignee_ids] + @assignee_filters = Current.account.users.where id: params[:assignee_ids] + end + end end diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 575b4e463..9730891b3 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -23,4 +23,8 @@ module FiltersHelper def bubble_filter_params @bubble_filter_params ||= params.permit :order_by, :status, :term, :assignee_ids, :tag_ids end + + def querying_unassigned_status? + params[:status] == "unassigned" + end end diff --git a/app/views/bubbles/_filters.html.erb b/app/views/bubbles/_filters.html.erb index a06fd8587..bfcc4e39c 100644 --- a/app/views/bubbles/_filters.html.erb +++ b/app/views/bubbles/_filters.html.erb @@ -8,7 +8,7 @@ <%= tag_filters ? "Tagged" : "with" %> <%= render "bubbles/filters/tags", bucket: bucket, tag_filters: tag_filters %> - <% unless status_filter_param.unassigned? %> + <% unless querying_unassigned_status? %> and <%= render "bubbles/filters/assignees", bucket: bucket, assignee_filters: assignee_filters %> <% end %>