Skip to content
Snippets Groups Projects
Commit caef0319 authored by Maël AUDEON's avatar Maël AUDEON
Browse files

[TRTL-206] Add search & order by on Groups list

parent f8c451ce
No related branches found
No related tags found
1 merge request!1Feature/design/1
...@@ -5,11 +5,41 @@ ...@@ -5,11 +5,41 @@
> >
<thead> <thead>
<tr> <tr>
<th><i class="vitamui-icon vitamui-icon-keys vitamui-row-icon"></i></th> <th>
<th i18n="Group name@@profileGroupListHeaderName">Nom du groupe</th> <div class="vitamui-table-header">
<th i18n="Group ID@@profileGroupListHeaderID">Identifiant</th> <i class="vitamui-icon vitamui-icon-keys vitamui-row-icon"></i>
<th i18n="Description@@profileGroupListHeaderDescription">Description</th> <vitamui-common-order-by-button orderByKey="status" [(orderBy)]="orderBy" [(direction)]="direction"
<th i18n="Description@@profileGroupListHeaderLevel">Niveau</th> (orderChange)="emitOrderChange()"></vitamui-common-order-by-button>
</div>
</th>
<th>
<div class="vitamui-table-header">
<span i18n="Group name@@profileGroupListHeaderName">Nom du groupe</span>
<vitamui-common-order-by-button orderByKey="name" [(orderBy)]="orderBy" [(direction)]="direction"
(orderChange)="emitOrderChange()"></vitamui-common-order-by-button>
</div>
</th>
<th>
<div class="vitamui-table-header">
<span i18n="Group ID@@profileGroupListHeaderID">Identifiant</span>
<vitamui-common-order-by-button orderByKey="identifier" [(orderBy)]="orderBy" [(direction)]="direction"
(orderChange)="emitOrderChange()"></vitamui-common-order-by-button>
</div>
</th>
<th>
<div class="vitamui-table-header">
<span i18n="Description@@profileGroupListHeaderDescription">Description</span>
<vitamui-common-order-by-button orderByKey="description" [(orderBy)]="orderBy" [(direction)]="direction"
(orderChange)="emitOrderChange()"></vitamui-common-order-by-button>
</div>
</th>
<th>
<div class="vitamui-table-header">
<span i18n="Description@@profileGroupListHeaderLevel">Niveau</span>
<vitamui-common-order-by-button orderByKey="level" [(orderBy)]="orderBy" [(direction)]="direction"
(orderChange)="emitOrderChange()"></vitamui-common-order-by-button>
</div>
</th>
</tr> </tr>
</thead> </thead>
......
...@@ -35,10 +35,17 @@ ...@@ -35,10 +35,17 @@
* knowledge of the CeCILL-C license and that you accept its terms. * knowledge of the CeCILL-C license and that you accept its terms.
*/ */
import { animate, state, style, transition, trigger } from '@angular/animations'; import { animate, state, style, transition, trigger } from '@angular/animations';
import { Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core'; import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import { Subscription } from 'rxjs'; import {merge, Subject, Subscription} from 'rxjs';
import { Group, InfiniteScrollTable } from 'ui-frontend-common'; import {
buildCriteriaFromSearch,
DEFAULT_PAGE_SIZE, Direction,
Group,
InfiniteScrollTable,
PageRequest,
SearchQuery
} from 'ui-frontend-common';
import { GroupService } from '../group.service'; import { GroupService } from '../group.service';
@Component({ @Component({
...@@ -65,6 +72,25 @@ export class GroupListComponent extends InfiniteScrollTable<Group> implements On ...@@ -65,6 +72,25 @@ export class GroupListComponent extends InfiniteScrollTable<Group> implements On
private updatedGroupSub: Subscription; private updatedGroupSub: Subscription;
@Input('search')
set searchText(text: string) {
this._search = text;
this.searchChange.next(text);
}
// tslint:disable-next-line:variable-name
private _search: string;
private readonly searchKeys = [
'name',
'level',
'description'
];
orderBy = 'name';
direction = Direction.ASCENDANT;
private readonly orderChange = new Subject<string>();
private readonly searchChange = new Subject<string>();
constructor(public groupService: GroupService) { constructor(public groupService: GroupService) {
super(groupService); super(groupService);
} }
...@@ -76,7 +102,24 @@ export class GroupListComponent extends InfiniteScrollTable<Group> implements On ...@@ -76,7 +102,24 @@ export class GroupListComponent extends InfiniteScrollTable<Group> implements On
if (profileGroupIndex > -1) { if (profileGroupIndex > -1) {
this.dataSource[profileGroupIndex] = updatedGroup; this.dataSource[profileGroupIndex] = updatedGroup;
} }
});
const searchCriteriaChange = merge(this.searchChange, this.orderChange);
searchCriteriaChange.subscribe(() => {
const query: SearchQuery = {
criteria: buildCriteriaFromSearch(this._search, this.searchKeys)
};
const pageRequest = new PageRequest(0, DEFAULT_PAGE_SIZE, this.orderBy, this.direction, JSON.stringify(query));
this.search(pageRequest);
}); });
}
emitOrderChange() {
this.orderChange.next();
} }
ngOnDestroy() { ngOnDestroy() {
......
...@@ -16,10 +16,11 @@ ...@@ -16,10 +16,11 @@
</h2> </h2>
<div class="controls"> <div class="controls">
<div class="search disabled"> <vitamui-common-search-bar
<input type="search" placeholder="Nom du groupe" i18n-placeholder="Group name@@profileGroupSearchInputPlaceholder" disabled> name="group-search"
<button type="submit" class="btn-circle primary btn-search"><i class="material-icons">search</i></button> (search)="onSearchSubmit($event)"
</div> placeholder="Nom du groupe" i18n-placeholder="Group name@@profileGroupSearchInputPlaceholder"
></vitamui-common-search-bar>
<div class="actions"> <div class="actions">
<button class="btn secondary" (click)="openCreateGroupDialog()"> <button class="btn secondary" (click)="openCreateGroupDialog()">
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
</div> </div>
<div class="vitamui-body vitamui-container"> <div class="vitamui-body vitamui-container">
<app-group-list (groupClick)="openPanel($event)"></app-group-list> <app-group-list [search]="search" (groupClick)="openPanel($event)"></app-group-list>
</div> </div>
</mat-sidenav-content> </mat-sidenav-content>
......
...@@ -51,6 +51,8 @@ export class GroupComponent extends SidenavPage<Group> implements OnInit { ...@@ -51,6 +51,8 @@ export class GroupComponent extends SidenavPage<Group> implements OnInit {
groups: Group[]; groups: Group[];
search: string;
@ViewChild(GroupListComponent, { static: true }) groupListComponent: GroupListComponent; @ViewChild(GroupListComponent, { static: true }) groupListComponent: GroupListComponent;
constructor(public dialog: MatDialog, route: ActivatedRoute, globalEventService: GlobalEventService) { constructor(public dialog: MatDialog, route: ActivatedRoute, globalEventService: GlobalEventService) {
...@@ -71,4 +73,9 @@ export class GroupComponent extends SidenavPage<Group> implements OnInit { ...@@ -71,4 +73,9 @@ export class GroupComponent extends SidenavPage<Group> implements OnInit {
if (!this.groupListComponent) { return; } if (!this.groupListComponent) { return; }
this.groupListComponent.search(); this.groupListComponent.search();
} }
onSearchSubmit(search: string) {
this.search = search;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment