2016-08-11 15:27:35 +02:00
|
|
|
class DossiersListFacades
|
2016-09-06 14:07:07 +02:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
2016-12-16 14:40:41 +01:00
|
|
|
attr_accessor :procedure, :current_devise_profil, :liste
|
2016-11-24 19:33:34 +01:00
|
|
|
|
2016-09-06 11:07:26 +02:00
|
|
|
def initialize current_devise_profil, liste, procedure = nil
|
2016-08-11 15:27:35 +02:00
|
|
|
@current_devise_profil = current_devise_profil
|
|
|
|
@liste = liste
|
2016-10-24 16:00:03 +02:00
|
|
|
@liste = 'all_state' if Features.opensimplif
|
2016-09-06 11:07:26 +02:00
|
|
|
@procedure = procedure
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def service
|
2016-08-12 13:56:10 +02:00
|
|
|
if gestionnaire?
|
2016-09-06 11:07:26 +02:00
|
|
|
@service ||= DossiersListGestionnaireService.new @current_devise_profil, @liste, @procedure
|
2016-08-12 13:56:10 +02:00
|
|
|
elsif user?
|
|
|
|
@service ||= DossiersListUserService.new @current_devise_profil, @liste
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-29 09:56:11 +01:00
|
|
|
def total_dossier
|
|
|
|
current_devise_profil.dossiers.where(archived: false).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_new_dossier
|
|
|
|
current_devise_profil.dossiers.where(state: :initiated, archived: false).count
|
|
|
|
end
|
|
|
|
|
2016-12-27 11:06:09 +01:00
|
|
|
def new_dossier_number procedure_id
|
|
|
|
current_devise_profil.dossiers.where(state: :initiated, archived: false, procedure_id: procedure_id).count
|
|
|
|
end
|
|
|
|
|
2016-09-09 17:29:21 +02:00
|
|
|
def gestionnaire_procedures_name_and_id_list
|
2017-01-02 18:27:01 +01:00
|
|
|
@current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossier_with_notification_for(procedure)}) }
|
2016-12-27 10:47:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def unread_notifications
|
2016-12-27 10:57:21 +01:00
|
|
|
current_devise_profil.notifications
|
2016-09-09 17:29:21 +02:00
|
|
|
end
|
|
|
|
|
2017-01-02 15:10:53 +01:00
|
|
|
def dossiers_with_unread_notifications
|
|
|
|
(unread_notifications.inject([]) { |acc, notif| acc.push(notif.dossier) }).uniq
|
|
|
|
end
|
|
|
|
|
2016-09-08 16:21:54 +02:00
|
|
|
def procedure_id
|
|
|
|
@procedure.nil? ? nil : @procedure.id
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def dossiers_to_display
|
2016-10-24 16:00:03 +02:00
|
|
|
service.dossiers_to_display
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
2016-09-08 16:21:54 +02:00
|
|
|
def preference_list_dossiers_filter
|
|
|
|
@list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id)
|
|
|
|
end
|
|
|
|
|
2016-10-14 12:02:39 +02:00
|
|
|
def active_filter? preference
|
|
|
|
return true if @procedure.nil? || preference.table != 'champs' || (preference.table == 'champs' && !preference.filter.blank?)
|
|
|
|
|
|
|
|
preference_list_dossiers_filter.where(table: :champs).where.not(filter: '').size == 0
|
|
|
|
end
|
|
|
|
|
2016-11-24 19:33:34 +01:00
|
|
|
def all_state_class
|
|
|
|
(@liste == 'all_state' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-10-05 16:45:51 +02:00
|
|
|
def brouillon_class
|
|
|
|
(@liste == 'brouillon' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-10-19 17:25:24 +02:00
|
|
|
def en_construction_class
|
|
|
|
(@liste == 'a_traiter' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-08-12 13:56:10 +02:00
|
|
|
def valides_class
|
|
|
|
(@liste == 'valides' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def en_instruction_class
|
|
|
|
(@liste == 'en_instruction' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def termine_class
|
|
|
|
(@liste == 'termine' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-08-12 13:56:10 +02:00
|
|
|
def invite_class
|
|
|
|
(@liste == 'invite' ? 'active' : '')
|
|
|
|
end
|
|
|
|
|
2016-11-24 19:33:34 +01:00
|
|
|
def all_state_total
|
|
|
|
service.all_state.count
|
|
|
|
end
|
|
|
|
|
2016-10-05 16:45:51 +02:00
|
|
|
def brouillon_total
|
|
|
|
service.brouillon.count
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def nouveaux_total
|
|
|
|
service.nouveaux.count
|
|
|
|
end
|
|
|
|
|
2016-10-19 17:25:24 +02:00
|
|
|
def en_construction_total
|
|
|
|
service.en_construction.count
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
2016-08-12 13:56:10 +02:00
|
|
|
def valides_total
|
|
|
|
service.valides.count
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
2016-08-12 13:56:10 +02:00
|
|
|
def en_instruction_total
|
|
|
|
service.en_instruction.count
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def termine_total
|
|
|
|
service.termine.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def suivi_total
|
|
|
|
service.suivi.count
|
|
|
|
end
|
2016-08-12 13:56:10 +02:00
|
|
|
|
|
|
|
def invite_total
|
|
|
|
service.invite.count
|
|
|
|
end
|
2016-10-05 16:45:51 +02:00
|
|
|
|
2016-10-04 19:19:03 +02:00
|
|
|
def filter_url
|
|
|
|
@procedure.nil? ? backoffice_dossiers_filter_path(liste: liste) : backoffice_dossiers_procedure_filter_path(id: @procedure.id, liste: liste)
|
|
|
|
end
|
|
|
|
|
2016-08-12 13:56:10 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def gestionnaire?
|
|
|
|
@current_devise_profil.class == Gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
def user?
|
|
|
|
@current_devise_profil.class == User
|
|
|
|
end
|
2016-09-06 14:07:07 +02:00
|
|
|
|
|
|
|
def base_url liste
|
|
|
|
@procedure.nil? ? backoffice_dossiers_path(liste: liste) : backoffice_dossiers_procedure_path(id: @procedure.id, liste: liste)
|
|
|
|
end
|
2016-10-24 16:00:03 +02:00
|
|
|
|
2016-12-27 15:26:41 +01:00
|
|
|
end
|