From 50126cc4c49ccf108ad9a58a9a754a9859e3188d Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 27 Feb 2024 22:23:02 +0100 Subject: [PATCH] Implement report filtering interface --- .../moderation/reports_controller.rb | 19 +++++++++++++++++++ app/views/moderation/reports/index.html.haml | 14 ++++++++++++++ config/locales/voc.en.yml | 2 ++ 3 files changed, 35 insertions(+) diff --git a/app/controllers/moderation/reports_controller.rb b/app/controllers/moderation/reports_controller.rb index e4977217..3bf50ef7 100644 --- a/app/controllers/moderation/reports_controller.rb +++ b/app/controllers/moderation/reports_controller.rb @@ -2,6 +2,8 @@ class Moderation::ReportsController < ApplicationController before_action :authenticate_user! + before_action :set_filter_enabled + before_action :set_type_options def index filter = ReportFilter.new(filter_params) @@ -20,4 +22,21 @@ class Moderation::ReportsController < ApplicationController def filter_params params.slice(*ReportFilter::KEYS).permit(*ReportFilter::KEYS) end + + def set_filter_enabled + @filter_enabled = params.slice(*ReportFilter::KEYS) + .reject! { |_, value| value.empty? || value.nil? } + .values + .any? + end + + def set_type_options + @type_options = [ + [t("voc.all"), ""], + [t("activerecord.models.answer.one"), :answer], + [t("activerecord.models.comment.one"), :comment], + [t("activerecord.models.question.one"), :question], + [t("activerecord.models.user.one"), :user] + ] + end end diff --git a/app/views/moderation/reports/index.html.haml b/app/views/moderation/reports/index.html.haml index 1df8ae9d..bac8e797 100644 --- a/app/views/moderation/reports/index.html.haml +++ b/app/views/moderation/reports/index.html.haml @@ -1,3 +1,17 @@ +.card + .card-body + .dropdown + %button.btn.dropdown-toggle{ class: @filter_enabled ? "btn-primary" : "btn-light", type: :button, data: { bs_toggle: :dropdown }, aria: { expanded: :false }} + %i.fa.fa-filter + = t("voc.filter") + .dropdown-menu{ style: "min-width: 300px;" } + = bootstrap_form_tag url: moderation_reports_path, method: :get, html: { class: "px-3 py-2" } do |f| + = f.select :type, options_for_select(@type_options, params[:type]), {}, { class: "form-control" } + = f.text_field :user, value: params[:user] + = f.text_field :target_user, value: params[:target_user] + .d-flex.flex-row-reverse + = f.primary t("voc.filter") + #reports - if @reports.empty? = render "shared/empty", icon: "fa-regular fa-smile-beam", translation_key: ".moderation.reports" diff --git a/config/locales/voc.en.yml b/config/locales/voc.en.yml index 01f1ff9c..58547a03 100644 --- a/config/locales/voc.en.yml +++ b/config/locales/voc.en.yml @@ -1,6 +1,7 @@ en: voc: add: "Add" + all: "All" answer: "Answer" block: "Block" block_site_wide: "Block user site-wide" @@ -9,6 +10,7 @@ en: confirm: "Are you sure?" delete: "Delete" edit: "Edit" + filter: "Filter" follow: "Follow" format_markdown: "Styling with Markdown is supported" load: "Load more"