Extract concern to share hidden content code

This commit is contained in:
Javi Martín
2022-08-08 14:27:58 +02:00
parent 3e50b7ccaf
commit f6fefde91d
7 changed files with 23 additions and 22 deletions

View File

@@ -1,16 +1,13 @@
class Admin::HiddenBudgetInvestmentsController < Admin::BaseController class Admin::HiddenBudgetInvestmentsController < Admin::BaseController
include FeatureFlags include FeatureFlags
include Admin::HiddenContent
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index
feature_flag :budgets feature_flag :budgets
before_action :load_investment, only: [:confirm_hide, :restore] before_action :load_investment, only: [:confirm_hide, :restore]
def index def index
@investments = Budget::Investment.only_hidden.send(@current_filter) @investments = hidden_content(Budget::Investment.all)
.order(hidden_at: :desc)
.page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,11 +1,10 @@
class Admin::HiddenCommentsController < Admin::BaseController class Admin::HiddenCommentsController < Admin::BaseController
has_filters %w[without_confirmed_hide all with_confirmed_hide] include Admin::HiddenContent
before_action :load_comment, only: [:confirm_hide, :restore] before_action :load_comment, only: [:confirm_hide, :restore]
def index def index
@comments = Comment.not_valuations.only_hidden.with_visible_author @comments = hidden_content(Comment.not_valuations).with_visible_author
.send(@current_filter).order(hidden_at: :desc).page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,14 +1,13 @@
class Admin::HiddenDebatesController < Admin::BaseController class Admin::HiddenDebatesController < Admin::BaseController
include FeatureFlags include FeatureFlags
include Admin::HiddenContent
feature_flag :debates feature_flag :debates
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index
before_action :load_debate, only: [:confirm_hide, :restore] before_action :load_debate, only: [:confirm_hide, :restore]
def index def index
@debates = Debate.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page]) @debates = hidden_content(Debate.all)
end end
def confirm_hide def confirm_hide

View File

@@ -1,13 +1,10 @@
class Admin::HiddenProposalNotificationsController < Admin::BaseController class Admin::HiddenProposalNotificationsController < Admin::BaseController
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index include Admin::HiddenContent
before_action :load_proposal, only: [:confirm_hide, :restore] before_action :load_proposal, only: [:confirm_hide, :restore]
def index def index
@proposal_notifications = ProposalNotification.only_hidden @proposal_notifications = hidden_content(ProposalNotification.all)
.send(@current_filter)
.order(hidden_at: :desc)
.page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,15 +1,13 @@
class Admin::HiddenProposalsController < Admin::BaseController class Admin::HiddenProposalsController < Admin::BaseController
include FeatureFlags include FeatureFlags
include Admin::HiddenContent
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index
feature_flag :proposals feature_flag :proposals
before_action :load_proposal, only: [:confirm_hide, :restore] before_action :load_proposal, only: [:confirm_hide, :restore]
def index def index
@proposals = Proposal.only_hidden.send(@current_filter).order(hidden_at: :desc) @proposals = hidden_content(Proposal.all)
.page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,10 +1,10 @@
class Admin::HiddenUsersController < Admin::BaseController class Admin::HiddenUsersController < Admin::BaseController
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index include Admin::HiddenContent
before_action :load_user, only: [:confirm_hide, :restore] before_action :load_user, only: [:confirm_hide, :restore]
def index def index
@users = User.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page]) @users = hidden_content(User.all)
end end
def show def show

View File

@@ -0,0 +1,11 @@
module Admin::HiddenContent
extend ActiveSupport::Concern
included do
has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index
end
def hidden_content(relation)
relation.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page])
end
end