Add some more state scopes and use them

This commit is contained in:
gregoirenovel 2017-05-26 18:32:56 +02:00
parent 9c2c0346b6
commit 7055aec634

View file

@ -43,8 +43,13 @@ class Dossier < ActiveRecord::Base
scope :state_brouillon, -> { where(state: BROUILLON) } scope :state_brouillon, -> { where(state: BROUILLON) }
scope :state_not_brouillon, -> { where.not(state: BROUILLON) } scope :state_not_brouillon, -> { where.not(state: BROUILLON) }
scope :state_nouveaux, -> { where(state: NOUVEAUX) }
scope :state_ouvert, -> { where(state: OUVERT) }
scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) }
scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) }
scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) }
scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) }
scope :state_a_instruire, -> { where(state: A_INSTRUIRE) }
scope :state_termine, -> { where(state: TERMINE) } scope :state_termine, -> { where(state: TERMINE) }
scope :archived, -> { where(archived: true) } scope :archived, -> { where(archived: true) }
@ -53,11 +58,11 @@ class Dossier < ActiveRecord::Base
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) }
scope :nouveaux, -> (order = :asc) { not_archived.where(state: NOUVEAUX).order_by_updated_at(order) } scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) }
scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) } scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) }
scope :waiting_for_user, -> (order = :asc) { not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) } scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) }
scope :ouvert, -> (order = :asc) { not_archived.where(state: OUVERT).order_by_updated_at(order) } scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) }
scope :a_instruire, -> (order = :asc) { not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) } scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) }
scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") }
accepts_nested_attributes_for :individual accepts_nested_attributes_for :individual