mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 04:06:22 +00:00
Merge branch 'issue-13611' into 'rails'
feat: recargar automáticamente el estado de publicación #13611 Closes #16126, #16125, #16116, #16074, #16073, #16064, #16063, #16051, #16050, #16024, #16023, #16016, #16015, #16004, #16003, #15975, #15974, #15973, #15894, #15893, #15884, #15883, #15881, and #15880 See merge request sutty/sutty!248
This commit is contained in:
commit
2a37844f28
15 changed files with 83 additions and 31 deletions
|
@ -15,6 +15,19 @@ class SitesController < ApplicationController
|
||||||
fresh_when @sites
|
fresh_when @sites
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Genera la caja del estado para HTMX
|
||||||
|
def status
|
||||||
|
authorize site
|
||||||
|
|
||||||
|
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
|
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
||||||
# artículos
|
# artículos
|
||||||
def show
|
def show
|
||||||
|
|
7
app/javascript/etc/htmx_abort.js
Normal file
7
app/javascript/etc/htmx_abort.js
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
});
|
|
@ -7,3 +7,4 @@ import './timezone'
|
||||||
import './turbolinks-anchors'
|
import './turbolinks-anchors'
|
||||||
import './validation'
|
import './validation'
|
||||||
import './new_editor'
|
import './new_editor'
|
||||||
|
import './htmx_abort'
|
||||||
|
|
|
@ -9,9 +9,16 @@ try {
|
||||||
host: window.env.PANEL_URL
|
host: window.env.PANEL_URL
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ignoredErrors = ["htmx:afterRequest", "htmx:sendAbort"];
|
||||||
|
|
||||||
console.originalError = console.error;
|
console.originalError = console.error;
|
||||||
console.error = (...e) => {
|
console.error = (...e) => {
|
||||||
|
const msg = e.join(" ");
|
||||||
|
|
||||||
|
if (!ignoredErrors.some(x => msg.includes(x))) {
|
||||||
window.airbrake.notify(e.join(" "));
|
window.airbrake.notify(e.join(" "));
|
||||||
|
}
|
||||||
|
|
||||||
return console.originalError(...e);
|
return console.originalError(...e);
|
||||||
};
|
};
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -33,3 +40,5 @@ import 'chartkick/chart.js'
|
||||||
Rails.start()
|
Rails.start()
|
||||||
Turbolinks.start()
|
Turbolinks.start()
|
||||||
ActiveStorage.start()
|
ActiveStorage.start()
|
||||||
|
|
||||||
|
window.htmx = require('htmx.org/dist/htmx.js')
|
||||||
|
|
|
@ -14,6 +14,10 @@ class SitePolicy
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def status?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
# Puede ver la versión privada del sitio?
|
# Puede ver la versión privada del sitio?
|
||||||
def private?
|
def private?
|
||||||
edit? && site.deploys.find_by_type('DeployPrivate')
|
edit? && site.deploys.find_by_type('DeployPrivate')
|
||||||
|
@ -57,6 +61,10 @@ class SitePolicy
|
||||||
show? && usuarie?
|
show? && usuarie?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def button?
|
||||||
|
show?
|
||||||
|
end
|
||||||
|
|
||||||
def enqueue?
|
def enqueue?
|
||||||
build?
|
build?
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
= render 'sites/header', site: @site
|
= render 'sites/header', site: @site
|
||||||
|
|
||||||
= render 'sites/status', site: @site
|
= render 'sites/status', site: @site
|
||||||
|
|
||||||
= render 'sites/build', site: @site, class: 'btn-block'
|
= render 'sites/build', site: @site, class: 'btn-block'
|
||||||
|
|
||||||
%h3= t('posts.new')
|
%h3= t('posts.new')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
- if policy(site).build?
|
- if policy(site).build?
|
||||||
|
%div{ 'hx-get': site_button_path(site, class: local_assigns[:class]), 'hx-trigger': 'every 10s', 'hx-swap': 'outerHTML' }
|
||||||
= form_tag site_enqueue_path(site),
|
= form_tag site_enqueue_path(site),
|
||||||
method: :post,
|
method: :post,
|
||||||
class: 'form-inline inline' do
|
class: 'form-inline inline' do
|
||||||
|
@ -6,4 +7,4 @@
|
||||||
class: "btn btn-secondary #{local_assigns[:class]}",
|
class: "btn btn-secondary #{local_assigns[:class]}",
|
||||||
title: site.enqueued? ? t('help.sites.enqueued') : t('help.sites.enqueue'),
|
title: site.enqueued? ? t('help.sites.enqueued') : t('help.sites.enqueue'),
|
||||||
data: { disable_with: t('sites.enqueued') },
|
data: { disable_with: t('sites.enqueued') },
|
||||||
disabled: site.enqueued?
|
disabled: !site.waiting?
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- cache site do
|
||||||
- link = nil
|
- link = nil
|
||||||
- if site.not_published_yet?
|
- if site.not_published_yet?
|
||||||
- message = t('.not_published_yet')
|
- message = t('.not_published_yet')
|
||||||
|
@ -17,5 +18,7 @@
|
||||||
- message = t('.available')
|
- message = t('.available')
|
||||||
- link = true
|
- link = true
|
||||||
|
|
||||||
|
-# 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
|
= render 'bootstrap/alert' do
|
||||||
= link_to_if link, message.html_safe, site_build_stats_path(site), class: 'alert-link'
|
= link_to_if link, message.html_safe, site_build_stats_path(site), class: 'alert-link'
|
||||||
|
|
1
app/views/sites/build.haml
Normal file
1
app/views/sites/build.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
= render 'sites/build', site: @site, class: params.permit(:class)[:class]
|
1
app/views/sites/status.haml
Normal file
1
app/views/sites/status.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
= render 'sites/status', site: @site
|
|
@ -389,7 +389,7 @@ en:
|
||||||
static_file_migration: 'File migration'
|
static_file_migration: 'File migration'
|
||||||
find_and_replace: 'Search and replace'
|
find_and_replace: 'Search and replace'
|
||||||
status:
|
status:
|
||||||
building: "Your site is building, refresh this page in <time datetime=\"PT%{seconds}S\">%{average_time}</time>."
|
building: "Your site is building, it will be ready in <time datetime=\"PT%{seconds}S\">%{average_time}</time>."
|
||||||
not_published_yet: "Your site is being published for the first time, please wait up to 1 minute..."
|
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."
|
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."
|
awaiting_publication: "There are unpublished changes. Click the button below and wait a moment to find them on your site."
|
||||||
|
|
|
@ -394,7 +394,7 @@ es:
|
||||||
static_file_migration: 'Migración de archivos'
|
static_file_migration: 'Migración de archivos'
|
||||||
find_and_replace: 'Búsqueda y reemplazo'
|
find_and_replace: 'Búsqueda y reemplazo'
|
||||||
status:
|
status:
|
||||||
building: "Tu sitio se está publicando, recargá esta página en <time datetime=\"PT%{seconds}S\">%{average_time}</time>."
|
building: "Tu sitio se está publicando, estará listo en <time datetime=\"PT%{seconds}S\">%{average_time}</time>."
|
||||||
not_published_yet: "Tu sitio se está publicando por primera vez, por favor espera hasta un minuto..."
|
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."
|
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."
|
awaiting_publication: "Hay cambios sin publicar, cliqueá el botón debajo y espera un momento para encontrarlos en tu sitio."
|
||||||
|
|
|
@ -37,6 +37,9 @@ Rails.application.routes.draw do
|
||||||
get 'pull', to: 'sites#fetch'
|
get 'pull', to: 'sites#fetch'
|
||||||
post 'pull', to: 'sites#merge'
|
post 'pull', to: 'sites#merge'
|
||||||
|
|
||||||
|
get 'status', to: 'sites#status'
|
||||||
|
get 'button', to: 'sites#button'
|
||||||
|
|
||||||
# Gestionar usuaries
|
# Gestionar usuaries
|
||||||
get 'usuaries/invite', to: 'usuaries#invite'
|
get 'usuaries/invite', to: 'usuaries#invite'
|
||||||
post 'usuaries/invite', to: 'usuaries#send_invitations'
|
post 'usuaries/invite', to: 'usuaries#send_invitations'
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
"commonmark": "^0.29.0",
|
"commonmark": "^0.29.0",
|
||||||
"fork-awesome": "^1.1.7",
|
"fork-awesome": "^1.1.7",
|
||||||
"fork-ts-checker-webpack-plugin": "^6.1.0",
|
"fork-ts-checker-webpack-plugin": "^6.1.0",
|
||||||
|
"htmx.org": "^1.9.11",
|
||||||
"input-map": "git+https://0xacab.org/sutty/input-map.git",
|
"input-map": "git+https://0xacab.org/sutty/input-map.git",
|
||||||
"input-tag": "git+https://0xacab.org/sutty/input-tag.git",
|
"input-tag": "git+https://0xacab.org/sutty/input-tag.git",
|
||||||
"leaflet": "^1.7.1",
|
"leaflet": "^1.7.1",
|
||||||
|
|
|
@ -4570,6 +4570,11 @@ html-entities@^1.3.1:
|
||||||
resolved "https://registry.npmjs.org/html-entities/-/html-entities-1.4.0.tgz"
|
resolved "https://registry.npmjs.org/html-entities/-/html-entities-1.4.0.tgz"
|
||||||
integrity sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA==
|
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:
|
http-deceiver@^1.2.7:
|
||||||
version "1.2.7"
|
version "1.2.7"
|
||||||
resolved "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz"
|
resolved "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz"
|
||||||
|
|
Loading…
Reference in a new issue