From f5701f2e7741f7ee054bdca93be0023210d104f9 Mon Sep 17 00:00:00 2001 From: Ana Date: Sat, 11 Jun 2016 14:09:23 +0200 Subject: [PATCH] Statistics on top of Events#index --- app/controllers/admin/events_controller.rb | 3 +++ app/models/conference.rb | 14 ++++++++++++++ app/views/admin/events/index.html.haml | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index f615aa5e..e08ddde7 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -21,6 +21,9 @@ module Admin @difficulty_levels = @program.difficulty_levels @machine_states = @events.state_machine.states.map @event_types = @program.event_types + @tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed) + @event_distribution = @conference.event_distribution + @scheduled_event_distribution = @conference.scheduled_event_distribution @mystates = [] @mytypes = [] diff --git a/app/models/conference.rb b/app/models/conference.rb index f0b73047..f190bff2 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -316,6 +316,20 @@ class Conference < ActiveRecord::Base Conference.calculate_event_distribution_hash(program.events.select(:state).group(:state).count) end + ## + # Returns a hash with scheduled vs unscheduled events + # { "Scheduled" => { value: number of confirmed and scheduled events, color: color }, + # "Unscheduled" => { value: number of confirmed and unscheduled events, color: color } + # + # ====Returns + # * +hash+ -> hash + def scheduled_event_distribution + confirmed_events = program.events.where(state: 'confirmed') + scheduled_value = { 'value' => confirmed_events.where('start_time IS NOT NULL').count, 'color' => 'green' } + unscheduled_value = { 'value' => confirmed_events.where('start_time IS NULL').count, 'color' => 'red' } + { 'Scheduled' => scheduled_value, 'Unscheduled' => unscheduled_value } + end + ## # Returns a hash with user distribution => {value: count of user state, color: color} # active: signed in during the last 3 months diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index f5aeea9c..e85a25d7 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -8,6 +8,13 @@ %p.text-muted All the submissions of your speakers .row + .col-md-4 + = render partial: 'admin/conference/doughnut_chart', locals: {title: 'Events state', data: @event_distribution} + .col-md-4 + = render partial: 'admin/conference/doughnut_chart', locals: {title: 'Confirmed events scheduled', data: @scheduled_event_distribution} + .col-md-4 + = render partial: 'admin/conference/doughnut_chart', locals: {title: 'Tracks of confirmed events', data: @tracks_distribution_confirmed} +.row{ style: "margin-top: 40px;"} .col-md-12 %table.table.table-striped.table-bordered.table-hover.datatable %thead