diff --git a/Gemfile b/Gemfile index cb25ccb4..8adc7e5a 100644 --- a/Gemfile +++ b/Gemfile @@ -56,7 +56,7 @@ gem 'devise-i18n' gem 'rails-i18n' # Store some specific content, like application name and static pages contents gem 'i18n-active_record', - git: 'git://github.com/svenfuchs/i18n-active_record.git', + github: 'svenfuchs/i18n-active_record', require: 'i18n/active_record' gem 'http_accept_language' @@ -74,6 +74,8 @@ gem 'activeadmin', github: 'gregbell/active_admin' # A nicer markdown editor in active admin gem 'activeadmin_pagedown' +gem 'jquery-sparkline-rails', github: 'cubus/jquery-sparkline-rails' + # Markdown display gem 'redcarpet' diff --git a/Gemfile.lock b/Gemfile.lock index 6ef53e65..6680e4b0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: git://github.com/cubus/jquery-sparkline-rails.git + revision: 5c2ced0fa68e5e099bec82b67bdf71f9d865da8a + specs: + jquery-sparkline-rails (2.1.1) + jquery-rails + rails (>= 3.2.2) + GIT remote: git://github.com/gregbell/active_admin.git revision: 05778f4b7c8e821d584c7b4b08bcd79c02a0db76 @@ -87,7 +95,7 @@ GEM builder (3.2.2) celluloid (0.16.0) timers (~> 4.0.0) - chunky_png (1.3.1) + chunky_png (1.3.2) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -176,7 +184,7 @@ GEM inherited_resources (1.4.1) has_scope (~> 0.6.0.rc) responders (~> 1.0.0.rc) - jbuilder (2.2.2) + jbuilder (2.2.3) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jquery-rails (3.1.2) @@ -185,7 +193,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks - jquery-ui-rails (5.0.1) + jquery-ui-rails (5.0.2) railties (>= 3.2.16) json (1.8.1) kaminari (0.16.1) @@ -376,6 +384,7 @@ DEPENDENCIES i18n-active_record! jbuilder (~> 2.0) jquery-rails + jquery-sparkline-rails! jquery-turbolinks leaflet-rails meta-tags diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 02609aba..1e37ece8 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -12,6 +12,7 @@ # #= require jquery #= require jquery_ujs +#= require jquery.sparkline #= require jquery.turbolinks #= require turbolinks #= require tinymce-jquery diff --git a/app/assets/javascripts/regions.js.coffee b/app/assets/javascripts/regions.js.coffee new file mode 100644 index 00000000..f565b5a0 --- /dev/null +++ b/app/assets/javascripts/regions.js.coffee @@ -0,0 +1,17 @@ +$(document).ready -> + $('table.list.dates tbody tr').each -> + vals = $(this).find('td.quantity').map -> + val = $(this).html().replace(' ', '').trim() + if (val != '') + return parseInt val + + $(this).find('.sparkline').sparkline vals, width: '5em' + + vals = $('table.list.dates tfoot th.quantity').map -> + return parseInt $(this).html().replace(' ', '') + + $('tfoot .sparkline').sparkline vals, + type: 'bar' + height: '3em' + barWidth: '100%' + barColor: '#9CC5EE' diff --git a/app/assets/stylesheets/events.css.sass b/app/assets/stylesheets/events.css.sass index ba1dfdf9..5ad7b1e6 100644 --- a/app/assets/stylesheets/events.css.sass +++ b/app/assets/stylesheets/events.css.sass @@ -22,6 +22,9 @@ p.full_address span:last-child:after content: '' +.calendar-header, .month + text-transform: capitalize + body.events.index table width: 90% max-width: 100% diff --git a/app/assets/stylesheets/list.css.sass b/app/assets/stylesheets/list.css.sass index cdb417ac..249e1a78 100644 --- a/app/assets/stylesheets/list.css.sass +++ b/app/assets/stylesheets/list.css.sass @@ -1,5 +1,8 @@ @import compass +.quantity + text-align: right + table margin: 1em auto border-spacing: 2px @@ -16,8 +19,6 @@ table font-size: larger td padding: 0.2em - &.quantity - text-align: right dl margin: 1em auto @@ -32,7 +33,6 @@ dl padding: 0.2em 1em text-align: left &.quantity - text-align: right padding-right: 16em h3 display: inline diff --git a/app/assets/stylesheets/region.css.sass b/app/assets/stylesheets/region.css.sass index 72d266e5..c03ca523 100644 --- a/app/assets/stylesheets/region.css.sass +++ b/app/assets/stylesheets/region.css.sass @@ -33,3 +33,6 @@ body.stats h3 text-align: center + +.sparkline + padding: 0 diff --git a/app/controllers/regions_controller.rb b/app/controllers/regions_controller.rb index 7ea0647e..587464ee 100644 --- a/app/controllers/regions_controller.rb +++ b/app/controllers/regions_controller.rb @@ -6,6 +6,12 @@ class RegionsController < InheritedResources::Base @city_events = Event.group(:city).having('count(city) > 3') .order('count(city) desc').count :city + # Used in sqlite + # .group('strftime("%Y", start_time)') + @year_events = Event + .group('extract(year from start_time)') + .count + # Used in sqlite # .group('strftime("%Y", start_time)') # .group('strftime("%m", start_time)') diff --git a/app/views/regions/stats.html.haml b/app/views/regions/stats.html.haml index 9ee26b0d..2edd42e4 100644 --- a/app/views/regions/stats.html.haml +++ b/app/views/regions/stats.html.haml @@ -9,7 +9,39 @@ %dt=t '.allModeration' %dd.quantity= number_with_delimiter Event.unscoped.where(moderated: 0).count() -%h3=t '.regional' +%h3 + %em.fa.fa-calendar + =t '.dates' + +%table.list.dates + %thead + %tr + %th/ + - @year_events.each do |year| + %th= year[0] + %tbody + - (1..12).each do |m| + %tr + %td.month= I18n.t('date.month_names')[m] + - @year_events.each do |year| + %td.quantity + - line = @month_events.find { |line| line[0][0] == year[0] && line[0][1] == m } + = number_with_delimiter line[1] if line + %td.sparkline/ + + %tfoot + %tr + %th=t '.total' + - @year_events.each do |year| + %th.quantity= number_with_delimiter year[1] + + %tr + %th/ + %td.sparkline(colspan="#{@year_events.size}")/ + +%h3 + %em.fa.fa-shield + =t '.regional' %dl - @region_events.each do |region| @@ -25,13 +57,6 @@ %dt.item= city[0] %dd.quantity= number_with_delimiter city[1] -%h3=t '.dates' - -%dl - - @month_events.each do |month| - %dt.item= l(Date.new(month[0][0].to_i, month[0][1].to_i), format: :month).capitalize - %dd.quantity= number_with_delimiter month[1] - %h3=t '.web' :markdown diff --git a/config/database.yml b/config/database.yml index e2623585..23dbe813 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,8 +1,12 @@ -development: +development_old: adapter: sqlite3 pool: 5 timeout: 5000 database: db/development.sqlite3 +development: + adapter: mysql2 + database: adl_fr + username: manu # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 690442ba..e840e66e 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -134,11 +134,12 @@ it more readable or agreable. title: Statistics all: Validated events allModeration: Events waiting for validation + dates: Per date regional: Per region city: Per city city_conditions: Only cities where more than 3 events have been organised are displayed. - dates: Per date + total: Total web: Web statistics webalizer: Statistics generated by Webalizer [are available](http://agendadulibre.org/stats/). They are protected by diff --git a/config/locales/views/fr.yml b/config/locales/views/fr.yml index 30b5dfe2..dfc83300 100644 --- a/config/locales/views/fr.yml +++ b/config/locales/views/fr.yml @@ -132,11 +132,12 @@ fr: title: Statistiques all: Événements validés allModeration: Événements en cours de modération + dates: Par date regional: Par région city: Par ville city_conditions: Seules les villes où plus de trois événements ont été organisés sont mentionnées. - dates: Par date + total: Total web: Statistiques Web webalizer: Des statistiques Web générées par Webalizer [sont disponibles](http://agendadulibre.org/stats/). Elles sont protégées par