]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Unify paginator disabling when no result is displayable, fix batch domain add for...
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / followers-list / followers-list.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { ConfirmService, Notifier } from '@app/core'
3 import { SortMeta } from 'primeng/api'
4 import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
5 import { RestPagination, RestTable } from '../../../shared'
6 import { FollowService } from '@app/shared/instance/follow.service'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8
9 @Component({
10 selector: 'my-followers-list',
11 templateUrl: './followers-list.component.html',
12 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
13 })
14 export class FollowersListComponent extends RestTable implements OnInit {
15 followers: ActorFollow[] = []
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 confirmService: ConfirmService,
24 private notifier: Notifier,
25 private i18n: I18n,
26 private followService: FollowService
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 this.initialize()
33 }
34
35 getIdentifier () {
36 return 'FollowersListComponent'
37 }
38
39 acceptFollower (follow: ActorFollow) {
40 follow.state = 'accepted'
41
42 this.followService.acceptFollower(follow)
43 .subscribe(
44 () => {
45 const handle = follow.follower.name + '@' + follow.follower.host
46 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
47 },
48
49 err => {
50 follow.state = 'pending'
51 this.notifier.error(err.message)
52 }
53 )
54 }
55
56 async rejectFollower (follow: ActorFollow) {
57 const message = this.i18n('Do you really want to reject this follower?')
58 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
59 if (res === false) return
60
61 this.followService.rejectFollower(follow)
62 .subscribe(
63 () => {
64 const handle = follow.follower.name + '@' + follow.follower.host
65 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
66
67 this.loadData()
68 },
69
70 err => {
71 follow.state = 'pending'
72 this.notifier.error(err.message)
73 }
74 )
75 }
76
77 async deleteFollower (follow: ActorFollow) {
78 const message = this.i18n('Do you really want to delete this follower?')
79 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
80 if (res === false) return
81
82 this.followService.removeFollower(follow)
83 .subscribe(
84 () => {
85 const handle = follow.follower.name + '@' + follow.follower.host
86 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
87
88 this.loadData()
89 },
90
91 err => this.notifier.error(err.message)
92 )
93 }
94
95 protected loadData () {
96 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
97 .subscribe(
98 resultList => {
99 this.followers = resultList.data
100 this.totalRecords = resultList.total
101 },
102
103 err => this.notifier.error(err.message)
104 )
105 }
106 }