From 27d7589f9aab294283df57a14fa3b9a7cb7c7ee9 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 4 Mar 2024 14:26:41 -0300 Subject: [PATCH] fix: no se pueden anidar formularios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit usando el atributo form, podemos crear un formulario vacío y colocar inputs por fuera de su contexto. de lo contrario el primer botón de acción individual no funciona --- app/models/instance_moderation.rb | 7 +++-- app/views/components/_checkbox.haml | 2 +- app/views/components/_dropdown_button.haml | 2 +- .../_instances_checked_submenu.haml | 5 ++- app/views/components/_instances_filters.haml | 2 +- app/views/components/_select_all.haml | 2 +- app/views/moderation_queue/_comment.haml | 2 +- app/views/moderation_queue/_instance.haml | 2 +- app/views/moderation_queue/_instances.haml | 31 ++++++++++--------- 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/models/instance_moderation.rb b/app/models/instance_moderation.rb index 10b5e8e0..7447cc89 100644 --- a/app/models/instance_moderation.rb +++ b/app/models/instance_moderation.rb @@ -3,6 +3,10 @@ # Mantiene el registro de relaciones entre sitios e instancias class InstanceModeration < ApplicationRecord include AASM + include AasmEventsConcern + + IGNORED_EVENTS = [] + IGNORED_STATES = [] belongs_to :site belongs_to :instance, class_name: 'ActivityPub::Instance' @@ -11,9 +15,6 @@ class InstanceModeration < ApplicationRecord # todas las que no estén bloqueadas ya. scope :may_block, -> { where.not(aasm_state: 'blocked') } scope :may_pause, -> { where.not(aasm_state: 'paused') } - scope :paused, -> { where(aasm_state: 'paused') } - scope :blocked, -> { where(aasm_state: 'blocked') } - scope :allowed, -> { where(aasm_state: 'allowed') } # Bloquear instancias en masa def self.block_all! diff --git a/app/views/components/_checkbox.haml b/app/views/components/_checkbox.haml index 596ff074..68f1a663 100644 --- a/app/views/components/_checkbox.haml +++ b/app/views/components/_checkbox.haml @@ -1,5 +1,5 @@ -# Componente Checkbox - local_assigns[:name] ||= id .custom-control.custom-checkbox - %input.custom-control-input{ type: 'checkbox', id: id, **local_assigns } + %input.custom-control-input{ form: local_assigns[:form_id], type: 'checkbox', id: id, **local_assigns } %label.custom-control-label{ for: id }= yield diff --git a/app/views/components/_dropdown_button.haml b/app/views/components/_dropdown_button.haml index 8b0c4684..c8c98209 100644 --- a/app/views/components/_dropdown_button.haml +++ b/app/views/components/_dropdown_button.haml @@ -1,4 +1,4 @@ -# @param name [String] @param value [String] -%button.dropdown-item{type: 'submit', data: { target: 'dropdown.item' }, name: name, value: value }= text +%button.dropdown-item{type: 'submit', data: { target: 'dropdown.item' }, name: name, value: value, form: local_assigns[:form_id] }= text diff --git a/app/views/components/_instances_checked_submenu.haml b/app/views/components/_instances_checked_submenu.haml index c3573ead..2d28fb1c 100644 --- a/app/views/components/_instances_checked_submenu.haml +++ b/app/views/components/_instances_checked_submenu.haml @@ -1,3 +1,2 @@ -= render 'components/dropdown_button', text: t('.submenu_pause'), name: 'instance_moderation_action', value: 'pause' -= render 'components/dropdown_button', text: t('.submenu_allow'), name: 'instance_moderation_action', value: 'allow' -= render 'components/dropdown_button', text: t('.submenu_block'), name: 'instance_moderation_action', value: 'block' +- InstanceModeration.events.each do |event| + = render 'components/dropdown_button', text: t(".submenu_#{event}"), name: 'instance_moderation_action', value: event, form_id: form_id diff --git a/app/views/components/_instances_filters.haml b/app/views/components/_instances_filters.haml index fe40ced3..2c05693a 100644 --- a/app/views/components/_instances_filters.haml +++ b/app/views/components/_instances_filters.haml @@ -1,6 +1,6 @@ .d-flex.py-2 = render 'components/dropdown', text: t('.text_checked') do - = render 'components/instances_checked_submenu' + = render 'components/instances_checked_submenu', form_id: form_id = render 'components/dropdown', text: t('.text_show') do = render 'components/instances_show_submenu', site: site diff --git a/app/views/components/_select_all.haml b/app/views/components/_select_all.haml index 2603dfd3..68711c4a 100644 --- a/app/views/components/_select_all.haml +++ b/app/views/components/_select_all.haml @@ -1,4 +1,4 @@ -# @param id [String] -= render 'components/checkbox', id: id, data: { action: 'select-all#toggle', target: 'select-all.toggle' } do += render 'components/checkbox', id: id, form: local_assigns[:form_id], data: { action: 'select-all#toggle', target: 'select-all.toggle' } do %span.sr-only= t('.label') diff --git a/app/views/moderation_queue/_comment.haml b/app/views/moderation_queue/_comment.haml index ffaf76cf..33ebc722 100644 --- a/app/views/moderation_queue/_comment.haml +++ b/app/views/moderation_queue/_comment.haml @@ -10,7 +10,7 @@ .row.no-gutters .col-1 - = render 'components/checkbox', id: activity_pub.id, name: 'activity_pub[]', value: activity_pub.id, data: { target: 'select-all.input' } + = render 'components/checkbox', id: activity_pub.id, name: 'activity_pub[]', value: activity_pub.id, data: { target: 'select-all.input' }, form: form_id .col-11 .d-flex.flex-row.align-items-center.justify-content-between %h4.mb-0 diff --git a/app/views/moderation_queue/_instance.haml b/app/views/moderation_queue/_instance.haml index 97d23f10..05510724 100644 --- a/app/views/moderation_queue/_instance.haml +++ b/app/views/moderation_queue/_instance.haml @@ -3,7 +3,7 @@ .row.no-gutters.pt-2 .col-1 - = render 'components/checkbox', id: instance.hostname, name: 'instance_moderation[]', value: instance_moderation.id, data: { target: 'select-all.input' } + = render 'components/checkbox', id: instance.hostname, form_id: form_id, name: 'instance_moderation[]', value: instance_moderation.id, data: { target: 'select-all.input' } .col-11 %h4 %a{ href: instance.uri }= sanitize(instance.content['title']) || instance.hostname diff --git a/app/views/moderation_queue/_instances.haml b/app/views/moderation_queue/_instances.haml index 77b6adea..83b0c772 100644 --- a/app/views/moderation_queue/_instances.haml +++ b/app/views/moderation_queue/_instances.haml @@ -1,22 +1,23 @@ +- form_id = 'instance_moderation_action_on_several' %section - %form{ action: site_instance_moderations_action_on_several_path, method: :post } - .row.no-gutters.pt-2{ data: { controller: 'select-all' } } - .col-1.d-flex.align-items-center - = render 'components/select_all', id: 'instances' - .col-11 - -# Filtros - = render 'components/instances_filters', site: site + %form{ id: form_id, action: site_instance_moderations_action_on_several_path, method: :post } + .row.no-gutters.pt-2{ data: { controller: 'select-all' } } + .col-1.d-flex.align-items-center + = render 'components/select_all', id: 'instances', form_id: form_id + .col-11 + -# Filtros + = render 'components/instances_filters', site: site, form_id: form_id - .col-12 - - if instance_moderations.count.zero? - %h4= t('moderation_queue.nothing') + .col-12 + - if instance_moderations.count.zero? + %h4= t('moderation_queue.nothing') - - instance_moderations.each do |instance_moderation| - - cache [instance_moderation.aasm_state, instance_moderation.instance] do - %hr - = render 'moderation_queue/instance', instance_moderation: instance_moderation, instance: instance_moderation.instance + - instance_moderations.each do |instance_moderation| + - cache [instance_moderation.aasm_state, instance_moderation.instance] do + %hr + = render 'moderation_queue/instance', instance_moderation: instance_moderation, instance: instance_moderation.instance, form_id: form_id - %hr + %hr %div %h3.mt-5= t('moderation_queue.instances.title') %lead= t('moderation_queue.instances.description')