centralizar valores

This commit is contained in:
f 2021-10-09 15:50:38 -03:00
parent c927a56bef
commit f36ea9629d
3 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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")