From 19bdfe5b4e146a34fa01a89f5ecd54d40a7d2202 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Thu, 26 Mar 2020 18:47:57 +0100
Subject: [PATCH] FEAT #13509 TIME 1:00 un-follow mails from basket and folder
 list

---
 .../UserFollowedResourceController.php        |  6 +++++-
 .../app/actions/actions-list.component.html   |  7 ++++++-
 .../app/actions/actions-list.component.scss   |  9 ++++++++-
 .../app/actions/actions-list.component.ts     | 20 ++++++++++++++++++-
 .../folder-action-list.component.html         |  7 ++++++-
 .../folder-action-list.component.scss         |  4 ++--
 .../folder-action-list.component.ts           | 14 +++++++++++++
 .../followed-action-list.component.html       |  2 +-
 .../followed-action-list.component.scss       |  4 ++--
 .../followed-action-list.component.ts         |  2 +-
 src/frontend/lang/lang-en.ts                  |  2 +-
 11 files changed, 65 insertions(+), 12 deletions(-)

diff --git a/src/app/resource/controllers/UserFollowedResourceController.php b/src/app/resource/controllers/UserFollowedResourceController.php
index c0ba07a3431..580fb000c44 100644
--- a/src/app/resource/controllers/UserFollowedResourceController.php
+++ b/src/app/resource/controllers/UserFollowedResourceController.php
@@ -62,6 +62,8 @@ class UserFollowedResourceController
             return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
         }
 
+        $nbUnFollowed = 0;
+
         foreach ($body['resources'] as $resId) {
             $following = UserFollowedResourceModel::get([
                 'where' => ['user_id = ?', 'res_id = ?'],
@@ -76,10 +78,12 @@ class UserFollowedResourceController
                 'userId' => $GLOBALS['id'],
                 'resId' => $resId
             ]);
+
+            $nbUnFollowed++;
         }
 
 
-        return $response->withStatus(204);
+        return $response->withJson(['unFollowed' => $nbUnFollowed]);
     }
 
     public function getFollowedResources(Request $request, Response $response)
diff --git a/src/frontend/app/actions/actions-list.component.html b/src/frontend/app/actions/actions-list.component.html
index e41d68a7b7a..ad2e4b1620d 100644
--- a/src/frontend/app/actions/actions-list.component.html
+++ b/src/frontend/app/actions/actions-list.component.html
@@ -14,5 +14,10 @@
         <span>{{action.label}}</span>
     </button>
     <mat-divider></mat-divider>
+    <button mat-menu-item class="followAction" (click)="unFollow()" [disabled]="selectedRes.length === 0">
+        <mat-icon class="far fa-star fa-2x"></mat-icon>
+        <span>{{lang.untrackThisMail}}</span>
+    </button>
+    <mat-divider></mat-divider>
     <folder-menu [resIds]="selectedRes" [currentFolders]="folderList" (refreshList)="refreshList()" (refreshFolders)="refreshFolders()"></folder-menu>
-</mat-menu>
\ No newline at end of file
+</mat-menu>
diff --git a/src/frontend/app/actions/actions-list.component.scss b/src/frontend/app/actions/actions-list.component.scss
index 2a110d93138..cf1fdb503f3 100644
--- a/src/frontend/app/actions/actions-list.component.scss
+++ b/src/frontend/app/actions/actions-list.component.scss
@@ -15,4 +15,11 @@
         padding-top: 0;
         padding-bottom: 0;
     }
-}
\ No newline at end of file
+}
+
+.followAction {
+    .mat-icon {
+        font-size:20px;
+        color: $warn;
+    }
+}
diff --git a/src/frontend/app/actions/actions-list.component.ts b/src/frontend/app/actions/actions-list.component.ts
index 2323cf3a0b7..0e505fbcd24 100644
--- a/src/frontend/app/actions/actions-list.component.ts
+++ b/src/frontend/app/actions/actions-list.component.ts
@@ -7,6 +7,9 @@ import { MatMenuTrigger } from '@angular/material/menu';
 import { Router } from '@angular/router';
 import { ActionsService } from './actions.service';
 import { Subscription } from 'rxjs';
