]>
Commit | Line | Data |
---|---|---|
e724fa93 | 1 | import { Component, OnInit } from '@angular/core' |
df98563e | 2 | import { NotificationsService } from 'angular2-notifications' |
1f30a185 | 3 | import { SortMeta } from 'primeng/components/common/sortmeta' |
df98563e | 4 | import { ConfirmService } from '../../../core' |
e724fa93 | 5 | import { RestPagination, RestTable, UserService } from '../../../shared' |
b1d40cff | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8569a870 | 7 | import { User } from '../../../../../../shared' |
7da18e44 C |
8 | |
9 | @Component({ | |
10 | selector: 'my-user-list', | |
ec8d8440 C |
11 | templateUrl: './user-list.component.html', |
12 | styleUrls: [ './user-list.component.scss' ] | |
7da18e44 | 13 | }) |
ab998f7b | 14 | export class UserListComponent extends RestTable implements OnInit { |
d592e0a9 C |
15 | users: User[] = [] |
16 | totalRecords = 0 | |
17 | rowsPerPage = 10 | |
ab998f7b | 18 | sort: SortMeta = { field: 'createdAt', order: 1 } |
d592e0a9 | 19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
141b177d | 20 | |
df98563e | 21 | constructor ( |
7ddd02c9 | 22 | private notificationsService: NotificationsService, |
5769e1db | 23 | private confirmService: ConfirmService, |
b1d40cff C |
24 | private userService: UserService, |
25 | private i18n: I18n | |
28798b5d | 26 | ) { |
d592e0a9 | 27 | super() |
7da18e44 C |
28 | } |
29 | ||
ab998f7b C |
30 | ngOnInit () { |
31 | this.loadSort() | |
32 | } | |
33 | ||
e724fa93 | 34 | onUserChanged () { |
141b177d C |
35 | this.loadData() |
36 | } | |
37 | ||
d592e0a9 C |
38 | protected loadData () { |
39 | this.userService.getUsers(this.pagination, this.sort) | |
40 | .subscribe( | |
41 | resultList => { | |
42 | this.users = resultList.data | |
43 | this.totalRecords = resultList.total | |
44 | }, | |
45 | ||
b1d40cff | 46 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
d592e0a9 C |
47 | ) |
48 | } | |
7da18e44 | 49 | } |