]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1import { SortMeta } from 'primeng/api'
2import { Component, OnInit, ViewChild } from '@angular/core'
3import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4import { AdvancedInputFilter } from '@app/shared/shared-forms'
5import { InstanceFollowService } from '@app/shared/shared-instance'
6import { ActorFollow } from '@shared/models'
7import { FollowModalComponent } from './follow-modal.component'
8import { DropdownAction } from '@app/shared/shared-main'
9import { prepareIcu } from '@app/helpers'
10
11@Component({
12 templateUrl: './following-list.component.html',
13 styleUrls: [ './following-list.component.scss' ]
14})
15export class FollowingListComponent extends RestTable implements OnInit {
16 @ViewChild('followModal') followModal: FollowModalComponent
17
18 following: ActorFollow[] = []
19 totalRecords = 0
20 sort: SortMeta = { field: 'createdAt', order: -1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22
23 searchFilters: AdvancedInputFilter[] = []
24
25 selectedFollows: ActorFollow[] = []
26 bulkFollowsActions: DropdownAction<ActorFollow[]>[] = []
27
28 constructor (
29 private notifier: Notifier,
30 private confirmService: ConfirmService,
31 private followService: InstanceFollowService
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 this.initialize()
38
39 this.searchFilters = this.followService.buildFollowsListFilters()
40
41 this.bulkFollowsActions = [
42 {
43 label: $localize`Delete`,
44 handler: follows => this.removeFollowing(follows)
45 }
46 ]
47 }
48
49 getIdentifier () {
50 return 'FollowingListComponent'
51 }
52
53 openFollowModal () {
54 this.followModal.openModal()
55 }
56
57 isInstanceFollowing (follow: ActorFollow) {
58 return follow.following.name === 'peertube'
59 }
60
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?`
73 )
74
75 const res = await this.confirmService.confirm(message, $localize`Unfollow`)
76 if (res === false) return
77
78 this.followService.unfollow(follows)
79 .subscribe({
80 next: () => {
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)
88 this.reloadData()
89 },
90
91 error: err => this.notifier.error(err.message)
92 })
93 }
94
95 protected reloadData () {
96 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
97 .subscribe({
98 next: resultList => {
99 this.following = resultList.data
100 this.totalRecords = resultList.total
101 },
102
103 error: err => this.notifier.error(err.message)
104 })
105 }
106}