2018-08-14 15:17:22 +02:00
|
|
|
module ProcedureHelper
|
|
|
|
def procedure_lien(procedure)
|
2018-09-13 18:33:35 +02:00
|
|
|
if procedure.path.present?
|
2018-08-14 15:17:22 +02:00
|
|
|
if procedure.brouillon_avec_lien?
|
2018-10-30 12:00:58 +01:00
|
|
|
commencer_test_url(path: procedure.path)
|
2018-08-14 15:17:22 +02:00
|
|
|
else
|
2018-10-30 12:00:58 +01:00
|
|
|
commencer_url(path: procedure.path)
|
2018-08-14 15:17:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def procedure_libelle(procedure)
|
2019-01-10 10:31:30 +01:00
|
|
|
parts = procedure.brouillon? ? [content_tag(:span, 'démarche en test', class: 'badge')] : []
|
2018-09-18 14:10:15 +02:00
|
|
|
parts << procedure.libelle
|
|
|
|
safe_join(parts, ' ')
|
2018-08-14 15:17:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def procedure_modal_text(procedure, key)
|
|
|
|
action = procedure.archivee? ? :reopen : :publish
|
|
|
|
t(action, scope: [:modal, :publish, key])
|
|
|
|
end
|
2018-12-27 13:29:39 +01:00
|
|
|
|
|
|
|
def logo_img(procedure)
|
|
|
|
logo = procedure.logo
|
|
|
|
|
|
|
|
if logo.blank?
|
|
|
|
ActionController::Base.helpers.image_url("marianne.svg")
|
|
|
|
else
|
2019-07-31 12:25:40 +02:00
|
|
|
if Rails.application.secrets.fog[:enabled]
|
2018-12-27 13:29:39 +01:00
|
|
|
RemoteDownloader.new(logo.filename).url
|
|
|
|
else
|
|
|
|
LocalDownloader.new(logo.path, 'logo').url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-14 16:28:02 +01:00
|
|
|
|
|
|
|
def types_de_champ_data(procedure)
|
|
|
|
{
|
2019-03-20 14:28:13 +01:00
|
|
|
isAnnotation: false,
|
|
|
|
typeDeChampsTypes: types_de_champ_types,
|
|
|
|
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ),
|
|
|
|
baseUrl: procedure_types_de_champ_path(procedure),
|
|
|
|
directUploadUrl: rails_direct_uploads_url
|
2018-11-14 16:28:02 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def types_de_champ_private_data(procedure)
|
|
|
|
{
|
2019-03-20 14:28:13 +01:00
|
|
|
isAnnotation: true,
|
|
|
|
typeDeChampsTypes: types_de_champ_types,
|
|
|
|
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ_private),
|
|
|
|
baseUrl: procedure_types_de_champ_path(procedure),
|
|
|
|
directUploadUrl: rails_direct_uploads_url
|
2018-11-14 16:28:02 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-03 14:29:30 +02:00
|
|
|
def procedure_dossiers_download_path(procedure, format:, version:)
|
2019-08-06 11:02:54 +02:00
|
|
|
download_dossiers_instructeur_procedure_path(format: format,
|
2019-04-03 14:29:30 +02:00
|
|
|
procedure_id: procedure.id,
|
|
|
|
tables: [:etablissements],
|
|
|
|
version: version)
|
|
|
|
end
|
|
|
|
|
2018-11-14 16:28:02 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
TOGGLES = {
|
2019-07-31 15:10:54 +02:00
|
|
|
TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number?
|
2018-11-14 16:28:02 +01:00
|
|
|
}
|
|
|
|
|
2019-03-20 14:28:13 +01:00
|
|
|
def types_de_champ_types
|
|
|
|
types_de_champ_types = TypeDeChamp.type_de_champs_list_fr
|
2018-11-14 16:28:02 +01:00
|
|
|
|
2019-03-20 14:28:13 +01:00
|
|
|
types_de_champ_types.select! do |tdc|
|
2018-11-14 16:28:02 +01:00
|
|
|
toggle = TOGGLES[tdc.last]
|
|
|
|
toggle.blank? || Flipflop.send(toggle)
|
|
|
|
end
|
|
|
|
|
2019-03-20 14:28:13 +01:00
|
|
|
types_de_champ_types
|
2018-11-14 16:28:02 +01:00
|
|
|
end
|
|
|
|
|
2019-01-17 15:15:46 +01:00
|
|
|
TYPES_DE_CHAMP_BASE = {
|
2019-03-20 14:28:13 +01:00
|
|
|
except: [
|
|
|
|
:created_at,
|
|
|
|
:options,
|
|
|
|
:order_place,
|
|
|
|
:parent_id,
|
|
|
|
:private,
|
|
|
|
:procedure_id,
|
|
|
|
:stable_id,
|
|
|
|
:type,
|
|
|
|
:updated_at
|
|
|
|
],
|
|
|
|
methods: [
|
|
|
|
:cadastres,
|
|
|
|
:drop_down_list_value,
|
|
|
|
:parcelles_agricoles,
|
|
|
|
:piece_justificative_template_filename,
|
|
|
|
:piece_justificative_template_url,
|
|
|
|
:quartiers_prioritaires
|
|
|
|
]
|
2019-01-17 15:15:46 +01:00
|
|
|
}
|
|
|
|
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
|
2019-02-06 18:19:27 +01:00
|
|
|
.merge(include: { types_de_champ: TYPES_DE_CHAMP_BASE })
|
2019-01-17 15:15:46 +01:00
|
|
|
|
2018-11-14 16:28:02 +01:00
|
|
|
def types_de_champ_as_json(types_de_champ)
|
2019-02-04 16:43:26 +01:00
|
|
|
types_de_champ.includes(:drop_down_list,
|
|
|
|
piece_justificative_template_attachment: :blob,
|
|
|
|
types_de_champ: [:drop_down_list, piece_justificative_template_attachment: :blob])
|
|
|
|
.as_json(TYPES_DE_CHAMP)
|
2018-11-14 16:28:02 +01:00
|
|
|
end
|
2018-08-14 15:17:22 +02:00
|
|
|
end
|