diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 5f7731658..242cc7085 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -6,7 +6,7 @@ class Admin::ProceduresController < AdminController def index @procedures = smart_listing_create :procedures, - current_administrateur.procedures.where(published: true, archived: false).order(created_at: :desc), + current_administrateur.procedures.published.where(archived: false).order(created_at: :desc), partial: "admin/procedures/list", array: true diff --git a/app/controllers/demo_controller.rb b/app/controllers/demo_controller.rb index 54f45464d..59b784814 100644 --- a/app/controllers/demo_controller.rb +++ b/app/controllers/demo_controller.rb @@ -6,7 +6,7 @@ class DemoController < ApplicationController return redirect_to root_path if Rails.env.production? smart_listing_create :procedures, - Procedure.where(archived: false, published: true).order("id DESC"), + Procedure.published.where(archived: false).order("id DESC"), partial: "demo/list", array: true end diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index a4ac3cbb1..5eec020c7 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -4,7 +4,7 @@ class StatsController < ApplicationController MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0 def index - procedures = Procedure.where(:published => true) + procedures = Procedure.published dossiers = Dossier.where.not(:state => :draft) @procedures_count = procedures.count diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 85209ca1e..1109f7dcd 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -60,7 +60,7 @@ class Users::DossiersController < UsersController end def new - procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id]) + procedure = Procedure.where(archived: false).published.find(params[:procedure_id]) dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft') siret = params[:siret] || current_user.siret diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 30185d0a2..b60f26353 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -108,7 +108,7 @@ class Gestionnaire < ActiveRecord::Base start_date = DateTime.now.beginning_of_week active_procedure_overviews = procedures - .where(published: true) + .published .all .map { |procedure| procedure.procedure_overview(start_date) } .select(&:had_some_activities?) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 83e88b823..c447138c9 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -32,6 +32,7 @@ class Procedure < ActiveRecord::Base mount_uploader :logo, ProcedureLogoUploader default_scope { where(hidden_at: nil) } + scope :published, -> { where(published: true) } scope :not_archived, -> { where(archived: false) } scope :by_libelle, -> { order(libelle: :asc) } @@ -61,7 +62,7 @@ class Procedure < ActiveRecord::Base end def self.active id - not_archived.where(published: true).find(id) + not_archived.published.find(id) end def switch_types_de_champ index_of_first_element diff --git a/app/views/administrations/_list.html.haml b/app/views/administrations/_list.html.haml index 91020b530..09950f13d 100644 --- a/app/views/administrations/_list.html.haml +++ b/app/views/administrations/_list.html.haml @@ -18,7 +18,7 @@ = admin.last_sign_in_at.localtime.strftime('%d/%m/%Y') ) %td - = admin.procedures.where(published: true).count + = admin.procedures.published.count %td - total_dossier = 0 - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.not(state: :draft).count end diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml index 385a0f38d..4d9a9a115 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml @@ -19,7 +19,7 @@ .procedure-list-element{ class: @active_class } Actives .badge.progress-bar-success - = current_administrateur.procedures.where(published: true, archived: false).count + = current_administrateur.procedures.published.where(archived: false).count %a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" } .procedure-list-element{ class: @archived_class } diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 875e9d908..8eee9d51b 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -80,7 +80,7 @@ %ul.numbers %li.number .number-value - = number_with_delimiter(Procedure.where(:published => true).count, :locale => :fr) + = number_with_delimiter(Procedure.published.count, :locale => :fr) .number-label< procédures %br<>