Skip to content

Commit

Permalink
Review for #958, optimize queries and improve the design a bit
Browse files Browse the repository at this point in the history
Removed all "for"s from the module Statistics, they would make things very
slow for large amounts of data. Now all stats are filtered directly in the
database with SQL.

Also reviewed the views and improved the design a little, made it look more
like the other pages.
  • Loading branch information
daronco committed Feb 28, 2018
1 parent 2d3b9a3 commit 1d847bf
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 211 deletions.
23 changes: 4 additions & 19 deletions app/assets/javascripts/app/manage/statistics.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@ $ ->
if isOnPage 'manage', 'statistics'
uri = window.location.href

if uri.indexOf("?") < 0
$('.starts-at-wrapper .btn.all').addClass("active")
$('.starts-at-wrapper .btn-group .btn.pick').removeClass("active")
else
$('.starts-at-wrapper .btn.all').removeClass("active")
$('.starts-at-wrapper .btn-group .btn.pick').addClass("active")

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

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

$('.starts-at-wrapper .btn.all').on 'click', ->
window.location.replace(uri.substring(0, uri.indexOf("?")))

filterByDate = (el) ->
if el
selected = $(el).data('attr-value')
else
selected = $('.starts-at-wrapper .btn.all').data('attr-value')
# 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'))
35 changes: 15 additions & 20 deletions app/assets/stylesheets/app/manage/statistics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

body.manage.statistics {

.title {
font-size: 20px;
color: $m-green-logo;
font-weight: bold;
margin: 8px 0;
}

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

.page-tools-menu {
padding-bottom: 5px;
margin-bottom: 10px;
Expand All @@ -33,8 +21,9 @@ body.manage.statistics {
}
}

.starts-at-wrapper {
#statistics-filters {
margin-bottom: 16px;
@include mconf-clearfix;

.csv {
padding-top: 0;
Expand All @@ -45,8 +34,7 @@ body.manage.statistics {

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

> .btn {
float: none;
Expand All @@ -56,13 +44,20 @@ body.manage.statistics {
}
}
}
}

.form-group {
display: table-cell;
width: 100%;
padding-left: 8px;
#statistics-list {
.table {
margin-bottom: 30px;

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

.open-modal {
text-decoration: none;
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/manage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ 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.present? ? @from_date = Date.strptime(from, '%m/%d/%Y') : @from_date = Time.at(0).utc
to.present? ? @to_date = Date.strptime(to, '%m/%d/%Y') : @to_date = Time.now.utc
@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
Expand Down
132 changes: 86 additions & 46 deletions app/views/manage/_statistics_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,52 +1,92 @@
-# locals:
.list-container.list-tablefied
.resource-filter-with-text
%div.table-wrapper

.resource-filter-without-text
.title= t('.users.title')
.text= t('.users.all', value: @statistics[:users][:all])
.text= t('.users.approved', value: @statistics[:users][:approved])
.text= t('.users.not_approved', value: @statistics[:users][:not_approved])
.text= t('.users.disabled', value: @statistics[:users][:disabled])
%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]

-#.list-container.list-tablefied
.title= t('.spaces.title')
.text= t('.spaces.all', value: @statistics[:spaces][:all])
.text= t('.spaces.private', value: @statistics[:spaces][:private])
.text= t('.spaces.public', value: @statistics[:spaces][:public])
.text= t('.spaces.disabled', value: @statistics[:spaces][: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]

-#.list-container.list-tablefied
.title= t('.meetings.title')
.text= t('.meetings.all', value: @statistics[:meetings][:all])
%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)

- total = @statistics[:meetings][:total]
- if total.zero?
.text= t('.meetings.total', value: total)
- else
.text= t('.meetings.total', value: distance_of_time_in_words_to_now(Time.now + total, include_seconds: false))

- average = @statistics[:meetings][:average]
- if average.zero?
.text= t('.meetings.average', value: average)
- else
.text= t('.meetings.average', value: distance_of_time_in_words_to_now(Time.now + average, include_seconds: false))

-#.list-container.list-tablefied
.title= t('.recordings.title')
.text= t('.recordings.all', value: @statistics[:recordings][:all])

- total = @statistics[:recordings][:total]
- if total.zero?
.text= t('.recordings.total', value: total)
- else
.text= t('.recordings.total', value: distance_of_time_in_words_to_now(Time.now + total, include_seconds: false))

- average = @statistics[:recordings][:average]
- if average.zero?
.text= t('.recordings.average', value: average)
- else
.text= t('.recordings.average', value: distance_of_time_in_words_to_now(Time.now + average, include_seconds: false))

.text= t('.recordings.size', value: human_file_size(@statistics[:recordings][:size]))
%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])
31 changes: 12 additions & 19 deletions app/views/manage/statistics.html.haml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#manage

.modal-header
#statistics-filters
= simple_form_for :statistics, url: manage_statistics_path, html: { class: 'single-column' } do |f|
.modal-body
.row
.col-xs-12.col-sm-9
.starts-at-wrapper
.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" }
.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'

%label.btn.btn-default.all{ 'data-attr-value': '0' }
%input{ type: 'radio' }
= t('.all')
.btn-group{ 'data-toggle': "buttons" }

%label.btn.btn-default.pick{ 'data-attr-value': '1' }
%input{ type: 'radio' }
= link_to manage_statistics_filter_path, class: "open-modal tooltipped", title: t('.date') do
= icon_later
= t('.date')
= 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
#statistics-list{ 'data-filtered-by-date': params[:statistics].present?.to_s }
= render partial: 'statistics_list'
16 changes: 7 additions & 9 deletions app/views/manage/statistics_filter.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
= t('.title')
= simple_form_for :statistics, url: manage_statistics_path, method: "get", html: { class: 'single-column' } do |f|
.modal-body
.row
.col-xs-12.col-sm-9
.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 }
.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
31 changes: 16 additions & 15 deletions config/locales/en/mconf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ en:
confirm: Ok
datetimepicker:
datepick: "mm/dd/yyyy"
datepick_rails: "%m/%d/%Y"
format: "mm/dd/yyyy hh:ii Z"
format_rails: "%m/%d/%Y %H:%M"
decline: "Decline"
Expand Down Expand Up @@ -1064,27 +1065,27 @@ en:
statistics_list:
users:
title: "Users Stats"
all: "All users: %{value}"
approved: "Approved users: %{value}"
not_approved: "Not approved users: %{value}"
disabled: "Disabled users: %{value}"
all: "All users"
approved: "Approved users"
not_approved: "Not approved users"
disabled: "Disabled users"
spaces:
title: "Spaces Stats"
all: "All spaces: %{value}"
private: "Private spaces: %{value}"
public: "Public spaces: %{value}"
disabled: "Disabled spaces: %{value}"
all: "All spaces"
private: "Private spaces"
public: "Public spaces"
disabled: "Disabled spaces"
meetings:
title: "Meetings Stats"
all: "All meetings: %{value}"
total: "Total meetings duration: %{value}"
average: "Average meetings duration: %{value}"
all: "All meetings"
total: "Total meetings duration"
average: "Average meetings duration"
recordings:
title: "Recordings Stats"
all: "All recordings: %{value}"
total: "Total recordings duration: %{value}"
average: "Average recordings duration: %{value}"
size: "Total size: %{value}"
all: "All recordings"
total: "Total recordings duration"
average: "Average recordings duration"
size: "Total size"
user_item:
allow_record: "Give the user permission to record conferences"
auth_using: "using"
Expand Down
Loading

0 comments on commit 1d847bf

Please sign in to comment.