color state on search result

This commit is contained in:
Xavier J 2015-11-19 18:04:09 +01:00
parent c4e0e6b402
commit b40b0e59b1
3 changed files with 28 additions and 6 deletions

View file

@ -31,4 +31,10 @@ class DossierDecorator < Draper::Decorator
fail 'State not valid' fail 'State not valid'
end end
end end
def state_color_class
return 'text-danger' if a_traiter?
return 'text-info' if en_attente?
return 'text-success' if termine?
end
end end

View file

@ -4,8 +4,8 @@ class Dossier < ActiveRecord::Base
replied: 'replied', replied: 'replied',
updated: 'updated', updated: 'updated',
validated: 'validated', validated: 'validated',
submitted: 'submitted', #-submit_validated submitted: 'submitted',
closed: 'closed'} #-processed closed: 'closed'}
has_one :etablissement, dependent: :destroy has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy has_one :entreprise, dependent: :destroy
@ -30,6 +30,10 @@ class Dossier < ActiveRecord::Base
validates :description, presence: true, allow_blank: false, allow_nil: true validates :description, presence: true, allow_blank: false, allow_nil: true
validates :user, presence: true validates :user, presence: true
A_TRAITER = %w(initiated updated submitted)
EN_ATTENTE = %w(replied validated)
TERMINE = %w(closed)
def retrieve_piece_justificative_by_type(type) def retrieve_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last pieces_justificatives.where(type_de_piece_justificative_id: type).last
end end
@ -116,16 +120,28 @@ class Dossier < ActiveRecord::Base
state state
end end
def a_traiter?
A_TRAITER.include?(state)
end
def en_attente?
EN_ATTENTE.include?(state)
end
def termine?
TERMINE.include?(state)
end
def self.a_traiter current_gestionnaire def self.a_traiter current_gestionnaire
Dossier.joins(:procedure).where("(state='initiated' OR state='updated' OR state='submitted') AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC') current_gestionnaire.dossiers.where(state: A_TRAITER).order('updated_at ASC')
end end
def self.en_attente current_gestionnaire def self.en_attente current_gestionnaire
Dossier.joins(:procedure).where("(state='replied' OR state='validated') AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC') current_gestionnaire.dossiers.where(state: EN_ATTENTE).order('updated_at ASC')
end end
def self.termine current_gestionnaire def self.termine current_gestionnaire
Dossier.joins(:procedure).where("state='closed' AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC') current_gestionnaire.dossiers.where(state: TERMINE).order('updated_at ASC')
end end
def self.search current_gestionnaire, terms def self.search current_gestionnaire, terms

View file

@ -44,4 +44,4 @@
%td= dossier.entreprise.raison_sociale %td= dossier.entreprise.raison_sociale
%td= dossier.user.email %td= dossier.user.email
%td= dossier.etablissement.siret %td= dossier.etablissement.siret
%td= dossier.state_fr %td{class: dossier.state_color_class}= dossier.state_fr