2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-08-14 15:17:22 +02:00
|
|
|
|
module ProcedureHelper
|
|
|
|
|
def procedure_libelle(procedure)
|
2022-10-06 18:08:00 +02:00
|
|
|
|
parts = procedure.brouillon? ? [procedure_badge(procedure)] : []
|
2018-09-18 14:10:15 +02:00
|
|
|
|
parts << procedure.libelle
|
|
|
|
|
safe_join(parts, ' ')
|
2018-08-14 15:17:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-10-06 18:08:00 +02:00
|
|
|
|
def procedure_badge(procedure)
|
|
|
|
|
return nil unless procedure.brouillon?
|
|
|
|
|
|
2023-06-08 15:07:43 +02:00
|
|
|
|
tag.span(t('helpers.procedure.testing_procedure'), class: 'fr-badge fr-badge--sm')
|
2022-10-06 18:08:00 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-10-12 16:17:01 +02:00
|
|
|
|
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')
|
2019-11-14 09:43:45 +01:00
|
|
|
|
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
|
|
|
|
|
2020-05-27 18:04:22 +02:00
|
|
|
|
def procedure_auto_archive_date(procedure)
|
2020-05-27 11:25:43 +02:00
|
|
|
|
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-27 18:04:22 +02:00
|
|
|
|
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
|
2021-09-15 10:37:19 +02:00
|
|
|
|
|
2021-09-23 15:03:20 +02:00
|
|
|
|
def can_send_groupe_message?(procedure)
|
2023-08-07 15:21:03 +02:00
|
|
|
|
groupe_instructeur_on_procedure_ids = procedure.groupe_instructeurs.active.ids.sort
|
|
|
|
|
groupe_instructeur_on_instructeur_ids = current_instructeur.groupe_instructeurs.active.where(procedure: procedure).ids.sort
|
2023-07-18 14:49:30 +02:00
|
|
|
|
|
2023-08-07 15:21:03 +02:00
|
|
|
|
groupe_instructeur_on_procedure_ids == groupe_instructeur_on_instructeur_ids
|
2021-09-23 15:03:20 +02:00
|
|
|
|
end
|
2022-04-25 17:38:30 +02:00
|
|
|
|
|
|
|
|
|
def url_or_email_to_lien_dpo(procedure)
|
|
|
|
|
URI::MailTo.build([procedure.lien_dpo, "subject="]).to_s
|
|
|
|
|
rescue URI::InvalidComponentError
|
2023-06-29 12:58:38 +02:00
|
|
|
|
uri = Addressable::URI.parse(procedure.lien_dpo)
|
2022-04-25 17:38:30 +02:00
|
|
|
|
return "//#{uri}" if uri.scheme.nil?
|
|
|
|
|
uri.to_s
|
|
|
|
|
end
|
2022-05-24 11:39:03 +02:00
|
|
|
|
|
|
|
|
|
def estimated_fill_duration_minutes(procedure)
|
2022-05-24 14:17:10 +02:00
|
|
|
|
seconds = procedure.active_revision.estimated_fill_duration
|
|
|
|
|
minutes = (seconds / 60.0).round
|
2022-05-24 11:39:03 +02:00
|
|
|
|
[1, minutes].max
|
|
|
|
|
end
|
2022-12-08 17:28:48 +01:00
|
|
|
|
|
|
|
|
|
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
|