Merge pull request #38 from sgmap/stats

Stats: add adminitrations stats view
This commit is contained in:
Mathieu Magnin 2017-03-08 10:59:06 +01:00 committed by GitHub
commit 5d4e8622f6
6 changed files with 57 additions and 1 deletions

View file

@ -0,0 +1,6 @@
.card {
background: white;
padding: 15px;
box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
border-radius: 2px;
}

View file

@ -0,0 +1,9 @@
@import "card";
.stats {
.stat-card {
@extend .card;
margin: 15px auto;
max-width: 1200px;
}
}

View file

@ -0,0 +1,24 @@
module Administrations
class StatsController < ApplicationController
before_action :authenticate_administration!
def index
procedures = Procedure.where(created_at: Time.current.all_quarter).group("date_trunc('day', created_at)").count
dossiers = Dossier.where(created_at: Time.current.all_quarter).group("date_trunc('day', created_at)").count
@procedures = clean_hash(procedures)
@dossiers = clean_hash(dossiers)
end
private
def clean_hash h
h.keys.each{ |key| h[key.to_date] = h[key]; h.delete(key) }
min_date = h.keys.min
max_date = h.keys.max
(min_date..max_date).each do |date|
h[date] = 0 if h[date].nil?
end
h
end
end
end

View file

@ -10,6 +10,9 @@
%br
.center
=link_to 'Stats', administrations_stats_path, style: 'margin-bottom: 50px; display: block', 'data-no-turbolink': true
= smart_listing_render :admins
%br

View file

@ -0,0 +1,11 @@
= javascript_include_tag 'https://code.highcharts.com/highcharts.js', 'chartkick'
.container
.stats
.stat-card
%h1 Procédures crées
= line_chart @procedures
.stat-card
%h1 Dossiers créés
= line_chart @dossiers

View file

@ -42,7 +42,10 @@ Rails.application.routes.draw do
get 'admin' => 'admin#index'
get 'backoffice' => 'backoffice#index'
resources :administrations
resources :administrations, only: [:index, :create]
namespace :administrations do
resources :stats, only: [:index]
end
namespace :france_connect do
get 'particulier' => 'particulier#login'