Skip to content

Commit

Permalink
Merge pull request #958 from mconf/feature-stats-view
Browse files Browse the repository at this point in the history
Feature stats view
  • Loading branch information
daronco authored Feb 28, 2018
2 parents 7954d34 + 1d847bf commit a0a074f
Show file tree
Hide file tree
Showing 19 changed files with 782 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class mconf.DateTimeInput
todayHighlight: true
fontAwesome: true
maxView: 3 # year
minView: $picker.data('minview')
language: $picker.data('language')
timezone: $picker.data('timezone')
pickerPosition: 'bottom-left'
Expand All @@ -36,6 +37,9 @@ class mconf.DateTimeInput
@setStartDate: (element, date) ->
getDatetimePickerTarget(element).datetimepicker('setStartDate', date)

@setEndDate: (element, date) ->
getDatetimePickerTarget(element).datetimepicker('setEndDate', date)

@show: (element) ->
getDatetimePickerTarget(element).datetimepicker('show')

Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/app/manage/statistics.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ ->
if isOnPage 'manage', 'statistics'
uri = window.location.href

mconf.Resources.addToBind ->
mconf.StatisticsFilter.bind()

# only kept here because this link is inside a .btn-group that disables the default
# click in the button, so we have to do the redirect it manually
$('#statistics-filters .btn.all').on 'click', ->
window.location.replace($(this).attr('href'))
45 changes: 45 additions & 0 deletions app/assets/javascripts/app/manage/statistics_filter.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
submitSelector = 'input[type=\'submit\']'

class mconf.StatisticsFilter

@bind: ->
start = $(statistics_starts_on_time)
end = $(statistics_ends_on_time)
mconf.DateTimeInput.setStartDate(start, new Date('2010-01-01'))

filterByDate()
$('.starts-at-wrapper .btn-group .btn').on 'click', ->
filterByDate(this)

$('.datetime-picker-input').on 'change', ->
checkDate()

start.on 'change', ->
limitMinimumEnd()

end.on 'change', ->
limitMaximumStart()

filterByDate = (el) ->
if el
selected = $(el).data('attr-value')
else
selected = $('.starts-at-wrapper .btn.active').data('attr-value')

limitMinimumEnd = ->
startDate = statistics_starts_on_time.value

if startDate != ""
mconf.DateTimeInput.setStartDate($(statistics_ends_on_time), new Date(startDate))

limitMaximumStart = ->
endDate = statistics_ends_on_time.value

if endDate != ""
mconf.DateTimeInput.setEndDate($(statistics_starts_on_time), new Date(endDate))

checkDate = ->
startDate = statistics_starts_on_time.value
endDate = statistics_ends_on_time.value

$(submitSelector).removeAttr('disabled')
66 changes: 66 additions & 0 deletions app/assets/stylesheets/app/manage/statistics.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@import "definitions";
@import "compass/css3";

body.manage.statistics {

.page-tools-menu {
padding-bottom: 5px;
margin-bottom: 10px;

.search-words {
input { width: 100%; }
}

.search-filters {
margin-top: 10px;

.search-filter-option {
margin-right: 5px;
margin-bottom: 10px;
}
}
}

#statistics-filters {
margin-bottom: 16px;
@include mconf-clearfix;

.csv {
padding-top: 0;
margin-top: 0;
border-top: 0;
float: right;
}

.btn-group {
white-space: nowrap;
float: left;

> .btn {
float: none;

&:last-child {
margin-left: -5px;
}
}
}
}

#statistics-list {
.table {
margin-bottom: 30px;

tbody td:first-child {
width: 40%;
}
tbody td:last-child {
width: 40%;
}
}
};

.open-modal {
text-decoration: none;
color: black;
}
}
52 changes: 52 additions & 0 deletions app/assets/stylesheets/app/manage/statistics_filter.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@import "definitions";
@import "compass/css3";