+import {ConfirmComponent} from "../../plugins/modal/confirm.component";
+import {exhaustMap, filter, tap} from "rxjs/operators";
+import {HeaderService} from "../../service/header.service";
 
 @Component({
     selector: 'app-actions-list',
@@ -47,7 +50,8 @@ export class ActionsListComponent implements OnInit {
         private notify: NotificationService,
         public dialog: MatDialog,
         private router: Router,
-        private actionService: ActionsService
+        private actionService: ActionsService,
+        private headerService: HeaderService
     ) { }
 
     dialogRef: MatDialogRef<any>;
@@ -126,4 +130,18 @@ export class ActionsListComponent implements OnInit {
     refreshFolders() {
         this.refreshPanelFolders.emit();
     }
+
+    unFollow() {
+        this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.lang.delete, msg: this.lang.stopFollowingAlert } });
+
+        this.dialogRef.afterClosed().pipe(
+            filter((data: string) => data === 'ok'),
+            exhaustMap(() => this.http.request('DELETE', '../../rest/resources/unfollow' , { body: { resources: this.selectedRes } })),
+            tap((data: any) => {
+                this.notify.success(this.lang.removedFromFolder);
+                this.headerService.nbResourcesFollowed -= data.unFollowed;
+                this.refreshList();
+            })
+        ).subscribe();
+    }
 }
diff --git a/src/frontend/app/folder/folder-action-list/folder-action-list.component.html b/src/frontend/app/folder/folder-action-list/folder-action-list.component.html
index 700eb239dee..a72beae853f 100644
--- a/src/frontend/app/folder/folder-action-list/folder-action-list.component.html
+++ b/src/frontend/app/folder/folder-action-list/folder-action-list.component.html
@@ -26,9 +26,14 @@
         </div>
     </mat-menu>
     <mat-divider></mat-divider>
+    <button mat-menu-item class="followAction" (click)="unFollow()" [disabled]="selectedRes.length === 0">
+        <mat-icon class="far fa-star fa-2x"></mat-icon>
+        <span>{{lang.untrackThisMail}}</span>
+    </button>
+    <mat-divider></mat-divider>
     <button mat-menu-item class="folderAction" (click)="unclassify()" [disabled]="selectedRes.length === 0">
         <mat-icon class="fa fa-folder-minus fa-2x"></mat-icon>
         <span>{{lang.removeFromFolder}}</span>
     </button>
     <folder-menu [resIds]="selectedRes" (refreshList)="refreshDaoAfterAction()" (refreshFolders)="refreshFolders()"></folder-menu>
-</mat-menu>
\ No newline at end of file
+</mat-menu>
diff --git a/src/frontend/app/folder/folder-action-list/folder-action-list.component.scss b/src/frontend/app/folder/folder-action-list/folder-action-list.component.scss
index e2674ba8da9..6c5e7ef5661 100644
--- a/src/frontend/app/folder/folder-action-list/folder-action-list.component.scss
+++ b/src/frontend/app/folder/folder-action-list/folder-action-list.component.scss
@@ -17,7 +17,7 @@
     }
 }
 
-.folderAction {
+.folderAction, .followAction {
     .mat-icon {
         font-size:20px;
         color: $warn;
@@ -42,4 +42,4 @@
     opacity: 0.5;
     font-style: italic;
     padding: 22px;
-}
\ No newline at end of file
+}
diff --git a/src/frontend/app/folder/folder-action-list/folder-action-list.component.ts b/src/frontend/app/folder/folder-action-list/folder-action-list.component.ts
index f86edbb38d6..c8051b40775 100644
--- a/src/frontend/app/folder/folder-action-list/folder-action-list.component.ts
+++ b/src/frontend/app/folder/folder-action-list/folder-action-list.component.ts
@@ -116,4 +116,18 @@ export class FolderActionListComponent implements OnInit {
             this.router.navigate(['/basketList/users/' + this.headerService.user.id + '/groups/' + basket.groupId + '/baskets/' + basket.basketId]);
         }
     }
