]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-blocklist/my-account-server-blocklist.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-blocklist / my-account-server-blocklist.component.ts
CommitLineData
af5767ff 1import { Component, OnInit } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
af5767ff
C
3import { I18n } from '@ngx-translate/i18n-polyfill'
4import { RestPagination, RestTable } from '@app/shared'
5import { SortMeta } from 'primeng/components/common/sortmeta'
6import { ServerBlock } from '../../../../../shared'
7import { 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})
14export class MyAccountServerBlocklistComponent extends RestTable implements OnInit {
92ea70a7 15 blockedServers: ServerBlock[] = []
af5767ff
C
16 totalRecords = 0
17 rowsPerPage = 10
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
21 constructor (
f8b2c1b4 22 private notifier: Notifier,
af5767ff
C
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 () => {
f8b2c1b4 39 this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host }))
af5767ff
C
40
41 this.loadData()
42 }
43 )
44 }
45
46 protected loadData () {
47 return this.blocklistService.getUserServerBlocklist(this.pagination, this.sort)
48 .subscribe(
49 resultList => {
92ea70a7 50 this.blockedServers = resultList.data
af5767ff
C
51 this.totalRecords = resultList.total
52 },
53
f8b2c1b4 54 err => this.notifier.error(err.message)
af5767ff
C
55 )
56 }
57}