]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { NotificationsService } from 'angular2-notifications' | |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
4 | import { RestPagination, RestTable } from '@app/shared' | |
5 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
6 | import { BlocklistService } from '@app/shared/blocklist' | |
7 | import { ServerBlock } from '../../../../../../shared' | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-instance-server-blocklist', | |
11 | styleUrls: [ './instance-server-blocklist.component.scss' ], | |
12 | templateUrl: './instance-server-blocklist.component.html' | |
13 | }) | |
14 | export class InstanceServerBlocklistComponent extends RestTable implements OnInit { | |
15 | blockedAccounts: ServerBlock[] = [] | |
16 | totalRecords = 0 | |
17 | rowsPerPage = 10 | |
18 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
20 | ||
21 | constructor ( | |
22 | private notificationsService: NotificationsService, | |
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.unblockServerByInstance(host) | |
37 | .subscribe( | |
38 | () => { | |
39 | this.notificationsService.success( | |
40 | this.i18n('Success'), | |
41 | this.i18n('Instance {{host}} unmuted by your instance.', { host }) | |
42 | ) | |
43 | ||
44 | this.loadData() | |
45 | } | |
46 | ) | |
47 | } | |
48 | ||
49 | protected loadData () { | |
50 | return this.blocklistService.getInstanceServerBlocklist(this.pagination, this.sort) | |
51 | .subscribe( | |
52 | resultList => { | |
53 | this.blockedAccounts = resultList.data | |
54 | this.totalRecords = resultList.total | |
55 | }, | |
56 | ||
57 | err => this.notificationsService.error(this.i18n('Error'), err.message) | |
58 | ) | |
59 | } | |
60 | } |