Skip to content
Snippets Groups Projects
Commit 7b501eb3 authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FEAT #15550 TIME 3:10 modify the display of filters selected in search component

parent ef0f3bc3
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,6 @@ export class PluginAutocompleteComponent implements OnInit { ...@@ -53,7 +53,6 @@ export class PluginAutocompleteComponent implements OnInit {
} else { } else {
this.http.get('../rest/autocomplete/users?search=' + ev.detail.value).pipe( this.http.get('../rest/autocomplete/users?search=' + ev.detail.value).pipe(
tap((res: any) => { tap((res: any) => {
console.log(res);
this.itemList = res; this.itemList = res;
}), }),
catchError(err => { catchError(err => {
......
...@@ -12,35 +12,39 @@ ...@@ -12,35 +12,39 @@
</ion-buttons> </ion-buttons>
</ion-toolbar> </ion-toolbar>
<ion-toolbar color="primary"> <ion-toolbar color="primary">
<ion-button *ngIf="getNbFilters() > 0"
shape="round" size="small" slot="start"
color="primary"
(click)="clearFilters()" style="margin-left: 4px;" [title]="'lang.clearFilters' | translate">
<ion-icon slot="icon-only" name="backspace" color="light"></ion-icon>
</ion-button>
<ion-title slot="end" *ngIf="getNbFilters() >= 0">{{getNbFilters()}} {{'lang.currentFilters' | translate}}</ion-title> <ion-title slot="end" *ngIf="getNbFilters() >= 0">{{getNbFilters()}} {{'lang.currentFilters' | translate}}</ion-title>
<div class="scrollfilters" slot="start"> <div class="scrollfilters" slot="start">
<ion-button *ngIf="getNbFilters() > 0" class="clearFilter"
shape="round" size="small" slot="start" color="primary" (click)="clearFilters()" [title]="'lang.clearFilters' | translate">
<ion-icon slot="icon-only" name="backspace" color="light"></ion-icon>
</ion-button>
<div *ngFor="let filter of filters" > <div *ngFor="let filter of filters" >
<ion-chip *ngIf="filter.id === 'title' && filter.val !== ''" color="light"> <ion-chip *ngIf="filter.id === 'title' && filter.val !== ''" color="light"
[title]="'lang.titleSearch' | translate" (click)="removeFilter(filter)">
<ion-icon name="document-text"></ion-icon> <ion-icon name="document-text"></ion-icon>
<ion-label >{{ filter.val}}</ion-label> <ion-label >{{ filter.val }}</ion-label>
<ion-icon name="close-circle"></ion-icon>
</ion-chip> </ion-chip>
<ion-chip *ngIf="filter.id === 'reference' && filter.val !== ''" color="light"> <ion-chip *ngIf="filter.id === 'reference' && filter.val !== ''" color="light"
[title]="'lang.referenceSearch' | translate" (click)="removeFilter(filter)">
<ion-icon name="key"></ion-icon> <ion-icon name="key"></ion-icon>
<ion-label >{{ filter.val}}</ion-label> <ion-label >{{ filter.val }}</ion-label>
<ion-icon name="close-circle"></ion-icon>
</ion-chip> </ion-chip>
<div *ngIf="filter.id === 'workflowStates'"> <div *ngIf="filter.id === 'workflowStates'">
<ion-chip *ngFor="let item of filter.val" color="light"> <ion-chip *ngFor="let item of filter.val" color="light"
<span *ngFor="let lang of filter.values"> [title]="'lang.workflowStatesSearch' | translate" (click)="removeFilter(filter, item)">
<ion-icon *ngIf="lang.id === item" name="options-outline"></ion-icon> <ion-icon name="options-outline"></ion-icon>
<ion-label *ngIf="lang.id === item">{{ lang.label | translate}}</ion-label> <ion-label>{{ getLabel(item) | translate}}</ion-label>
</span> <ion-icon name="close-circle"></ion-icon>
</ion-chip> </ion-chip>
</div> </div>
<div *ngIf="filter.id === 'workflowUsers'"> <div *ngIf="filter.id === 'workflowUsers'">
<ion-chip *ngFor="let item of filter.val" color="light"> <ion-chip *ngFor="let item of filter.val" color="light"
[title]="'lang.workflowUsersSearch' | translate" (click)="removeFilter(filter, item)">
<ion-icon name="person-circle"></ion-icon> <ion-icon name="person-circle"></ion-icon>
<ion-label >{{ item.firstname}} {{ item.lastname }}</ion-label> <ion-label >{{ item.firstname}} {{ item.lastname }}</ion-label>
<ion-icon name="close-circle"></ion-icon>
</ion-chip> </ion-chip>
</div> </div>
</div> </div>
...@@ -150,7 +154,7 @@ ...@@ -150,7 +154,7 @@
<ion-item> <ion-item>
<ion-label color="secondary" position="floating">{{'lang.' + filter.id + 'Search' | translate}} <ion-label color="secondary" position="floating">{{'lang.' + filter.id + 'Search' | translate}}
</ion-label> </ion-label>
<ion-input [(ngModel)]="filter.val"></ion-input> <ion-input [(ngModel)]="filter.val" [value]="filter.val"></ion-input>
</ion-item> </ion-item>
</ng-container> </ng-container>
<ng-container *ngIf="filter.type === 'checkbox'"> <ng-container *ngIf="filter.type === 'checkbox'">
...@@ -160,7 +164,7 @@ ...@@ -160,7 +164,7 @@
<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 (ionChange)="toggleItem(filter, val, $event.detail.checked)"
[checked]="filter.val.indexOf(val.id) > -1" slot="end" class="checkedAction"></ion-checkbox> [checked]="filter.val.indexOf(val.id) > -1" slot="end" [value]="val.id" class="workflowStates"></ion-checkbox>
</ion-item> </ion-item>
</ng-container> </ng-container>
<ng-container *ngIf="filter.type === 'autocompleteUsers'"> <ng-container *ngIf="filter.type === 'autocompleteUsers'">
......
...@@ -65,7 +65,13 @@ ...@@ -65,7 +65,13 @@
white-space: nowrap; white-space: nowrap;
ion-chip, div { ion-chip, div {
height: auto; height: auto;
margin: 4px;
display: inline-block; display: inline-block;
} }
}
ion-button.clearFilter {
position: -webkit-sticky;
position: sticky;
left: 0;
z-index: 1;
} }
\ No newline at end of file
...@@ -112,7 +112,7 @@ export class SearchComponent implements OnInit { ...@@ -112,7 +112,7 @@ export class SearchComponent implements OnInit {
this.signaturesService.initTemplate(this.rightContent, this.viewContainerRef, 'rightContent'); this.signaturesService.initTemplate(this.rightContent, this.viewContainerRef, 'rightContent');
setTimeout(() => { setTimeout(() => {
this.menu.open('right-menu'); this.menu.open('right-menu');
}, 500); }, 500);
} }
ionViewWillLeave() { ionViewWillLeave() {
...@@ -157,14 +157,14 @@ export class SearchComponent implements OnInit { ...@@ -157,14 +157,14 @@ 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 = 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 { } else {
objToSend[filter.id] = filter.val; objToSend[filter.id] = filter.val;
} }
}); });
return objToSend; return objToSend;
} }
...@@ -239,7 +239,7 @@ export class SearchComponent implements OnInit { ...@@ -239,7 +239,7 @@ export class SearchComponent implements OnInit {
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.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;
...@@ -408,7 +408,7 @@ export class SearchComponent implements OnInit { ...@@ -408,7 +408,7 @@ export class SearchComponent implements OnInit {
} }
clearFilters() { clearFilters() {
$(".checkedAction").each(function(){ $(".workflowStates").each(function(){
$(this).prop("checked", false); $(this).prop("checked", false);
}); });
for (let index = 0; index < this.filters.length; index++) { for (let index = 0; index < this.filters.length; index++) {
...@@ -424,4 +424,30 @@ export class SearchComponent implements OnInit { ...@@ -424,4 +424,30 @@ export class SearchComponent implements OnInit {
this.launchSearch(); this.launchSearch();
} }
} }
removeFilter(filter: any, item: any) {
if (!Array.isArray(filter.val)) {
filter.val = '';
} else {
if (filter.id === 'workflowStates') {
$(".workflowStates").each(function() {
if ($(this).val() === item) {
$(this).prop("checked", false);
return false;
}
});
} else {
const index = filter.val.indexOf(item);
filter.val.splice(index, 1);
}
}
if (this.ressources.length > 0) {
this.launchSearch();
}
}
getLabel(filter: any) {
const obj = this.filters.filter((item: any) => item.id === 'workflowStates')[0].values;
return obj.find((element: any) => element.id === filter).label;
}
} }
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