mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-27 21:46:25 +00:00
Merge branch 'issue-10492' into panel.sutty.nl
This commit is contained in:
commit
cafd0a1b0d
7 changed files with 78 additions and 3 deletions
|
@ -8,6 +8,7 @@ class Site < ApplicationRecord
|
||||||
include Site::FindAndReplace
|
include Site::FindAndReplace
|
||||||
include Site::Api
|
include Site::Api
|
||||||
include Site::DeployDependencies
|
include Site::DeployDependencies
|
||||||
|
include Site::BuildStats
|
||||||
include Tienda
|
include Tienda
|
||||||
|
|
||||||
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty
|
# 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
|
%main.row
|
||||||
%aside.menu.col-md-3
|
%aside.menu.col-md-3
|
||||||
%h1= link_to @site.title, @site.url
|
%h1= @site.title
|
||||||
%p.lead= @site.description
|
%p.lead= @site.description
|
||||||
|
- cache_if @usuarie, [@site, I18n.locale] do
|
||||||
|
= render 'sites/status', site: @site
|
||||||
|
|
||||||
%h3= t('posts.new')
|
%h3= t('posts.new')
|
||||||
%table.mb-3
|
%table.mb-3
|
||||||
|
|
|
@ -53,10 +53,10 @@
|
||||||
= render 'bootstrap/alert' do
|
= render 'bootstrap/alert' do
|
||||||
= t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.help',
|
= t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.help',
|
||||||
layouts: site.incompatible_layouts.to_sentence)
|
layouts: site.incompatible_layouts.to_sentence)
|
||||||
.row.designs
|
.row.row-cols-1.row-cols-md-2.designs
|
||||||
-# Demasiado complejo para un f.collection_radio_buttons
|
-# Demasiado complejo para un f.collection_radio_buttons
|
||||||
- Design.all.find_each do |design|
|
- Design.all.find_each do |design|
|
||||||
.design.col-md-4.d-flex.flex-column
|
.design.col.d-flex.flex-column
|
||||||
.custom-control.custom-radio
|
.custom-control.custom-radio
|
||||||
= f.radio_button :design_id, design.id,
|
= f.radio_button :design_id, design.id,
|
||||||
checked: design.id == site.design_id,
|
checked: design.id == site.design_id,
|
||||||
|
|
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
|
|
@ -357,6 +357,10 @@ en:
|
||||||
designer_url: 'Support the designer'
|
designer_url: 'Support the designer'
|
||||||
static_file_migration: 'File migration'
|
static_file_migration: 'File migration'
|
||||||
find_and_replace: 'Search and replace'
|
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:
|
index:
|
||||||
title: 'My Sites'
|
title: 'My Sites'
|
||||||
pull: 'Upgrade'
|
pull: 'Upgrade'
|
||||||
|
|
|
@ -362,6 +362,10 @@ es:
|
||||||
designer_url: 'Apoyá a le(s) diseñadore(s)'
|
designer_url: 'Apoyá a le(s) diseñadore(s)'
|
||||||
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:
|
||||||
|
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:
|
index:
|
||||||
title: 'Mis sitios'
|
title: 'Mis sitios'
|
||||||
pull: 'Actualizar'
|
pull: 'Actualizar'
|
||||||
|
|
Loading…
Reference in a new issue