From af3d59d34afaadbd625682e4acdb52725d02b582 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 16 Apr 2021 11:06:24 -0300 Subject: [PATCH 1/2] asegurarse que solo podamos encolar el sitio una vez --- test/models/site_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/models/site_test.rb b/test/models/site_test.rb index c50bfd2..c894932 100644 --- a/test/models/site_test.rb +++ b/test/models/site_test.rb @@ -108,5 +108,10 @@ class SiteTest < ActiveSupport::TestCase assert_equal %w[book editorial post], site.data['layouts'].keys assert_equal %i[book editorial post], site.layouts.to_h.keys + + test 'se pueden encolar una sola vez' do + assert site.enqueue! + assert site.enqueued? + assert_not site.enqueue! end end From f60fbd70f4f21da280e428c081ecad4081646711 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 16 Apr 2021 11:07:28 -0300 Subject: [PATCH 2/2] =?UTF-8?q?deshabilitar=20el=20bot=C3=B3n=20de=20publi?= =?UTF-8?q?caci=C3=B3n=20una=20vez=20que=20se=20lo=20toca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/submit_once_controller.js | 15 +++++++++++++++ app/views/sites/_build.haml | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 app/javascript/controllers/submit_once_controller.js diff --git a/app/javascript/controllers/submit_once_controller.js b/app/javascript/controllers/submit_once_controller.js new file mode 100644 index 0000000..b47a33e --- /dev/null +++ b/app/javascript/controllers/submit_once_controller.js @@ -0,0 +1,15 @@ +import { Controller } from 'stimulus' + +/* + * Deshabilita el elemento que recibe el evento, para evitar que la + * acción se realice varias veces. + * + *
+ * + *
+ */ +export default class extends Controller { + disable (event) { + event.target.disabled = true + } +} diff --git a/app/views/sites/_build.haml b/app/views/sites/_build.haml index 4115e97..d9d6be8 100644 --- a/app/views/sites/_build.haml +++ b/app/views/sites/_build.haml @@ -4,12 +4,15 @@ tooltip: t('help.sites.enqueued'), text: t('sites.enqueued'), type: 'secondary', - link: nil + link: nil, + disabled: true - else = form_tag site_enqueue_path(site), - method: :post, class: 'form-inline inline' do + method: :post, + data: { controller: 'submit-once' }, + class: 'form-inline inline' do = button_tag type: 'submit', class: 'btn no-border-radius', title: t('help.sites.enqueue'), - data: { toggle: 'tooltip' } do + data: { action: 'submit-once#disable' } do = t('sites.enqueue')