From 948a9125a5140d7e3cb0b17d7c6db2d8635c4b51 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 19 Jan 2021 15:24:46 +0100
Subject: [PATCH] FEAT #10240 TIME 3:30 add mass actions

---
 .../app/document/document.component.ts        | 47 ++++----------
 .../main-document-detail.component.html       |  2 +-
 .../app/modal/reject-info.component.ts        | 24 ++++---
 .../app/modal/success-info-valid.component.ts | 24 ++++---
 src/frontend/app/service/actions.service.ts   | 65 ++++++++++++-------
 src/frontend/app/service/filters.service.ts   | 27 ++++++--
 .../signature-method-modal.component.ts       | 23 ++++---
 .../signature-method.service.ts               | 29 ++++++---
 .../app/sidebar/sidebar.component.html        |  4 +-
 src/frontend/app/sidebar/sidebar.component.ts | 16 ++---
 10 files changed, 142 insertions(+), 119 deletions(-)

diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts
index b588ea41c8..13a88578f9 100755
--- a/src/frontend/app/document/document.component.ts
+++ b/src/frontend/app/document/document.component.ts
@@ -244,7 +244,7 @@ export class DocumentComponent implements OnInit {
         });
         await actionSheet.present();
     }
-    
+
     async openSignatures() {
         const modal = await this.modalController.create({
             component: SignaturesComponent,
@@ -331,10 +331,6 @@ export class DocumentComponent implements OnInit {
                     this.http.get('../rest/documents/' + params['id']).pipe(
                         tap((data: any) => {
                             this.mainDocument = data.document;
-
-                            // FOR TEST
-                            this.mainDocument.groupMailId = 14;
-
                             this.mainDocument.workflow = this.mainDocument.workflow.map((item: any) => {
                                 if (item.note) {
                                     this.hasWorkflowNotes = true;
@@ -574,7 +570,7 @@ export class DocumentComponent implements OnInit {
             this.signaturesService.currentPage = this.pageNum;
         }
         // this.exportAsImage();
-        this.renderImage();        
+        this.renderImage();
     }
 
     goTo(page: number) {
@@ -593,7 +589,7 @@ export class DocumentComponent implements OnInit {
             this.signaturesService.currentPage = this.pageNum;
         }
         // this.exportAsImage();
-        this.renderImage();        
+        this.renderImage();
     }
 
     pagesArray(n: number): number[] {
@@ -632,14 +628,11 @@ export class DocumentComponent implements OnInit {
                 {
                     text: this.translate.instant('lang.reject'),
                     handler: async (data: any) => {
-                        const res = await this.actionsService.sendDocument(data.paragraph);
+                        const idsToProcess = await this.actionsService.checkGroupMail(this.mainDocument);
+
+                        const res = await this.signatureMethodService.launchDefaultMode(data.paragraph, idsToProcess);
+
                         if (!this.functionsService.empty(res)) {
-                            if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList] !== undefined) {
-                                this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1);
-                                if (this.signaturesService.documentsListCount.current > 0) {
-                                    this.signaturesService.documentsListCount.current--;
-                                }
-                            }
                             const config: MatBottomSheetConfig = {
                                 disableClose: true,
                                 direction: 'ltr'
@@ -680,27 +673,11 @@ export class DocumentComponent implements OnInit {
                     text: this.translate.instant('lang.validate'),
                     handler: async (data: any) => {
                         const currentUserWorkflow = this.mainDocument.workflow.filter((line: { current: boolean; }) => line.current === true)[0];
-                        
-                        const massAction = await this.actionsService.checkGroupMail(this.mainDocument);
-                        console.log('massAction', massAction);
-                        this.loadingController.create({
-                            message: this.translate.instant('lang.loadingValidation'),
-                            spinner: 'dots',
-                        }).then((load: HTMLIonLoadingElement) => {
-                            this.load = load;
-                            this.load.present();
-                            if ((currentUserWorkflow.signatureMode === 'rgs_2stars') || (currentUserWorkflow.signatureMode === 'inca_card') || (currentUserWorkflow.signatureMode === 'rgs_2stars_timestamped') || (currentUserWorkflow.signatureMode === 'inca_card_eidas')) {
-                                this.load.dismiss();
-                            }
-                        });
-                        const res = await this.signatureMethodService.checkAuthenticationAndLaunchAction(currentUserWorkflow, data.paragraph);
+                        const idsToProcess = await this.actionsService.checkGroupMail(this.mainDocument);
+
+                        const res = await this.signatureMethodService.checkAuthenticationAndLaunchAction(currentUserWorkflow, data.paragraph, idsToProcess);
+
                         if (!this.functionsService.empty(res)) {
-                            if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList] !== undefined) {
-                                this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1);
-                                if (this.signaturesService.documentsListCount.current > 0) {
-                                    this.signaturesService.documentsListCount.current--;
-                                }
-                            }
                             const config: MatBottomSheetConfig = {
                                 disableClose: true,
                                 direction: 'ltr'
@@ -708,7 +685,6 @@ export class DocumentComponent implements OnInit {
                             this.bottomSheet.open(SuccessInfoValidBottomSheetComponent, config);
                             this.localStorage.remove(this.mainDocument.id.toString());
                         }
-                        this.load.dismiss();
                     }
                 }
             ]
@@ -716,6 +692,7 @@ export class DocumentComponent implements OnInit {
 
         await alert.present();
     }
+
     async removeTags() {
         this.signaturesService.currentAction = 0;
 
diff --git a/src/frontend/app/document/main-document-detail/main-document-detail.component.html b/src/frontend/app/document/main-document-detail/main-document-detail.component.html
index fb9b7e2327..bb24cec591 100644
--- a/src/frontend/app/document/main-document-detail/main-document-detail.component.html
+++ b/src/frontend/app/document/main-document-detail/main-document-detail.component.html
@@ -9,7 +9,7 @@
     </ion-toolbar>
 </ion-header>
 <ion-content>
-    <ion-card *ngIf="!functionsService.empty(mainDocument.groupMailId)">
+    <ion-card *ngIf="!functionsService.empty(mainDocument.mailingId)">
         <ion-item color="danger">
             <ion-icon name="alert-circle" slot="start"></ion-icon>
             <ion-label>{{'lang.docIsInMailGroup' | translate}}</ion-label>
diff --git a/src/frontend/app/modal/reject-info.component.ts b/src/frontend/app/modal/reject-info.component.ts
index 8a87da2d97..acee60c2ca 100644
--- a/src/frontend/app/modal/reject-info.component.ts
+++ b/src/frontend/app/modal/reject-info.component.ts
@@ -1,10 +1,8 @@
 import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router';
 import { SignaturesContentService } from '../service/signatures.service';
 import { MatBottomSheetRef } from '@angular/material/bottom-sheet';
-import { TranslateService } from '@ngx-translate/core';
-import { AuthService } from '../service/auth.service';
 import { FiltersService } from '../service/filters.service';
+import { AuthService } from '../service/auth.service';
 
 @Component({
     templateUrl: '../modal/reject-info.html',
@@ -12,18 +10,18 @@ import { FiltersService } from '../service/filters.service';
 })
 export class RejectInfoBottomSheetComponent implements OnInit {
     date: Date = new Date();
-    constructor(private translate: TranslateService, private router: Router, public signaturesService: SignaturesContentService, public authService: AuthService, public filtersService: FiltersService, private bottomSheetRef: MatBottomSheetRef<RejectInfoBottomSheetComponent>) { }
+    constructor(
+        public signaturesService: SignaturesContentService,
+        public filtersService: FiltersService,
+        public authService: AuthService,
+        private bottomSheetRef: MatBottomSheetRef<RejectInfoBottomSheetComponent>
+    ) { }
+
     ngOnInit(): void {
         setTimeout(() => {
-            if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList]) {
-                this.signaturesService.currentToobal = 'mainDocumentDetail';
-                this.filtersService.resfreshDocuments();
-                this.router.navigate(['/documents/' + this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].id]);
-            } else {
-                this.signaturesService.currentToobal = 'mainDocumentDetail';
-                this.router.navigate(['/documents']);
-            }
+            this.signaturesService.currentToobal = 'mainDocumentDetail';
+            this.filtersService.resfreshDocuments(true);
             this.bottomSheetRef.dismiss();
         }, 2000);
-     }
+    }
 }
diff --git a/src/frontend/app/modal/success-info-valid.component.ts b/src/frontend/app/modal/success-info-valid.component.ts
index 42bac99930..3f97a4eb14 100644
--- a/src/frontend/app/modal/success-info-valid.component.ts
+++ b/src/frontend/app/modal/success-info-valid.component.ts
@@ -1,8 +1,6 @@
 import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router';
 import { SignaturesContentService } from '../service/signatures.service';
 import { MatBottomSheetRef } from '@angular/material/bottom-sheet';
-import { TranslateService } from '@ngx-translate/core';
 import { AuthService } from '../service/auth.service';
 import { FiltersService } from '../service/filters.service';
 
@@ -12,18 +10,18 @@ import { FiltersService } from '../service/filters.service';
 })
 export class SuccessInfoValidBottomSheetComponent implements OnInit {
     date: Date = new Date();
-    constructor(private translate: TranslateService, private router: Router, public signaturesService: SignaturesContentService, public filtersService: FiltersService, public authService: AuthService, private bottomSheetRef: MatBottomSheetRef<SuccessInfoValidBottomSheetComponent>) { }
-     ngOnInit(): void {
+    constructor(
+        public signaturesService: SignaturesContentService,
+        public filtersService: FiltersService,
+        public authService: AuthService,
+        private bottomSheetRef: MatBottomSheetRef<SuccessInfoValidBottomSheetComponent>
+    ) { }
+
+    ngOnInit(): void {
         setTimeout(() => {
-            if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList]) {
-                this.signaturesService.currentToobal = 'mainDocumentDetail';
-                this.filtersService.resfreshDocuments();
-                this.router.navigate(['/documents/' + this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].id]);
-            } else {
-                this.signaturesService.currentToobal = 'mainDocumentDetail';
-                this.router.navigate(['/documents']);
-            }
+            this.signaturesService.currentToobal = 'mainDocumentDetail';
+            this.filtersService.resfreshDocuments(true);
             this.bottomSheetRef.dismiss();
         }, 2000);
-     }
+    }
 }
diff --git a/src/frontend/app/service/actions.service.ts b/src/frontend/app/service/actions.service.ts
index f9820d2af1..22701d3ac5 100644
--- a/src/frontend/app/service/actions.service.ts
+++ b/src/frontend/app/service/actions.service.ts
@@ -23,7 +23,7 @@ export class ActionsService {
         public alertController: AlertController,
     ) { }
 
-    sendDocument(note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgDocElements: any[] = null) {
+    sendDocument(documentId: number, note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgDocElements: any[] = null) {
         return new Promise(async (resolve) => {
             let data: any = {};
 
@@ -51,7 +51,7 @@ export class ActionsService {
                     data.tmpUniqueId = tmpUniqueId;
                 }
 
-                this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, data)
+                this.http.put('../rest/documents/' + documentId + '/actions/' + this.signaturesService.currentAction, data)
                     .pipe(
                         tap((res: any) => {
                             if (eSignature !== null) {
@@ -150,32 +150,47 @@ export class ActionsService {
         });
     }
 
-    checkGroupMail(mainDocument: any) {
+    checkGroupMail(mainDocument: any): Promise<any[]> {
         return new Promise(async (resolve) => {
-            if (this.functionsService.empty(mainDocument.groupMailId)) {
-                resolve(false);
+            if (this.functionsService.empty(mainDocument.mailingId)) {
+                resolve([this.signaturesService.mainDocumentId]);
             } else {
-                const alert = await this.alertController.create({
-                    header: this.translate.instant('lang.mailing'),
-                    message: this.translate.instant('lang.makeActionOnDocInMailGroup'),
-                    buttons: [
-                        {
-                            text: this.translate.instant('lang.yes'),
-                            handler: () => {
-                                resolve(true);
-                            }
-                        },
-                        {
-                            role: 'cancel',
-                            text: this.translate.instant('lang.no'),
-                            cssClass: 'secondary',
-                            handler: () => {
-                                resolve(false);
+                this.http.get(`../rest/documents/${this.signaturesService.mainDocumentId}/linkedMailing`)
+                    .pipe(
+                        tap(async (res: any) => {
+                            if (res.documents.length > 1) {
+                                const alert = await this.alertController.create({
+                                    header: this.translate.instant('lang.mailing'),
+                                    message: this.translate.instant('lang.makeActionOnDocInMailGroup'),
+                                    backdropDismiss: false,
+                                    buttons: [
+                                        {
+                                            text: this.translate.instant('lang.yes'),
+                                            handler: () => {
+                                                resolve(res.documents);
+                                            }
+                                        },
+                                        {
+                                            role: 'cancel',
+                                            text: this.translate.instant('lang.no'),
+                                            cssClass: 'secondary',
+                                            handler: () => {
+                                                resolve([this.signaturesService.mainDocumentId]);
+                                            }
+                                        }
+                                    ]
+                                });
+                                await alert.present();
+                            } else {
+                                resolve([this.signaturesService.mainDocumentId]);
                             }
-                        }
-                    ]
-                });
-                await alert.present();
+                        }),
+                        catchError((err: any) => {
+                            this.notificationService.handleErrors(err);
+                            resolve([]);
+                            return of(false);
+                        })
+                    ).subscribe();
             }
         });
     }
diff --git a/src/frontend/app/service/filters.service.ts b/src/frontend/app/service/filters.service.ts
index 1016b8ff01..ca946df0d8 100644
--- a/src/frontend/app/service/filters.service.ts
+++ b/src/frontend/app/service/filters.service.ts
@@ -2,18 +2,37 @@ import { Injectable } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 
 import { SignaturesContentService } from '../service/signatures.service';
+import { Router } from '@angular/router';
 
 @Injectable()
 export class FiltersService {
 
-    constructor(public http: HttpClient, public signaturesService: SignaturesContentService) { }
+    currentIndex: number = 0;
+    offset: number = 0;
+    limit: number = 10;
 
-    resfreshDocuments() {
-        this.http.get('../rest/documents?limit=10&offset=0&mode=')
+    constructor(
+        public http: HttpClient,
+        public signaturesService: SignaturesContentService,
+        private router: Router
+    ) { }
+
+    resfreshDocuments(redirect: boolean = false) {
+        const limit = this.limit + this.offset;
+
+        this.http.get('../rest/documents?limit=' + limit + '&offset=0' + '&mode=' + this.signaturesService.mode)
             .subscribe((data: any) => {
-                this.signaturesService.mode = '';
                 this.signaturesService.documentsList = data.documents;
                 this.signaturesService.documentsListCount = data.count;
+                if (redirect) {
+                    if (this.signaturesService.documentsList[this.currentIndex] !== undefined) {
+                        this.router.navigate(['/documents/' + this.signaturesService.documentsList[this.currentIndex].id]);
+                    } else if (this.signaturesService.documentsList.length > 0) {
+                        this.router.navigate(['/documents/' + this.signaturesService.documentsList[0].id]);
+                    } else {
+                        this.router.navigate(['/home']);
+                    }
+                }
             });
     }
 }
diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.ts b/src/frontend/app/service/signature-method/signature-method-modal.component.ts
index 613c0ead26..4836f47325 100644
--- a/src/frontend/app/service/signature-method/signature-method-modal.component.ts
+++ b/src/frontend/app/service/signature-method/signature-method-modal.component.ts
@@ -36,6 +36,7 @@ export class SignatureMethodModalComponent implements OnInit {
 
     @Input() note: string;
     @Input() signatureMode: string;
+    @Input() idsToProcess: any[];
 
     constructor(
         public modalController: ModalController,
@@ -50,8 +51,6 @@ export class SignatureMethodModalComponent implements OnInit {
     ) { }
 
     async ngOnInit(): Promise<void> {
-        this.signatures = await this.actionsService.getElementsFromDoc();
-
         const signatureModeData = this.authService.signatureRoles.filter((mode: any) => mode.id === this.signatureMode)[0];
         if (!this.functionsService.empty(signatureModeData.issuer)) {
             this.filters.issuerDNMatch = new RegExp(signatureModeData.issuer, 'i');
@@ -87,24 +86,28 @@ export class SignatureMethodModalComponent implements OnInit {
                 certificate: this.certPem
             };
 
-            const result = await this.sendAndSign();
+            let result: any = false;
 
+            for (let index = 0; index < this.idsToProcess.length; index++) {
+                this.signatures = await this.actionsService.getElementsFromDoc();
+                result = await this.sendAndSign(this.idsToProcess[index]);
+            }
             load.dismiss();
             this.modalController.dismiss(result);
         });
     }
 
-    async sendAndSign() {
+    async sendAndSign(idToProcess: number) {
         let allSignaturesComplete: boolean = false;
         let res: any = {};
         while (!allSignaturesComplete) {
             let signDocComplete: any = false;
             while (signDocComplete === false) {
-                res = await this.fusionStampAndGenerateSignature(res.tmpUniqueId);
+                res = await this.fusionStampAndGenerateSignature(idToProcess, res.tmpUniqueId);
                 if (res === null) {
                     return false;
                 } else if (res !== false) {
-                    signDocComplete = await this.signDocument(res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId);
+                    signDocComplete = await this.signDocument(idToProcess, res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId);
                     console.log('signDocComplete', signDocComplete);
                     if (signDocComplete === true) {
                         this.signatures.shift();
@@ -120,13 +123,13 @@ export class SignatureMethodModalComponent implements OnInit {
         return allSignaturesComplete;
     }
 
-    async fusionStampAndGenerateSignature(tmpUniqueId: string = null) {
+    async fusionStampAndGenerateSignature(idToProcess: number, tmpUniqueId: string = null) {
         let res: any = {};
-        res = await this.actionsService.sendDocument(null, this.certificate, this.signatureLength, tmpUniqueId, this.signatures);
+        res = await this.actionsService.sendDocument(idToProcess, null, this.certificate, this.signatureLength, tmpUniqueId, this.signatures);
         return res;
     }
 
-    signDocument(hashDocument: any, eSignatureLength: any, signatureFieldName: any, tmpUniqueId: string) {
+    signDocument(idToProcess: number, hashDocument: any, eSignatureLength: any, signatureFieldName: any, tmpUniqueId: string) {
         return new Promise(async (resolve) => {
             const alg = {
                 name: this.privateKey.algorithm.name,
@@ -159,7 +162,7 @@ export class SignatureMethodModalComponent implements OnInit {
 
             const objToSend = {...note, ...objEsign };
 
-            this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, objToSend)
+            this.http.put('../rest/documents/' + idToProcess + '/actions/' + this.signaturesService.currentAction, objToSend)
                 .pipe(
                     tap(() => {
                         resolve(true);
diff --git a/src/frontend/app/service/signature-method/signature-method.service.ts b/src/frontend/app/service/signature-method/signature-method.service.ts
index 4aa0543b0c..0fd5094a55 100644
--- a/src/frontend/app/service/signature-method/signature-method.service.ts
+++ b/src/frontend/app/service/signature-method/signature-method.service.ts
@@ -1,8 +1,9 @@
 import { Injectable } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
-import { ModalController } from '@ionic/angular';
+import { LoadingController, ModalController } from '@ionic/angular';
 import { SignatureMethodModalComponent } from './signature-method-modal.component';
 import { ActionsService } from '../actions.service';
+import { TranslateService } from '@ngx-translate/core';
 
 @Injectable({
     providedIn: 'root'
@@ -13,32 +14,44 @@ export class SignatureMethodService {
         public http: HttpClient,
         public modalController: ModalController,
         public actionsService: ActionsService,
+        public loadingController: LoadingController,
+        private translate: TranslateService,
     ) { }
 
-    async checkAuthenticationAndLaunchAction(userWorkflow: any, note: any = null) {
+    async checkAuthenticationAndLaunchAction(userWorkflow: any, note: any = null, idsToProcess: any[]) {
         if (['rgs_2stars', 'rgs_2stars_timestamped', 'inca_card', 'inca_card_eidas'].indexOf(userWorkflow.signatureMode) > -1) {
-            const res = await this.openRgsAuth(note, userWorkflow.signatureMode);
+            const res = await this.openRgsAuth(note, userWorkflow.signatureMode, idsToProcess);
             return res;
         } else {
-            const res = await this.launchDefaultMode(note);
+            const res = await this.launchDefaultMode(note, idsToProcess);
             return res;
         }
     }
 
-    async launchDefaultMode(note: string) {
+    async launchDefaultMode(note: string, idsToProcess: any[]) {
         return new Promise(async (resolve) => {
-            const res = await this.actionsService.sendDocument(note);
+            const loading = await this.loadingController.create({
+                message: this.translate.instant('lang.loadingValidation'),
+                spinner: 'dots',
+            });
+            loading.present();
+            let res: any = true;
+            for (let index = 0; index < idsToProcess.length; index++) {
+                res = await this.actionsService.sendDocument(idsToProcess[index], note);
+            }
+            loading.dismiss();
             resolve(res);
         });
     }
 
-    async openRgsAuth(note: string, signatureMode: string) {
+    async openRgsAuth(note: string, signatureMode: string, idsToProcess: any[]) {
         return new Promise(async (resolve) => {
             const modal = await this.modalController.create({
                 component: SignatureMethodModalComponent,
                 componentProps: {
                     note: note,
-                    signatureMode: signatureMode
+                    signatureMode: signatureMode,
+                    idsToProcess: idsToProcess
                 }
             });
             await modal.present();
diff --git a/src/frontend/app/sidebar/sidebar.component.html b/src/frontend/app/sidebar/sidebar.component.html
index e14d8b332e..75323d8d86 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)="selectedIndex = i" routerDirection="root"
+            <ion-item class="doc-item" (click)="filterService.currentIndex = i" 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>
@@ -86,7 +86,7 @@
                 <ion-icon *ngIf="document.mode == 'note'" color="primary" slot="start"
                     name="chatbubble-ellipses-outline">
                 </ion-icon>
-                <ion-icon *ngIf="!functionsService.empty(document.groupMailId)" slot="start" color="danger" name="layers" class="groupMailIcon"></ion-icon>
+                <ion-icon *ngIf="!functionsService.empty(document.mailingId)" slot="start" color="danger" name="layers" class="groupMailIcon"></ion-icon>
                 <div>
                     <ion-label class="sub-label">{{document.reference}}</ion-label>
                     <ion-label class="ion-text-wrap" color="primary">{{document.title | shorten: 50: '...'}}</ion-label>
diff --git a/src/frontend/app/sidebar/sidebar.component.ts b/src/frontend/app/sidebar/sidebar.component.ts
index eb9fdb2d55..58a1542714 100755
--- a/src/frontend/app/sidebar/sidebar.component.ts
+++ b/src/frontend/app/sidebar/sidebar.component.ts
@@ -9,6 +9,7 @@ import { AuthService } from '../service/auth.service';
 import { MenuController, ModalController } from '@ionic/angular';
 import { ProfileComponent } from '../profile/profile.component';
 import { FunctionsService } from '../service/functions.service';
+import { FiltersService } from '../service/filters.service';
 
 
 @Component({
@@ -19,8 +20,6 @@ import { FunctionsService } from '../service/functions.service';
 export class SidebarComponent implements OnInit {
 
     loadingList: boolean = false;
-    offset: number = 0;
-    limit: number = 10;
     searchMode: boolean = false;
 
     @ViewChild('listContent') listContent: ElementRef;
@@ -38,12 +37,13 @@ export class SidebarComponent implements OnInit {
         public authService: AuthService,
         public modalController: ModalController,
         public functionsService: FunctionsService,
+        public filterService: FiltersService
     ) {
         this.searchTerm.valueChanges.pipe(
             debounceTime(500),
             distinctUntilChanged(),
             tap((value) => this.loadingList = true),
-            switchMap(data => this.http.get('../rest/documents?limit=' + this.limit + '&search=' + data))
+            switchMap(data => this.http.get('../rest/documents?limit=' + this.filterService.limit + '&search=' + data))
         ).subscribe((response: any) => {
             this.signaturesService.documentsList = response.documents;
             this.signaturesService.documentsListCount = response.count;
@@ -53,7 +53,7 @@ export class SidebarComponent implements OnInit {
 
     ngOnInit() {
         $('.avatar').css({ 'background': 'url(data:image/png;base64,' + this.authService.user.picture + ') no-repeat #135F7F' }).css({ 'background-size': 'cover' }).css({ 'background-position': 'center' });
-        this.http.get('../rest/documents?limit=' + this.limit + '&offset=' + this.offset + '&mode=' + this.signaturesService.mode)
+        this.http.get('../rest/documents?limit=' + this.filterService.limit + '&offset=' + this.filterService.offset + '&mode=' + this.signaturesService.mode)
             .subscribe((data: any) => {
                 this.signaturesService.documentsList = data.documents;
                 this.signaturesService.documentsListCount = data.count;
@@ -110,8 +110,8 @@ export class SidebarComponent implements OnInit {
 
         this.loadingList = true;
         this.signaturesService.mode === mode ? this.signaturesService.mode = '' : this.signaturesService.mode = mode;
-        this.offset = 0;
-        this.http.get('../rest/documents?limit=' + this.limit + '&offset=' + this.offset + '&mode=' + this.signaturesService.mode)
+        this.filterService.offset = 0;
+        this.http.get('../rest/documents?limit=' + this.filterService.limit + '&offset=' + this.filterService.offset + '&mode=' + this.signaturesService.mode)
             .pipe(
                 finalize(() => {
                     this.loadingList = false;
@@ -133,9 +133,9 @@ export class SidebarComponent implements OnInit {
     }
 
     loadData(event: any) {
-        this.offset = this.offset + this.limit;
+        this.filterService.offset = this.filterService.offset + this.filterService.limit;
 
-        this.http.get('../rest/documents?limit=' + this.limit + '&offset=' + this.offset + '&mode=' + this.signaturesService.mode).pipe(
+        this.http.get('../rest/documents?limit=' + this.filterService.limit + '&offset=' + this.filterService.offset + '&mode=' + this.signaturesService.mode).pipe(
             tap((data: any) => {
                 this.signaturesService.documentsList = this.signaturesService.documentsList.concat(data.documents);
                 event.target.complete();
-- 
GitLab