]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-list.component.ts
Support bulk registration request removal
[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})
cd940f40 15export class FollowingListComponent extends RestTable <ActorFollow> 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
cd940f40 25 bulkActions: DropdownAction<ActorFollow[]>[] = []
073deef8 26
51548b31 27 constructor (
f8b2c1b4 28 private notifier: Notifier,
7e9334c3 29 private confirmService: ConfirmService,
66357162 30 private followService: InstanceFollowService
9df52d66 31 ) {
51548b31
C
32 super()
33 }
34
ab998f7b 35 ngOnInit () {
24b9417c 36 this.initialize()
e3d6c643
C
37
38 this.searchFilters = this.followService.buildFollowsListFilters()
39
cd940f40 40 this.bulkActions = [
e3d6c643
C
41 {
42 label: $localize`Delete`,
43 handler: follows => this.removeFollowing(follows)
44 }
45 ]
ab998f7b
C
46 }
47
8e11a1b3
C
48 getIdentifier () {
49 return 'FollowingListComponent'
50 }
51
4d029ef8
C
52 openFollowModal () {
53 this.followModal.openModal()
bb152476
RK
54 }
55
4d029ef8
C
56 isInstanceFollowing (follow: ActorFollow) {
57 return follow.following.name === 'peertube'
bb152476
RK
58 }
59
e3d6c643
C
60 buildFollowingName (follow: ActorFollow) {
61 return follow.following.name + '@' + follow.following.host
62 }
63
64 async removeFollowing (follows: ActorFollow[]) {
65 const message = prepareIcu($localize`Do you really want to unfollow {count, plural, =1 {{entryName}?} other {{count} entries?}}`)(
66 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
67 $localize`Do you really want to unfollow these entries?`
b1d40cff 68 )
e3d6c643
C
69
70 const res = await this.confirmService.confirm(message, $localize`Unfollow`)
1f30a185 71 if (res === false) return
7e9334c3 72
e3d6c643 73 this.followService.unfollow(follows)
1378c0d3
C
74 .subscribe({
75 next: () => {
e3d6c643
C
76 // eslint-disable-next-line max-len
77 const message = prepareIcu($localize`You are not following {count, plural, =1 {{entryName} anymore.} other {these {count} entries anymore.}}`)(
78 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
79 $localize`You are not following them anymore.`
80 )
81
82 this.notifier.success(message)
1378c0d3
C
83 this.reloadData()
84 },
7e9334c3 85
1378c0d3
C
86 error: err => this.notifier.error(err.message)
87 })
7e9334c3
C
88 }
89
2e46eb97 90 protected reloadData () {
b8f4167f 91 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
1378c0d3
C
92 .subscribe({
93 next: resultList => {
51548b31
C
94 this.following = resultList.data
95 this.totalRecords = resultList.total
96 },
97
1378c0d3
C
98 error: err => this.notifier.error(err.message)
99 })
51548b31
C
100 }
101}