From f84cd7f11b455c1d04d88cc3c126883b91335237 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 24 Mar 2017 18:04:37 +0100 Subject: [PATCH] Make Stats a public page --- .../{administrations => }/stats.scss | 0 .../administrations/stats_controller.rb | 24 ------------------- app/controllers/stats_controller.rb | 21 ++++++++++++++++ app/views/administrations/index.html.haml | 3 --- .../stats/index.html.haml | 0 config/routes.rb | 4 ++-- 6 files changed, 23 insertions(+), 29 deletions(-) rename app/assets/stylesheets/{administrations => }/stats.scss (100%) delete mode 100644 app/controllers/administrations/stats_controller.rb create mode 100644 app/controllers/stats_controller.rb rename app/views/{administrations => }/stats/index.html.haml (100%) diff --git a/app/assets/stylesheets/administrations/stats.scss b/app/assets/stylesheets/stats.scss similarity index 100% rename from app/assets/stylesheets/administrations/stats.scss rename to app/assets/stylesheets/stats.scss diff --git a/app/controllers/administrations/stats_controller.rb b/app/controllers/administrations/stats_controller.rb deleted file mode 100644 index ea04c0ebb..000000000 --- a/app/controllers/administrations/stats_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -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/controllers/stats_controller.rb b/app/controllers/stats_controller.rb new file mode 100644 index 000000000..45a37327d --- /dev/null +++ b/app/controllers/stats_controller.rb @@ -0,0 +1,21 @@ +class StatsController < ApplicationController + + 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 diff --git a/app/views/administrations/index.html.haml b/app/views/administrations/index.html.haml index dc8c27cc1..c4e7eefc5 100644 --- a/app/views/administrations/index.html.haml +++ b/app/views/administrations/index.html.haml @@ -7,9 +7,6 @@ = f.submit 'Créer un administrateur', class: 'btn btn-success', id: 'submit_new_administrateur' - .text-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/stats/index.html.haml similarity index 100% rename from app/views/administrations/stats/index.html.haml rename to app/views/stats/index.html.haml diff --git a/config/routes.rb b/config/routes.rb index 216951ace..6f0d9edad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,14 +45,14 @@ Rails.application.routes.draw do authenticate :administration do resources :administrations, only: [:index, :create] namespace :administrations do - resources :stats, only: [:index] - require 'sidekiq/web' require 'sidekiq/cron/web' mount Sidekiq::Web => '/sidekiq' end end + resources :stats, only: [:index] + namespace :france_connect do get 'particulier' => 'particulier#login' get 'particulier/callback' => 'particulier#callback'