mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 21:56:21 +00:00
Merge branch 'issue-10492' into 'rails'
Issue 10492 See merge request sutty/sutty!139
This commit is contained in:
commit
c4d1f5f505
7 changed files with 78 additions and 3 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 > 1
|
||||
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
|
||||
|
|
|
@ -53,10 +53,10 @@
|
|||
= render 'bootstrap/alert' do
|
||||
= t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.help',
|
||||
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
|
||||
- Design.all.find_each do |design|
|
||||
.design.col-md-4.d-flex.flex-column
|
||||
.design.col.d-flex.flex-column
|
||||
.custom-control.custom-radio
|
||||
= f.radio_button :design_id, 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_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
|
||||
- message = t('.available')
|
||||
- link = true
|
||||
|
||||
= render 'bootstrap/alert' do
|
||||
= link_to_if link, message.html_safe, site.url, class: 'alert-link'
|
|
@ -353,6 +353,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> to refresh this page..."
|
||||
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'
|
||||
|
|
|
@ -358,6 +358,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> para recargar esta página..."
|
||||
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