From fbe922874a12fadf10734cb9fc1b0c127abcc527 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 1 Feb 2019 17:22:08 +0100
Subject: [PATCH] FEAT #9398 add selectedRes in body route

---
 .../list/list-administration.component.ts     | 293 ++++++++++--------
 .../list/filters/filters-tool.component.ts    |   4 +-
 2 files changed, 158 insertions(+), 139 deletions(-)

diff --git a/src/frontend/app/administration/list/list-administration.component.ts b/src/frontend/app/administration/list/list-administration.component.ts
index f355123e047..d7dae5fd9a4 100644
--- a/src/frontend/app/administration/list/list-administration.component.ts
+++ b/src/frontend/app/administration/list/list-administration.component.ts
@@ -3,222 +3,223 @@ import { HttpClient } from '@angular/common/http';
 import { LANG } from '../../translate.component';
 import { NotificationService } from '../../notification.service';
 import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
-import {MAT_DIALOG_DATA} from '@angular/material';
+import { MAT_DIALOG_DATA } from '@angular/material';
 
 declare function $j(selector: any): any;
 
 @Component({
-    templateUrl : "list-administration.component.html",
-    styleUrls   : ['list-administration.component.scss'],
-    providers   : [NotificationService],
+    templateUrl: "list-administration.component.html",
+    styleUrls: ['list-administration.component.scss'],
+    providers: [NotificationService],
 })
 export class ListAdministrationComponent implements OnInit {
 
-    lang            : any       = LANG;
-    loading         : boolean   = false;
-    loadingExport   : boolean   = false;
+    lang: any = LANG;
+    loading: boolean = false;
+    loadingExport: boolean = false;
 
-    delimiters          = [';', ',', 'TAB'];
-    exportModel : any   = {
-        delimiter   : ';',
-        data        : []
+    delimiters = [';', ',', 'TAB'];
+    exportModel: any = {
+        delimiter: ';',
+        data: [],
+        resources: []
     };
 
-    dataAvailable : any[] = [
+    dataAvailable: any[] = [
         {
-            value : 'res_id',
-            label : this.lang.resId,
-            isFunction : false
+            value: 'res_id',
+            label: this.lang.resId,
+            isFunction: false
         },
         {
-            value : 'type_label',
-            label : this.lang.doctype,
-            isFunction : false
+            value: 'type_label',
+            label: this.lang.doctype,
+            isFunction: false
         },
         {
-            value : 'doctypes_first_level_label',
-            label : this.lang.firstLevelDoctype,
-            isFunction : false
+            value: 'doctypes_first_level_label',
+            label: this.lang.firstLevelDoctype,
+            isFunction: false
         },
         {
-            value : 'doctypes_second_level_label',
-            label : this.lang.secondLevelDoctype,
-            isFunction : false
+            value: 'doctypes_second_level_label',
+            label: this.lang.secondLevelDoctype,
+            isFunction: false
         },
         {
-            value : 'format',
-            label : this.lang.format,
-            isFunction : false
+            value: 'format',
+            label: this.lang.format,
+            isFunction: false
         },
         {
-            value : 'doc_date',
-            label : this.lang.docDate,
-            isFunction : false
+            value: 'doc_date',
+            label: this.lang.docDate,
+            isFunction: false
         },
         {
-            value : 'reference_number',
-            label : this.lang.reference,
-            isFunction : false
+            value: 'reference_number',
+            label: this.lang.reference,
+            isFunction: false
         },
         {
-            value : 'departure_date',
-            label : this.lang.departureDate,
-            isFunction : false
+            value: 'departure_date',
+            label: this.lang.departureDate,
+            isFunction: false
         },
         {
-            value : 'department_number_id',
-            label : this.lang.department,
-            isFunction : false
+            value: 'department_number_id',
+            label: this.lang.department,
+            isFunction: false
         },
         {
-            value : 'barcode',
-            label : this.lang.barcode,
-            isFunction : false
+            value: 'barcode',
+            label: this.lang.barcode,
+            isFunction: false
         },
         {
-            value : 'fold_status',
-            label : this.lang.folderStatus,
-            isFunction : false
+            value: 'fold_status',
+            label: this.lang.folderStatus,
+            isFunction: false
         },
         {
-            value : 'folder_name',
-            label : this.lang.folderName,
-            isFunction : false
+            value: 'folder_name',
+            label: this.lang.folderName,
+            isFunction: false
         },
         {
-            value : 'confidentiality',
-            label : this.lang.confidentiality,
-            isFunction : false
+            value: 'confidentiality',
+            label: this.lang.confidentiality,
+            isFunction: false
         },
         {
-            value : 'nature_id',
-            label : this.lang.nature,
-            isFunction : false
+            value: 'nature_id',
+            label: this.lang.nature,
+            isFunction: false
         },
         {
-            value : 'alt_identifier',
-            label : this.lang.chronoNumber,
-            isFunction : false
+            value: 'alt_identifier',
+            label: this.lang.chronoNumber,
+            isFunction: false
         },
         {
-            value : 'admission_date',
-            label : this.lang.admissionDate,
-            isFunction : false
+            value: 'admission_date',
+            label: this.lang.admissionDate,
+            isFunction: false
         },
         {
-            value : 'process_limit_date',
-            label : this.lang.processLimitDate,
-            isFunction : false
+            value: 'process_limit_date',
+            label: this.lang.processLimitDate,
+            isFunction: false
         },
         {
-            value : 'recommendation_limit_date',
-            label : this.lang.recommendationLimitDate,
-            isFunction : false
+            value: 'recommendation_limit_date',
+            label: this.lang.recommendationLimitDate,
+            isFunction: false
         },
         {
-            value : 'closing_date',
-            label : this.lang.closingDate,
-            isFunction : false
+            value: 'closing_date',
+            label: this.lang.closingDate,
+            isFunction: false
         },
         {
-            value : 'sve_start_date',
-            label : this.lang.sveStartDate,
-            isFunction : false
+            value: 'sve_start_date',
+            label: this.lang.sveStartDate,
+            isFunction: false
         },
         {
-            value : 'subject',
-            label : this.lang.subject,
-            isFunction : false
+            value: 'subject',
+            label: this.lang.subject,
+            isFunction: false
         },
         {
-            value : 'case_label',
-            label : this.lang.caseLabel,
-            isFunction : false
+            value: 'case_label',
+            label: this.lang.caseLabel,
+            isFunction: false
         },
         {
-            value : 'getStatus',
-            label : this.lang.status,
-            isFunction : true
+            value: 'getStatus',
+            label: this.lang.status,
+            isFunction: true
         },
         {
-            value : 'getPriority',
-            label : this.lang.priority,
-            isFunction : true
+            value: 'getPriority',
+            label: this.lang.priority,
+            isFunction: true
         },
         {
-            value : 'getCopies',
-            label : this.lang.copyUsersEntities,
-            isFunction : true
+            value: 'getCopies',
+            label: this.lang.copyUsersEntities,
+            isFunction: true
         },
         {
-            value : 'getDetailLink',
-            label : this.lang.detailLink,
-            isFunction : true
+            value: 'getDetailLink',
+            label: this.lang.detailLink,
+            isFunction: true
         },
         {
-            value : 'getParentFolder',
-            label : this.lang.parentFolder,
-            isFunction : true
+            value: 'getParentFolder',
+            label: this.lang.parentFolder,
+            isFunction: true
         },
         {
-            value : 'getCategory',
-            label : this.lang.category_id,
-            isFunction : true
+            value: 'getCategory',
+            label: this.lang.category_id,
+            isFunction: true
         },
         {
-            value : 'getInitiatorEntity',
-            label : this.lang.initiatorEntity,
-            isFunction : true
+            value: 'getInitiatorEntity',
+            label: this.lang.initiatorEntity,
+            isFunction: true
         },
         {
-            value : 'getDestinationEntity',
-            label : this.lang.destinationEntity,
-            isFunction : true
+            value: 'getDestinationEntity',
+            label: this.lang.destinationEntity,
+            isFunction: true
         },
         {
-            value : 'getDestinationEntityType',
-            label : this.lang.destinationEntityType,
-            isFunction : true
+            value: 'getDestinationEntityType',
+            label: this.lang.destinationEntityType,
+            isFunction: true
         },
         {
-            value : 'getSender',
-            label : this.lang.sender,
-            isFunction : true
+            value: 'getSender',
+            label: this.lang.sender,
+            isFunction: true
         },
         {
-            value : 'getRecipient',
-            label : this.lang.recipient,
-            isFunction : true
+            value: 'getRecipient',
+            label: this.lang.recipient,
+            isFunction: true
         },
         {
-            value : 'getTypist',
-            label : this.lang.typist,
-            isFunction : true
+            value: 'getTypist',
+            label: this.lang.typist,
+            isFunction: true
         },
         {
-            value : 'getAssignee',
-            label : this.lang.dest_user,
-            isFunction : true
+            value: 'getAssignee',
+            label: this.lang.dest_user,
+            isFunction: true
         },
         {
-            value : 'getTags',
-            label : this.lang.tags,
-            isFunction : true
+            value: 'getTags',
+            label: this.lang.tags,
+            isFunction: true
         },
         {
-            value : 'getSignatories',
-            label : this.lang.signUser,
-            isFunction : true
+            value: 'getSignatories',
+            label: this.lang.signUser,
+            isFunction: true
         },
         {
-            value : 'getSignatureDates',
-            label : this.lang.signatureDate,
-            isFunction : true
+            value: 'getSignatureDates',
+            label: this.lang.signatureDate,
+            isFunction: true
         },
         {
-            value : '',
-            label : this.lang.comment,
-            isFunction : true
+            value: '',
+            label: this.lang.comment,
+            isFunction: true
         }
     ];
 
@@ -231,10 +232,11 @@ export class ListAdministrationComponent implements OnInit {
         this.http.get('../../rest/resourcesList/exportTemplate')
             .subscribe((data: any) => {
                 if (data["delimiter"] != '') {
+                    this.exportModel.resources = this.data.selectedRes;
                     this.exportModel.data = data["template"];
                     this.exportModel.delimiter = data["delimiter"];
-                    this.exportModel.data.forEach((value : any) => {
-                        this.dataAvailable.forEach((availableValue : any, index : number) => {
+                    this.exportModel.data.forEach((value: any) => {
+                        this.dataAvailable.forEach((availableValue: any, index: number) => {
                             if (value.value == availableValue.value) {
                                 this.dataAvailable.splice(index, 1);
                             }
@@ -260,8 +262,8 @@ export class ListAdministrationComponent implements OnInit {
                     realIndex = this.dataAvailable.map((dataAv: any) => (dataAv.value)).indexOf(fakeIndex);
                 }
             }
-            
-            
+
+
             transferArrayItem(event.previousContainer.data,
                 event.container.data,
                 realIndex,
@@ -271,17 +273,34 @@ export class ListAdministrationComponent implements OnInit {
             setTimeout(() => {
                 this.listFilter.nativeElement.value = curFilter;
             }, 10);
-            
+
         }
     }
 
     exportData() {
         this.loadingExport = true;
-        this.http.put('../../rest/resourcesList/users/' + this.data.ownerId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/exports?init' + this.data.filters, this.exportModel, {responseType: "blob"})
+        this.http.put('../../rest/resourcesList/users/' + this.data.ownerId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/exports', this.exportModel, { responseType: "blob" })
             .subscribe((data) => {
                 let downloadLink = document.createElement('a');
                 downloadLink.href = window.URL.createObjectURL(data);
-                downloadLink.setAttribute('download', "export_maarch.csv");
+                let today: any;
+                let dd: any;
+                let mm: any;
+                let yyyy: any;
+
+                today = new Date();
+                dd = today.getDate();
+                mm = today.getMonth() + 1;
+                yyyy = today.getFullYear();
+
+                if (dd < 10) {
+                    dd = '0' + dd;
+                }
+                if (mm < 10) {
+                    mm = '0' + mm;
+                }
+                today = dd + '_' + mm + '_' + yyyy;
+                downloadLink.setAttribute('download', "export_maarch_" + today + ".csv");
                 document.body.appendChild(downloadLink);
                 downloadLink.click();
 
@@ -294,7 +313,7 @@ export class ListAdministrationComponent implements OnInit {
     addData(item: any) {
         var realIndex = 0;
 
-        this.dataAvailable.forEach((value : any, index : number) => {
+        this.dataAvailable.forEach((value: any, index: number) => {
             if (value.value == item.value) {
                 realIndex = index;
             }
diff --git a/src/frontend/app/list/filters/filters-tool.component.ts b/src/frontend/app/list/filters/filters-tool.component.ts
index ae80ad6f563..b6369f09a07 100644
--- a/src/frontend/app/list/filters/filters-tool.component.ts
+++ b/src/frontend/app/list/filters/filters-tool.component.ts
@@ -281,7 +281,7 @@ export class FiltersToolComponent implements OnInit {
                 ownerId: this.currentBasketInfo.ownerId,
                 groupId: this.currentBasketInfo.groupId,
                 basketId: this.currentBasketInfo.basketId,
-                filters: this.filtersListService.getUrlFilters()
+                selectedRes: this.selectedRes
             }
         });
     }
@@ -294,7 +294,7 @@ export class FiltersToolComponent implements OnInit {
                 ownerId: this.currentBasketInfo.ownerId,
                 groupId: this.currentBasketInfo.groupId,
                 basketId: this.currentBasketInfo.basketId,
-                selectedRes: this.selectedRes,
+                selectedRes: this.selectedRes
             }
         });
     }
-- 
GitLab