diff --git a/app/models/site.rb b/app/models/site.rb
index f4ac56dd..3f2aa34e 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -8,6 +8,7 @@ class Site < ApplicationRecord
include Site::FindAndReplace
include Site::Api
include Site::DeployDependencies
+ include Site::BuildStats
include Tienda
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty
diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb
new file mode 100644
index 00000000..8b23942d
--- /dev/null
+++ b/app/models/site/build_stats.rb
@@ -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
diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml
index 68e92899..3497b0a4 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= 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
diff --git a/app/views/sites/_form.haml b/app/views/sites/_form.haml
index 48e30e0c..06b66ebb 100644
--- a/app/views/sites/_form.haml
+++ b/app/views/sites/_form.haml
@@ -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,
diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml
new file mode 100644
index 00000000..fb38896a
--- /dev/null
+++ b/app/views/sites/_status.haml
@@ -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
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 09ee1b3e..43176f5e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -357,6 +357,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 ..."
+ 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'
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 800c4b5f..a95f03b3 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -362,6 +362,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 ..."
+ 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'