Skip to content

Commit

Permalink
#9 Fix bugs on system selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Jhoiro committed Aug 2, 2019
1 parent f303b5a commit 9e3066a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/app/core/services/crud/filter.service.ts
Original file line number Diff line number Diff line change
@@ -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<Column>, 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"
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/services/crud/invariants.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ 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); }
}
removeSystem(badge) {
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);
}
Expand Down
9 changes: 6 additions & 3 deletions src/app/shared/datatable-page/datatable-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9e3066a

Please sign in to comment.