Skip to content
Snippets Groups Projects
Commit f71800c8 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FIX #15550 TIME 1 fix current filters + do not use jquery

parent 4382f2d1
No related branches found
No related tags found
No related merge requests found
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
<div *ngIf="currentFilter.id === 'workflowStates' && currentFilter.val.length > 0"> <div *ngIf="currentFilter.id === 'workflowStates' && currentFilter.val.length > 0">
<ion-chip outline *ngFor="let item of currentFilter.val" color="primary" <ion-chip outline *ngFor="let item of currentFilter.val" color="primary"
style="background: white;" [title]="'lang.workflowStatesSearch' | translate" style="background: white;" [title]="'lang.workflowStatesSearch' | translate"
(click)="removeFilter(currentFilter, item)"> (click)="removeFilter(currentFilter, item.id)">
<ion-icon name="options-outline"></ion-icon> <ion-icon name="options-outline"></ion-icon>
<ion-label>{{ getLabel(item) | translate}}</ion-label> <ion-label>{{ item.label | translate}}</ion-label>
<ion-icon name="close-circle"></ion-icon> <ion-icon name="close-circle"></ion-icon>
</ion-chip> </ion-chip>
</div> </div>
...@@ -174,8 +174,8 @@ ...@@ -174,8 +174,8 @@
</ion-list-header> </ion-list-header>
<ion-item *ngFor="let val of filter.values;let i=index;"> <ion-item *ngFor="let val of filter.values;let i=index;">
<ion-label>{{val.label | translate}}</ion-label> <ion-label>{{val.label | translate}}</ion-label>
<ion-checkbox (ionChange)="toggleItem(filter, val, $event.detail.checked)" <ion-checkbox (ngModelChange)="toggleItem(filter, val, !val.selected)" [(ngModel)]="val.selected" [checked]="val.selected"
[checked]="filter.val.indexOf(val.id) > -1" slot="end" [value]="val.id" class="workflowStates"> slot="end" [value]="val.id" class="workflowStates">
</ion-checkbox> </ion-checkbox>
</ion-item> </ion-item>
</ng-container> </ng-container>
......
...@@ -43,19 +43,23 @@ export class SearchComponent implements OnInit { ...@@ -43,19 +43,23 @@ export class SearchComponent implements OnInit {
values: [ values: [
{ {
id: 'PROG', id: 'PROG',
label: 'lang.inprogress' label: 'lang.inprogress',
selected: false
}, },
{ {
id: 'STOP', id: 'STOP',
label: 'lang.interrupt' label: 'lang.interrupt',
selected: false
}, },
{ {
id: 'VAL', id: 'VAL',
label: 'lang.end' label: 'lang.end',
selected: false
}, },
{ {
id: 'REF', id: 'REF',
label: 'lang.refused' label: 'lang.refused',
selected: false
} }
] ]
}, },
...@@ -148,7 +152,7 @@ export class SearchComponent implements OnInit { ...@@ -148,7 +152,7 @@ export class SearchComponent implements OnInit {
this.menu.close('right-menu'); this.menu.close('right-menu');
} }
toggleItem(filter: any, item: any, state: boolean) { toggleItem(filter: any, item: any, state: any) {
if (!state) { if (!state) {
const index = filter.val.indexOf(item.id); const index = filter.val.indexOf(item.id);
filter.val.splice(index, 1); filter.val.splice(index, 1);
...@@ -159,11 +163,13 @@ export class SearchComponent implements OnInit { ...@@ -159,11 +163,13 @@ export class SearchComponent implements OnInit {
formatDatas() { formatDatas() {
const objToSend: any = {}; const objToSend: any = {};
const tmpArr = this.filters.filter((filter: any) => (filter.type === 'text' && filter.val !== '') || (filter.type !== 'text' && filter.val.length > 0)); const tmpArr = JSON.parse(JSON.stringify(this.filters.filter((filter: any) => (filter.type === 'text' && filter.val !== '') || (filter.type !== 'text' && filter.val.length > 0))));
tmpArr.forEach((filter: any) => { tmpArr.forEach((filter: any) => {
if (filter.id === 'workflowUsers') { if (filter.id === 'workflowUsers') {
objToSend[filter.id] = filter.val.map((item: any) => item.id); objToSend[filter.id] = filter.val.map((item: any) => item.id);
} else if (filter.id === 'workflowStates') {
objToSend[filter.id] = filter.values.filter((item: any) => item.selected).map((item: any) => item.id);
} else { } else {
objToSend[filter.id] = filter.val; objToSend[filter.id] = filter.val;
} }
...@@ -239,11 +245,12 @@ export class SearchComponent implements OnInit { ...@@ -239,11 +245,12 @@ export class SearchComponent implements OnInit {
launchSearch() { launchSearch() {
this.ressources = []; this.ressources = [];
this.offset = 0; this.offset = 0;
this.refreshCurrentFilter();
return new Promise((resolve) => { return new Promise((resolve) => {
this.http.post(`../rest/search/documents?limit=10&offset=0`, this.formatDatas()) this.http.post(`../rest/search/documents?limit=10&offset=0`, this.formatDatas())
.pipe( .pipe(
tap((data: any) => { tap((data: any) => {
this.currentFilters = JSON.parse(JSON.stringify(this.filters.filter((item: any) => !this.functionsService.empty(item.val))));
this.ressources = this.formatListDatas(data.documents); this.ressources = this.formatListDatas(data.documents);
this.count = data.count; this.count = data.count;
this.infiniteScroll.disabled = false; this.infiniteScroll.disabled = false;
...@@ -258,6 +265,17 @@ export class SearchComponent implements OnInit { ...@@ -258,6 +265,17 @@ export class SearchComponent implements OnInit {
}); });
} }
refreshCurrentFilter() {
this.currentFilters = JSON.parse(JSON.stringify(this.filters.filter((item: any) => !this.functionsService.empty(item.val))));
if (this.currentFilters.filter((item: any) => item.id === 'workflowStates').length > 0) {
this.currentFilters.filter((item: any) => item.id === 'workflowStates')[0].val = this.currentFilters.filter((item: any) => item.id === 'workflowStates')[0].values.filter((item: any) => item.selected);
if (this.currentFilters.filter((item: any) => item.id === 'workflowStates')[0].val.length === 0) {
this.currentFilters = this.currentFilters.filter((item: any) => item.id !== 'workflowStates');
}
}
}
loadData(event: any) { loadData(event: any) {
if (this.count <= this.limit) { if (this.count <= this.limit) {
event.target.complete(); event.target.complete();
...@@ -412,16 +430,19 @@ export class SearchComponent implements OnInit { ...@@ -412,16 +430,19 @@ export class SearchComponent implements OnInit {
} }
clearFilters() { clearFilters() {
$(".workflowStates").each(function () {
$(this).prop("checked", false);
});
for (let index = 0; index < this.filters.length; index++) { for (let index = 0; index < this.filters.length; index++) {
if (!Array.isArray(this.filters[index].val) && this.filters[index].val !== '') { if (!Array.isArray(this.filters[index].val) && this.filters[index].val !== '') {
this.filters[index].val = ''; this.filters[index].val = '';
} }
if (Array.isArray(this.filters[index].val) && this.filters[index].val.length > 0 && (this.filters[index].id === 'workflowUsers')) { if (Array.isArray(this.filters[index].val)) {
this.filters[index].val = []; this.filters[index].val = [];
this.filters[index].values = this.filters[index].values.map((item: any) => {
return {
...item,
selected : false
};
});
} }
} }
if (this.ressources.length > 0) { if (this.ressources.length > 0) {
...@@ -434,15 +455,10 @@ export class SearchComponent implements OnInit { ...@@ -434,15 +455,10 @@ export class SearchComponent implements OnInit {
this.filters.find((element: any) => element.id === filter.id).val = ''; this.filters.find((element: any) => element.id === filter.id).val = '';
} else { } else {
if (filter.id === 'workflowStates') { if (filter.id === 'workflowStates') {
$(".workflowStates").each(function () { this.filters.find((element: any) => element.id === filter.id).values.filter((element: any) => element.id === item)[0].selected = false;
if ($(this).val() === item) {
$(this).prop("checked", false);
return false;
}
});
} else { } else {
const index = filter.val.indexOf(item); const index = filter.val.indexOf(item);
filter.val.splice(index, 1); this.filters.filter((element: any) => element.id === filter.id)[0].val.splice(index, 1);
} }
} }
this.launchSearch(); this.launchSearch();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment