]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-list.component.ts
Fix sort in admin tables
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
CommitLineData
ab998f7b 1import { Component, OnInit } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
41b15c89 3import { SortMeta } from 'primeng/api'
c48e82b5 4import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
7e9334c3 5import { ConfirmService } from '../../../core/confirm/confirm.service'
60862425 6import { RestPagination, RestTable } from '../../../shared'
a6dbbf03 7import { FollowService } from '@app/shared/instance/follow.service'
b1d40cff 8import { I18n } from '@ngx-translate/i18n-polyfill'
51548b31
C
9
10@Component({
11 selector: 'my-followers-list',
c48e82b5
C
12 templateUrl: './following-list.component.html',
13 styleUrls: [ './following-list.component.scss' ]
51548b31 14})
ab998f7b 15export class FollowingListComponent extends RestTable implements OnInit {
c48e82b5 16 following: ActorFollow[] = []
51548b31
C
17 totalRecords = 0
18 rowsPerPage = 10
19 sort: SortMeta = { field: 'createdAt', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 constructor (
f8b2c1b4 23 private notifier: Notifier,
7e9334c3 24 private confirmService: ConfirmService,
b1d40cff
C
25 private followService: FollowService,
26 private i18n: I18n
51548b31
C
27 ) {
28 super()
29 }
30
ab998f7b 31 ngOnInit () {
24b9417c 32 this.initialize()
ab998f7b
C
33 }
34
8e11a1b3
C
35 getIdentifier () {
36 return 'FollowingListComponent'
37 }
38
c48e82b5 39 async removeFollowing (follow: ActorFollow) {
b1d40cff 40 const res = await this.confirmService.confirm(
25acef90 41 this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
b1d40cff
C
42 this.i18n('Unfollow')
43 )
1f30a185 44 if (res === false) return
7e9334c3 45
1f30a185
C
46 this.followService.unfollow(follow).subscribe(
47 () => {
f8b2c1b4 48 this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
1f30a185
C
49 this.loadData()
50 },
7e9334c3 51
f8b2c1b4 52 err => this.notifier.error(err.message)
7e9334c3
C
53 )
54 }
55
51548b31 56 protected loadData () {
b8f4167f 57 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
51548b31
C
58 .subscribe(
59 resultList => {
60 this.following = resultList.data
61 this.totalRecords = resultList.total
62 },
63
f8b2c1b4 64 err => this.notifier.error(err.message)
51548b31
C
65 )
66 }
67}