From 761d68604b9bbb1ce2a597d0717bd4121762f4e2 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 26 Feb 2024 17:03:18 -0300 Subject: [PATCH] feat: poder seleccionar todas las instancias --- .../controllers/select_all_controller.js | 11 +++++++ app/views/components/_checkbox.haml | 2 +- app/views/components/_select_all.haml | 4 +++ app/views/moderation_queue/_instance.haml | 2 +- app/views/moderation_queue/_instances.haml | 33 ++++++++++--------- 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 app/javascript/controllers/select_all_controller.js create mode 100644 app/views/components/_select_all.haml diff --git a/app/javascript/controllers/select_all_controller.js b/app/javascript/controllers/select_all_controller.js new file mode 100644 index 00000000..7aca0f59 --- /dev/null +++ b/app/javascript/controllers/select_all_controller.js @@ -0,0 +1,11 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + static targets = ["toggle", "input"]; + + toggle(event = undefined) { + this.inputTargets.forEach(input => { + input.checked = this.toggleTarget.checked; + }); + } +} diff --git a/app/views/components/_checkbox.haml b/app/views/components/_checkbox.haml index 27f9a776..1932df90 100644 --- a/app/views/components/_checkbox.haml +++ b/app/views/components/_checkbox.haml @@ -1,4 +1,4 @@ -# Componente Checkbox .custom-control.custom-checkbox - %input.custom-control-input{ type: 'checkbox', id: id, name: id, class: local_assigns[:class] } + %input.custom-control-input{ type: 'checkbox', id: id, name: id, **local_assigns } %label.custom-control-label{ for: id }= yield diff --git a/app/views/components/_select_all.haml b/app/views/components/_select_all.haml new file mode 100644 index 00000000..2603dfd3 --- /dev/null +++ b/app/views/components/_select_all.haml @@ -0,0 +1,4 @@ +-# + @param id [String] += render 'components/checkbox', id: id, data: { action: 'select-all#toggle', target: 'select-all.toggle' } do + %span.sr-only= t('.label') diff --git a/app/views/moderation_queue/_instance.haml b/app/views/moderation_queue/_instance.haml index 958a0199..327ea892 100644 --- a/app/views/moderation_queue/_instance.haml +++ b/app/views/moderation_queue/_instance.haml @@ -1,6 +1,6 @@ .row.no-gutters.pt-2 .col-1 - = render 'components/checkbox', id: instance.hostname + = render 'components/checkbox', id: instance.hostname, data: { target: 'select-all.input' } .col-11 %h4 %a{ href: instance.uri }= instance.content['title'] diff --git a/app/views/moderation_queue/_instances.haml b/app/views/moderation_queue/_instances.haml index 20501370..1540ae53 100644 --- a/app/views/moderation_queue/_instances.haml +++ b/app/views/moderation_queue/_instances.haml @@ -1,24 +1,25 @@ -.row.no-gutters.pt-2 +.row.no-gutters.pt-2{ data: { controller: 'select-all' } } .col-1.d-flex.align-items-center - = render 'components/checkbox', id: 'all' do - %span.sr-only= t('moderation_queue.everything') + = render 'components/select_all', id: 'instances' .col-11 -# Filtros = render 'components/instances_filters' -- if instance_moderations.count.zero? - %h3= t('moderation_queue.nothing') + .col-12 + - if instance_moderations.count.zero? + %h3= t('moderation_queue.nothing') -- instance_moderations.each do |instance_moderation| - %hr - = render 'moderation_queue/instance', instance: instance_moderation.instance + - instance_moderations.each do |instance_moderation| + %hr + = render 'moderation_queue/instance', instance: instance_moderation.instance - -# Botones moderaciĆ³n - .d-flex.pb-4 - = render 'components/instances_btn_box', site: site, instance_moderation: instance_moderation + -# Botones moderaciĆ³n + .d-flex.pb-4 + = render 'components/instances_btn_box', site: site, instance_moderation: instance_moderation -%hr -%h3.mt-5= t('moderation_queue.instances.title') -%lead= t('moderation_queue.instances.description') -= render 'components/block_lists', blocklists: @blocklists -= render 'moderation_queue/block_instances_textarea' + %hr + .col-12 + %h3.mt-5= t('moderation_queue.instances.title') + %lead= t('moderation_queue.instances.description') + = render 'components/block_lists', blocklists: @blocklists + = render 'moderation_queue/block_instances_textarea'