diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 8045a653..093fbe93 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -8,15 +8,12 @@ class StatsController < ApplicationController before_action :authenticate_usuarie! before_action :authorize_stats - INTERVALS = %i[hour day week month year].freeze - RESOURCES = %i[builds space_used build_time].freeze EXTRA_OPTIONS = { builds: {}, space_used: { bytes: true }, build_time: {} }.freeze - # XXX: Permitir a Chart.js inyectar su propio CSS content_security_policy only: :index do |policy| policy.style_src :self, :unsafe_inline @@ -85,7 +82,7 @@ class StatsController < ApplicationController # toma de estadísticas y restando el tiempo que pasó desde ese # momento. def chart_options - time = last_stat.created_at + (1.send(interval)) + time = last_stat.created_at + 1.try(interval) please_return_at = { please_return_at: distance_of_time_in_words(Time.now, time) } @chart_options ||= { @@ -102,14 +99,14 @@ class StatsController < ApplicationController def interval @interval ||= begin i = params[:interval].to_sym - INTERVALS.include?(i) ? i : :day + Stat::INTERVALS.include?(i) ? i : :day end end def resource @resource ||= begin r = params[:resource].to_sym - RESOURCES.include?(r) ? r : :builds + Stat::RESOURCES.include?(r) ? r : :builds end end diff --git a/app/models/stat.rb b/app/models/stat.rb index cf717b05..1e3af9e9 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -1,3 +1,6 @@ # frozen_string_literal: true -class Stat < ApplicationRecord; end +class Stat < ApplicationRecord + INTERVALS = %i[hour day week month year].freeze + RESOURCES = %i[builds space_used build_time].freeze +end diff --git a/app/views/stats/index.haml b/app/views/stats/index.haml index 101dee1e..992200a4 100644 --- a/app/views/stats/index.haml +++ b/app/views/stats/index.haml @@ -9,7 +9,7 @@ "#{time_ago_in_words @last_stat.created_at}." .mb-3 - - StatsController::INTERVALS.each do |interval| + - Stat::INTERVALS.each do |interval| = link_to t(".#{interval}"), site_stats_path(interval: interval), class: "btn #{'btn-primary active' if params[:interval].to_sym == interval}" .mb-3 @@ -17,7 +17,7 @@ %p.lead= t('.host.description') = line_chart site_stats_host_path(@chart_params), **@chart_options - - StatsController::RESOURCES.each do |resource| + - Stat::RESOURCES.each do |resource| .mb-3 %h2= t(".resources.#{resource}.title") %p.lead= t(".resources.#{resource}.description")