Start making some helpers for redundant visual elements (widgets)

This commit is contained in:
James Mason 2018-03-20 11:19:17 -07:00
parent 780eb5c51d
commit 8b414e096c
No known key found for this signature in database
GPG key ID: 1B3951886C449023
5 changed files with 54 additions and 94 deletions

View file

@ -18,12 +18,6 @@
padding-bottom: 20px; padding-bottom: 20px;
} }
.dashbox .icon {
padding-left: 8px;
display: block;
font-size: 3.8em;
}
.dashbox label { .dashbox label {
display: block; display: block;
font-size: 1.1em; 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' = javascript_include_tag 'Chart'
.row .row
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('user', 'User', @total_user, @new_user)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('check-square', 'Registration', @total_reg, @new_reg)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('file-text', 'Submission', @total_submissions, @new_submission)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('archive', 'Withdrawn', @total_withdrawn, @new_withdrawn, true)
%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
.row#registrations .row#registrations
.col-md-8 .col-md-8

View file

@ -6,56 +6,16 @@
%hr %hr
.row .row
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('user', 'Registration', @total_reg, @new_reg)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('check-square', 'Submission', @total_submissions, @new_submissions)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('file-text', 'Hour', @program_length, @new_program_length)
%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
.col-sm-3.col-xs-3 .col-sm-3.col-xs-3
.dashbox.text-center = big_statistic('archive', 'Withdrawn', @total_withdrawn, @new_withdrawn, true)
%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
.row .row
.col-md-12 .col-md-12