Skip to content

Commit

Permalink
[122] Afficher le nom du groupe pour inviter une personne (#387)
Browse files Browse the repository at this point in the history
* [122] Afficher le nom du groupe pour inviter une personne

* S'assurer que seul les groupes dans la zone s'affiche
  • Loading branch information
jdauphant authored and Lucien Pereira committed Jan 6, 2020
1 parent 351392c commit 7f602a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
7 changes: 5 additions & 2 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
case Some(application) =>
if(application.canBeShowedBy(request.currentUser)) {
val usersThatCanBeInvited = usersThatCanBeInvitedOn(application)

val groups = userGroupService.byIds(usersThatCanBeInvited.flatMap(_.groupIds)).filter(_.areaIds.contains(application.area))
val groupsWithUsersThatCanBeInvited = groups.map { group =>
group -> usersThatCanBeInvited.filter(_.groupIds.contains(group.id))
}
val renderedApplication = if((application.haveUserInvitedOn(request.currentUser) || request.currentUser.id == application.creatorUserId) && request.currentUser.expert && request.currentUser.admin && !application.closed) {
// If user is expert, admin and invited to the application we desanonymate
applicationService.byId(id, request.currentUser.id, false).get
Expand All @@ -340,7 +343,7 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
val openedTab = request.flash.get("opened-tab").getOrElse("answer")

eventService.info("APPLICATION_SHOWED", s"Demande $id consulté", Some(application))
Ok(views.html.showApplication(request.currentUser)(usersThatCanBeInvited, renderedApplication, answerForm, openedTab))
Ok(views.html.showApplication(request.currentUser)(groupsWithUsersThatCanBeInvited, renderedApplication, answerForm, openedTab))
}
else {
eventService.warn("APPLICATION_UNAUTHORIZED", s"L'accès à la demande $id n'est pas autorisé", Some(application))
Expand Down
32 changes: 18 additions & 14 deletions app/views/showApplication.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(user: User)(usersThatCanBeInvited: List[User], application: Application, answerToAgentsForm: Form[_], openedTab: String, attachments: Iterable[String] = Nil)(implicit webJarsUtil: org.webjars.play.WebJarsUtil, flash: Flash, messagesProvider: MessagesProvider, request: RequestHeader)
@(user: User)(groupsWithUsersThatCanBeInvited: List[(UserGroup,List[User])], application: Application, answerToAgentsForm: Form[_], openedTab: String, attachments: Iterable[String] = Nil)(implicit webJarsUtil: org.webjars.play.WebJarsUtil, flash: Flash, messagesProvider: MessagesProvider, request: RequestHeader)
@import java.util.Locale

@main(user)(s"Demande de ${application.creatorUserName} - ${Area.fromId(application.area).get.name}") {
Expand Down Expand Up @@ -381,7 +381,7 @@ <h2 class="mdl-card__title-text">@application.subject</h2>
<div class="mdl-tabs__tab-bar">
<a href="#answer" class="mdl-tabs__tab mdl-color-text--primary @if(openedTab =="answer"){ is-active } "><i class="material-icons">
reply_all</i> Ajouter une réponse</a>
@if(usersThatCanBeInvited.nonEmpty) {
@if(groupsWithUsersThatCanBeInvited.nonEmpty) {
<a href="#invite" class="mdl-tabs__tab mdl-color-text--primary @if(openedTab =="invite"){ is-active }"><i class="material-icons">
person_add</i> Inviter une personne</a>
}
Expand Down Expand Up @@ -447,29 +447,33 @@ <h5 class="mdl-cell mdl-cell--12-col">Ajouter informations concernant l'usager</
</form>
</div>

@if(usersThatCanBeInvited.nonEmpty) {
@if(groupsWithUsersThatCanBeInvited.nonEmpty) {
<div class="mdl-tabs__panel @if(openedTab =="invite"){ is-active }" id="invite">
<form action='@routes.ApplicationController.invite(application.id)' class="mdl-cell mdl-cell--12-col mdl-grid" method="post">
@helper.CSRF.formField
<table class="mdl-data-table mdl-js-data-table mdl-cell mdl-cell--12-col" style="border: none;">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric"></th>
<th class="mdl-data-table__cell--non-numeric">Qualité</th>
<th class="mdl-data-table__cell--non-numeric">Structure</th>
<th class="mdl-data-table__cell--non-numeric">Nom</th>
<th class="mdl-data-table__cell--non-numeric">Qualité</th>
</tr>
</thead>
<tbody>
@for(user <- usersThatCanBeInvited.sortBy(_.qualite)) {
<tr>
<td>
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-js-ripple-effect--ignore-events">
<input type="checkbox" class="mdl-checkbox__input" name="users[]" value="@user.id">
</label>
</td>
<td class="mdl-data-table__cell--non-numeric">@user.qualite</td>
<td class="mdl-data-table__cell--non-numeric">@user.name</td>
</tr>
@for((group, users) <- groupsWithUsersThatCanBeInvited.sortBy(_._1.name)) {
@for(user <- users.sortBy(_.name)) {
<tr>
<td>
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-js-ripple-effect--ignore-events">
<input type="checkbox" class="mdl-checkbox__input" name="users[]" value="@user.id">
</label>
</td>
<td class="mdl-data-table__cell--non-numeric">@group.name</td>
<td class="mdl-data-table__cell--non-numeric">@user.name</td>
<td class="mdl-data-table__cell--non-numeric">@user.qualite</td>
</tr>
}
}
</tbody>
</table>
Expand Down

0 comments on commit 7f602a2

Please sign in to comment.