From c05201d7764691c6db935f33e2d0e255ca115031 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 5 Sep 2019 11:53:09 +0200
Subject: [PATCH] FEAT #11641 TIME 2 add handle empty folder + add var lang

---
 .../app/actions/actions-list.component.html   |  2 +-
 .../app/actions/actions-list.component.ts     |  3 +++
 .../folder-action-list.component.html         |  2 +-
 .../folder-menu/folder-menu.component.html    | 10 +++++++-
 .../folder-menu/folder-menu.component.scss    |  8 ++++++-
 .../folder-menu/folder-menu.component.ts      | 23 +++++++++++++++++--
 .../app/folder/folder-tree.component.html     |  7 ++++--
 .../app/folder/folder-tree.component.scss     | 11 +++++++++
 src/frontend/lang/lang-en.ts                  |  1 +
 src/frontend/lang/lang-fr.ts                  |  1 +
 src/frontend/lang/lang-nl.ts                  |  1 +
 src/frontend/plugins/sorting.pipe.ts          |  2 +-
 12 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/src/frontend/app/actions/actions-list.component.html b/src/frontend/app/actions/actions-list.component.html
index a196d2be05e..35c2a18b49b 100644
--- a/src/frontend/app/actions/actions-list.component.html
+++ b/src/frontend/app/actions/actions-list.component.html
@@ -14,5 +14,5 @@
         <span>{{action.label_action}}</span>
     </button>
     <mat-divider></mat-divider>
-    <folder-menu [resIds]="selectedRes" (refreshList)="refreshList()" (refreshFolders)="refreshFolders()"></folder-menu>
+    <folder-menu [resIds]="selectedRes" [currentFolders]="folderList" (refreshList)="refreshList()" (refreshFolders)="refreshFolders()"></folder-menu>
 </mat-menu>
