]>
Commit | Line | Data |
---|---|---|
af5767ff | 1 | import { Component, OnInit } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
af5767ff C |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { RestPagination, RestTable } from '@app/shared' | |
f77eb73b | 5 | import { SortMeta } from 'primeng/api' |
f8b2c1b4 | 6 | import { AccountBlock, BlocklistService } from '@app/shared/blocklist' |
af5767ff C |
7 | |
8 | @Component({ | |
9 | selector: 'my-account-blocklist', | |
10 | styleUrls: [ './my-account-blocklist.component.scss' ], | |
11 | templateUrl: './my-account-blocklist.component.html' | |
12 | }) | |
13 | export class MyAccountBlocklistComponent extends RestTable implements OnInit { | |
14 | blockedAccounts: AccountBlock[] = [] | |
15 | totalRecords = 0 | |
16 | rowsPerPage = 10 | |
17 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
18 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
19 | ||
20 | constructor ( | |
f8b2c1b4 | 21 | private notifier: Notifier, |
af5767ff C |
22 | private blocklistService: BlocklistService, |
23 | private i18n: I18n | |
24 | ) { | |
25 | super() | |
26 | } | |
27 | ||
28 | ngOnInit () { | |
29 | this.initialize() | |
30 | } | |
31 | ||
8e11a1b3 C |
32 | getIdentifier () { |
33 | return 'MyAccountBlocklistComponent' | |
34 | } | |
35 | ||
af5767ff C |
36 | unblockAccount (accountBlock: AccountBlock) { |
37 | const blockedAccount = accountBlock.blockedAccount | |
38 | ||
39 | this.blocklistService.unblockAccountByUser(blockedAccount) | |
40 | .subscribe( | |
41 | () => { | |
f8b2c1b4 | 42 | this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: blockedAccount.nameWithHost })) |
af5767ff C |
43 | |
44 | this.loadData() | |
45 | } | |
46 | ) | |
47 | } | |
48 | ||
49 | protected loadData () { | |
50 | return this.blocklistService.getUserAccountBlocklist(this.pagination, this.sort) | |
51 | .subscribe( | |
52 | resultList => { | |
53 | this.blockedAccounts = resultList.data | |
54 | this.totalRecords = resultList.total | |
55 | }, | |
56 | ||
f8b2c1b4 | 57 | err => this.notifier.error(err.message) |
af5767ff C |
58 | ) |
59 | } | |
60 | } |