Make Stats a public page

This commit is contained in:
gregoirenovel 2017-03-24 18:04:37 +01:00
parent 9c59d634b0
commit f84cd7f11b
6 changed files with 23 additions and 29 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'