\ No newline at end of file
diff --git a/src/frontend/app/actions/actions-list.component.ts b/src/frontend/app/actions/actions-list.component.ts
index 72d43f38eb2..3d0d7372aba 100644
--- a/src/frontend/app/actions/actions-list.component.ts
+++ b/src/frontend/app/actions/actions-list.component.ts
@@ -45,6 +45,7 @@ export class ActionsListComponent implements OnInit {
     contextResId = 0;
     currentLock: any = null;
     arrRes: any[] = [];
+    folderList: any [] = [];
 
     actionsList: any[] = [];
 
@@ -72,6 +73,8 @@ export class ActionsListComponent implements OnInit {
         this.contextMenuTitle = row.alt_identifier;
         this.contextResId = row.res_id;
 
+        this.folderList = row.folders !== undefined ? row.folders : [];
+
         // Opens the menu
         this.contextMenu.openMenu();
 
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 e9eb561dd0b..5a8fa8bf3b1 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
@@ -16,7 +16,7 @@
     <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>Retirer du dossier</span>
+        <span>{{lang.removeFromFolder}}</span>
     </button>
     <folder-menu [resIds]="selectedRes" (refreshFolders)="refreshFolders()"></folder-menu>
 </mat-menu>
\ No newline at end of file
diff --git a/src/frontend/app/folder/folder-menu/folder-menu.component.html b/src/frontend/app/folder/folder-menu/folder-menu.component.html
index ad81d93c858..908e66b50e7 100644
--- a/src/frontend/app/folder/folder-menu/folder-menu.component.html
+++ b/src/frontend/app/folder/folder-menu/folder-menu.component.html
@@ -1,7 +1,15 @@
+<button mat-menu-item [matMenuTriggerFor]="currentFolders" *ngIf="currentFoldersList !== undefined && currentFoldersList.length > 0" class="folderAction">
+    <mat-icon color="warn" class="fa fa-folder-minus fa-2x"></mat-icon>
+    <span>{{lang.removeFromFolder}}...</span>
+</button>
+<mat-menu #currentFolders="matMenu" [class]="'folderListMenu'">
+    <button mat-menu-item *ngFor="let currentfolder of currentFoldersList | sortBy : 'label'" class="labelFolder" (click)="unclassifyDocuments(currentfolder)" [title]="currentfolder.label"><i class="fa fa-users private" *ngIf="currentfolder.public" title="{{lang.sharedFolder}}"></i> {{currentfolder.label}}</button>
+</mat-menu>
 <button mat-menu-item [matMenuTriggerFor]="folders" class="folderAction" (menuOpened)="getFolders()" [disabled]="resIds.length === 0">
-    <mat-icon class="fa fa-folder-open fa-2x"></mat-icon>
+    <mat-icon color="primary" class="fa fa-folder-open fa-2x"></mat-icon>
     <span>{{lang.classifyIn}}</span>
 </button>
 <mat-menu #folders="matMenu" [class]="'folderListMenu'">
+    <button *ngIf="foldersList.length === 0" mat-menu-item class="noFolder" disabled>{{lang.noAvailableFolder}}</button>
     <button mat-menu-item *ngFor="let folder of foldersList | sortBy : 'label'" class="labelFolder" (click)="classifyDocuments(folder)" [title]="folder.label"><i class="fa fa-users private" *ngIf="folder.public" title="{{lang.sharedFolder}}"></i> {{folder.label}}</button>
 </mat-menu>
\ No newline at end of file
diff --git a/src/frontend/app/folder/folder-menu/folder-menu.component.scss b/src/frontend/app/folder/folder-menu/folder-menu.component.scss
index f56b9f085e4..5ec433d5b41 100644
--- a/src/frontend/app/folder/folder-menu/folder-menu.component.scss
+++ b/src/frontend/app/folder/folder-menu/folder-menu.component.scss
@@ -5,7 +5,6 @@
 
     .mat-icon {
         font-size:20px;
-        color: $primary;
     }
 }
 
@@ -21,4 +20,11 @@
 
 ::ng-deep.folderListMenu {
     width: auto;
+}
+
+.noFolder {
+    font-size: 12px;
+    color: rgb(102, 102, 102);
+    text-align: center;
+    font-style: italic;
 }
\ No newline at end of file
diff --git a/src/frontend/app/folder/folder-menu/folder-menu.component.ts b/src/frontend/app/folder/folder-menu/folder-menu.component.ts
index ec2201468fe..c77708ba78f 100644
--- a/src/frontend/app/folder/folder-menu/folder-menu.component.ts
+++ b/src/frontend/app/folder/folder-menu/folder-menu.component.ts
@@ -1,9 +1,11 @@
 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
 import { LANG } from '../../translate.component';
 import { HttpClient } from '@angular/common/http';
-import { map, tap, catchError } from 'rxjs/operators';
+import { map, tap, catchError, filter, exhaustMap } from 'rxjs/operators';
 import { of } from 'rxjs';
 import { NotificationService } from '../../notification.service';
+import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
+import { MatDialogRef, MatDialog } from '@angular/material/dialog';
 
 @Component({
     selector: 'folder-menu',
@@ -17,13 +19,17 @@ export class FolderMenuComponent implements OnInit {
 
     foldersList: any[] = [];
     @Input('resIds') resIds: number[];
+    @Input('currentFolders') currentFoldersList: any[];
 
     @Output('refreshFolders') refreshFolders = new EventEmitter<string>();
     @Output('refreshList') refreshList = new EventEmitter<string>();
 
+    dialogRef: MatDialogRef<any>;
+    
     constructor(
         public http: HttpClient,
-        private notify: NotificationService
+        private notify: NotificationService,
+        public dialog: MatDialog
     ) { }
 
     ngOnInit(): void { }
@@ -52,4 +58,17 @@ export class FolderMenuComponent implements OnInit {
         ).subscribe();
     }
 
+    unclassifyDocuments(folder: any) {
+        this.dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.delete, msg: 'Voulez-vous enlever <b>' + this.resIds.length + '</b> document(s) du classement ?' } });
+
+        this.dialogRef.afterClosed().pipe(
+            filter((data: string) => data === 'ok'),
+            exhaustMap(() => this.http.request('DELETE', '../../rest/folders/' + folder.id + '/resources', { body: { resources: this.resIds } })),
+            tap((data: any) => {
+                this.notify.success(this.lang.removedFromFolder);
+                this.refreshFolders.emit();
+                this.refreshList.emit();
+            })
+        ).subscribe();
+    }
 }
