]>
Commit | Line | Data |
---|---|---|
bb152476 | 1 | import { Component, OnInit, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
65b21c96 C |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { RestPagination, RestTable } from '@app/shared' | |
f77eb73b | 5 | import { SortMeta } from 'primeng/api' |
65b21c96 C |
6 | import { BlocklistService } from '@app/shared/blocklist' |
7 | import { ServerBlock } from '../../../../../../shared' | |
bb152476 | 8 | import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component' |
65b21c96 C |
9 | |
10 | @Component({ | |
11 | selector: 'my-instance-server-blocklist', | |
e0a92917 | 12 | styleUrls: [ '../moderation.component.scss', './instance-server-blocklist.component.scss' ], |
65b21c96 C |
13 | templateUrl: './instance-server-blocklist.component.html' |
14 | }) | |
15 | export class InstanceServerBlocklistComponent extends RestTable implements OnInit { | |
bb152476 RK |
16 | @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent |
17 | ||
92ea70a7 | 18 | blockedServers: ServerBlock[] = [] |
65b21c96 | 19 | totalRecords = 0 |
65b21c96 C |
20 | sort: SortMeta = { field: 'createdAt', order: -1 } |
21 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
22 | ||
23 | constructor ( | |
f8b2c1b4 | 24 | private notifier: Notifier, |
65b21c96 C |
25 | private blocklistService: BlocklistService, |
26 | private i18n: I18n | |
27 | ) { | |
28 | super() | |
29 | } | |
30 | ||
31 | ngOnInit () { | |
32 | this.initialize() | |
33 | } | |
34 | ||
8e11a1b3 C |
35 | getIdentifier () { |
36 | return 'InstanceServerBlocklistComponent' | |
37 | } | |
38 | ||
65b21c96 C |
39 | unblockServer (serverBlock: ServerBlock) { |
40 | const host = serverBlock.blockedServer.host | |
41 | ||
42 | this.blocklistService.unblockServerByInstance(host) | |
43 | .subscribe( | |
44 | () => { | |
f8b2c1b4 | 45 | this.notifier.success(this.i18n('Instance {{host}} unmuted by your instance.', { host })) |
65b21c96 C |
46 | |
47 | this.loadData() | |
48 | } | |
49 | ) | |
50 | } | |
51 | ||
bb152476 RK |
52 | addServersToBlock () { |
53 | this.batchDomainsModal.openModal() | |
54 | } | |
55 | ||
56 | onDomainsToBlock (domains: string[]) { | |
57 | domains.forEach(domain => { | |
58 | this.blocklistService.blockServerByInstance(domain) | |
59 | .subscribe( | |
60 | () => { | |
61 | this.notifier.success(this.i18n('Instance {{domain}} muted by your instance.', { domain })) | |
62 | ||
63 | this.loadData() | |
64 | } | |
65 | ) | |
66 | }) | |
67 | } | |
68 | ||
65b21c96 | 69 | protected loadData () { |
e0a92917 RK |
70 | return this.blocklistService.getInstanceServerBlocklist({ |
71 | pagination: this.pagination, | |
72 | sort: this.sort, | |
73 | search: this.search | |
74 | }) | |
65b21c96 C |
75 | .subscribe( |
76 | resultList => { | |
92ea70a7 | 77 | this.blockedServers = resultList.data |
65b21c96 C |
78 | this.totalRecords = resultList.total |
79 | }, | |
80 | ||
f8b2c1b4 | 81 | err => this.notifier.error(err.message) |
65b21c96 C |
82 | ) |
83 | } | |
84 | } |