From 5ff31545ad0c15f676313f2f1fe148c7847c6f1e Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Mon, 28 Oct 2019 19:33:38 +0100
Subject: [PATCH] FEAT #12091 TIME 0:20 fix resfresh folder information when
 updated + fix no basket msg

---
 .../app/basket/basket-home.component.html     |  7 ++-
 .../app/basket/basket-home.component.scss     |  7 +++
 .../folder-document-list.component.html       |  2 +-
 .../folder-document-list.component.ts         | 49 ++++++++++++++-----
 .../app/folder/folder-tree.component.ts       |  7 ++-
 src/frontend/app/folder/folders.service.ts    |  4 ++
 .../folder/panel/panel-folder.component.ts    |  2 +-
 src/frontend/lang/lang-fr.ts                  |  2 -
 8 files changed, 61 insertions(+), 19 deletions(-)

diff --git a/src/frontend/app/basket/basket-home.component.html b/src/frontend/app/basket/basket-home.component.html
index 78c19519847..6909dc72d7f 100755
--- a/src/frontend/app/basket/basket-home.component.html
+++ b/src/frontend/app/basket/basket-home.component.html
@@ -1,11 +1,11 @@
-<mat-expansion-panel #basketPanel *ngIf="loading || homeData.regroupedBaskets.length > 0 || homeData.assignedBaskets.length > 0" class="basketList" [expanded]="!loading">
+<mat-expansion-panel #basketPanel class="basketList" [expanded]="!loading">
     <mat-expansion-panel-header>
         <mat-panel-title>
             <i class="fa fa-inbox panelIconMenu"></i>&nbsp;{{lang.myBaskets}}
         </mat-panel-title>
     </mat-expansion-panel-header>
     <ng-container *ngIf="!loading">
-        <mat-form-field floatLabel="never" appearance="outline" class="basketsFilter"
+        <mat-form-field [style.display]="homeData.assignedBaskets.length > 0 || homeData.regroupedBaskets.length > 0 ? 'inline-block' : 'none'" floatLabel="never" appearance="outline" class="basketsFilter"
             style="padding-left:20px;padding-right:20px;font-size: 11px;">
             <input matInput placeholder="{{lang.filterBy}}" #listFilter>
         </mat-form-field>
@@ -61,5 +61,8 @@
                 </a>
             </mat-nav-list>
         </ng-container>
+        <div class="noBasket" *ngIf="homeData.assignedBaskets.length === 0 && homeData.regroupedBaskets.length === 0">
+            {{lang.noAvailableBasket}}
+        </div>
     </ng-container>
 </mat-expansion-panel>
\ No newline at end of file
diff --git a/src/frontend/app/basket/basket-home.component.scss b/src/frontend/app/basket/basket-home.component.scss
index 6e490a254d4..988bbcc6e43 100644
--- a/src/frontend/app/basket/basket-home.component.scss
+++ b/src/frontend/app/basket/basket-home.component.scss
@@ -60,4 +60,11 @@
 
 .panelIconMenu {
     font-size: 22px;
+}
+
+.noBasket {
+    text-align: center;
+    font-size: 13px;
+    opacity: 0.5;
+    font-style: italic;
 }
\ No newline at end of file
diff --git a/src/frontend/app/folder/document-list/folder-document-list.component.html b/src/frontend/app/folder/document-list/folder-document-list.component.html
index a9262b981b0..0eb9a52ac67 100644
--- a/src/frontend/app/folder/document-list/folder-document-list.component.html
+++ b/src/frontend/app/folder/document-list/folder-document-list.component.html
@@ -8,7 +8,7 @@
         <basket-home #basketHome [snavL]="snav"></basket-home>
         <mat-divider></mat-divider>
         <panel-folder #panelFolder *ngIf="folderInfo.id !== '' && folderInfo.id !== undefined"
