From 3a63c929f691fefea65c4b4bba33671bb8297a1f Mon Sep 17 00:00:00 2001 From: Hamza HRAMCHI <hamza.hramchi@xelians.fr> Date: Tue, 26 Apr 2022 16:55:39 +0200 Subject: [PATCH] FIX #16636 TIME 1:10 be able to access the main document from the list of documents when an attached document is selected --- .../document-list/document-list.component.ts | 23 +++++++++++++++---- .../app/document/document.component.ts | 18 ++++++++++++--- .../app/sidebar/sidebar.component.html | 2 +- src/frontend/app/sidebar/sidebar.component.ts | 4 ++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/frontend/app/document/document-list/document-list.component.ts b/src/frontend/app/document/document-list/document-list.component.ts index ab11d5a3b0..ba25663d8e 100644 --- a/src/frontend/app/document/document-list/document-list.component.ts +++ b/src/frontend/app/document/document-list/document-list.component.ts @@ -1,15 +1,17 @@ -import { Component, Input, OnInit, Output, EventEmitter, ViewChild, AfterViewInit } from '@angular/core'; +import { Component, Input, OnInit, Output, EventEmitter, ViewChild, AfterViewInit, OnDestroy } from '@angular/core'; import { SignaturesContentService } from '../../service/signatures.service'; import { HttpClient } from '@angular/common/http'; import { DomSanitizer } from '@angular/platform-browser'; import { IonSlides, MenuController } from '@ionic/angular'; +import { Subscription } from 'rxjs'; +import { ActionsService } from '../../service/actions.service'; @Component({ selector: 'app-document-list', templateUrl: 'document-list.component.html', styleUrls: ['document-list.component.scss'], }) -export class DocumentListComponent implements OnInit, AfterViewInit { +export class DocumentListComponent implements OnInit, AfterViewInit, OnDestroy { @Input() docList: any; @Input() currentDocId: any; @@ -18,6 +20,8 @@ export class DocumentListComponent implements OnInit, AfterViewInit { @ViewChild('slides', { static: false }) slides: IonSlides; + subscription: Subscription; + loading: boolean = true; scrolling: boolean = false; @@ -30,9 +34,16 @@ export class DocumentListComponent implements OnInit, AfterViewInit { constructor( public http: HttpClient, public signaturesService: SignaturesContentService, + private menu: MenuController, + private actionsService: ActionsService, private sanitizer: DomSanitizer, - private menu: MenuController - ) { } + ) { + this.subscription = this.actionsService.catchEvent().subscribe((event: any) => { + if (event === 'scrollToTop') { + this.slides.slideTo(0, 0); + } + }); + } ngOnInit(): void { this.docList.forEach((element: any, index: number) => { @@ -49,6 +60,10 @@ export class DocumentListComponent implements OnInit, AfterViewInit { this.loading = false; } + ngOnDestroy(): void { + this.subscription.unsubscribe(); + } + loadDoc(id: string) { this.triggerEvent.emit(id); this.menu.close('right-menu'); diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts index f5732e1476..ffbda0c365 100755 --- a/src/frontend/app/document/document.component.ts +++ b/src/frontend/app/document/document.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild, TemplateRef, ViewContainerRef, Injectable } from '@angular/core'; +import { Component, OnInit, ViewChild, TemplateRef, ViewContainerRef, Injectable, OnDestroy } from '@angular/core'; import { SignaturesContentService } from '../service/signatures.service'; import { DomSanitizer } from '@angular/platform-browser'; import { MatBottomSheet, MatBottomSheetConfig } from '@angular/material/bottom-sheet'; @@ -18,7 +18,7 @@ import { LocalStorageService } from '../service/local-storage.service'; import { ActionSheetController, AlertController, LoadingController, MenuController, ModalController, NavController } from '@ionic/angular'; import { NgxExtendedPdfViewerService } from 'ngx-extended-pdf-viewer'; import { catchError, exhaustMap, tap } from 'rxjs/operators'; -import { of } from 'rxjs'; +import { of, Subscription } from 'rxjs'; import { SignatureMethodService } from '../service/signature-method/signature-method.service'; import { FunctionsService } from '../service/functions.service'; import { ActionsService } from '../service/actions.service'; @@ -31,7 +31,7 @@ import { SuccessInfoValidBottomSheetComponent } from '../modal/success-info-vali }) -export class DocumentComponent implements OnInit { +export class DocumentComponent implements OnInit, OnDestroy { @ViewChild('mainContent') mainContent: any; @ViewChild('img') img: any; @@ -73,6 +73,8 @@ export class DocumentComponent implements OnInit { workflow: [], }; + subscription: Subscription; + signaturesContent: any = []; docList: any = []; @@ -125,6 +127,16 @@ export class DocumentComponent implements OnInit { private cookieService: CookieService, ) { this.draggable = false; + this.subscription = this.actionsService.catchEvent().subscribe((event: any) => { + if (event.id === 'gotoDocument' && event.documentIndex === 0) { + this.loadDoc(event.documentIndex); + this.actionsService.setEvent('scrollToTop'); + } + }); + } + + ngOnDestroy(): void { + this.subscription.unsubscribe(); } imageLoaded(ev: any) { diff --git a/src/frontend/app/sidebar/sidebar.component.html b/src/frontend/app/sidebar/sidebar.component.html index 29ecbe9a84..5c8945f637 100755 --- a/src/frontend/app/sidebar/sidebar.component.html +++ b/src/frontend/app/sidebar/sidebar.component.html @@ -77,7 +77,7 @@ </ion-label> </ion-item> <ion-menu-toggle auto-hide="false" *ngFor="let document of signaturesService.documentsList;let i=index"> - <ion-item class="doc-item" (click)="filterService.currentIndex = i" routerDirection="root" + <ion-item class="doc-item" (click)="filterService.currentIndex = i; goTo(document.id);" routerDirection="root" [routerLink]="['/documents/'+document.id]" detail="false" [class.selected]="router.url === '/documents/'+document.id"> <ion-icon *ngIf="document.mode == 'sign'" color="primary" slot="start" name="pencil-outline"></ion-icon> diff --git a/src/frontend/app/sidebar/sidebar.component.ts b/src/frontend/app/sidebar/sidebar.component.ts index e5d662cce7..9bcbedeeb7 100755 --- a/src/frontend/app/sidebar/sidebar.component.ts +++ b/src/frontend/app/sidebar/sidebar.component.ts @@ -165,4 +165,8 @@ export class SidebarComponent implements OnInit, AfterViewInit { canIndex() { return this.authService.user.appPrivileges.map((item: any) => item.id).indexOf('indexation') > -1; } + + goTo() { + this.actionsService.setEvent({id: 'gotoDocument', documentIndex: 0}); + } } -- GitLab