Skip to content

Commit 2c895d5

Browse files
committed
Filtro e lista de usuário.
1 parent be0baa4 commit 2c895d5

19 files changed

+134
-49
lines changed

src/app/domain/pagination.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class Pagination<T> {
2+
Items: Array<T>;
3+
Offset: Number;
4+
Limit: Number;
5+
Total: Number;
6+
}

src/app/modules/animations/list.animation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ export const ListAnimation = trigger('list-transition', [
1818
),
1919
query(':leave',
2020
[
21-
animate('50ms',
22-
style({
23-
opacity: 0
24-
}))
21+
style({ opacity: 1 }),
22+
animate('0.5s', style({ opacity: 0 }))
2523
],
2624
{ optional: true}
2725
)

src/app/modules/core/http-backend.interceptor.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import { Injectable } from '@angular/core';
22
import { HttpRequest, HttpResponse, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
33
import { Observable, of, throwError } from 'rxjs';
44
import { delay, mergeMap, materialize, dematerialize } from 'rxjs/operators';
5-
import { Jwt } from './../../domain/Jwt';
5+
import { Jwt } from '../../domain/jwt';
66
import { Card } from './../../domain/card';
7-
import { User } from './../../domain/User';
7+
import { User } from '../../domain/user';
8+
import { Pagination } from 'src/app/domain/pagination';
89

910
@Injectable()
1011
export class HttpBackendInterceptor implements HttpInterceptor {
1112
constructor() { }
1213

1314
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
14-
if (req.url.endsWith('/identity') ||
15-
req.url.endsWith('/users') ||
16-
req.url.endsWith('/error') ||
17-
req.url.endsWith('/cards')) {
15+
if (req.url.startsWith('http://localhost:5000/identity') ||
16+
req.url.startsWith('http://localhost:5000/users') ||
17+
req.url.startsWith('http://localhost:5000/error') ||
18+
req.url.startsWith('http://localhost:5000/cards')) {
1819

1920
return of(null).pipe(mergeMap(() => {
20-
if (req.url.endsWith('/identity') && req.method === 'POST') {
21+
if (req.url.startsWith('http://localhost:5000/identity') && req.method === 'POST') {
2122
var data = new Date();
2223
data.setDate(data.getDate() + 1);
2324

@@ -32,7 +33,7 @@ export class HttpBackendInterceptor implements HttpInterceptor {
3233
return of(new HttpResponse({ status: 200, body: jwt }));
3334
}
3435

35-
if (req.url.endsWith('/cards') && req.method === 'GET') {
36+
if (req.url.startsWith('http://localhost:5000/cards') && req.method === 'GET') {
3637
let cards: Card[] = [];
3738

3839
var card: Card = {
@@ -48,7 +49,7 @@ export class HttpBackendInterceptor implements HttpInterceptor {
4849
return of(new HttpResponse({ status: 200, body: cards }));
4950
}
5051

51-
if (req.url.endsWith('/users') && req.method === 'GET') {
52+
if (req.url.startsWith('http://localhost:5000/users') && req.method === 'GET') {
5253
let users: User[] = [];
5354

5455
var data = new Date();
@@ -63,11 +64,18 @@ export class HttpBackendInterceptor implements HttpInterceptor {
6364
for (let i = 0; i < 10; i++) {
6465
users.push(user);
6566
}
67+
68+
let pagination: Pagination<User> = {
69+
Items: users,
70+
Limit: 10,
71+
Offset: 0,
72+
Total: 192
73+
};
6674

67-
return of(new HttpResponse({ status: 200, body: users }));
75+
return of(new HttpResponse({ status: 200, body: pagination }));
6876
}
6977

70-
if (req.url.endsWith('/error') && req.method === 'GET') {
78+
if (req.url.startsWith('http://localhost:5000/error') && req.method === 'GET') {
7179
return throwError({ error: { message: 'Error thrown.' } });
7280
}
7381

src/app/modules/ui/filter.component.ts

Whitespace-only changes.

src/app/modules/ui/header.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { AuthenticationService } from './../../services/authentication.service';
4-
import { Jwt } from './../../domain/Jwt';
4+
import { Jwt } from '../../domain/jwt';
55

66
@Component({
77
selector: 'app-header',

src/app/modules/ui/page-crud.component.ts

Whitespace-only changes.

src/app/modules/ui/panel.component.ts

Whitespace-only changes.

src/app/routes/identity/identity-page/identity-page.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, ViewEncapsulation } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
33
import { Router, ActivatedRoute } from '@angular/router';
44
import { AuthenticationService } from './../../../services/authentication.service';
5-
import { Jwt } from './../../../domain/Jwt';
5+
import { Jwt } from '../../../domain/jwt';
66

77
@Component({
88
selector: 'identity-page',
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
<div class="row mb-5">
2-
32
<div class="col-lg-12">
4-
<form novalidate>
3+
<form [formGroup]="filters" novalidate>
54
<div class="form-row">
65
<div class="form-group col-md-3">
76
<label for="Name">Name</label>
8-
<input id="Name" type="text" class="form-control" placeholder="User's name">
7+
<input formControlName="Name" type="text" class="form-control" placeholder="User's name">
98
</div>
109
<div class="form-group col-md-3">
1110
<label for="Email">Email</label>
12-
<input id="Email" type="text" class="form-control" placeholder="User's email">
11+
<input formControlName="Email" type="text" class="form-control" placeholder="User's email">
1312
</div>
1413
<div class="form-group col-md-3">
1514
<label for="Document">Document</label>
16-
<input id="Document" type="text" class="form-control" id="Document" placeholder="User's document">
15+
<input formControlName="Document" type="text" class="form-control" id="Document" placeholder="User's document">
1716
</div>
1817
</div>
1918

20-
<button class="btn btn-primary" type="submit">Search</button>
19+
<button class="btn btn-primary" (click)="filter()">Search</button>
2120
</form>
2221
</div>
2322
</div>
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1-
import { Component, ViewEncapsulation } from '@angular/core';
1+
import { Component, ViewEncapsulation, OnInit, EventEmitter, Output } from '@angular/core';
2+
import { FormGroup, FormControl } from '@angular/forms';
3+
import { debounceTime } from 'rxjs/operators';
24

35
@Component({
46
selector: 'users-filter',
57
templateUrl: './users-filter.component.html',
68
encapsulation: ViewEncapsulation.None
79
})
810

9-
export class UsersFilterComponent {
10-
constructor() { }
11+
export class UsersFilterComponent implements OnInit {
12+
@Output() filterEvent: EventEmitter<FormGroup> = new EventEmitter<FormGroup>();
13+
14+
public filters = new FormGroup({
15+
Name: new FormControl(),
16+
Email: new FormControl(),
17+
Document: new FormControl()
18+
});
19+
20+
ngOnInit(): void {
21+
this.filters.controls.Name.valueChanges.pipe(
22+
debounceTime(500)).subscribe(() => {
23+
this.filter();
24+
});
25+
26+
this.filters.controls.Email.valueChanges.pipe(
27+
debounceTime(500)).subscribe(() => {
28+
this.filter();
29+
});
30+
31+
this.filters.controls.Document.valueChanges.pipe(
32+
debounceTime(500)).subscribe(() => {
33+
this.filter();
34+
});
35+
}
36+
37+
filter(): void {
38+
this.filterEvent.emit(this.filters);
39+
}
1140
}

0 commit comments

Comments
 (0)