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