diff --git a/src/frontend/app/folder/folder-tree.component.html b/src/frontend/app/folder/folder-tree.component.html
index 475477856f0..03c7e446cb2 100644
--- a/src/frontend/app/folder/folder-tree.component.html
+++ b/src/frontend/app/folder/folder-tree.component.html
@@ -1,4 +1,4 @@
-<div class="folderTools">
+<div *ngIf="dataSource.data.length > 0" class="folderTools">
     <div class="filter">
         <plugin-autocomplete [size]="'small'" [labelPlaceholder]="lang.searchFolder"
             [routeDatas]="['/rest/autocomplete/folders']" [targetSearchKey]="'idToDisplay'"
@@ -10,6 +10,9 @@
         </button>
     </div>
 </div>
+<div *ngIf="dataSource.data.length === 0" class="noFolder">
+    {{lang.noAvailableFolder}}<br/><a (click)="toggleInput()">{{lang.addFolder}}</a>
+</div>
 <mat-list *ngIf="createRootNode">
     <mat-list-item role="listitem" class="rootFolder">
         <form>
@@ -24,7 +27,7 @@
         </form>
     </mat-list-item>
 </mat-list>
-<mat-nav-list>
+<mat-nav-list *ngIf="dataSource.data.length > 0">
     <mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
         <!-- This is the tree node template for leaf nodes -->
         <mat-tree-node cdkDropList [id]="'folder-list-'+node.id"
diff --git a/src/frontend/app/folder/folder-tree.component.scss b/src/frontend/app/folder/folder-tree.component.scss
index 994b277b761..6cb108bbae6 100644
--- a/src/frontend/app/folder/folder-tree.component.scss
+++ b/src/frontend/app/folder/folder-tree.component.scss
@@ -124,4 +124,15 @@ button:disabled {
     .filter {
         flex: 1;
     }
+}
+
+.noFolder {
+    font-size: 12px;
+    color: rgb(102, 102, 102);
+    text-align: center;
+    font-style: italic;
+
+    a {
+        cursor: pointer;
+    }
 }
\ No newline at end of file
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index c04005049b7..48fafd8cfa1 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -1070,4 +1070,5 @@ export const LANG_EN = {
     "moveQuestion" : "Do you want move",
     "classify" : "Classify",
     "mailClassified" : "Mail(s) classified",
+    "noAvailableFolder" : "No available folder",
 };
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 388be320a80..8cf2c5f03ce 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1107,4 +1107,5 @@ export const LANG_FR = {
     "moveQuestion" : "Voulez-vous déplacer",
     "classify" : "Classer",
     "mailClassified" : "Courrier(s) classé(s)",
+    "noAvailableFolder" : "Aucun dossier disponible",
 };
diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts
index 303c76202ce..e18884e7b75 100755
--- a/src/frontend/lang/lang-nl.ts
+++ b/src/frontend/lang/lang-nl.ts
@@ -1096,4 +1096,5 @@ export const LANG_NL = {
     "moveQuestion" : "Do you want move", //_TO_TRANSLATE
     "classify" : "Classify", //_TO_TRANSLATE
     "mailClassified" : "Mail(s) classified", //_TO_TRANSLATE
+    "noAvailableFolder" : "No available folder", //_TO_TRANSLATE
 };
diff --git a/src/frontend/plugins/sorting.pipe.ts b/src/frontend/plugins/sorting.pipe.ts
index acd1a157b9b..3689b286e16 100755
--- a/src/frontend/plugins/sorting.pipe.ts
+++ b/src/frontend/plugins/sorting.pipe.ts
@@ -10,7 +10,7 @@ export class SortPipe {
 	transform(array: Array<string>, args: string): Array<string> {
 		let normA = '';
 		let normB = '';
-		if (array !== undefined) {
+		if (array !== undefined && array.length > 0) {
 			array.sort((a: any, b: any) => {
 				if (args === undefined) {
 					normA = this.latinisePipe.transform(a).toLocaleLowerCase();
-- 
GitLab