From b8d9010fe00c314f4948a4be835ededc8b5f0f3a Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 28 Jan 2021 17:37:56 +0100
Subject: [PATCH] FEAT #16063 TIME 0:30 WIP menu dashboard

---
 .../home/dashboard/dashboard.component.html   | 12 ++++++----
 .../app/home/dashboard/dashboard.component.ts | 22 +++++++++++++++++
 .../app/home/dashboard/dashboard.service.ts   | 24 +++++++++----------
 3 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/src/frontend/app/home/dashboard/dashboard.component.html b/src/frontend/app/home/dashboard/dashboard.component.html
index ce718d7178a..45f14b0f1ce 100644
--- a/src/frontend/app/home/dashboard/dashboard.component.html
+++ b/src/frontend/app/home/dashboard/dashboard.component.html
@@ -12,14 +12,16 @@
             </button>
             <mat-menu #toolMenu="matMenu">
                 <ng-container  *ngFor="let menu of tile.menus">
-                    <button *ngIf="menu!=='view'" mat-menu-item>{{menu}}</button>
-                    <button *ngIf="menu==='view'" mat-menu-item [matMenuTriggerFor]="toolMenuView">{{menu}}</button>
+                    <button *ngIf="menu!=='view'" mat-menu-item (click)="launchAction(menu, tile)">{{'lang.'+ menu | translate}}</button>
+                    <button *ngIf="menu==='view'" mat-menu-item [matMenuTriggerFor]="toolMenuView">{{'lang.'+ menu | translate}}</button>
                 </ng-container>
             </mat-menu>
             <mat-menu #toolMenuView="matMenu">
-                <button mat-menu-item *ngFor="let view of tile.views" [disabled]="tile.view === view" (click)="changeView(tile,view.id)">
-                    <mat-icon class="fa fa-list" color="primary" style="height: auto;width: auto;"></mat-icon>
-                    <span>{{view.id}}</span>
+                <button mat-menu-item *ngFor="let view of tile.views" [disabled]="tile.view === view.id" (click)="changeView(tile,view.id)">
+                    <mat-icon *ngIf="view.id==='list'" class="fa fa-list" color="primary" style="height: auto;width: auto;"></mat-icon>
+                    <mat-icon *ngIf="view.id==='resume'" class="fas fa-equals" color="primary" style="height: auto;width: auto;"></mat-icon>
+                    <mat-icon *ngIf="view.id==='chart'" class="fas fa-chart-pie" color="primary" style="height: auto;width: auto;"></mat-icon>
+                    <span>{{'lang.' + view.id | translate}}</span>
                 </button>
             </mat-menu>
         </div>
diff --git a/src/frontend/app/home/dashboard/dashboard.component.ts b/src/frontend/app/home/dashboard/dashboard.component.ts
index a1f5dc36382..193eb5c4300 100644
--- a/src/frontend/app/home/dashboard/dashboard.component.ts
+++ b/src/frontend/app/home/dashboard/dashboard.component.ts
@@ -6,6 +6,7 @@ import { FunctionsService } from '@service/functions.service';
 import { TileCreateComponent } from './tile/tile-create.component';
 import { exhaustMap, filter, tap } from 'rxjs/operators';
 import { MatDialog } from '@angular/material/dialog';
+import { ConfirmComponent } from '@plugins/modal/confirm.component';
 
 @Component({
     selector: 'app-dashboard',
@@ -87,6 +88,7 @@ export class DashboardComponent implements OnInit, AfterViewInit {
     changeView(tile: any, view: string) {
         const indexTile = this.tiles.filter((tileItem: any) => tileItem.id !== null).map((tileItem: any) => tileItem.sequence).indexOf(tile.sequence);
         this.tileComponent.toArray()[indexTile].changeView(view);
+        tile.view = view;
     }
 
     transferDataSuccess() {
@@ -106,4 +108,24 @@ export class DashboardComponent implements OnInit, AfterViewInit {
             })
         ).subscribe();
     }
+
+    launchAction(action: string, tile: any) {
+        this[action](tile);
+    }
+
+    delete(tile: any) {
+        const dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.delete'), msg: this.translate.instant('lang.confirmAction') } });
+
+        // TO DO: SAVE IN BACK
+        dialogRef.afterClosed().pipe(
+            filter((data: string) => data === 'ok'),
+            tap(() => {
+                this.tiles[tile.sequence] = {
+                    id: null,
+                    sequence: tile.sequence,
+                    editMode: false
+                };
+            })
+        ).subscribe();
+    }
 }
diff --git a/src/frontend/app/home/dashboard/dashboard.service.ts b/src/frontend/app/home/dashboard/dashboard.service.ts
index 50067a8efd6..53d4916273d 100644
--- a/src/frontend/app/home/dashboard/dashboard.service.ts
+++ b/src/frontend/app/home/dashboard/dashboard.service.ts
@@ -8,8 +8,8 @@ export class DashboardService {
     tileTypes: any = {
         myLastResources : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
@@ -28,8 +28,8 @@ export class DashboardService {
         },
         basket : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
@@ -48,8 +48,8 @@ export class DashboardService {
         },
         searchTemplate : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
@@ -68,8 +68,8 @@ export class DashboardService {
         },
         followedMail : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
@@ -88,8 +88,8 @@ export class DashboardService {
         },
         folder : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
@@ -108,8 +108,8 @@ export class DashboardService {
         },
         externalSignatoryBook : {
             menus : [
-                'delete',
-                'view'
+                'view',
+                'delete'
             ],
             views: [
                 {
-- 
GitLab