demarches-normaliennes/app/helpers/champ_helper.rb
Judith c27b2da90b datetime type de champ: changed the years range from [1950;2100] to [to current year - 1;
current year + 50] (or [entered_date; current_year + 50] if old date already entered) because:
The type_de_champ Datetime is used for close future dates and very close past dates (for accident declaration for ex.)
The select currently has a range from 1950 to 2100, so 70+ years not supposed to be used, leading to:
- many bad data entered (0000 or 1950 to not scroll)
- making it difficult for users to give the proper date (current date is lost in the middle of 149 others) so risk to be lazy and select a random one or genuinely make a mistake
2020-08-13 13:41:45 +00:00

67 lines
2 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module ChampHelper
def has_label?(champ)
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
!types_without_label.include?(champ.type_champ)
end
def champ_carte_params(champ)
if champ.persisted?
{ champ_id: champ.id }
else
{ type_de_champ_id: champ.type_de_champ_id }
end
end
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
def describedby_id(champ)
if champ.description.present?
"desc-#{champ.type_de_champ.id}-#{champ.row}"
end
end
def auto_attach_url(form, object)
if object.is_a?(Champ) && object.persisted? && object.public?
champs_piece_justificative_url(object.id)
end
end
def geo_area_label(geo_area)
case geo_area.source
when GeoArea.sources.fetch(:cadastre)
capture do
concat "Parcelle n° #{geo_area.numero} - Feuille #{geo_area.code_arr} #{geo_area.section} #{geo_area.feuille} - #{geo_area.surface_parcelle.round} m"
concat content_tag(:sup, "2")
end
when GeoArea.sources.fetch(:quartier_prioritaire)
"#{geo_area.commune} : #{geo_area.nom}"
when GeoArea.sources.fetch(:parcelle_agricole)
"Culture : #{geo_area.culture} - Surface : #{geo_area.surface} ha"
when GeoArea.sources.fetch(:selection_utilisateur)
if geo_area.polygon?
capture do
concat "Une aire de surface #{geo_area.area} m"
concat content_tag(:sup, "2")
end
elsif geo_area.line?
"Une ligne longue de #{geo_area.length} m"
elsif geo_area.point?
"Un point situé à #{geo_area.location}"
end
end
end
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
end