]>
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 |
e0a92917 RK |
20 | rowsPerPageOptions = [ 20, 50, 100 ] |
21 | rowsPerPage = this.rowsPerPageOptions[0] | |
65b21c96 C |
22 | sort: SortMeta = { field: 'createdAt', order: -1 } |
23 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
24 | ||
25 | constructor ( | |
f8b2c1b4 | 26 | private notifier: Notifier, |
65b21c96 C |
27 | private blocklistService: BlocklistService, |
28 | private i18n: I18n | |
29 | ) { | |
30 | super() | |
31 | } | |
32 | ||
33 | ngOnInit () { | |
34 | this.initialize() | |
35 | } | |
36 | ||
8e11a1b3 C |
37 | getIdentifier () { |
38 | return 'InstanceServerBlocklistComponent' | |
39 | } | |
40 | ||
65b21c96 C |
41 | unblockServer (serverBlock: ServerBlock) { |
42 | const host = serverBlock.blockedServer.host | |
43 | ||
44 | this.blocklistService.unblockServerByInstance(host) | |
45 | .subscribe( | |
46 | () => { | |
f8b2c1b4 | 47 | this.notifier.success(this.i18n('Instance {{host}} unmuted by your instance.', { host })) |
65b21c96 C |
48 | |
49 | this.loadData() | |
50 | } | |
51 | ) | |
52 | } | |
53 | ||
bb152476 RK |
54 | httpEnabled () { |
55 | return window.location.protocol === 'https:' | |
56 | } | |
57 | ||
58 | addServersToBlock () { | |
59 | this.batchDomainsModal.openModal() | |
60 | } | |
61 | ||
62 | onDomainsToBlock (domains: string[]) { | |
63 | domains.forEach(domain => { | |
64 | this.blocklistService.blockServerByInstance(domain) | |
65 | .subscribe( | |
66 | () => { | |
67 | this.notifier.success(this.i18n('Instance {{domain}} muted by your instance.', { domain })) | |
68 | ||
69 | this.loadData() | |
70 | } | |
71 | ) | |
72 | }) | |
73 | } | |
74 | ||
65b21c96 | 75 | protected loadData () { |
e0a92917 RK |
76 | return this.blocklistService.getInstanceServerBlocklist({ |
77 | pagination: this.pagination, | |
78 | sort: this.sort, | |
79 | search: this.search | |
80 | }) | |
65b21c96 C |
81 | .subscribe( |
82 | resultList => { | |
92ea70a7 | 83 | this.blockedServers = resultList.data |
65b21c96 C |
84 | this.totalRecords = resultList.total |
85 | }, | |
86 | ||
f8b2c1b4 | 87 | err => this.notifier.error(err.message) |
65b21c96 C |
88 | ) |
89 | } | |
90 | } |