This commit is contained in:
James Mason 2018-09-26 00:48:27 +00:00 committed by GitHub
commit ba7407aa00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 94 deletions

View file

@ -18,12 +18,6 @@
padding-bottom: 20px;
}
.dashbox .icon {
padding-left: 8px;
display: block;
font-size: 3.8em;
}
.dashbox label {
display: block;
font-size: 1.1em;

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
module Admin
module WidgetsHelper
# DRY up rendering of visual elements
def big_statistic(icon, subtitle, value, delta, reverse_delta = false)
content_tag('div', class: 'dashbox text-center') do
content_tag('span', class: 'fa') do
fa_icon(icon) +
value.to_s.html_safe # rubocop:disable Rails/OutputSafety
end +
content_tag('p') do
content_tag('small', subtitle.pluralize(value)) +
' '.html_safe + # rubocop:disable Rails/OutputSafety
login_delta_label(delta, reverse_delta)
end
end
end
def login_delta_label(delta, reverse = false)
variant = if delta.to_i.positive?
reverse ? :warning : :success
elsif delta.to_i.negative?
reverse ? :success : :warning
else
:info
end
bootstrap_label(
format('%+d', delta.to_i),
variant,
title: "#{delta} since you last logged in"
)
end
end
end

View file

@ -0,0 +1,8 @@
module WidgetsHelper
# DRY up rendering of visual elements
# https://getbootstrap.com/docs/3.3/components/#labels
def bootstrap_label(value, variant, options = {})
content_tag('span', value, class: "label label-#{variant}", **options)
end
end

View file

@ -1,53 +1,15 @@
= javascript_include_tag 'Chart'
.row
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-user.fa-lg
%span.fa.fa-lg
= @total_user
%p
%small
#{'User'.pluralize(@total_user)}
- if @new_user
%span.label.label-success{ title: "+ #{@new_user} since you last logged in!" }
+
= @new_user
= big_statistic('user', 'User', @total_user, @new_user)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-check-square.fa-lg
%span.fa.fa-lg
= @total_reg
%p
%small
#{'Registration'.pluralize(@total_reg)}
- if @new_reg
%span.label.label-success{ title: "+#{@new_reg} since you last logged in!" }
+
= @new_reg
= big_statistic('check-square', 'Registration', @total_reg, @new_reg)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-file-text.fa-lg
%span.fa.fa-lg
= @total_submissions
%p
%small
#{'Submission'.pluralize(@total_submissions)}
- if @new_submissions
%span.label.label-success{ title: "+#{@new_submissions} since you last logged in!" }
+
= @new_submissions
= big_statistic('file-text', 'Submission', @total_submissions, @new_submission)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-archive.fa-lg
%span.fa.fa-lg
= @total_withdrawn
%p
%small
#{'Withdrawn'.pluralize(@total_withdrawn)}
- if @new_withdrawn
%span.label.label-success{ title: "+#{@new_withdrawn} since you last logged in!" }
+
= @new_withdrawn
= big_statistic('archive', 'Withdrawn', @total_withdrawn, @new_withdrawn, true)
.row#registrations
.col-md-8

View file

@ -6,56 +6,16 @@
%hr
.row
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-user.fa-lg
%span.fa.fa-lg
= @total_reg
%p
%small
#{'Registration'.pluralize(@total_reg)}
- if @new_reg
%span.label.label-success{ title: "+#{@new_reg} since you last logged in!" }
+
= @new_reg
= big_statistic('user', 'Registration', @total_reg, @new_reg)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-check-square.fa-lg
%span.fa.fa-lg
= @total_submissions
%p
%small
#{'Submission'.pluralize(@total_submissions)}
- if @new_submissions
%span.label.label-success{ title: "+#{@new_submissions} since you last logged in!" }
+
= @new_submissions
= big_statistic('check-square', 'Submission', @total_submissions, @new_submissions)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-file-text.fa-lg
%span.fa.fa-lg
= @program_length
%p
%small
#{'Hour'.pluralize(@program_length)}
- if @new_reg
%span.label.label-success{ title: "+#{@new_program_length} since you last logged in!" }
+
= @new_program_length
= big_statistic('file-text', 'Hour', @program_length, @new_program_length)
.col-sm-3.col-xs-3
.dashbox.text-center
%span.fa.fa-archive.fa-lg
%span.fa.fa-lg
= @total_withdrawn
%p
%small
#{'Withdrawn'.pluralize(@total_withdrawn)}
- if @new_withdrawn
%span.label.label-success{ title: "+#{@new_withdrawn} since you last logged in!" }
+
= @new_withdrawn
= big_statistic('archive', 'Withdrawn', @total_withdrawn, @new_withdrawn, true)
.row
.col-md-12