2016-08-11 15:27:35 +02:00
|
|
|
class DossiersListGestionnaireService
|
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-09-06 11:07:26 +02:00
|
|
|
@procedure = procedure
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def dossiers_to_display
|
|
|
|
{'nouveaux' => nouveaux,
|
|
|
|
'a_traiter' => waiting_for_gestionnaire,
|
|
|
|
'en_attente' => waiting_for_user,
|
|
|
|
'deposes' => deposes,
|
|
|
|
'a_instruire' => a_instruire,
|
2016-09-06 11:07:26 +02:00
|
|
|
'termine' => termine}[@liste]
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def nouveaux
|
2016-09-06 11:07:26 +02:00
|
|
|
@nouveaux ||= filter_dossiers.nouveaux
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_gestionnaire
|
2016-09-06 11:07:26 +02:00
|
|
|
@waiting_for_gestionnaire ||= filter_dossiers.waiting_for_gestionnaire
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_user
|
2016-09-06 11:07:26 +02:00
|
|
|
@waiting_for_user ||= filter_dossiers.waiting_for_user
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def deposes
|
2016-09-06 11:07:26 +02:00
|
|
|
@deposes ||= filter_dossiers.deposes
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def a_instruire
|
2016-09-06 11:07:26 +02:00
|
|
|
@a_instruire ||= filter_dossiers.a_instruire
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def termine
|
2016-09-06 11:07:26 +02:00
|
|
|
@termine ||= filter_dossiers.termine
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
2016-09-06 11:07:26 +02:00
|
|
|
def filter_dossiers
|
2016-09-08 16:21:54 +02:00
|
|
|
@filter_dossiers ||= @procedure.nil? ? @current_devise_profil.dossiers : @procedure.dossiers
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|
2016-09-27 17:26:49 +02:00
|
|
|
|
|
|
|
def filter_procedure_reset!
|
|
|
|
filter_procedure! nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_procedure! procedure_id
|
|
|
|
@current_devise_profil.update_column :procedure_filter, procedure_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sort
|
|
|
|
sort_preference = @current_devise_profil.preference_list_dossiers
|
|
|
|
.where(procedure: @procedure)
|
|
|
|
.where.not(order: nil).first
|
|
|
|
|
|
|
|
return {'nil' => 'nil'} if sort_preference.nil?
|
|
|
|
|
|
|
|
{
|
|
|
|
[sort_preference.table, sort_preference.attr]
|
|
|
|
.reject(&:nil?)
|
|
|
|
.join('.') => sort_preference.order
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_sort! new_sort
|
|
|
|
|
|
|
|
raw_table_attr = new_sort.keys.first.split('.')
|
|
|
|
order = new_sort.values.first
|
|
|
|
|
|
|
|
table = (raw_table_attr.size == 2 ? raw_table_attr.first : nil)
|
|
|
|
attr = (raw_table_attr.size == 2 ? raw_table_attr.second : raw_table_attr.first)
|
|
|
|
|
|
|
|
reset_sort!
|
|
|
|
|
|
|
|
@current_devise_profil.preference_list_dossiers
|
|
|
|
.find_by(table: table, attr: attr, procedure: @procedure)
|
2016-09-27 17:53:46 +02:00
|
|
|
.update order: order
|
2016-09-27 17:26:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_sort!
|
|
|
|
@current_devise_profil.preference_list_dossiers
|
|
|
|
.where(procedure: @procedure)
|
|
|
|
.where.not(order: nil)
|
|
|
|
.update_all order: nil
|
|
|
|
end
|
2016-08-11 15:27:35 +02:00
|
|
|
end
|