From a2204779af2bca3f5b158e59553fa6c8787986b0 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 4 Mar 2024 13:59:01 -0300 Subject: [PATCH] feat: filtrar por estado del comentario --- app/helpers/moderation_queue_helper.rb | 7 +++++++ app/models/activity_pub.rb | 1 + app/models/actor_moderation.rb | 1 + app/models/concerns/aasm_events_concern.rb | 7 +++++++ app/views/components/_comments_filters.haml | 2 +- app/views/components/_comments_show_submenu.haml | 8 ++++---- app/views/components/_profiles_show_submenu.haml | 4 ++-- app/views/moderation_queue/_comments.haml | 2 +- config/locales/en.yml | 8 ++++---- config/locales/es.yml | 8 ++++---- 10 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 app/helpers/moderation_queue_helper.rb diff --git a/app/helpers/moderation_queue_helper.rb b/app/helpers/moderation_queue_helper.rb new file mode 100644 index 00000000..3681bec3 --- /dev/null +++ b/app/helpers/moderation_queue_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module ModerationQueueHelper + def filter_states(**args) + params.permit(:state, :actor_state, :activity_pub_state).merge(**args) + end +end diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index 95fa3bf3..51ee0d71 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -12,6 +12,7 @@ class ActivityPub < ApplicationRecord include AasmEventsConcern IGNORED_EVENTS = %i[remove] + IGNORED_STATES = %i[removed] belongs_to :instance belongs_to :site diff --git a/app/models/actor_moderation.rb b/app/models/actor_moderation.rb index 1fc1a42a..421d4c6e 100644 --- a/app/models/actor_moderation.rb +++ b/app/models/actor_moderation.rb @@ -6,6 +6,7 @@ class ActorModeration < ApplicationRecord include AasmEventsConcern IGNORED_EVENTS = [] + IGNORED_STATES = [] belongs_to :site belongs_to :remote_flag, class_name: 'ActivityPub::RemoteFlag' diff --git a/app/models/concerns/aasm_events_concern.rb b/app/models/concerns/aasm_events_concern.rb index 79250ea9..59ea243f 100644 --- a/app/models/concerns/aasm_events_concern.rb +++ b/app/models/concerns/aasm_events_concern.rb @@ -10,5 +10,12 @@ module AasmEventsConcern def self.events aasm.events.map(&:name) - self::IGNORED_EVENTS end + + # Todos los estados de la máquina de estados + # + # @return [Array] + def self.states + aasm.states.map(&:name) - self::IGNORED_STATES + end end end diff --git a/app/views/components/_comments_filters.haml b/app/views/components/_comments_filters.haml index 7c453088..b4597be5 100644 --- a/app/views/components/_comments_filters.haml +++ b/app/views/components/_comments_filters.haml @@ -3,4 +3,4 @@ = render 'components/comments_checked_submenu' = render 'components/dropdown', text: t('.text_show') do - = render 'components/comments_show_submenu' \ No newline at end of file + = render 'components/comments_show_submenu', activity_pubs: activity_pubs diff --git a/app/views/components/_comments_show_submenu.haml b/app/views/components/_comments_show_submenu.haml index 0308b926..eb037975 100644 --- a/app/views/components/_comments_show_submenu.haml +++ b/app/views/components/_comments_show_submenu.haml @@ -1,4 +1,4 @@ -= render 'components/dropdown_item', text: t('.submenu_pause'), path: '/' -= render 'components/dropdown_item', text: t('.submenu_accept'), path: '/' -= render 'components/dropdown_item', text: t('.submenu_report'), path: '/' -= render 'components/dropdown_item', text: t('.submenu_reject'), path: '/' \ No newline at end of file +- ActivityPub.states.each do |state| + = render 'components/dropdown_item', + text: t(".submenu_#{state}", count: activity_pubs.unscope(where: :aasm_state).public_send(state).count), + path: site_moderation_queue_path(filter_states(activity_pub_state: state)) diff --git a/app/views/components/_profiles_show_submenu.haml b/app/views/components/_profiles_show_submenu.haml index 703e4a15..0209ef2f 100644 --- a/app/views/components/_profiles_show_submenu.haml +++ b/app/views/components/_profiles_show_submenu.haml @@ -1,4 +1,4 @@ -- ActorModeration.aasm.states.map(&:name).each do |actor_state| +- ActorModeration.states.each do |actor_state| = render 'components/dropdown_item', text: t(".submenu_#{actor_state}", count: actor_moderations.unscope(where: :aasm_state).public_send(actor_state).count), - path: site_moderation_queue_path(params.permit(:state, :actor_state).merge(actor_state: actor_state)) + path: site_moderation_queue_path(filter_states(actor_state: actor_state)) diff --git a/app/views/moderation_queue/_comments.haml b/app/views/moderation_queue/_comments.haml index 97f77e3c..f243b02a 100644 --- a/app/views/moderation_queue/_comments.haml +++ b/app/views/moderation_queue/_comments.haml @@ -4,7 +4,7 @@ = render 'components/select_all', id: 'select-all-comments' .col-md-9 -# Filtros - = render 'components/comments_filters' + = render 'components/comments_filters', activity_pubs: moderation_queue - if moderation_queue.count.zero? %h4= t('moderation_queue.nothing') diff --git a/config/locales/en.yml b/config/locales/en.yml index f69d60b0..eecd5ebd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,10 +72,10 @@ en: submenu_accept: Accept submenu_reject: Reject comments_show_submenu: - submenu_pause: Pause - submenu_accept: Accept - submenu_report: Report - submenu_reject: Reject + submenu_paused: "Paused (%{count})" + submenu_approved: "Approved (%{count})" + submenu_rejected: "Rejected (%{count})" + submenu_reported: "Reported (%{count})" profiles_filters: text_show: Show text_checked: With selected diff --git a/config/locales/es.yml b/config/locales/es.yml index a0aaa4d6..0f9eb68a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -72,10 +72,10 @@ es: submenu_accept: Aceptado submenu_reject: Rechazado comments_show_submenu: - submenu_pause: Pausado - submenu_accept: Aceptado - submenu_report: Reportado - submenu_reject: Rechazado + submenu_paused: "Pausados (%{count})" + submenu_approved: "Aprobados (%{count})" + submenu_rejected: "Rechazados (%{count})" + submenu_reported: "Reportados (%{count})" profiles_filters: text_show: Ver text_checked: Con los marcados