From fb38600884faffea66a9ff832d854fec3eb5dc03 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 22 Mar 2024 18:34:24 -0300 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20recargar=20autom=C3=A1ticamente=20e?= =?UTF-8?q?l=20estado=20de=20publicaci=C3=B3n=20#13611?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/sites_controller.rb | 7 +++++ app/javascript/packs/application.js | 2 ++ app/views/sites/_status.haml | 41 ++++++++++++++++------------- app/views/sites/status.haml | 1 + config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/routes.rb | 2 ++ package.json | 3 ++- yarn.lock | 5 ++++ 9 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 app/views/sites/status.haml diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index bec42b39..49527cf7 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -15,6 +15,13 @@ class SitesController < ApplicationController fresh_when @sites end + # Genera la caja del estado para HTMX + def status + authorize site + + render('sites/status', layout: false) if stale? site + end + # No tenemos propiedades de un sitio aún, así que vamos al listado de # artículos def show diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 9cbc30bf..9ddc9753 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -33,3 +33,5 @@ import 'chartkick/chart.js' Rails.start() Turbolinks.start() ActiveStorage.start() + +window.htmx = require('htmx.org/dist/htmx') diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index 6a610e73..47bed657 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -1,21 +1,24 @@ -- link = nil -- if site.not_published_yet? - - message = t('.not_published_yet') -- elsif site.awaiting_publication? - - message = t('.awaiting_publication') -- elsif site.building? - - if site.average_publication_time_calculable? - - average_building_time = site.average_publication_time - - elsif !site.similar_sites? - - average_building_time = 60 +- cache site do + - link = nil + - if site.not_published_yet? + - message = t('.not_published_yet') + - elsif site.awaiting_publication? + - message = t('.awaiting_publication') + - elsif site.building? + - if site.average_publication_time_calculable? + - average_building_time = site.average_publication_time + - elsif !site.similar_sites? + - average_building_time = 60 + - else + - average_building_time = site.average_publication_time_for_similar_sites + + - average_publication_time_human = distance_of_time_in_words average_building_time + - message = t('.building', average_time: average_publication_time_human, seconds: average_building_time) - else - - average_building_time = site.average_publication_time_for_similar_sites + - message = t('.available') + - link = true - - average_publication_time_human = distance_of_time_in_words average_building_time - - message = t('.building', average_time: average_publication_time_human, seconds: average_building_time) -- else - - message = t('.available') - - link = true - -= render 'bootstrap/alert' do - = link_to_if link, message.html_safe, site_build_stats_path(site), class: 'alert-link' + -# TODO: Calcular cada cuanto 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' diff --git a/app/views/sites/status.haml b/app/views/sites/status.haml new file mode 100644 index 00000000..3d9793a5 --- /dev/null +++ b/app/views/sites/status.haml @@ -0,0 +1 @@ += render 'sites/status', site: @site diff --git a/config/locales/en.yml b/config/locales/en.yml index fc9d4894..720f784a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -389,7 +389,7 @@ en: static_file_migration: 'File migration' find_and_replace: 'Search and replace' status: - building: "Your site is building, refresh this page in ." + building: "Your site is building, it will be ready in ." not_published_yet: "Your site is being published for the first time, please wait up to 1 minute..." available: "Your site is available! Click here to find all the different ways to visit it." awaiting_publication: "There are unpublished changes. Click the button below and wait a moment to find them on your site." diff --git a/config/locales/es.yml b/config/locales/es.yml index 4bda4982..e7ff0864 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -394,7 +394,7 @@ es: static_file_migration: 'Migración de archivos' find_and_replace: 'Búsqueda y reemplazo' status: - building: "Tu sitio se está publicando, recargá esta página en ." + building: "Tu sitio se está publicando, estará listo en ." not_published_yet: "Tu sitio se está publicando por primera vez, por favor espera hasta un minuto..." available: "¡Tu sitio está disponible! Cliqueá aquí para encontrar todas las formas en que podés visitarlo." awaiting_publication: "Hay cambios sin publicar, cliqueá el botón debajo y espera un momento para encontrarlos en tu sitio." diff --git a/config/routes.rb b/config/routes.rb index 635be07a..557439e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,8 @@ Rails.application.routes.draw do get 'pull', to: 'sites#fetch' post 'pull', to: 'sites#merge' + get 'status', to: 'sites#status' + # Gestionar usuaries get 'usuaries/invite', to: 'usuaries#invite' post 'usuaries/invite', to: 'usuaries#send_invitations' diff --git a/package.json b/package.json index 7901ad41..871c9d9b 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "zepto": "^1.2.0" }, "devDependencies": { - "@types/rails__activestorage": "^6.0.0" + "@types/rails__activestorage": "^6.0.0", + "htmx.org": "^1.9.11" } } diff --git a/yarn.lock b/yarn.lock index 0c52b9d3..4619169e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4548,6 +4548,11 @@ html-entities@^1.3.1: resolved "https://registry.npmjs.org/html-entities/-/html-entities-1.4.0.tgz" integrity sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA== +htmx.org@^1.9.11: + version "1.9.11" + resolved "https://registry.yarnpkg.com/htmx.org/-/htmx.org-1.9.11.tgz#00192041ee682d6ca7146d0fbd901169ffe72d87" + integrity sha512-WlVuICn8dfNOOgYmdYzYG8zSnP3++AdHkMHooQAzGZObWpVXYathpz/I37ycF4zikR6YduzfCvEcxk20JkIUsw== + http-deceiver@^1.2.7: version "1.2.7" resolved "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz" From 736f0552f73e9a88a81552da1725b87dfeea33e4 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 22 Mar 2024 18:46:21 -0300 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20poder=20importar=20htmx=20en=20produ?= =?UTF-8?q?cci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/packs/application.js | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 9ddc9753..d8ff0dd1 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -34,4 +34,4 @@ Rails.start() Turbolinks.start() ActiveStorage.start() -window.htmx = require('htmx.org/dist/htmx') +window.htmx = require('htmx.org/dist/htmx.js') diff --git a/package.json b/package.json index 871c9d9b..870b8e9b 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "commonmark": "^0.29.0", "fork-awesome": "^1.1.7", "fork-ts-checker-webpack-plugin": "^6.1.0", + "htmx.org": "^1.9.11", "input-map": "git+https://0xacab.org/sutty/input-map.git", "input-tag": "git+https://0xacab.org/sutty/input-tag.git", "leaflet": "^1.7.1", @@ -34,7 +35,6 @@ "zepto": "^1.2.0" }, "devDependencies": { - "@types/rails__activestorage": "^6.0.0", - "htmx.org": "^1.9.11" + "@types/rails__activestorage": "^6.0.0" } } From 95231511b78243dede6c4cab52ab6116fb145a54 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 22 Mar 2024 18:54:18 -0300 Subject: [PATCH 3/9] fix: poder ver el estado --- app/policies/site_policy.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/policies/site_policy.rb b/app/policies/site_policy.rb index 2ca96256..d5465d6b 100644 --- a/app/policies/site_policy.rb +++ b/app/policies/site_policy.rb @@ -14,6 +14,10 @@ class SitePolicy true end + def status? + true + end + # Puede ver la versión privada del sitio? def private? edit? && site.deploys.find_by_type('DeployPrivate') From 629549c916d45ee79be189dbcfab536ed1396ba4 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 11:49:30 -0300 Subject: [PATCH 4/9] =?UTF-8?q?fix:=20rehabilitar=20el=20bot=C3=B3n=20tamb?= =?UTF-8?q?i=C3=A9n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/posts/index.haml | 2 -- app/views/sites/_status.haml | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 374f06ee..29f6471f 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -4,8 +4,6 @@ = render 'sites/status', site: @site - = render 'sites/build', site: @site, class: 'btn-block' - %h3= t('posts.new') %table.table.table-sm.mb-3 %tbody diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index 47bed657..d3da5c73 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -22,3 +22,5 @@ %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' From 7cca88b4f3ce0845cdbdfb55885b406b89199d1d Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 12:15:30 -0300 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20al=20salir=20de=20la=20p=C3=A1gina,?= =?UTF-8?q?=20cancelar=20todas=20las=20peticiones=20de=20htmx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #15880 closes #15881 closes #15883 closes #15884 closes #15893 closes #15894 closes #15973 closes #15974 closes #15975 closes #16003 closes #16004 --- app/javascript/etc/htmx_abort.js | 7 +++++++ app/javascript/etc/index.js | 1 + 2 files changed, 8 insertions(+) create mode 100644 app/javascript/etc/htmx_abort.js diff --git a/app/javascript/etc/htmx_abort.js b/app/javascript/etc/htmx_abort.js new file mode 100644 index 00000000..308d0315 --- /dev/null +++ b/app/javascript/etc/htmx_abort.js @@ -0,0 +1,7 @@ +// Cancela las peticiones pendientes de htmx para todos los elementos al +// cambiar de página. +document.addEventListener("turbolinks:click", () => { + for (const hx of document.querySelectorAll("[hx-get]")) { + window.htmx.trigger(hx, "htmx:abort"); + } +}); diff --git a/app/javascript/etc/index.js b/app/javascript/etc/index.js index d4b9f7a3..9ee6a95a 100644 --- a/app/javascript/etc/index.js +++ b/app/javascript/etc/index.js @@ -7,3 +7,4 @@ import './timezone' import './turbolinks-anchors' import './validation' import './new_editor' +import './htmx_abort' From 847af3374ce02fa352b7ce163ddebbb5d19da247 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 13:26:22 -0300 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20no=20multiplicar=20el=20bot=C3=B3n!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/sites/_status.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index d3da5c73..9ac27c15 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -23,4 +23,4 @@ = 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' + = render 'sites/build', site: site, class: 'btn-block' From 5e1def1028cb1946e2b2f232cc4aaa3bad9c189c Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 13:32:37 -0300 Subject: [PATCH 7/9] =?UTF-8?q?feat:=20deshabilitar=20el=20bot=C3=B3n=20mi?= =?UTF-8?q?entras=20est=C3=A1=20compilando=20tambi=C3=A9n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit para no lanzar más de una compilación por vez --- app/views/sites/_build.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/sites/_build.haml b/app/views/sites/_build.haml index b0961e31..c723a3ac 100644 --- a/app/views/sites/_build.haml +++ b/app/views/sites/_build.haml @@ -6,4 +6,4 @@ 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.enqueued? + disabled: !site.waiting? From 5f0672bcaebd1d68d81738c9d74f4275eb6866b9 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 30 Apr 2024 17:44:33 -0300 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20recargar=20el=20bot=C3=B3n=20de=20p?= =?UTF-8?q?ublicar=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' From 79be9538bb8ccf9350e5e4cb71150e92440fdcb6 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 30 Apr 2024 17:45:33 -0300 Subject: [PATCH 9/9] fix: ignorar los errores de abort de htmx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit el problema es que cuando se envía un abort a htmx, se loguea un mensaje de todas formas. closes #15880 closes #15881 closes #15883 closes #15884 closes #15893 closes #15894 closes #15973 closes #15974 closes #15975 closes #16003 closes #16004 closes #16015 closes #16016 closes #16023 closes #16024 closes #16050 closes #16051 closes #16063 closes #16064 closes #16073 closes #16074 closes #16116 closes #16125 closes #16126 --- app/javascript/packs/application.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index d8ff0dd1..e10e2b5d 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -9,9 +9,16 @@ try { host: window.env.PANEL_URL }); + const ignoredErrors = ["htmx:afterRequest", "htmx:sendAbort"]; + console.originalError = console.error; console.error = (...e) => { - window.airbrake.notify(e.join(" ")); + const msg = e.join(" "); + + if (!ignoredErrors.some(x => msg.includes(x))) { + window.airbrake.notify(e.join(" ")); + } + return console.originalError(...e); }; } catch(e) {