Commit 71b753b8 by Emile TAVERNE

Ajout recherche et tri des personnes

parent a7f74ad2
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core'; import {NgModule} from '@angular/core';
import {HttpClientModule} from '@angular/common/http'; import {HttpClientModule} from '@angular/common/http';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
...@@ -16,10 +17,13 @@ import * as Pipes from './pipes'; ...@@ -16,10 +17,13 @@ import * as Pipes from './pipes';
Components.PageTrombinoscopeComponent, Components.PageTrombinoscopeComponent,
Components.TrombinoscopeCardComponent, Components.TrombinoscopeCardComponent,
Pipes.CapitalizePipe, Pipes.CapitalizePipe,
Pipes.OrderByFullNamePipe,
Pipes.SearchPersonPipe,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
HttpClientModule HttpClientModule,
FormsModule
], ],
providers: [ providers: [
Services.PersonService Services.PersonService
......
<main bp="grid 3"> <main bp="grid">
<ng-container *ngIf="persons; else loading"> <ng-container *ngIf="persons; else loading">
<div bp="12">
<input [(ngModel)]="searchField" placeholder="Rechercher..." type="text">
</div>
<app-trombinoscope-card <app-trombinoscope-card
*ngFor="let person of persons" *ngFor="let person of persons | searchPerson:searchField | orderByFullName"
bp="3"
[person]="person"> [person]="person">
</app-trombinoscope-card> </app-trombinoscope-card>
</ng-container> </ng-container>
......
...@@ -3,4 +3,24 @@ main { ...@@ -3,4 +3,24 @@ main {
margin: 0 auto 30px; margin: 0 auto 30px;
padding-top: 30px; padding-top: 30px;
grid-gap: 30px; grid-gap: 30px;
input[type=text] {
color: #333;
border: none;
border-radius: 100px;
background-color: #e0e0e0;
padding: 5px 16px;
margin-left: 8px;
width: 180px;
max-width: 300px;
transition: width .7s ease-in-out;
line-height: 30px;
letter-spacing: 0.4px;
float: right;
&:focus {
width: 100%;
outline-width: 0;
}
}
} }
...@@ -9,6 +9,7 @@ import {PersonService} from '../../services'; ...@@ -9,6 +9,7 @@ import {PersonService} from '../../services';
}) })
export class PageTrombinoscopeComponent implements OnInit { export class PageTrombinoscopeComponent implements OnInit {
persons: PersonModel[]; persons: PersonModel[];
searchField: string;
constructor(private personService: PersonService) { constructor(private personService: PersonService) {
} }
......
export * from './capitalize.pipe'; export * from './capitalize.pipe';
export * from './order-by-full-name.pipe';
export * from './search-person.pipe';
import {Pipe, PipeTransform} from '@angular/core';
import {PersonModel} from '../models';
@Pipe({name: 'orderByFullName'})
export class OrderByFullNamePipe implements PipeTransform {
transform(value: PersonModel[]): PersonModel[] {
return value.sort((a: PersonModel, b: PersonModel): number => {
if (a.fullName < b.fullName) {
return -1;
}
if (a.fullName > b.fullName) {
return 1;
}
return 0;
});
}
}
import {Pipe, PipeTransform} from '@angular/core';
import {PersonModel} from '../models';
@Pipe({name: 'searchPerson'})
export class SearchPersonPipe implements PipeTransform {
transform(value: PersonModel[], search: string): PersonModel[] {
if (!search || search.length === 0) {
return value;
}
return value.filter((item: PersonModel): boolean => {
return item.fullName.toLowerCase().includes(search.toLowerCase());
});
}
}
Markdown is supported
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