diff --git a/Gemfile b/Gemfile index 1afac9e..f39c2fd 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,8 @@ gem 'font-awesome-rails' gem 'nested_form' gem 'jquery-datatables-rails' +gem 'morrisjs-rails' +gem 'raphael-rails' group :development do gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 2c3bb9c..ccfd87b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,6 +149,8 @@ GEM mime-types (2.4.1) mini_portile (0.6.0) minitest (5.4.2) + morrisjs-rails (0.5.1) + railties (> 3.1, < 5) multi_json (1.10.1) nested_form (0.3.2) net-scp (1.2.1) @@ -196,6 +198,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) + raphael-rails (2.1.2) rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) @@ -301,6 +304,7 @@ DEPENDENCIES guard-rspec jquery-datatables-rails jquery-rails + morrisjs-rails nested_form pg phony_rails @@ -308,6 +312,7 @@ DEPENDENCIES rails (= 4.1.6) rails-erd rails-i18n + raphael-rails rmagick rspec-rails sass-rails (~> 4.0.3) diff --git a/app/assets/javascripts/management/application.js b/app/assets/javascripts/management/application.js index 334f889..d4d7f14 100644 --- a/app/assets/javascripts/management/application.js +++ b/app/assets/javascripts/management/application.js @@ -5,4 +5,6 @@ //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap //= require bootstrap-sprockets //= require metisMenu/metisMenu +//= require raphael +//= require morris //= require_directory . diff --git a/app/assets/javascripts/management/conferences.js.coffee b/app/assets/javascripts/management/conferences.js.coffee new file mode 100644 index 0000000..e50bbf7 --- /dev/null +++ b/app/assets/javascripts/management/conferences.js.coffee @@ -0,0 +1,9 @@ +$ -> + Morris.Line + element: 'submissions-chart' + data: $('#submissions-chart').data('submissions') + xkey: 'created_at' + ykeys: ['all_submissions', 'all_confirmations'] + labels: ['Submissions', 'Confirmed submissions'] + lineColors: ['#D9230F', '#469408'] + resize: true diff --git a/app/assets/stylesheets/management/application.css.scss b/app/assets/stylesheets/management/application.css.scss index 563c000..1e992e2 100644 --- a/app/assets/stylesheets/management/application.css.scss +++ b/app/assets/stylesheets/management/application.css.scss @@ -7,6 +7,7 @@ @import "metisMenu/metisMenu"; @import "dataTables/jquery.dataTables"; @import "dataTables/bootstrap/3/jquery.dataTables.bootstrap"; +@import "morris"; @import "layout"; @import "navigation"; diff --git a/app/helpers/conferences_helper.rb b/app/helpers/conferences_helper.rb new file mode 100644 index 0000000..9b22a0e --- /dev/null +++ b/app/helpers/conferences_helper.rb @@ -0,0 +1,31 @@ +module ConferencesHelper + def submissions_chart_data(conference) + submissions_by_day = conference.submissions_grouped_by_day + confirmed_by_day = conference.submissions_grouped_by_confirmation_day + start_date = conference.created_at.to_date + end_date = Time.zone.now.to_date < conference.start_date.to_date ? Time.zone.now.to_date : conference.start_date.to_date + + chart_data = (start_date..end_date).map do |date| + { + created_at: date, + new_submissions: submissions_by_day[date].try(:first).try(:number) || 0, + new_confirmations: confirmed_by_day[date].try(:first).try(:number) || 0 + } + end + + chart_data.each_with_index do |entry, index| + entry[:all_submissions] = if index == 0 + entry[:new_submissions] + else + chart_data[index - 1][:all_submissions] + entry[:new_submissions] + end + + entry[:all_confirmations] = if index == 0 + entry[:new_confirmations] + else + chart_data[index - 1][:all_confirmations] + entry[:new_confirmations] + end + end + chart_data + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index af02deb..58cc590 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -23,6 +23,20 @@ class Conference < ActiveRecord::Base future.first || last end + def submissions_grouped_by_day + submissions = Event.where(track: tracks, created_at: created_at..start_date) + submissions = submissions.group('date(created_at)') + submissions = submissions.select('created_at, count(id) as number') + submissions.group_by { |s| s.created_at.to_date } + end + + def submissions_grouped_by_confirmation_day + submissions = Event.approved.where(track: tracks, created_at: created_at..start_date).where.not(confirmed_at: nil) + submissions = submissions.group('date(confirmed_at)') + submissions = submissions.select('confirmed_at, count(id) as number') + submissions.group_by { |s| s.confirmed_at.to_date } + end + private def close_all_other_calls_for_papers diff --git a/app/views/management/conferences/show.html.slim b/app/views/management/conferences/show.html.slim index 80a2457..c42546c 100644 --- a/app/views/management/conferences/show.html.slim +++ b/app/views/management/conferences/show.html.slim @@ -69,3 +69,6 @@ span.pull-left = t 'views.conference.see_details' span.pull-right = fa_icon 'arrow-circle-right' span.clearfix +.row + .col-lg-12 + .submissions-chart#submissions-chart data-submissions="#{submissions_chart_data(@conference).to_json}"