From f480f26bd4d586e2f6cdba3d74f8828e253242d7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 10 Jul 2017 16:11:12 +0200 Subject: [PATCH] Use the state_not_brouillon Dossier scope --- app/controllers/api/statistiques_controller.rb | 4 ++-- app/controllers/api/v1/dossiers_controller.rb | 2 +- app/facades/admin_procedures_show_facades.rb | 4 ++-- app/models/gestionnaire.rb | 2 +- app/models/procedure.rb | 2 +- app/models/search.rb | 2 +- app/views/administrations/_list.html.haml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/statistiques_controller.rb b/app/controllers/api/statistiques_controller.rb index fe12ffa2a..2300337f9 100644 --- a/app/controllers/api/statistiques_controller.rb +++ b/app/controllers/api/statistiques_controller.rb @@ -9,10 +9,10 @@ class API::StatistiquesController < ApplicationController private def total_dossiers - Dossier.where.not(state: :draft).size + Dossier.state_not_brouillon.size end def dossiers_mois - Dossier.where.not(state: :draft).where(created_at: (1.month.ago)..Time.now).size + Dossier.state_not_brouillon.where(created_at: (1.month.ago)..Time.now).size end end diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index ddafcf82c..b144148b0 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -7,7 +7,7 @@ class API::V1::DossiersController < APIController def index procedure = current_administrateur.procedures.find(params[:procedure_id]) - dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) + dossiers = procedure.dossiers.state_not_brouillon.paginate(page: params[:page]) render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200 rescue ActiveRecord::RecordNotFound diff --git a/app/facades/admin_procedures_show_facades.rb b/app/facades/admin_procedures_show_facades.rb index 650959746..98b51f669 100644 --- a/app/facades/admin_procedures_show_facades.rb +++ b/app/facades/admin_procedures_show_facades.rb @@ -8,11 +8,11 @@ class AdminProceduresShowFacades end def dossiers - @procedure.dossiers.where.not(state: :draft) + @procedure.dossiers.state_not_brouillon end def dossiers_for_pie_highchart - dossiers.where.not(state: :draft, archived: true).group(:state).count + dossiers.state_not_brouillon.where.not(archived: true).group(:state).count .reduce({}) do |acc, (key, val)| translated_key = DossierDecorator.case_state_fr(key) acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 4b65d0941..dddc94685 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -8,7 +8,7 @@ class Gestionnaire < ActiveRecord::Base has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to - has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures + has_many :dossiers, -> { state_not_brouillon }, through: :procedures has_many :followed_dossiers, through: :follows, source: :dossier has_many :follows has_many :preference_list_dossiers diff --git a/app/models/procedure.rb b/app/models/procedure.rb index c447138c9..c82aec9ca 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -128,7 +128,7 @@ class Procedure < ActiveRecord::Base end def total_dossier - self.dossiers.where.not(state: :draft).size + self.dossiers.state_not_brouillon.size end def generate_export diff --git a/app/models/search.rb b/app/models/search.rb index 6b4557677..17ead5d94 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -47,7 +47,7 @@ class Search < ActiveRecord::Base dossier_ids = @gestionnaire.dossiers .select(:id) .where(archived: false) - .where.not(state: "draft") + .state_not_brouillon q = Search .select("DISTINCT(searches.dossier_id)") diff --git a/app/views/administrations/_list.html.haml b/app/views/administrations/_list.html.haml index 09950f13d..aab406cf6 100644 --- a/app/views/administrations/_list.html.haml +++ b/app/views/administrations/_list.html.haml @@ -21,7 +21,7 @@ = admin.procedures.published.count %td - total_dossier = 0 - - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.not(state: :draft).count end + - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.state_not_brouillon.count end = total_dossier = smart_listing.paginate = smart_listing.pagination_per_page_links