]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
align ownership change video list table with moderation tables
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-ownership / my-account-ownership.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { VideoOwnershipService, Actor, Video, Account } from '@app/shared/shared-main'
5 import { VideoChangeOwnership } from '@shared/models'
6 import { MyAccountAcceptOwnershipComponent } from './my-account-accept-ownership/my-account-accept-ownership.component'
7 import { getAbsoluteAPIUrl } from '@app/helpers'
8
9 @Component({
10 selector: 'my-account-ownership',
11 templateUrl: './my-account-ownership.component.html',
12 styleUrls: [ './my-account-ownership.component.scss' ]
13 })
14 export class MyAccountOwnershipComponent extends RestTable implements OnInit {
15 videoChangeOwnerships: VideoChangeOwnership[] = []
16 totalRecords = 0
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
20 @ViewChild('myAccountAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent
21
22 constructor (
23 private notifier: Notifier,
24 private videoOwnershipService: VideoOwnershipService
25 ) {
26 super()
27 }
28
29 ngOnInit () {
30 this.initialize()
31 }
32
33 getIdentifier () {
34 return 'MyAccountOwnershipComponent'
35 }
36
37 switchToDefaultAvatar ($event: Event) {
38 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
39 }
40
41 openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
42 this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership)
43 }
44
45 accepted () {
46 this.loadData()
47 }
48
49 refuse (videoChangeOwnership: VideoChangeOwnership) {
50 this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id)
51 .subscribe(
52 () => this.loadData(),
53 err => this.notifier.error(err.message)
54 )
55 }
56
57 protected loadData () {
58 return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort)
59 .subscribe(
60 resultList => {
61 this.videoChangeOwnerships = resultList.data.map(change => ({
62 ...change,
63 initiatorAccount: new Account(change.initiatorAccount),
64 nextOwnerAccount: new Account(change.nextOwnerAccount)
65 }))
66 this.totalRecords = resultList.total
67 },
68
69 err => this.notifier.error(err.message)
70 )
71 }
72 }