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