diff --git a/app/assets/stylesheets/_card.scss b/app/assets/stylesheets/_card.scss new file mode 100644 index 000000000..5e1e54578 --- /dev/null +++ b/app/assets/stylesheets/_card.scss @@ -0,0 +1,6 @@ +.card { + background: white; + padding: 15px; + box-shadow: 0 1px 3px rgba(0, 0, 0, .15); + border-radius: 2px; +} \ No newline at end of file diff --git a/app/assets/stylesheets/administrations/stats.scss b/app/assets/stylesheets/administrations/stats.scss new file mode 100644 index 000000000..005075eff --- /dev/null +++ b/app/assets/stylesheets/administrations/stats.scss @@ -0,0 +1,9 @@ +@import "card"; + +.stats { + .stat-card { + @extend .card; + margin: 15px auto; + max-width: 1200px; + } +} diff --git a/app/controllers/administrations/stats_controller.rb b/app/controllers/administrations/stats_controller.rb new file mode 100644 index 000000000..ea04c0ebb --- /dev/null +++ b/app/controllers/administrations/stats_controller.rb @@ -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 diff --git a/app/views/administrations/index.html.haml b/app/views/administrations/index.html.haml index b0f2e40b7..bf4e66d9a 100644 --- a/app/views/administrations/index.html.haml +++ b/app/views/administrations/index.html.haml @@ -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 diff --git a/app/views/administrations/stats/index.html.haml b/app/views/administrations/stats/index.html.haml new file mode 100644 index 000000000..7c9a3f696 --- /dev/null +++ b/app/views/administrations/stats/index.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 2f96e0031..716893f09 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'