-            [selectedId]="folderInfo.id"></panel-folder>
+            [selectedId]="folderInfo.id" [showTree]="true"></panel-folder>
     </mat-sidenav>
     <mat-sidenav-content>
         <mat-card id="viewThumbnail" style="display:none;position: fixed;z-index: 2;margin-left: 1px;">
diff --git a/src/frontend/app/folder/document-list/folder-document-list.component.ts b/src/frontend/app/folder/document-list/folder-document-list.component.ts
index f8f4a3869e1..09cb50518f0 100644
--- a/src/frontend/app/folder/document-list/folder-document-list.component.ts
+++ b/src/frontend/app/folder/document-list/folder-document-list.component.ts
@@ -1,7 +1,7 @@
 import { Component, OnInit, ViewChild, EventEmitter, ViewContainerRef } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { LANG } from '../../translate.component';
-import { merge, Observable, of as observableOf, Subject, of } from 'rxjs';
+import { merge, Observable, of as observableOf, Subject, of, Subscription } from 'rxjs';
 import { NotificationService } from '../../notification.service';
 import { MatDialog, MatDialogRef } from '@angular/material/dialog';
 import { MatPaginator } from '@angular/material/paginator';
@@ -94,6 +94,7 @@ export class FolderDocumentListComponent implements OnInit {
     folderInfoOpened: boolean = false;
 
     private destroy$ = new Subject<boolean>();
+    subscription: Subscription;
 
     @ViewChild('actionsListContext', { static: true }) actionsList: FolderActionListComponent;
     @ViewChild('appPanelList', { static: true }) appPanelList: PanelListComponent;
@@ -112,13 +113,24 @@ export class FolderDocumentListComponent implements OnInit {
         public dialog: MatDialog,
         private sanitizer: DomSanitizer,
         private headerService: HeaderService,
-        public filtersListService: FiltersListService, 
+        public filtersListService: FiltersListService,
         private notify: NotificationService,
         public overlay: Overlay,
         public viewContainerRef: ViewContainerRef,
         public appService: AppService,
         private foldersService: FoldersService) {
+
         $j("link[href='merged_css.php']").remove();
+
+        // Event after process action 
+        this.subscription = this.foldersService.catchEvent().subscribe((result: any) => {
+            
+            if (result.type === 'refreshFolderInformations') {
+                if(result.content.id == this.folderInfo.id) {
+                    this.refreshFolderInformations();
+                }
+            }
+        });
     }
 
     ngOnInit(): void {
@@ -144,9 +156,9 @@ export class FolderDocumentListComponent implements OnInit {
                     this.foldersService.setFolder(this.folderInfo);
                     this.headerService.setHeader(this.folderInfo.label, '', 'fa fa-folder-open');
                     setTimeout(() => {
-                        this.basketHome.togglePanel(false); 
+                        this.basketHome.togglePanel(false);
                     }, 200);
-                    
+
                 });
             this.basketUrl = '../../rest/folders/' + params['folderId'] + '/resources';
             this.filtersListService.filterMode = false;
@@ -170,6 +182,7 @@ export class FolderDocumentListComponent implements OnInit {
 
     ngOnDestroy() {
         this.destroy$.next(true);
+        this.subscription.unsubscribe();
     }
 
     initResultList() {
@@ -245,6 +258,20 @@ export class FolderDocumentListComponent implements OnInit {
         this.currentResource.countNotes = nb;
     }
 
+    refreshFolderInformations() {
+        this.http.get('../../rest/folders/' + this.folderInfo.id)
+            .subscribe((data: any) => {
+                this.folderInfo =
+                    {
+                        'id': data.folder.id,
+                        'label': data.folder.label,
+                        'ownerDisplayName': data.folder.ownerDisplayName,
+                        'entitiesSharing': data.folder.sharing.entities.map((entity: any) => entity.label),
+                    };
+                this.headerService.setHeader(this.folderInfo.label, '', 'fa fa-folder-open');
+            });
+    }
+
     refreshBadgeAttachments(nb: number) {
         this.currentResource.countAttachments = nb;
     }
@@ -317,18 +344,18 @@ export class FolderDocumentListComponent implements OnInit {
     }
 
     selectSpecificRes(row: any) {
-        let thisSelect = { checked : true };
-        let thisDeselect = { checked : false };
-        
+        let thisSelect = { checked: true };
+        let thisDeselect = { checked: false };
+
         this.toggleAllRes(thisDeselect);
         this.toggleRes(thisSelect, row);
     }
 
     open({ x, y }: MouseEvent, row: any) {
-        
-        let thisSelect = { checked : true };
-        let thisDeselect = { checked : false };
-        if ( row.checked === false) {
+
+        let thisSelect = { checked: true };
+        let thisDeselect = { checked: false };
+        if (row.checked === false) {
             row.checked = true;
             this.toggleAllRes(thisDeselect);
             this.toggleRes(thisSelect, row);
diff --git a/src/frontend/app/folder/folder-tree.component.ts b/src/frontend/app/folder/folder-tree.component.ts
index 36df9a34c34..4455e46c108 100644
--- a/src/frontend/app/folder/folder-tree.component.ts
+++ b/src/frontend/app/folder/folder-tree.component.ts
@@ -144,7 +144,9 @@ export class FolderTreeComponent implements OnInit {
             } else if (result.type === 'refreshFolderPinned') {
                 this.treeControl.dataNodes.filter(folder => folder.id === result.content.id)[0].pinned = result.content.pinned;
             } else {
-                this.openTree(this.foldersService.getCurrentFolder().id);
+                if (this.treeControl.dataNodes !== undefined) {
+                    this.openTree(this.foldersService.getCurrentFolder().id);
+                }
             }
         }); 
     }
@@ -361,7 +363,8 @@ export class FolderTreeComponent implements OnInit {
                 if (data !== undefined) {
                     this.getFolders();
                     this.foldersService.getPinnedFolders();
-                }                
+                    this.foldersService.setEvent({type:'refreshFolderInformations', content: node});
+                }
             })
         ).subscribe();
     }
