Stats: add adminitrations stats view

This commit is contained in:
Simon Lehericey 2017-03-07 18:09:09 +01:00
parent 2e19dd26b7
commit 6cb88a995f
5 changed files with 51 additions and 1 deletions

View file

@ -0,0 +1,10 @@
.stats {
padding: 15px;
.stat-card {
background-color: white;
margin: 15px auto;
max-width: 1200px;
padding: 15px;
}
}

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,10 @@
= javascript_include_tag 'https://code.highcharts.com/highcharts.js', 'chartkick'
.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'