body.manage.statistics_filter {

.text {
font-size: 15px;
margin: 0 15px;
}

.page-tools-menu {
padding-bottom: 5px;
margin-bottom: 10px;

.search-words {
input { width: 100%; }
}

.search-filters {
margin-top: 10px;

.search-filter-option {
margin-right: 5px;
margin-bottom: 10px;
}
}
}

.starts-at-wrapper {
margin-bottom: 16px;

.btn-group {
white-space: nowrap;
display: table-cell;
width: 1%;

> .btn {
float: none;

&:last-child {
margin-left: -5px;
}
}
}

.form-group {
display: table-cell;
width: 100%;
padding-left: 8px;
}
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/manage.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*= require ./app/manage/users
*= require ./app/manage/spaces
*= require ./app/manage/recordings
*= require ./app/manage/statistics
*/
30 changes: 30 additions & 0 deletions app/controllers/manage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,34 @@ def recordings
render layout: 'manage'
end
end

def check_statistics_params
if params[:statistics].present?
from = params[:statistics][:starts_on_time]
to = params[:statistics][:ends_on_time]
date_format = I18n.t('_other.datetimepicker.datepick_rails')

@from_date = from.present? ? Date.strptime(from, date_format) : Time.at(0).utc
@to_date = to.present? ? Date.strptime(to, date_format) : Time.now.utc
else
@from_date = Time.at(0).utc
@to_date = Time.now.utc
end
end

def statistics
check_statistics_params
@statistics = Mconf::StatisticsModule.generate(@from_date, @to_date)
end

def statistics_filter
render layout: false
end

def statistics_csv
check_statistics_params
respond_to do |format|
format.csv { send_data Mconf::StatisticsModule.generate_csv(@from_date, @to_date), type: Mime::CSV, disposition: "attachment", filename: "overview-from-#{@from_date.strftime('%m-%d-%Y')}-to-#{@to_date.strftime('%m-%d-%Y')}.csv" }
end
end
end
4 changes: 4 additions & 0 deletions app/views/manage/_menu.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
%li{ :class => "#{'active' if params[:controller] == 'sites'}" }
= link_to t('.general'), site_path

- if can?(:statistics, :manage)
%li{ :class => "#{'active' if params[:controller] == 'manage' && params[:action] == 'statistics'}" }
= link_to t('.statistics'), manage_statistics_path

- if can?(:users, :manage)
%li{ :class => "#{'active' if params[:controller] == 'manage' && params[:action] == 'users'}" }
= link_to t('.users'), manage_users_path
Expand Down
92 changes: 92 additions & 0 deletions app/views/manage/_statistics_list.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
-# locals:
%div.table-wrapper

%table.table
%thead
%tr
%th{ colspan: 2 }= t('.users.title')
%tbody
%tr
%td= t('.users.all')
%td= @statistics[:users][:count]
%tr
%td= t('.users.approved')
%td= @statistics[:users][:approved]
%tr
%td= t('.users.not_approved')
%td= @statistics[:users][:not_approved]
%tr
%td= t('.users.disabled')
%td= @statistics[:users][:disabled]

%table.table
%thead
%tr
%th{ colspan: 2 }= t('.spaces.title')
%tbody
%tr
%td= t('.spaces.all')
%td= @statistics[:spaces][:count]
%tr
%td= t('.spaces.private')
%td= @statistics[:spaces][:private]
%tr
%td= t('.spaces.public')
%td= @statistics[:spaces][:public]
%tr
%td= t('.spaces.disabled')
%td= @statistics[:spaces][:disabled]

%table.table
%thead
%tr
%th{ colspan: 2 }= t('.meetings.title')
%tbody
%tr
%td= t('.meetings.all')
%td= @statistics[:meetings][:count]
%tr
%td= t('.meetings.total')
%td
- total = @statistics[:meetings][:total_duration]
- if total.zero?
= total
- else
= distance_of_time_in_words_to_now(Time.now + total, include_seconds: false)
%tr
%td= t('.meetings.average')
%td
- average = @statistics[:meetings][:average_duration]
- if average.zero?
= average
- else
= distance_of_time_in_words_to_now(Time.now + average, include_seconds: false)

%table.table
%thead
%tr
%th{ colspan: 2 }= t('.recordings.title')
%tbody
%tr
%td= t('.recordings.all')
%td= @statistics[:recordings][:count]
%tr
%td= t('.recordings.total')
%td
- total = @statistics[:recordings][:total_duration]
- if total.zero?
= total
- else
= distance_of_time_in_words_to_now(Time.now + total, include_seconds: false)
%tr
%td= t('.recordings.average')
%td
- average = @statistics[:recordings][:average_duration]
- if average.zero?
= average
- else
= distance_of_time_in_words_to_now(Time.now + average, include_seconds: false)
%tr
%td= t('.recordings.size')
%td= human_file_size(@statistics[:recordings][:size])
19 changes: 19 additions & 0 deletions app/views/manage/statistics.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#manage

#statistics-filters
= simple_form_for :statistics, url: manage_statistics_path, html: { class: 'single-column' } do |f|
.csv
- starts = params[:statistics].present? ? params[:statistics][:starts_on_time] : nil
- ends = params[:statistics].present? ? params[:statistics][:ends_on_time] : nil
= link_to t('.csv'), manage_statistics_csv_path(format: :csv, statistics: { starts_on_time: starts, ends_on_time: ends }), class: 'btn btn-primary'

.btn-group{ 'data-toggle': "buttons" }

= link_to manage_statistics_path, class: "btn btn-default all #{'active' unless params[:statistics].present?}" do
= t('.all')
= link_to manage_statistics_filter_path, class: "btn btn-default pick open-modal #{'active' if params[:statistics].present?}" do
= icon_date
= t('.date')

#statistics-list{ 'data-filtered-by-date': params[:statistics].present?.to_s }
= render partial: 'statistics_list'
18 changes: 18 additions & 0 deletions app/views/manage/statistics_filter.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#statistics_filter

.modal-header
= modal_close_button
%h3
= t('.title')
= simple_form_for :statistics, url: manage_statistics_path, method: "get", html: { class: 'single-column' } do |f|
.modal-body
.starts-at-wrapper
- tz = user_timezone_abbreviation(current_user)
- lang = locale_for_datetime_picker
= f.label (t('.from')), required: false
.start= f.input :starts_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 }
= f.label (t('.to')), required: false
.end= f.input :ends_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 }

.modal-footer
= f.button :wrapped, t('_other.send'), disabled: true, class: "btn btn-primary", cancel_modal: true
Loading

0 comments on commit a0a074f

Please sign in to comment.