+
+    unFollow() {
+        this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.lang.delete, msg: this.lang.stopFollowingAlert } });
+
+        this.dialogRef.afterClosed().pipe(
+            filter((data: string) => data === 'ok'),
+            exhaustMap(() => this.http.request('DELETE', '../../rest/resources/unfollow' , { body: { resources: this.selectedRes } })),
+            tap((data: any) => {
+                this.notify.success(this.lang.removedFromFolder);
+                this.headerService.nbResourcesFollowed -= data.unFollowed;
+                this.refreshDaoAfterAction();
+            })
+        ).subscribe();
+    }
 }
diff --git a/src/frontend/app/home/followed-action-list/followed-action-list.component.html b/src/frontend/app/home/followed-action-list/followed-action-list.component.html
index 001e268eb07..d70c83016a1 100644
--- a/src/frontend/app/home/followed-action-list/followed-action-list.component.html
+++ b/src/frontend/app/home/followed-action-list/followed-action-list.component.html
@@ -26,7 +26,7 @@
         </div>
     </mat-menu>
     <mat-divider></mat-divider>
-    <button mat-menu-item class="folderAction" (click)="unFollow()" [disabled]="selectedRes.length === 0">
+    <button mat-menu-item class="followAction" (click)="unFollow()" [disabled]="selectedRes.length === 0">
         <mat-icon class="far fa-star fa-2x"></mat-icon>
         <span>{{lang.untrackThisMail}}</span>
     </button>
diff --git a/src/frontend/app/home/followed-action-list/followed-action-list.component.scss b/src/frontend/app/home/followed-action-list/followed-action-list.component.scss
index e2674ba8da9..8b9a4c21fb4 100644
--- a/src/frontend/app/home/followed-action-list/followed-action-list.component.scss
+++ b/src/frontend/app/home/followed-action-list/followed-action-list.component.scss
@@ -17,7 +17,7 @@
     }
 }
 
-.folderAction {
+.followAction {
     .mat-icon {
         font-size:20px;
         color: $warn;
@@ -42,4 +42,4 @@
     opacity: 0.5;
     font-style: italic;
     padding: 22px;
-}
\ No newline at end of file
+}
diff --git a/src/frontend/app/home/followed-action-list/followed-action-list.component.ts b/src/frontend/app/home/followed-action-list/followed-action-list.component.ts
index 520e3b0a2b3..a0987700c55 100644
--- a/src/frontend/app/home/followed-action-list/followed-action-list.component.ts
+++ b/src/frontend/app/home/followed-action-list/followed-action-list.component.ts
@@ -94,7 +94,7 @@ export class FollowedActionListComponent implements OnInit {
             exhaustMap(() => this.http.request('DELETE', '../../rest/resources/unfollow' , { body: { resources: this.selectedRes } })),
             tap((data: any) => {
                 this.notify.success(this.lang.removedFromFolder);
-                this.headerService.nbResourcesFollowed -= this.selectedRes.length;
+                this.headerService.nbResourcesFollowed -= data.unFollowed;
                 this.refreshDaoAfterAction();
             })
         ).subscribe();
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index 319e36eb582..b66ff2dc735 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -1290,7 +1290,7 @@ export const LANG_EN = {
     "removeSignature":                             "Remove signature",
     "removeUserRedirect":                          "Remove the user from the diffusion lists",
     "removeUserRedirectInformations":              "<em>The user will be removed from the mails and entity's diffusion lists <b>except in the case where it is assignee</b></em>",
-    "removedFromFolder":                           "Mail removed from folder",
+    "removedFromFolder":                           "Mail(s) removed",
     "renewPsw":                                    "Enter the password again",
     "reports":                                     "Reports",
     "reportsAdmin":                                "Reports administration",
-- 
GitLab