From 5f0672bcaebd1d68d81738c9d74f4275eb6866b9 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 30 Apr 2024 17:44:33 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20recargar=20el=20bot=C3=B3n=20de=20publi?= =?UTF-8?q?car=20por=20separado=20#16180?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/sites_controller.rb | 6 ++++++ app/policies/site_policy.rb | 4 ++++ app/views/posts/index.haml | 1 + app/views/sites/_build.haml | 17 +++++++++-------- app/views/sites/_status.haml | 4 +--- app/views/sites/build.haml | 1 + config/routes.rb | 1 + 7 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 app/views/sites/build.haml diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 49527cf7..e911daac 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -22,6 +22,12 @@ class SitesController < ApplicationController render('sites/status', layout: false) if stale? site end + def button + authorize site + + render('sites/build', layout: false) + end + # No tenemos propiedades de un sitio aún, así que vamos al listado de # artículos def show diff --git a/app/policies/site_policy.rb b/app/policies/site_policy.rb index d5465d6b..ce56a2e7 100644 --- a/app/policies/site_policy.rb +++ b/app/policies/site_policy.rb @@ -61,6 +61,10 @@ class SitePolicy show? && usuarie? end + def button? + show? + end + def enqueue? build? end diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 29f6471f..3ea82309 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -3,6 +3,7 @@ = render 'sites/header', site: @site = render 'sites/status', site: @site + = render 'sites/build', site: @site, class: 'btn-block' %h3= t('posts.new') %table.table.table-sm.mb-3 diff --git a/app/views/sites/_build.haml b/app/views/sites/_build.haml index c723a3ac..8db4d370 100644 --- a/app/views/sites/_build.haml +++ b/app/views/sites/_build.haml @@ -1,9 +1,10 @@ - if policy(site).build? - = form_tag site_enqueue_path(site), - method: :post, - class: 'form-inline inline' do - = submit_tag site.enqueued? ? t('sites.enqueued') : t('sites.enqueue'), - class: "btn btn-secondary #{local_assigns[:class]}", - title: site.enqueued? ? t('help.sites.enqueued') : t('help.sites.enqueue'), - data: { disable_with: t('sites.enqueued') }, - disabled: !site.waiting? + %div{ 'hx-get': site_button_path(site, class: local_assigns[:class]), 'hx-trigger': 'every 10s', 'hx-swap': 'outerHTML' } + = form_tag site_enqueue_path(site), + method: :post, + class: 'form-inline inline' do + = submit_tag site.enqueued? ? t('sites.enqueued') : t('sites.enqueue'), + class: "btn btn-secondary #{local_assigns[:class]}", + title: site.enqueued? ? t('help.sites.enqueued') : t('help.sites.enqueue'), + data: { disable_with: t('sites.enqueued') }, + disabled: !site.waiting? diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index 9ac27c15..a3dfd4ad 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -18,9 +18,7 @@ - message = t('.available') - link = true - -# TODO: Calcular cada cuanto sería óptimo recargar + -# TODO: Calcular cada cuánto sería óptimo recargar %div{ 'hx-get': site_status_path(site), 'hx-trigger': 'every 10s', 'hx-swap': 'outerHTML' } = render 'bootstrap/alert' do = link_to_if link, message.html_safe, site_build_stats_path(site), class: 'alert-link' - - = render 'sites/build', site: site, class: 'btn-block' diff --git a/app/views/sites/build.haml b/app/views/sites/build.haml new file mode 100644 index 00000000..c2becec0 --- /dev/null +++ b/app/views/sites/build.haml @@ -0,0 +1 @@ += render 'sites/build', site: @site, class: params.permit(:class)[:class] diff --git a/config/routes.rb b/config/routes.rb index 557439e9..d97611fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,7 @@ Rails.application.routes.draw do post 'pull', to: 'sites#merge' get 'status', to: 'sites#status' + get 'button', to: 'sites#button' # Gestionar usuaries get 'usuaries/invite', to: 'usuaries#invite'