2017-12-14 17:10:13 +01:00
|
|
|
|
module CommentaireHelper
|
2018-09-11 18:35:29 +02:00
|
|
|
|
def commentaire_is_from_me_class(commentaire, connected_user)
|
2018-09-11 18:36:54 +02:00
|
|
|
|
if commentaire_is_from_me(commentaire, connected_user)
|
2017-12-14 17:10:13 +01:00
|
|
|
|
"from-me"
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-06 15:04:43 +02:00
|
|
|
|
|
2018-09-11 18:40:10 +02:00
|
|
|
|
def commentaire_answer_action(commentaire, connected_user)
|
|
|
|
|
if commentaire_is_from_me(commentaire, connected_user)
|
|
|
|
|
"Envoyer un message à l’instructeur"
|
|
|
|
|
else
|
|
|
|
|
"Répondre dans la messagerie"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-06 16:08:24 +02:00
|
|
|
|
def commentaire_is_from_guest(commentaire)
|
|
|
|
|
commentaire.dossier.invites.map(&:email).include?(commentaire.email)
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-06 15:04:43 +02:00
|
|
|
|
def commentaire_date(commentaire)
|
|
|
|
|
is_current_year = (commentaire.created_at.year == Date.current.year)
|
|
|
|
|
template = is_current_year ? :message_date : :message_date_with_year
|
2018-10-25 22:25:43 +02:00
|
|
|
|
I18n.l(commentaire.created_at, format: template)
|
2018-09-06 15:04:43 +02:00
|
|
|
|
end
|
2018-09-11 18:36:54 +02:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def commentaire_is_from_me(commentaire, connected_user)
|
|
|
|
|
commentaire.email == connected_user.email
|
|
|
|
|
end
|
2017-12-14 17:10:13 +01:00
|
|
|
|
end
|