]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-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 / following-list / following-list.component.ts
CommitLineData
bb152476 1import { Component, OnInit, ViewChild } 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'
bb152476 9import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component'
51548b31
C
10
11@Component({
12 selector: 'my-followers-list',
c48e82b5 13 templateUrl: './following-list.component.html',
d3840613 14 styleUrls: [ '../follows.component.scss', './following-list.component.scss' ]
51548b31 15})
ab998f7b 16export class FollowingListComponent extends RestTable implements OnInit {
bb152476
RK
17 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
18
c48e82b5 19 following: ActorFollow[] = []
51548b31 20 totalRecords = 0
b8cf27c0
RK
21 rowsPerPageOptions = [ 20, 50, 100 ]
22 rowsPerPage = this.rowsPerPageOptions[0]
bb152476 23 sort: SortMeta = { field: 'createdAt', order: -1 }
51548b31
C
24 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
25
26 constructor (
f8b2c1b4 27 private notifier: Notifier,
7e9334c3 28 private confirmService: ConfirmService,
b1d40cff
C
29 private followService: FollowService,
30 private i18n: I18n
51548b31
C
31 ) {
32 super()
33 }
34
ab998f7b 35 ngOnInit () {
24b9417c 36 this.initialize()
ab998f7b
C
37 }
38
8e11a1b3
C
39 getIdentifier () {
40 return 'FollowingListComponent'
41 }
42
bb152476
RK
43 addDomainsToFollow () {
44 this.batchDomainsModal.openModal()
45 }
46
b8cf27c0
RK
47 httpEnabled () {
48 return window.location.protocol === 'https:'
49 }
50
bb152476
RK
51 async addFollowing (hosts: string[]) {
52 this.followService.follow(hosts).subscribe(
53 () => {
54 this.notifier.success(this.i18n('Follow request(s) sent!'))
55 this.loadData()
56 },
57
58 err => this.notifier.error(err.message)
59 )
60 }
61
c48e82b5 62 async removeFollowing (follow: ActorFollow) {
b1d40cff 63 const res = await this.confirmService.confirm(
25acef90 64 this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
b1d40cff
C
65 this.i18n('Unfollow')
66 )
1f30a185 67 if (res === false) return
7e9334c3 68
1f30a185
C
69 this.followService.unfollow(follow).subscribe(
70 () => {
f8b2c1b4 71 this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
1f30a185
C
72 this.loadData()
73 },
7e9334c3 74
f8b2c1b4 75 err => this.notifier.error(err.message)
7e9334c3
C
76 )
77 }
78
51548b31 79 protected loadData () {
b8f4167f 80 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
51548b31
C
81 .subscribe(
82 resultList => {
83 this.following = resultList.data
84 this.totalRecords = resultList.total
85 },
86
f8b2c1b4 87 err => this.notifier.error(err.message)
51548b31
C
88 )
89 }
90}