-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuser-search.component.ts
63 lines (52 loc) · 1.91 KB
/
user-search.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {UserFacade} from "../../core/store/user/user.facade";
import {Subject} from "rxjs";
import {User, UserState} from "../../core/store/user/user.state";
import {MatTableDataSource} from "@angular/material/table";
import {MatSort} from "@angular/material/sort";
import {MatPaginator} from "@angular/material/paginator";
import {filter, takeUntil} from "rxjs/operators";
import {UserService} from "../../core/service/user/user.service";
import { Router } from '@angular/router';
@Component({
templateUrl: './user-search.component.html',
styleUrls: ['./user-search.component.scss']
})
export class UserSearchComponent implements AfterViewInit, OnDestroy, OnInit {
constructor(private userFacade: UserFacade, private userSrvice: UserService, private router: Router) {}
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
destroyed$ = new Subject<void>();
state: UserState | undefined;
tableFields: string[] = ['name', 'updated','edit','delete'];
tableSource!: MatTableDataSource<User>;
ngAfterViewInit(): void {
this.userFacade
.retrieve()
.pipe(
takeUntil(this.destroyed$),
filter(state => state?.data?.length > 0)
)
.subscribe((state) => {
this.state = state;
this.tableSource = new MatTableDataSource<User>(state.data);
this.tableSource.paginator = this.paginator;
this.tableSource.sort = this.sort;
});
}
ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}
ngOnInit(): void {
this.userFacade.dispatchRetrieve();
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.tableSource.filter = filterValue.trim().toLowerCase();
}
editRecord(rowData:any){
this.userSrvice.rowData=rowData;
this.router.navigate(['/user/form'])
}
}