1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { Account, VideoOwnershipService } from '@app/shared/shared-main'
5 import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '@shared/models'
6 import { MyAcceptOwnershipComponent } from './my-accept-ownership/my-accept-ownership.component'
9 templateUrl: './my-ownership.component.html',
10 styleUrls: [ './my-ownership.component.scss' ]
12 export class MyOwnershipComponent extends RestTable implements OnInit {
13 videoChangeOwnerships: VideoChangeOwnership[] = []
15 sort: SortMeta = { field: 'createdAt', order: -1 }
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
18 @ViewChild('myAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAcceptOwnershipComponent
21 private notifier: Notifier,
22 private videoOwnershipService: VideoOwnershipService
32 return 'MyOwnershipComponent'
35 getStatusClass (status: VideoChangeOwnershipStatus) {
37 case VideoChangeOwnershipStatus.ACCEPTED:
39 case VideoChangeOwnershipStatus.REFUSED:
46 switchToDefaultAvatar ($event: Event) {
47 ($event.target as HTMLImageElement).src = Account.GET_DEFAULT_AVATAR_URL()
50 openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
51 this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership)
58 refuse (videoChangeOwnership: VideoChangeOwnership) {
59 this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id)
61 () => this.loadData(),
62 err => this.notifier.error(err.message)
66 protected loadData () {
67 return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort)
70 this.videoChangeOwnerships = resultList.data.map(change => ({
72 initiatorAccount: new Account(change.initiatorAccount),
73 nextOwnerAccount: new Account(change.nextOwnerAccount)
75 this.totalRecords = resultList.total
78 err => this.notifier.error(err.message)