mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 08:41:42 +00:00
feat: informar el estado del sitio #10492
This commit is contained in:
parent
0d0c8c8b07
commit
c2fafac7f0
6 changed files with 76 additions and 1 deletions
|
@ -7,6 +7,7 @@ class Site < ApplicationRecord
|
|||
include Site::Forms
|
||||
include Site::FindAndReplace
|
||||
include Site::Api
|
||||
include Site::BuildStats
|
||||
include Tienda
|
||||
|
||||
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty
|
||||
|
|
45
app/models/site/build_stats.rb
Normal file
45
app/models/site/build_stats.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Site
|
||||
module BuildStats
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
# Devuelve el tiempo promedio de publicación para este sitio
|
||||
#
|
||||
# @return [Integer]
|
||||
def average_publication_time
|
||||
build_stats.group(:action).average(:seconds).values.reduce(:+).round
|
||||
end
|
||||
|
||||
# Devuelve el tiempo promedio de compilación para sitios similares
|
||||
# a este.
|
||||
#
|
||||
# @return [Integer]
|
||||
def average_publication_time_for_similar_sites
|
||||
similar_deploys = Deploy.where(type: deploys.pluck(:type)).pluck(:id)
|
||||
|
||||
BuildStat.where(deploy_id: similar_deploys).group(:action).average(:seconds).values.reduce(:+).round
|
||||
end
|
||||
|
||||
# Define si podemos calcular el tiempo promedio de publicación
|
||||
# para este sitio
|
||||
#
|
||||
# @return [Boolean]
|
||||
def average_publication_time_calculable?
|
||||
build_stats.jekyll.where(status: true).count > 0
|
||||
end
|
||||
|
||||
def similar_sites?
|
||||
!design.no_theme?
|
||||
end
|
||||
|
||||
# Detecta si el sitio todavía no ha sido publicado
|
||||
#
|
||||
# @return [Boolean]
|
||||
def not_published_yet?
|
||||
build_stats.jekyll.where(status: true).count.zero?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,9 @@
|
|||
%main.row
|
||||
%aside.menu.col-md-3
|
||||
%h1= link_to @site.title, @site.url
|
||||
%h1= @site.title
|
||||
%p.lead= @site.description
|
||||
- cache_if @usuarie, [@site, I18n.locale] do
|
||||
= render 'sites/status', site: @site
|
||||
|
||||
%h3= t('posts.new')
|
||||
%table.mb-3
|
||||
|
|
19
app/views/sites/_status.haml
Normal file
19
app/views/sites/_status.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
- link = nil
|
||||
- if site.not_published_yet?
|
||||
- message = t('.not_published_yet')
|
||||
- if site.building?
|
||||
- if site.average_publication_time_calculable?
|
||||
- average_building_time = site.average_building_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
|
||||
- message = t('.available')
|
||||
- link = true
|
||||
|
||||
= render 'bootstrap/alert' do
|
||||
= link_to_if link, message.html_safe, site.url
|
|
@ -330,6 +330,10 @@ en:
|
|||
designer_url: 'Support the designer'
|
||||
static_file_migration: 'File migration'
|
||||
find_and_replace: 'Search and replace'
|
||||
status:
|
||||
building: "Your site is building, please wait <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..."
|
||||
available: "Your site is available! Click here to visit it."
|
||||
index:
|
||||
title: 'My Sites'
|
||||
pull: 'Upgrade'
|
||||
|
|
|
@ -335,6 +335,10 @@ es:
|
|||
designer_url: 'Apoyá a le(s) diseñadore(s)'
|
||||
static_file_migration: 'Migración de archivos'
|
||||
find_and_replace: 'Búsqueda y reemplazo'
|
||||
status:
|
||||
building: "Tu sitio se está publicando, por favor espera <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..."
|
||||
available: "¡Tu sitio está disponible! Cliquea aquí para visitarlo."
|
||||
index:
|
||||
title: 'Mis sitios'
|
||||
pull: 'Actualizar'
|
||||
|
|
Loading…
Reference in a new issue