From 28293cb4c41d64ea977ebdf82fcae5f4d69d77ab Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Wed, 4 Jun 2014 16:11:33 +0200 Subject: [PATCH] Implements recent items tabs and top submitter for dashboard --- app/assets/stylesheets/osem.css | 4 ++ .../admin/conference_controller.rb | 7 ++++ app/helpers/application_helper.rb | 21 ++++++++++ app/models/conference.rb | 38 +++++++++++++++++++ app/models/user.rb | 4 ++ .../_recent_registrations.html.haml | 18 +++++++++ .../conference/_recent_submissions.html.haml | 21 ++++++++++ .../admin/conference/_recent_users.html.haml | 22 +++++++++++ .../admin/conference/_top_submitter.html.haml | 17 +++++++++ app/views/admin/conference/index.html.haml | 33 +++++++++++++++- app/views/admin/conference/show.html.haml | 2 + 11 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/conference/_recent_registrations.html.haml create mode 100644 app/views/admin/conference/_recent_submissions.html.haml create mode 100644 app/views/admin/conference/_recent_users.html.haml create mode 100644 app/views/admin/conference/_top_submitter.html.haml diff --git a/app/assets/stylesheets/osem.css b/app/assets/stylesheets/osem.css index 3d7a01fc..396957dd 100644 --- a/app/assets/stylesheets/osem.css +++ b/app/assets/stylesheets/osem.css @@ -79,3 +79,7 @@ body { .todolist-ok span { color: #02A10F; } + +.top-submitter img { + margin: 0 auto; +} diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index 618513eb..13a3fc36 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -14,6 +14,12 @@ class Admin::ConferenceController < ApplicationController @conferences = Conference.select('id, short_title, color, start_date, registration_end_date, registration_start_date') + @recent_users = User.limit(5).order(created_at: :desc) + @recent_events = Event.limit(5).order(created_at: :desc) + @recent_registrations = Registration.limit(5).order(created_at: :desc) + + @top_submitter = Conference.get_top_submitter + @submissions = {} @cfp_weeks = [0] @@ -78,6 +84,7 @@ class Admin::ConferenceController < ApplicationController def show @conference = Conference.find_by(short_title: params[:id]) @conference_progress = @conference.get_status + @top_submitter = @conference.get_top_submitter respond_to do |format| format.html format.json { render json: @conference.to_json } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 70366714..baf1cd0d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,6 +15,27 @@ module ApplicationHelper end end + def label_for(event_state) + result = '' + case event_state + when 'Withdrawn' + result = 'label label-danger' + when 'Review Pending' + result = 'label label-primary' + when 'Accepted (confirmation pending)' + result = 'label label-success' + when 'Confirmed' + result = 'label label-success' + when 'Rejected' + result = 'label label-warning' + when 'Cancelled' + result = 'label label-danger' + when 'Submitted' + result = 'label label-primary' + end + result + end + def icon_for_todo(bool) if bool return 'glyphicon glyphicon-ok' diff --git a/app/models/conference.rb b/app/models/conference.rb index b1ee2b32..7f13cdd2 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -239,8 +239,46 @@ class Conference < ActiveRecord::Base result end + ## + # Returns a hash with person => submissions ordered by submissions for all conferences + # + # ====Returns + # * +hash+ -> person: submissions + def self.get_top_submitter(limit = 5) + submitter = EventPerson.where('event_role = ?', 'submitter').limit(limit).group(:person_id) + counter = submitter.count + calculate_person_submission_hash(submitter, counter) + end + + ## + # Returns a hash with person => submissions ordered by submissions + # + # ====Returns + # * +hash+ -> person: submissions + def get_top_submitter(limit = 5) + submitter = EventPerson.joins(:event). + where('event_role = ? and conference_id = ?', 'submitter', id). + limit(limit).group(:person_id) + + counter = submitter.count + Conference.calculate_person_submission_hash(submitter, counter) + end + private + ## + # Returns a hash with person => submissions ordered by submissions for all conferences + # + # ====Returns + # * +hash+ -> person: submissions + def self.calculate_person_submission_hash(submitter, counter) + result = {} + submitter.each do |s| + result[s.person] = counter[s.person_id] + end + result + end + ## # Creates a venue and sets self.venue_id to it's id. Used as before_create. # diff --git a/app/models/user.rb b/app/models/user.rb index 6fd103d7..21200f4a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,6 +48,10 @@ class User < ActiveRecord::Base details += "#{self.created_at}
" end + def confirmed? + !confirmed_at.nil? + end + private def create_person # TODO Search people for existing email address, add to their account diff --git a/app/views/admin/conference/_recent_registrations.html.haml b/app/views/admin/conference/_recent_registrations.html.haml new file mode 100644 index 00000000..eefab05a --- /dev/null +++ b/app/views/admin/conference/_recent_registrations.html.haml @@ -0,0 +1,18 @@ +- if recent_registrations && !recent_registrations.empty? + %table.table + %thead + %tr + %th # + %th Public Name + %th Conference + %th Date + - recent_registrations.each_with_index do |registration, index| + %tbody + %tr + %td #{index + 1} + %td #{registration.public_name} + %td #{registration.conference.title} + %td #{registration.created_at.strftime('%m/%d/%Y')} +- else + %h5.text-warning.text-center + No registrations! \ No newline at end of file diff --git a/app/views/admin/conference/_recent_submissions.html.haml b/app/views/admin/conference/_recent_submissions.html.haml new file mode 100644 index 00000000..7d298fdd --- /dev/null +++ b/app/views/admin/conference/_recent_submissions.html.haml @@ -0,0 +1,21 @@ +- if recent_events && !recent_events.empty? + %table.table + %thead + %tr + %th # + %th Submitter + %th Title + %th Conference + %th Status + - recent_events.each_with_index do |event, index| + %tbody + %tr + %td #{index + 1} + %td #{event.submitter} + %td #{event.title} + %td #{event.conference.title} + %td + .span{'class'=>label_for(event.public_state)} #{event.public_state} +- else + %h5.text-warning.text-center + No submissions! \ No newline at end of file diff --git a/app/views/admin/conference/_recent_users.html.haml b/app/views/admin/conference/_recent_users.html.haml new file mode 100644 index 00000000..016c08ae --- /dev/null +++ b/app/views/admin/conference/_recent_users.html.haml @@ -0,0 +1,22 @@ +- if recent_users && !recent_users.empty? + %table.table + %thead + %tr + %th # + %th E-Mail + %th Date registered + %th Status + - recent_users.each_with_index do |user, index| + %tbody + %tr + %td #{index} + %td #{user.email} + %td #{user.created_at.strftime('%m/%d/%Y')} + %td + - if user.confirmed? + %span.label.label-success Confirmed + -else + %span.label.label-danger Unconfirmed +- else + %h5.text-warning.text-center + No sign ups! \ No newline at end of file diff --git a/app/views/admin/conference/_top_submitter.html.haml b/app/views/admin/conference/_top_submitter.html.haml new file mode 100644 index 00000000..0a79ed54 --- /dev/null +++ b/app/views/admin/conference/_top_submitter.html.haml @@ -0,0 +1,17 @@ +.row + %h3 + Top Submitter + - if @top_submitter && !@top_submitter.empty? + - @top_submitter.each do |key, value| + .row.top-submitter + .col-md-2 + = image_tag(key.gravatar_url(size: '25'), title: "Yo #{key.public_name}!", :alt => '', 'class'=>'img-circle img-responsive text-center') + .col-md-10 + %h4 + #{key} + %div + %small + #{pluralize(value, 'submission')} + - else + %h4.text-warning + No submissions! diff --git a/app/views/admin/conference/index.html.haml b/app/views/admin/conference/index.html.haml index d4f8fd15..da58db4b 100644 --- a/app/views/admin/conference/index.html.haml +++ b/app/views/admin/conference/index.html.haml @@ -10,4 +10,35 @@ .col-md-8 = render partial: 'registrations', locals: { conferences: @conferences, registrations: @registrations, registration_weeks: @registration_weeks } - .col-md-4 \ No newline at end of file + .col-md-4 + .col-md-8 + .row + %ul.nav.nav-tabs#recentTable + %li.active + %a{:href=>"#recent_user", "data-toggle"=>"tab"} + %span.glyphicon.glyphicon-user + Recent Users + %li + %a{:href=>"#recent_reg", "data-toggle"=>"tab"} + %span.glyphicon.glyphicon-star + Recent Registrations + %li + %a{:href=>"#recent_submissions", "data-toggle"=>"tab"} + %span.glyphicon.glyphicon-comment + Recent Submissions + .tab-content + .tab-pane.active#recent_user + = render partial: 'recent_users', locals: {recent_users: @recent_users} + .tab-pane#recent_reg + = render partial: 'recent_registrations', locals: {recent_registrations: @recent_registrations} + .tab-pane#recent_submissions + = render partial: 'recent_submissions', locals: {recent_events: @recent_events} + .col-md-4 + = render partial: 'top_submitter', locals: {top_submitter: @top_submitter} + + +:javascript + $('#recentTable a').click(function (e) { + e.preventDefault(); + $(this).tab('show'); + }) diff --git a/app/views/admin/conference/show.html.haml b/app/views/admin/conference/show.html.haml index 5ea86ffe..be43e9f8 100644 --- a/app/views/admin/conference/show.html.haml +++ b/app/views/admin/conference/show.html.haml @@ -5,3 +5,5 @@ .row .col-md-4 = render partial: 'todo_list', locals: { conference_progress: @conference_progress } + .col-md-4 + = render partial: 'top_submitter', locals: {top_submitter: @top_submitter} \ No newline at end of file