From 3bad9d785181e7c25c7ecd3e1cf2dbb2c1fb5622 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 7 Jun 2019 18:26:25 +0200
Subject: [PATCH] FEAT #10742 TIME 1:30 reload doclist after substitute

---
 src/frontend/app/app.module.ts                |  6 ++++--
 .../app/profile/profile.component.html        |  2 +-
 src/frontend/app/profile/profile.component.ts | 14 ++++++++++---
 src/frontend/app/service/filters.service.ts   | 21 +++++++++++++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 src/frontend/app/service/filters.service.ts

diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts
index a8880f806d..7190c55fd1 100755
--- a/src/frontend/app/app.module.ts
+++ b/src/frontend/app/app.module.ts
@@ -46,12 +46,13 @@ import { OverlayComponent } from './overlay/overlay.component';
 import { VisaWorkflowComponent } from './document/visa-workflow/visa-workflow.component';
 import { DocumentListComponent } from './document/document-list/document-list.component';
 import { MainDocumentDetailComponent } from './document/main-document-detail/main-document-detail.component';
-
+import { UpdatePasswordComponent } from './login/updatePassword/updatePassword.component';
 
 // SERVICES
 import { NotificationService, CustomSnackbarComponent } from './service/notification.service';
 import { SignaturesContentService } from './service/signatures.service';
-import { UpdatePasswordComponent } from './login/updatePassword/updatePassword.component';
+import { FiltersService } from './service/filters.service';
+
 
 
 
@@ -118,6 +119,7 @@ import { UpdatePasswordComponent } from './login/updatePassword/updatePassword.c
     SignaturesComponent
   ],
   providers: [SignaturesContentService,
+    FiltersService,
     NotificationService,
     {
       provide: HAMMER_GESTURE_CONFIG,
diff --git a/src/frontend/app/profile/profile.component.html b/src/frontend/app/profile/profile.component.html
index e14ead7de1..0bc72e0d59 100644
--- a/src/frontend/app/profile/profile.component.html
+++ b/src/frontend/app/profile/profile.component.html
@@ -243,7 +243,7 @@
                                             <mat-select placeholder="{{'lang.chooseSubstitute' | translate}}" name="usersRest"
                                                 [(ngModel)]="profileInfo.substitute">
                                                 <ng-container *ngFor="let userRest of usersRest">
-                                                    <mat-option *ngIf="userRest.id !== profileInfo.id"
+                                                    <mat-option *ngIf="userRest.id !== profileInfo.id && !userRest.substitute"
                                                         [value]="userRest.id">
                                                         {{userRest.firstname}}
                                                         {{userRest.lastname}}</mat-option>
diff --git a/src/frontend/app/profile/profile.component.ts b/src/frontend/app/profile/profile.component.ts
index 2884578870..0b0a9c2728 100644
--- a/src/frontend/app/profile/profile.component.ts
+++ b/src/frontend/app/profile/profile.component.ts
@@ -7,6 +7,8 @@ import { NotificationService } from '../service/notification.service';
 import { CookieService } from 'ngx-cookie-service';
 import * as EXIF from 'exif-js';
 import { TranslateService } from '@ngx-translate/core';
+import { FiltersService } from '../service/filters.service';
+import { Router } from '@angular/router';
 
 @Component({
     selector: 'app-my-profile',
@@ -19,6 +21,7 @@ export class ProfileComponent implements OnInit {
     @Input('snavRightComponent') snavRightComponent: MatSidenav;
     @Input('snavLeftComponent') snavLeftComponent: MatSidenav;
 
+
     @ViewChild('passwordContent') passwordContent: MatExpansionPanel;
 
     profileInfo: any = {
@@ -61,9 +64,7 @@ export class ProfileComponent implements OnInit {
     msgButton = 'lang.validate';
     loading: boolean = false;
 
-    constructor(private translate: TranslateService, public http: HttpClient, iconReg: MatIconRegistry, public sanitizer: DomSanitizer, public notificationService: NotificationService, public signaturesService: SignaturesContentService, private cookieService: CookieService) {
-        iconReg.addSvgIcon('maarchLogo', sanitizer.bypassSecurityTrustResourceUrl('../src/frontend/assets/logo_white.svg'));
-    }
+    constructor(private translate: TranslateService, public http: HttpClient,  private router: Router, public sanitizer: DomSanitizer, public notificationService: NotificationService, public signaturesService: SignaturesContentService, private cookieService: CookieService, public filtersService: FiltersService) { }
 
     ngOnInit(): void {
         if (this.cookieService.check('maarchParapheurAuth')) {
@@ -227,6 +228,13 @@ export class ProfileComponent implements OnInit {
                 this.setLang(this.signaturesService.userLogged.preferences.lang);
                 this.cookieService.set( 'maarchParapheurLang', this.signaturesService.userLogged.preferences.lang );
 
+                if (this.profileInfo.substitute !== null) {
+                    this.filtersService.resfreshDocuments();
+                    if (this.signaturesService.documentsList.length > 0 && this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].owner === false) {
+                        this.router.navigate(['/documents']);
+                    }
+                }
+
                 $('.avatarProfile').css({ 'transform': 'rotate(0deg)' });
 
                 if (this.showPassword) {
diff --git a/src/frontend/app/service/filters.service.ts b/src/frontend/app/service/filters.service.ts
new file mode 100644
index 0000000000..1721a73746
--- /dev/null
+++ b/src/frontend/app/service/filters.service.ts
@@ -0,0 +1,21 @@
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+
+import { SignaturesContentService } from '../service/signatures.service';
+
+@Injectable()
+export class FiltersService {
+
+    constructor(public http: HttpClient, public signaturesService: SignaturesContentService) { }
+
+    resfreshDocuments() {
+        this.http.get('../rest/documents?limit=25&offset=0&mode=')
+            .subscribe((data: any) => {
+                this.signaturesService.mode = '';
+                this.signaturesService.documentsList = data.documents;
+                this.signaturesService.documentsListCount = data.count;
+            }, (err: any) => {
+                console.log(err.error.errors);
+            });
+    }
+}
-- 
GitLab