]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
Update angular to fix localize extraction bug
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-ownership / my-account-ownership.component.ts
CommitLineData
f77eb73b 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit, ViewChild } from '@angular/core'
3import { Notifier, RestPagination, RestTable } from '@app/core'
4c9e9d2e 4import { VideoOwnershipService, Actor, Video, Account } from '@app/shared/shared-main'
4f5d0459 5import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '@shared/models'
f8b2c1b4 6import { MyAccountAcceptOwnershipComponent } from './my-account-accept-ownership/my-account-accept-ownership.component'
4c9e9d2e 7import { getAbsoluteAPIUrl } from '@app/helpers'
74d63469
GR
8
9@Component({
10 selector: 'my-account-ownership',
4c9e9d2e
RK
11 templateUrl: './my-account-ownership.component.html',
12 styleUrls: [ './my-account-ownership.component.scss' ]
74d63469
GR
13})
14export class MyAccountOwnershipComponent extends RestTable implements OnInit {
15 videoChangeOwnerships: VideoChangeOwnership[] = []
16 totalRecords = 0
74d63469
GR
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
f36da21e 20 @ViewChild('myAccountAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent
74d63469
GR
21
22 constructor (
f8b2c1b4
C
23 private notifier: Notifier,
24 private videoOwnershipService: VideoOwnershipService
74d63469
GR
25 ) {
26 super()
27 }
28
29 ngOnInit () {
24b9417c 30 this.initialize()
74d63469
GR
31 }
32
8e11a1b3
C
33 getIdentifier () {
34 return 'MyAccountOwnershipComponent'
35 }
36
4f5d0459
RK
37 getStatusClass (status: VideoChangeOwnershipStatus) {
38 switch (status) {
39 case VideoChangeOwnershipStatus.ACCEPTED:
40 return 'badge-green'
41 case VideoChangeOwnershipStatus.REFUSED:
42 return 'badge-red'
43 default:
44 return 'badge-yellow'
45 }
46 }
47
4c9e9d2e
RK
48 switchToDefaultAvatar ($event: Event) {
49 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
74d63469
GR
50 }
51
52 openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
53 this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership)
54 }
55
56 accepted () {
57 this.loadData()
58 }
59
60 refuse (videoChangeOwnership: VideoChangeOwnership) {
61 this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id)
62 .subscribe(
63 () => this.loadData(),
f8b2c1b4 64 err => this.notifier.error(err.message)
74d63469
GR
65 )
66 }
dffd5d12
B
67
68 protected loadData () {
69 return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort)
70 .subscribe(
71 resultList => {
4c9e9d2e
RK
72 this.videoChangeOwnerships = resultList.data.map(change => ({
73 ...change,
74 initiatorAccount: new Account(change.initiatorAccount),
75 nextOwnerAccount: new Account(change.nextOwnerAccount)
76 }))
dffd5d12
B
77 this.totalRecords = resultList.total
78 },
79
f8b2c1b4 80 err => this.notifier.error(err.message)
dffd5d12
B
81 )
82 }
74d63469 83}