diff --git a/src/frontend/app/folder/folders.service.ts b/src/frontend/app/folder/folders.service.ts
index 8ddbe34e54f..23c40f91fe3 100644
--- a/src/frontend/app/folder/folders.service.ts
+++ b/src/frontend/app/folder/folders.service.ts
@@ -42,6 +42,10 @@ export class FoldersService {
         return this.eventAction.asObservable();
     }
 
+    setEvent(content: any) {
+        return this.eventAction.next(content);
+    }
+
     goToFolder(folder: any) {
         this.setFolder(folder);
         this.router.navigate(['/folders/' + folder.id]);
diff --git a/src/frontend/app/folder/panel/panel-folder.component.ts b/src/frontend/app/folder/panel/panel-folder.component.ts
index bb0479e6fa4..db6a4bff9fb 100644
--- a/src/frontend/app/folder/panel/panel-folder.component.ts
+++ b/src/frontend/app/folder/panel/panel-folder.component.ts
@@ -14,8 +14,8 @@ export class PanelFolderComponent implements OnInit {
 
     lang: any = LANG;
 
-    showTree: boolean = false;
     @Input('selectedId') id: number;
+    @Input('showTree') showTree: boolean = false;
     @ViewChild('folderTree', { static: false }) folderTree: FolderTreeComponent;
     
     @Output('refreshEvent') refreshEvent = new EventEmitter<string>();
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 0ef8877927f..22e14d95062 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1250,6 +1250,4 @@ export const LANG_FR = {
     "configVisaWorkflowInDetailDesc" : "Permet de configurer le circuit de visa depuis la fiche détaillée",
     "noFile" : "Aucun fichier",
     "noFileMsg" : "<b>Attention</b>, aucun fichier téléversé.<br/><br/>Voulez-vous continuer ?",
-
-
 };
-- 
GitLab