mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 15:51:41 +00:00
centralizar valores
This commit is contained in:
parent
c927a56bef
commit
f36ea9629d
3 changed files with 9 additions and 9 deletions
|
@ -8,15 +8,12 @@ class StatsController < ApplicationController
|
||||||
before_action :authenticate_usuarie!
|
before_action :authenticate_usuarie!
|
||||||
before_action :authorize_stats
|
before_action :authorize_stats
|
||||||
|
|
||||||
INTERVALS = %i[hour day week month year].freeze
|
|
||||||
RESOURCES = %i[builds space_used build_time].freeze
|
|
||||||
EXTRA_OPTIONS = {
|
EXTRA_OPTIONS = {
|
||||||
builds: {},
|
builds: {},
|
||||||
space_used: { bytes: true },
|
space_used: { bytes: true },
|
||||||
build_time: {}
|
build_time: {}
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
|
||||||
# XXX: Permitir a Chart.js inyectar su propio CSS
|
# XXX: Permitir a Chart.js inyectar su propio CSS
|
||||||
content_security_policy only: :index do |policy|
|
content_security_policy only: :index do |policy|
|
||||||
policy.style_src :self, :unsafe_inline
|
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
|
# toma de estadísticas y restando el tiempo que pasó desde ese
|
||||||
# momento.
|
# momento.
|
||||||
def chart_options
|
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) }
|
please_return_at = { please_return_at: distance_of_time_in_words(Time.now, time) }
|
||||||
|
|
||||||
@chart_options ||= {
|
@chart_options ||= {
|
||||||
|
@ -102,14 +99,14 @@ class StatsController < ApplicationController
|
||||||
def interval
|
def interval
|
||||||
@interval ||= begin
|
@interval ||= begin
|
||||||
i = params[:interval].to_sym
|
i = params[:interval].to_sym
|
||||||
INTERVALS.include?(i) ? i : :day
|
Stat::INTERVALS.include?(i) ? i : :day
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource
|
def resource
|
||||||
@resource ||= begin
|
@resource ||= begin
|
||||||
r = params[:resource].to_sym
|
r = params[:resource].to_sym
|
||||||
RESOURCES.include?(r) ? r : :builds
|
Stat::RESOURCES.include?(r) ? r : :builds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# 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
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"#{time_ago_in_words @last_stat.created_at}."
|
"#{time_ago_in_words @last_stat.created_at}."
|
||||||
|
|
||||||
.mb-3
|
.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}"
|
= link_to t(".#{interval}"), site_stats_path(interval: interval), class: "btn #{'btn-primary active' if params[:interval].to_sym == interval}"
|
||||||
|
|
||||||
.mb-3
|
.mb-3
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
%p.lead= t('.host.description')
|
%p.lead= t('.host.description')
|
||||||
= line_chart site_stats_host_path(@chart_params), **@chart_options
|
= line_chart site_stats_host_path(@chart_params), **@chart_options
|
||||||
|
|
||||||
- StatsController::RESOURCES.each do |resource|
|
- Stat::RESOURCES.each do |resource|
|
||||||
.mb-3
|
.mb-3
|
||||||
%h2= t(".resources.#{resource}.title")
|
%h2= t(".resources.#{resource}.title")
|
||||||
%p.lead= t(".resources.#{resource}.description")
|
%p.lead= t(".resources.#{resource}.description")
|
||||||
|
|
Loading…
Reference in a new issue