demarches-normaliennes/app/helpers/procedure_helper.rb

78 lines
2.3 KiB
Ruby
Raw Normal View History

2018-08-14 15:17:22 +02:00
module ProcedureHelper
def procedure_libelle(procedure)
parts = procedure.brouillon? ? [procedure_badge(procedure)] : []
parts << procedure.libelle
safe_join(parts, ' ')
2018-08-14 15:17:22 +02:00
end
def procedure_badge(procedure)
return nil unless procedure.brouillon?
tag.span(t('helpers.procedure.testing_procedure'), class: 'fr-badge fr-badge--sm')
end
def procedure_publish_label(procedure, key)
2021-02-02 15:48:53 +01:00
# i18n-tasks-use t('modal.publish.body.publish')
# i18n-tasks-use t('modal.publish.body.reopen')
# i18n-tasks-use t('modal.publish.submit.publish')
# i18n-tasks-use t('modal.publish.submit.reopen')
# i18n-tasks-use t('modal.publish.title.publish')
# i18n-tasks-use t('modal.publish.title.reopen')
action = procedure.close? ? :reopen : :publish
2018-08-14 15:17:22 +02:00
t(action, scope: [:modal, :publish, key])
end
2018-12-27 13:29:39 +01:00
def procedure_auto_archive_date(procedure)
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
end
def procedure_auto_archive_time(procedure)
"à 23 h 59 (heure de " + Rails.application.config.time_zone + ")"
end
def procedure_auto_archive_datetime(procedure)
procedure_auto_archive_date(procedure) + ' ' + procedure_auto_archive_time(procedure)
end
def can_manage_groupe_instructeurs?(procedure)
2022-11-04 10:10:57 +01:00
procedure.routing_enabled? && current_administrateur&.owns?(procedure)
end
2021-09-23 15:03:20 +02:00
def can_send_groupe_message?(procedure)
procedure.dossiers
.state_brouillon
.includes(:groupe_instructeur)
.exists?(groupe_instructeur: current_instructeur.groupe_instructeurs)
end
def url_or_email_to_lien_dpo(procedure)
URI::MailTo.build([procedure.lien_dpo, "subject="]).to_s
rescue URI::InvalidComponentError
uri = Addressable::URI.parse(procedure.lien_dpo)
return "//#{uri}" if uri.scheme.nil?
uri.to_s
end
def estimated_fill_duration_minutes(procedure)
seconds = procedure.active_revision.estimated_fill_duration
minutes = (seconds / 60.0).round
[1, minutes].max
end
def admin_procedures_back_path(procedure)
statut = if procedure.discarded?
'supprimees'
else
case procedure.aasm_state
when 'brouillon'
'brouillons'
when 'close', 'depubliee'
'archivees'
else
'publiees'
end
end
admin_procedures_path(statut:)
end
2018-08-14 15:17:22 +02:00
end