-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: answer message to administrateur as gestionnaire
- Loading branch information
1 parent
6a00110
commit 2368143
Showing
25 changed files
with
321 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...onents/groupe_gestionnaire/groupe_gestionnaire_list_commentaires/commentaire_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class GroupeGestionnaire::GroupeGestionnaireListCommentaires::CommentaireComponent < ApplicationComponent | ||
include ApplicationHelper | ||
|
||
def initialize(groupe_gestionnaire:, commentaire:) | ||
@groupe_gestionnaire = groupe_gestionnaire | ||
@commentaire = commentaire | ||
end | ||
|
||
def email | ||
if @commentaire.sender == current_gestionnaire | ||
"#{current_gestionnaire.email} (C’est vous !)" | ||
else | ||
@commentaire.sender_email | ||
end | ||
end | ||
|
||
def created_at | ||
try_format_datetime(@commentaire.created_at) | ||
end | ||
|
||
def see_button | ||
link_to 'Voir', | ||
gestionnaire_groupe_gestionnaire_commentaire_path(@groupe_gestionnaire, @commentaire), | ||
class: 'button' | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...oupe_gestionnaire_list_commentaires/commentaire_component/commentaire_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%tr{ id: dom_id(@commentaire) } | ||
%td= email | ||
%td= created_at | ||
%td= see_button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/controllers/gestionnaires/groupe_gestionnaire_commentaires_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Gestionnaires | ||
class GroupeGestionnaireCommentairesController < GestionnaireController | ||
before_action :retrieve_groupe_gestionnaire | ||
before_action :retrieve_last_commentaire, only: [:show, :create, :destroy] | ||
|
||
def index | ||
end | ||
|
||
def show | ||
@commentaire = CommentaireGroupeGestionnaire.new | ||
end | ||
|
||
def create | ||
@commentaire = @groupe_gestionnaire.commentaire_groupe_gestionnaires.create(commentaire_params.merge(sender: @last_commentaire.sender, gestionnaire: current_gestionnaire)) | ||
|
||
if @commentaire.errors.empty? | ||
flash.notice = "Message envoyé" | ||
redirect_to gestionnaire_groupe_gestionnaire_commentaire_path(@groupe_gestionnaire, @commentaire) | ||
else | ||
flash.alert = @commentaire.errors.full_messages | ||
render :show | ||
end | ||
end | ||
|
||
def destroy | ||
if @last_commentaire.soft_deletable?(current_gestionnaire) | ||
@last_commentaire.soft_delete! | ||
|
||
flash.notice = t('.notice') | ||
else | ||
flash.alert = t('.alert_acl') | ||
end | ||
# redirect_to gestionnaire_groupe_gestionnaire_commentaire_path(@groupe_gestionnaire, @last_commentaire) | ||
rescue Discard::RecordNotDiscarded | ||
flash.alert = t('.alert_already_discarded') | ||
end | ||
|
||
private | ||
|
||
def retrieve_last_commentaire | ||
@last_commentaire = @groupe_gestionnaire.commentaire_groupe_gestionnaires.find(params[:id]) | ||
end | ||
|
||
def commentaire_params | ||
params.require(:commentaire_groupe_gestionnaire).permit(:body) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/views/gestionnaires/groupe_gestionnaire_commentaires/destroy.turbo_stream.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- if @last_commentaire.discarded? | ||
= turbo_stream.update @last_commentaire do | ||
= render(GroupeGestionnaire::GroupeGestionnaireCommentaires::CommentaireComponent.new(commentaire: @last_commentaire, connected_user: current_gestionnaire)) |
16 changes: 16 additions & 0 deletions
16
app/views/gestionnaires/groupe_gestionnaire_commentaires/index.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
= render partial: 'gestionnaires/breadcrumbs', | ||
locals: { steps: [['Groupes gestionnaire', gestionnaire_groupe_gestionnaires_path], | ||
["#{@groupe_gestionnaire.name.truncate_words(10)}", gestionnaire_groupe_gestionnaire_path(@groupe_gestionnaire)], | ||
["Messagerie"]], preview: false } | ||
|
||
.container | ||
%h1 Messagerie de « #{@groupe_gestionnaire.name} » | ||
|
||
%table.table | ||
%thead | ||
%tr | ||
%th= 'Adresse email' | ||
%th= 'Dernier message' | ||
%th | ||
%tbody#commentaires | ||
= render(GroupeGestionnaire::GroupeGestionnaireListCommentaires::CommentaireComponent.with_collection(@groupe_gestionnaire.commentaire_groupe_gestionnaires.select("sender_id, sender_type, sender_email, MAX(id) as id, MAX(created_at) as created_at").group(:sender_id, :sender_type, :sender_email).order("MAX(id) DESC"), groupe_gestionnaire: @groupe_gestionnaire)) |
15 changes: 15 additions & 0 deletions
15
app/views/gestionnaires/groupe_gestionnaire_commentaires/show.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
= render partial: 'gestionnaires/breadcrumbs', | ||
locals: { steps: [['Groupes gestionnaire', gestionnaire_groupe_gestionnaires_path], | ||
["#{@groupe_gestionnaire.name.truncate_words(10)}", gestionnaire_groupe_gestionnaire_path(@groupe_gestionnaire)], | ||
["Messagerie", gestionnaire_groupe_gestionnaire_commentaires_path(@groupe_gestionnaire)], | ||
[@last_commentaire.sender_email]], preview: false } | ||
|
||
.container | ||
%h1 Messages de « #{ @last_commentaire.sender_email } » | ||
.messagerie.container | ||
%ul.messages-list{ data: { controller: 'scroll-to' } } | ||
- @groupe_gestionnaire.commentaire_groupe_gestionnaires.where(sender_id: @last_commentaire.sender_id, sender_type: @last_commentaire.sender_type).each do |commentaire| | ||
%li.message{ class: commentaire_is_from_me_class(commentaire, current_gestionnaire), id: dom_id(commentaire) } | ||
= render(GroupeGestionnaire::GroupeGestionnaireCommentaires::CommentaireComponent.new(commentaire: commentaire, connected_user: current_gestionnaire)) | ||
- if @last_commentaire.sender | ||
= render partial: "shared/groupe_gestionnaires/commentaires/form", locals: { commentaire: @commentaire, form_url: gestionnaire_groupe_gestionnaire_commentaires_path(@groupe_gestionnaire) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
app/views/shared/groupe_gestionnaires/commentaires/_form.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
= render NestedForms::FormOwnerComponent.new | ||
= form_for(commentaire, url: form_url) do |f| | ||
- dossier = commentaire.dossier | ||
- placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder') | ||
- if instructeur_signed_in? || administrateur_signed_in? || expert_signed_in? | ||
- placeholder = t('views.shared.dossiers.messages.form.write_message_placeholder') | ||
- if @last_commentaire | ||
= f.hidden_field :last_commentaire, value: @last_commentaire.id, name: :id | ||
%p.mandatory-explanation= t('asterisk_html', scope: [:utils]) | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :body, input_type: :text_area, opts: { rows: 5, placeholder: placeholder, title: placeholder, class: 'fr-input message-textarea'}) | ||
= render Dsfr::InputComponent.new(form: f, attribute: :body, input_type: :text_area, opts: { rows: 5, placeholder: t('views.gestionnaires.groupe_gestionnaires.messages.form.write_message_placeholder'), title: t('views.gestionnaires.groupe_gestionnaires.messages.form.write_message_placeholder'), class: 'fr-input message-textarea'}) | ||
|
||
.fr-mt-3w | ||
= f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'fr-btn', data: { disable: true } | ||
= f.submit t('views.gestionnaires.groupe_gestionnaires.messages.form.send_message'), class: 'fr-btn', data: { disable: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fr: | ||
activerecord: | ||
attributes: | ||
commentaire_groupe_gestionnaire: | ||
body: 'Votre message' |
7 changes: 7 additions & 0 deletions
7
config/locales/views/gestionnaires/groupe_gestionnaire_commentaires/en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
en: | ||
gestionnaires: | ||
groupe_gestionnaire_commentaires: | ||
destroy: | ||
notice: Your message had been deleted | ||
alert_acl: "Can not destroy message: it does not belong to you" | ||
alert_already_discarded: "Can not destroy message: it was already destroyed" |
7 changes: 7 additions & 0 deletions
7
config/locales/views/gestionnaires/groupe_gestionnaire_commentaires/fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fr: | ||
gestionnaires: | ||
groupe_gestionnaire_commentaires: | ||
destroy: | ||
notice: Votre message a été supprimé | ||
alert_acl: Impossible de supprimer le message, celui-ci ne vous appartient pas | ||
alert_already_discarded: Ce message a déjà été supprimé |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/migrate/20231025134902_add_emails_to_commentaire_groupe_gestionnaires.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddEmailsToCommentaireGroupeGestionnaires < ActiveRecord::Migration[6.1] | ||
def change | ||
# in case sender or gestionnaire would have been deleted | ||
add_column :commentaire_groupe_gestionnaires, :sender_email, :string | ||
add_column :commentaire_groupe_gestionnaires, :gestionnaire_email, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.