diff --git a/app/assets/stylesheets/osem-dashboard.scss b/app/assets/stylesheets/osem-dashboard.scss index b2d0d125..3b5685ad 100644 --- a/app/assets/stylesheets/osem-dashboard.scss +++ b/app/assets/stylesheets/osem-dashboard.scss @@ -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; diff --git a/app/helpers/admin/widgets_helper.rb b/app/helpers/admin/widgets_helper.rb new file mode 100644 index 00000000..213b0918 --- /dev/null +++ b/app/helpers/admin/widgets_helper.rb @@ -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 diff --git a/app/helpers/widgets_helper.rb b/app/helpers/widgets_helper.rb new file mode 100644 index 00000000..dd9e3927 --- /dev/null +++ b/app/helpers/widgets_helper.rb @@ -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 diff --git a/app/views/admin/conferences/index.html.haml b/app/views/admin/conferences/index.html.haml index b81cfa26..0c5e5bab 100644 --- a/app/views/admin/conferences/index.html.haml +++ b/app/views/admin/conferences/index.html.haml @@ -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 diff --git a/app/views/admin/conferences/show.html.haml b/app/views/admin/conferences/show.html.haml index ad4cef31..cd4bd341 100644 --- a/app/views/admin/conferences/show.html.haml +++ b/app/views/admin/conferences/show.html.haml @@ -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