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