From 4eb23a787bbdf66fbf9d26d1c44f4413fe0f4ab9 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 15 Apr 2023 18:36:56 -0300 Subject: [PATCH 01/10] feat: lista de links #13096 --- app/controllers/application_controller.rb | 4 +++ app/controllers/build_stats_controller.rb | 41 +++++++++++++++++++++++ app/controllers/posts_controller.rb | 4 --- app/policies/site_build_stat_policy.rb | 16 +++++++++ app/views/build_stats/index.haml | 21 ++++++++++++ config/locales/en.yml | 3 ++ config/locales/es.yml | 3 ++ config/routes.rb | 2 ++ 8 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 app/controllers/build_stats_controller.rb create mode 100644 app/policies/site_build_stat_policy.rb create mode 100644 app/views/build_stats/index.haml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b4be5a97..ee153394 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -91,6 +91,10 @@ class ApplicationController < ActionController::Base breadcrumb 'stats.index', root_path, match: :exact end + def site + @site ||= find_site + end + protected def configure_permitted_parameters diff --git a/app/controllers/build_stats_controller.rb b/app/controllers/build_stats_controller.rb new file mode 100644 index 00000000..31a4c5d6 --- /dev/null +++ b/app/controllers/build_stats_controller.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# La lista de estados de compilación, por ahora solo mostramos el último +# estado. +class BuildStatsController < ApplicationController + include ActionView::Helpers::NumberHelper + include ActionView::Helpers::DateHelper + + before_action :authenticate_usuarie! + + breadcrumb -> { current_usuarie.email }, :edit_usuarie_registration_path + breadcrumb 'sites.index', :sites_path, match: :exact + breadcrumb -> { site.title }, -> { site_posts_path(site, locale: locale) }, match: :exact + + def index + authorize SiteBuildStat.new(site) + breadcrumb I18n.t('build_stats.index.title'), '' + + @headers = %w[type url seconds size].map do |header| + t("deploy_mailer.deployed.th.#{header}") + end + + @table = site.deployment_list.map do |deploy| + type = deploy.class.name.underscore + urls = deploy.respond_to?(:urls) ? deploy.urls : [deploy.url].compact + urls = [nil] if urls.empty? + build_stat = deploy.build_stats.where(status: true).last + seconds = build_stat&.seconds || 0 + + { + title: t("deploy_mailer.deployed.#{type}.title"), + urls: urls, + seconds: { + human: distance_of_time_in_words(seconds), + machine: "PT#{seconds}S" + }, + size: number_to_human_size(build_stat&.bytes || 0, precision: 2) + } + end + end +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3c529c24..9720fe13 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -159,10 +159,6 @@ class PostsController < ApplicationController end.transform_keys(&:to_sym) end - def site - @site ||= find_site - end - def post @post ||= site.posts(lang: locale).find(params[:post_id] || params[:id]) end diff --git a/app/policies/site_build_stat_policy.rb b/app/policies/site_build_stat_policy.rb new file mode 100644 index 00000000..03f09d21 --- /dev/null +++ b/app/policies/site_build_stat_policy.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Quiénes pueden ver estados de compilación de un sitio +class SiteBuildStatPolicy + attr_reader :site_build_stat, :usuarie + + def initialize(usuarie, site_build_stat) + @usuarie = usuarie + @site_build_stat = site_build_stat + end + + # Todes les usuaries e invitades de este sitio + def index? + site_build_stat.site.usuarie?(usuarie) || site_build_stat.site.invitade?(usuarie) + end +end diff --git a/app/views/build_stats/index.haml b/app/views/build_stats/index.haml new file mode 100644 index 00000000..dab5fc9a --- /dev/null +++ b/app/views/build_stats/index.haml @@ -0,0 +1,21 @@ +%main.row + %aside.menu.col-md-3 + %h1= @site.title + %p.lead= @site.description + .col + %h1= t('.title') + + %table.table + %thead + %tr + - @headers.each do |header| + %th{ scope: 'col' }= header + %tbody + - @table.each do |row| + - row[:urls].each do |url| + %tr + %th{ scope: 'row' }= row[:title] + %td= link_to_if url.present?, url, url + %td + %time{ datetime: row[:seconds][:machine] }= row[:seconds][:human] + %td= row[:size] diff --git a/config/locales/en.yml b/config/locales/en.yml index 3ddf681d..d92aa42a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -697,3 +697,6 @@ en: queries: show: empty: '(empty)' + build_stats: + index: + title: "Publications" diff --git a/config/locales/es.yml b/config/locales/es.yml index 01f1085c..db116e37 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -705,3 +705,6 @@ es: queries: show: empty: '(vacío)' + build_stats: + index: + title: "Publicaciones" diff --git a/config/routes.rb b/config/routes.rb index 511ca654..3828915c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,5 +75,7 @@ Rails.application.routes.draw do get :'stats/host', to: 'stats#host' get :'stats/uris', to: 'stats#uris' get :'stats/resources', to: 'stats#resources' + + resources :build_stats, only: %i[index] end end From 5d541ebee64c34885baba12f7a4370984138f257 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 15 Apr 2023 19:06:20 -0300 Subject: [PATCH 02/10] fixup! feat: lista de links #13096 --- app/models/site_build_stat.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/models/site_build_stat.rb diff --git a/app/models/site_build_stat.rb b/app/models/site_build_stat.rb new file mode 100644 index 00000000..1a63a0bb --- /dev/null +++ b/app/models/site_build_stat.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +SiteBuildStat = Struct.new(:site) From 251dde865b534f93a2fd8a090d13676a34d0814f Mon Sep 17 00:00:00 2001 From: f Date: Sat, 15 Apr 2023 19:13:23 -0300 Subject: [PATCH 03/10] fix: siempre devolver un array --- app/models/deploy_distributed_press.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/deploy_distributed_press.rb b/app/models/deploy_distributed_press.rb index 32a3049e..ff2f7325 100644 --- a/app/models/deploy_distributed_press.rb +++ b/app/models/deploy_distributed_press.rb @@ -85,20 +85,22 @@ class DeployDistributedPress < Deploy private + # @return [Array] def gateway_urls - remote_info.dig(:distributed_press, :links).values.map do |protocol| + remote_info.dig(:distributed_press, :links)&.values&.map do |protocol| [ protocol[:link], protocol[:gateway] ] - end.flatten.compact.select do |link| + end&.flatten&.compact&.select do |link| link.include? '://' - end + end || [] end + # @return [Array] def protocol_urls - remote_info.dig(:distributed_press, :protocols).select do |_, enabled| + remote_info.dig(:distributed_press, :protocols)&.select do |_, enabled| enabled - end.map do |protocol, _| + end&.map do |protocol, _| "#{protocol}://#{site.hostname}" - end + end || [] end # El cliente de la API From 07d6b14b872d50c4bcca1b092a1599eee72a4199 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 15 Apr 2023 19:24:45 -0300 Subject: [PATCH 04/10] fix: cortar los links largos --- app/assets/stylesheets/application.scss | 4 ++++ app/views/build_stats/index.haml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index bba48558..fadbcbab 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -383,6 +383,8 @@ $bezier: cubic-bezier(0.75, 0, 0.25, 1); } } +.word-break-all { word-break: break-all !important; } + /* * Modificadores de Bootstrap que no tienen versión responsive. */ @@ -405,6 +407,8 @@ $bezier: cubic-bezier(0.75, 0, 0.25, 1); .text-#{$grid-breakpoint}-right { text-align: right !important; } .text-#{$grid-breakpoint}-center { text-align: center !important; } + .word-break-#{$grid-breakpoint}-all { word-break: break-all !important; } + // posición @each $position in $positions { .position-#{$grid-breakpoint}-#{$position} { position: $position !important; } diff --git a/app/views/build_stats/index.haml b/app/views/build_stats/index.haml index dab5fc9a..27dc20d1 100644 --- a/app/views/build_stats/index.haml +++ b/app/views/build_stats/index.haml @@ -15,7 +15,7 @@ - row[:urls].each do |url| %tr %th{ scope: 'row' }= row[:title] - %td= link_to_if url.present?, url, url + %td= link_to_if url.present?, url, url, class: 'word-break-all' %td %time{ datetime: row[:seconds][:machine] }= row[:seconds][:human] %td= row[:size] From 6651781cac78f169cc220d16cc680748694dad72 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 17 Apr 2023 14:45:12 -0300 Subject: [PATCH 05/10] feat: poder ir a la lista de publicaciones del sitio --- 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 a731aa7d..4cf480df 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -16,4 +16,4 @@ - link = true = render 'bootstrap/alert' do - = link_to_if link, message.html_safe, site.url, class: 'alert-link' + = link_to_if link, message.html_safe, site_build_stats_path(site), class: 'alert-link' From 31b66373aec1073e1742f33585e568bddf6c7aff Mon Sep 17 00:00:00 2001 From: f Date: Mon, 17 Apr 2023 15:03:00 -0300 Subject: [PATCH 06/10] fix: mejorar el mensaje de espera, dando un accionable --- config/locales/en.yml | 4 ++-- config/locales/es.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index d92aa42a..76fc20ab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -362,9 +362,9 @@ en: static_file_migration: 'File migration' find_and_replace: 'Search and replace' status: - building: "Your site is building, please wait to refresh this page..." + building: "Your site is building, refresh this page 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 visit it." + available: "Your site is available! Click here to visit find all the different ways to visit it." index: title: 'My Sites' pull: 'Upgrade' diff --git a/config/locales/es.yml b/config/locales/es.yml index db116e37..f4c579f1 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -367,9 +367,9 @@ es: static_file_migration: 'Migración de archivos' find_and_replace: 'Búsqueda y reemplazo' status: - building: "Tu sitio se está publicando, por favor espera para recargar esta página..." + building: "Tu sitio se está publicando, recargá esta página en ." not_published_yet: "Tu sitio se está publicando por primera vez, por favor espera hasta un minuto..." - available: "¡Tu sitio está disponible! Cliquea aquí para visitarlo." + available: "¡Tu sitio está disponible! Cliqueá aquí para encontrar todas las formas en que podés visitarlo." index: title: 'Mis sitios' pull: 'Actualizar' From 6e5fcc17ff25adedbbb9c5f5f4ad1a085cc6ef15 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 18 Apr 2023 17:38:45 -0300 Subject: [PATCH 07/10] fix: palabra sobrante --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 76fc20ab..2423ab61 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -364,7 +364,7 @@ en: status: building: "Your site is building, refresh this page 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 visit find all the different ways to visit it." + available: "Your site is available! Click here to find all the different ways to visit it." index: title: 'My Sites' pull: 'Upgrade' From f35df41d1be8b0e699246a27091a499c8ff4a752 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 20 Apr 2023 18:17:41 -0300 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20usar=20guionado=20en=20t=C3=ADtulo?= =?UTF-8?q?=20y=20descripci=C3=B3n=20#13160?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/application.scss | 2 ++ app/views/posts/index.haml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index bba48558..fa07a185 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -383,6 +383,8 @@ $bezier: cubic-bezier(0.75, 0, 0.25, 1); } } +.hyphens { hyphens: auto; } + /* * Modificadores de Bootstrap que no tienen versión responsive. */ diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 4f814cda..ba8f3ee5 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -1,7 +1,9 @@ %main.row %aside.menu.col-md-3 - %h1= @site.title - %p.lead= @site.description + .hyphens{ lang: @site.default_locale } + %h1= @site.title + %p.lead= @site.description + - cache_if @usuarie, [@site, I18n.locale] do = render 'sites/status', site: @site From 8ed5aedf757db07da0cbfbabe156913886c1ea5f Mon Sep 17 00:00:00 2001 From: f Date: Fri, 21 Apr 2023 12:31:46 -0300 Subject: [PATCH 09/10] feat: componente de cabecera de sitio --- app/views/posts/index.haml | 4 +--- app/views/sites/_header.haml | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 app/views/sites/_header.haml diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index ba8f3ee5..dd0bf052 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -1,8 +1,6 @@ %main.row %aside.menu.col-md-3 - .hyphens{ lang: @site.default_locale } - %h1= @site.title - %p.lead= @site.description + = render 'sites/header', site: @site - cache_if @usuarie, [@site, I18n.locale] do = render 'sites/status', site: @site diff --git a/app/views/sites/_header.haml b/app/views/sites/_header.haml new file mode 100644 index 00000000..c8931041 --- /dev/null +++ b/app/views/sites/_header.haml @@ -0,0 +1,3 @@ +.hyphens{ lang: site.default_locale } + %h1= site.title + %p.lead= site.description From f1aefbcb34526a02acdd41b9bba80bcb9de6c4d5 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 21 Apr 2023 12:36:40 -0300 Subject: [PATCH 10/10] fix: guionar titulo y descripciones largas #13096 --- app/views/build_stats/index.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/build_stats/index.haml b/app/views/build_stats/index.haml index 27dc20d1..27c063f9 100644 --- a/app/views/build_stats/index.haml +++ b/app/views/build_stats/index.haml @@ -1,7 +1,6 @@ %main.row %aside.menu.col-md-3 - %h1= @site.title - %p.lead= @site.description + = render 'sites/header', site: @site .col %h1= t('.title')