2017-12-14 16:23:15 +01:00
|
|
|
|
module ChampHelper
|
2018-06-18 11:30:26 +02:00
|
|
|
|
def has_label?(champ)
|
2018-08-28 16:22:34 +02:00
|
|
|
|
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
|
2018-06-18 11:30:26 +02:00
|
|
|
|
!types_without_label.include?(champ.type_champ)
|
2017-12-14 16:23:15 +01:00
|
|
|
|
end
|
2018-10-17 12:07:25 +02:00
|
|
|
|
|
2019-02-19 16:14:42 +01:00
|
|
|
|
def champ_carte_params(champ)
|
|
|
|
|
if champ.persisted?
|
|
|
|
|
{ champ_id: champ.id }
|
|
|
|
|
else
|
|
|
|
|
{ type_de_champ_id: champ.type_de_champ_id }
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-09-26 17:40:52 +02:00
|
|
|
|
|
|
|
|
|
def format_text_value(text)
|
|
|
|
|
sanitized_text = sanitize(text)
|
|
|
|
|
auto_linked_text = Anchored::Linker.auto_link(sanitized_text, target: '_blank', rel: 'noopener') do |link_href|
|
|
|
|
|
truncate(link_href, length: 60)
|
|
|
|
|
end
|
|
|
|
|
simple_format(auto_linked_text, {}, sanitize: false)
|
|
|
|
|
end
|
2019-11-20 20:47:36 +01:00
|
|
|
|
|
2022-05-07 17:49:27 +02:00
|
|
|
|
def auto_attach_url(object)
|
|
|
|
|
if object.is_a?(Champ)
|
2020-04-02 17:30:59 +02:00
|
|
|
|
champs_piece_justificative_url(object.id)
|
2020-03-30 15:34:56 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-09 17:32:20 +02:00
|
|
|
|
|
2022-05-07 17:49:27 +02:00
|
|
|
|
def autosave_available?(champ)
|
|
|
|
|
# FIXME: enable autosave on champs private? once we figured out how to batch audit events
|
2022-05-31 08:44:40 +02:00
|
|
|
|
champ.dossier&.brouillon? && !champ.repetition?
|
2022-05-07 17:49:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-07-12 18:32:16 +02:00
|
|
|
|
def autosave_controller(champ)
|
|
|
|
|
if autosave_available?(champ)
|
|
|
|
|
{ controller: 'autosave' }
|
|
|
|
|
elsif !champ.repetition? && champ.dossier&.en_construction?
|
|
|
|
|
{ controller: 'check-conditions' }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
def geo_area_label(geo_area)
|
|
|
|
|
case geo_area.source
|
|
|
|
|
when GeoArea.sources.fetch(:cadastre)
|
|
|
|
|
capture do
|
2021-05-06 18:50:06 +02:00
|
|
|
|
concat "Parcelle n° #{geo_area.numero} - Feuille #{geo_area.prefixe} #{geo_area.section} - #{geo_area.surface.round} m"
|
2020-09-24 15:14:48 +02:00
|
|
|
|
concat tag.sup("2")
|
2020-04-09 17:32:20 +02:00
|
|
|
|
end
|
2020-04-15 15:43:38 +02:00
|
|
|
|
when GeoArea.sources.fetch(:selection_utilisateur)
|
|
|
|
|
if geo_area.polygon?
|
2020-09-20 13:18:36 +02:00
|
|
|
|
if geo_area.area.present?
|
|
|
|
|
capture do
|
|
|
|
|
concat "Une aire de surface #{geo_area.area} m"
|
2020-09-24 15:14:48 +02:00
|
|
|
|
concat tag.sup("2")
|
2020-09-20 13:18:36 +02:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
"Une aire de surface inconnue"
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|
|
|
|
|
elsif geo_area.line?
|
2020-09-20 13:18:36 +02:00
|
|
|
|
if geo_area.length.present?
|
|
|
|
|
"Une ligne longue de #{geo_area.length} m"
|
|
|
|
|
else
|
|
|
|
|
"Une ligne de longueur inconnue"
|
|
|
|
|
end
|
2020-04-15 15:43:38 +02:00
|
|
|
|
elsif geo_area.point?
|
|
|
|
|
"Un point situé à #{geo_area.location}"
|
|
|
|
|
end
|
2020-04-09 17:32:20 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-08-13 10:23:11 +02:00
|
|
|
|
|
|
|
|
|
def datetime_start_year(date)
|
|
|
|
|
if date == nil || date.year == 0 || date.year >= Date.today.year - 1
|
|
|
|
|
Date.today.year - 1
|
|
|
|
|
else
|
|
|
|
|
date.year
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-14 16:23:15 +01:00
|
|
|
|
end
|