]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-list.component.ts
Add bulk action on following/followers
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
CommitLineData
41b15c89 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit, ViewChild } from '@angular/core'
3import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
073deef8 4import { AdvancedInputFilter } from '@app/shared/shared-forms'
67ed6552 5import { InstanceFollowService } from '@app/shared/shared-instance'
67ed6552 6import { ActorFollow } from '@shared/models'
4d029ef8 7import { FollowModalComponent } from './follow-modal.component'
e3d6c643
C
8import { DropdownAction } from '@app/shared/shared-main'
9import { prepareIcu } from '@app/helpers'
51548b31
C
10
11@Component({
c48e82b5 12 templateUrl: './following-list.component.html',
eeae8142 13 styleUrls: [ './following-list.component.scss' ]
51548b31 14})
ab998f7b 15export class FollowingListComponent extends RestTable implements OnInit {
4d029ef8 16 @ViewChild('followModal') followModal: FollowModalComponent
bb152476 17
c48e82b5 18 following: ActorFollow[] = []
51548b31 19 totalRecords = 0
bb152476 20 sort: SortMeta = { field: 'createdAt', order: -1 }
51548b31
C
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22
e3d6c643
C
23 searchFilters: AdvancedInputFilter[] = []
24
25 selectedFollows: ActorFollow[] = []
26 bulkFollowsActions: DropdownAction<ActorFollow[]>[] = []
073deef8 27
51548b31 28 constructor (
f8b2c1b4 29 private notifier: Notifier,
7e9334c3 30 private confirmService: ConfirmService,
66357162 31 private followService: InstanceFollowService
9df52d66 32 ) {
51548b31
C
33 super()
34 }
35
ab998f7b 36 ngOnInit () {
24b9417c 37 this.initialize()
e3d6c643
C
38
39 this.searchFilters = this.followService.buildFollowsListFilters()
40
41 this.bulkFollowsActions = [
42 {
43 label: $localize`Delete`,
44 handler: follows => this.removeFollowing(follows)
45 }
46 ]
ab998f7b
C
47 }
48
8e11a1b3
C
49 getIdentifier () {
50 return 'FollowingListComponent'
51 }
52
4d029ef8
C
53 openFollowModal () {
54 this.followModal.openModal()
bb152476
RK
55 }
56
4d029ef8
C
57 isInstanceFollowing (follow: ActorFollow) {
58 return follow.following.name === 'peertube'
bb152476
RK
59 }
60
e3d6c643
C
61 isInSelectionMode () {
62 return this.selectedFollows.length !== 0
63 }
64
65 buildFollowingName (follow: ActorFollow) {
66 return follow.following.name + '@' + follow.following.host
67 }
68
69 async removeFollowing (follows: ActorFollow[]) {
70 const message = prepareIcu($localize`Do you really want to unfollow {count, plural, =1 {{entryName}?} other {{count} entries?}}`)(
71 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
72 $localize`Do you really want to unfollow these entries?`
b1d40cff 73 )
e3d6c643
C
74
75 const res = await this.confirmService.confirm(message, $localize`Unfollow`)
1f30a185 76 if (res === false) return
7e9334c3 77
e3d6c643 78 this.followService.unfollow(follows)
1378c0d3
C
79 .subscribe({
80 next: () => {
e3d6c643
C
81 // eslint-disable-next-line max-len
82 const message = prepareIcu($localize`You are not following {count, plural, =1 {{entryName} anymore.} other {these {count} entries anymore.}}`)(
83 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
84 $localize`You are not following them anymore.`
85 )
86
87 this.notifier.success(message)
1378c0d3
C
88 this.reloadData()
89 },
7e9334c3 90
1378c0d3
C
91 error: err => this.notifier.error(err.message)
92 })
7e9334c3
C
93 }
94
2e46eb97 95 protected reloadData () {
b8f4167f 96 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
1378c0d3
C
97 .subscribe({
98 next: resultList => {
51548b31
C
99 this.following = resultList.data
100 this.totalRecords = resultList.total
101 },
102
1378c0d3
C
103 error: err => this.notifier.error(err.message)
104 })
51548b31
C
105 }
106}