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