]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/instance-blocklist/instance-account-blocklist.component.ts
Empty states for tables
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / instance-blocklist / instance-account-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 { AccountBlock, BlocklistService } from '@app/shared/blocklist'
7 import { Actor } from '@app/shared/actor/actor.model'
8
9 @Component({
10 selector: 'my-instance-account-blocklist',
11 styleUrls: [ '../moderation.component.scss', './instance-account-blocklist.component.scss' ],
12 templateUrl: './instance-account-blocklist.component.html'
13 })
14 export class InstanceAccountBlocklistComponent extends RestTable implements OnInit {
15 blockedAccounts: AccountBlock[] = []
16 totalRecords = 0
17 rowsPerPageOptions = [ 20, 50, 100 ]
18 rowsPerPage = this.rowsPerPageOptions[0]
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 constructor (
23 private notifier: Notifier,
24 private blocklistService: BlocklistService,
25 private i18n: I18n
26 ) {
27 super()
28 }
29
30 ngOnInit () {
31 this.initialize()
32 }
33
34 getIdentifier () {
35 return 'InstanceAccountBlocklistComponent'
36 }
37
38 switchToDefaultAvatar ($event: Event) {
39 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
40 }
41
42 unblockAccount (accountBlock: AccountBlock) {
43 const blockedAccount = accountBlock.blockedAccount
44
45 this.blocklistService.unblockAccountByInstance(blockedAccount)
46 .subscribe(
47 () => {
48 this.notifier.success(
49 this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost })
50 )
51
52 this.loadData()
53 }
54 )
55 }
56
57 protected loadData () {
58 return this.blocklistService.getInstanceAccountBlocklist({
59 pagination: this.pagination,
60 sort: this.sort,
61 search: this.search
62 })
63 .subscribe(
64 resultList => {
65 this.blockedAccounts = resultList.data
66 this.totalRecords = resultList.total
67 },
68
69 err => this.notifier.error(err.message)
70 )
71 }
72 }