diff --git a/src/app/core/services/crud/filter.service.ts b/src/app/core/services/crud/filter.service.ts index ab25b0ad..11de48aa 100644 --- a/src/app/core/services/crud/filter.service.ts +++ b/src/app/core/services/crud/filter.service.ts @@ -1,19 +1,21 @@ import { Injectable } from '@angular/core'; import { Column } from 'src/app/shared/model/column.model'; +import { InvariantsService } from './invariants.service'; @Injectable({ providedIn: 'root' }) export class FilterService { - constructor() { } + constructor(private invariantService: InvariantsService) { } generateQueryStringParameters(columnList: Array, pageInformation: { size: number, sort: any, number: number, totalCount: number }, globalSearch: string): string { let queryParameter = ""; let formData = {} - let columnListWithActiveFilter = columnList.filter(e => e.sSearch).filter(e => e.sSearch.length != 0 || e.contentName == pageInformation.sort[0].prop); + let columnListWithActiveFilter = columnList.filter(e => e.sSearch).filter(e => e.sSearch.length != 0 || e.contentName == pageInformation.sort[0].prop || e.contentName == 'system'); // contaign all columns to filter&sort - + console.log(this.invariantService.systemsSelected); + //generate request header // ? "sEcho" @@ -32,8 +34,12 @@ export class FilterService { formData["sColumns"] = columnListWithActiveFilter.map(column => column.databaseName).join(','); // list of columns to filter&sort // ? "iColumns" for (let column in columnListWithActiveFilter) { - if (columnList[column].type === 'label') { + if (columnListWithActiveFilter[column].type === 'label') { formData["sSearch_" + column] = (columnListWithActiveFilter[column].sSearch) ? columnListWithActiveFilter[column].sSearch.map(a => a.label).join(',') : ''; // value(s) to filter (only label) + } else if(columnListWithActiveFilter[column].contentName === 'system'){ + let systemByFilter = ((columnListWithActiveFilter[column].sSearch.length!=0) ? columnListWithActiveFilter[column].sSearch.join(',') : ''); + let systemByService = (this.invariantService.systemsSelected.length!=0)? ',' + this.invariantService.systemsSelected.join(','): '' + formData["sSearch_" + column] = systemByFilter + ((systemByFilter!='' && systemByService!='')? ',' : '') + systemByService; // value(s) to filter } else { formData["sSearch_" + column] = (columnListWithActiveFilter[column].sSearch) ? columnListWithActiveFilter[column].sSearch.join(',') : ''; // value(s) to filter } diff --git a/src/app/core/services/crud/invariants.service.ts b/src/app/core/services/crud/invariants.service.ts index 26d7ad57..e9143739 100644 --- a/src/app/core/services/crud/invariants.service.ts +++ b/src/app/core/services/crud/invariants.service.ts @@ -63,6 +63,7 @@ export class InvariantsService { // @ts-ignore if (!this.systemsSelected.includes(system)) { this.systemsSelected.push(system); + this.observableSystemsSelected.next(this.systemsSelected); console.log('new badge is : ' + system); } else { console.log('System already selected : ' + system); } } @@ -70,6 +71,7 @@ export class InvariantsService { if (this.systemsSelected.indexOf(badge) != null) { console.log('deleting badge : ' + badge); this.systemsSelected.splice(this.systemsSelected.indexOf(badge), 1); + this.observableSystemsSelected.next(this.systemsSelected); } console.log(this.systemsSelected); } diff --git a/src/app/shared/datatable-page/datatable-page.component.ts b/src/app/shared/datatable-page/datatable-page.component.ts index af882145..27fb9ba3 100644 --- a/src/app/shared/datatable-page/datatable-page.component.ts +++ b/src/app/shared/datatable-page/datatable-page.component.ts @@ -31,14 +31,17 @@ export class DatatablePageComponent implements OnInit { ngOnInit() { this.search(); + this.invariantsService.observableSystemsSelected.subscribe(rep => { + this.search(); + }) } search(globalSearch?: string) { if (this.servlet) { this.globalSearch = (globalSearch)? globalSearch : ''; - this.columns.filter(a => a.contentName==="system")[0].sSearch = this.columns.filter(a => a.contentName==="system")[0].sSearch.concat(this.invariantsService.systemsSelected); - let systemArray = this.columns.filter(a => a.contentName==="system")[0].sSearch; - this.columns.filter(a => a.contentName==="system")[0].sSearch = systemArray.filter((a,i) => systemArray.indexOf(a)===i); + // this.columns.filter(a => a.contentName==="system")[0].sSearch = this.columns.filter(a => a.contentName==="system")[0].sSearch.concat(this.invariantsService.systemsSelected); + // let systemArray = this.columns.filter(a => a.contentName==="system")[0].sSearch; + // this.columns.filter(a => a.contentName==="system")[0].sSearch = systemArray.filter((a,i) => systemArray.indexOf(a)===i); this.testService.getFromRequest(this.servlet, this.filterService.generateQueryStringParameters(this.columns, this.page, this.globalSearch), (list, length) => { this.rows = list; this.page.totalCount = length;