]>
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' |
af5767ff C |
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 { | |
92ea70a7 | 15 | blockedServers: ServerBlock[] = [] |
af5767ff C |
16 | totalRecords = 0 |
17 | rowsPerPage = 10 | |
18 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
20 | ||
21 | constructor ( | |
f8b2c1b4 | 22 | private notifier: Notifier, |
af5767ff C |
23 | private blocklistService: BlocklistService, |
24 | private i18n: I18n | |
25 | ) { | |
26 | super() | |
27 | } | |
28 | ||
29 | ngOnInit () { | |
30 | this.initialize() | |
31 | } | |
32 | ||
33 | unblockServer (serverBlock: ServerBlock) { | |
34 | const host = serverBlock.blockedServer.host | |
35 | ||
36 | this.blocklistService.unblockServerByUser(host) | |
37 | .subscribe( | |
38 | () => { | |
f8b2c1b4 | 39 | this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host })) |
af5767ff C |
40 | |
41 | this.loadData() | |
42 | } | |
43 | ) | |
44 | } | |
45 | ||
46 | protected loadData () { | |
47 | return this.blocklistService.getUserServerBlocklist(this.pagination, this.sort) | |
48 | .subscribe( | |
49 | resultList => { | |
92ea70a7 | 50 | this.blockedServers = resultList.data |
af5767ff C |
51 | this.totalRecords = resultList.total |
52 | }, | |
53 | ||
f8b2c1b4 | 54 | err => this.notifier.error(err.message) |
af5767ff C |
55 | ) |
56 | } | |
57 | } |