e735d4ab7c4890b2073c590fc8c1fdd6c6faf647
[oweals/peertube.git] / client / src / app / +my-account / my-account-blocklist / my-account-server-blocklist.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { RestPagination, RestTable } from '@app/shared'
5 import { SortMeta } from 'primeng/api'
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 {
15   blockedServers: 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 notifier: Notifier,
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         () => {
39           this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host }))
40
41           this.loadData()
42         }
43       )
44   }
45
46   protected loadData () {
47     return this.blocklistService.getUserServerBlocklist(this.pagination, this.sort)
48       .subscribe(
49         resultList => {
50           this.blockedServers = resultList.data
51           this.totalRecords = resultList.total
52         },
53
54         err => this.notifier.error(err.message)
55       )
56   }
57 }