]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-ownership/my-ownership.component.ts
Fix client lint
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-ownership / my-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'
c418d483 4import { Account, VideoOwnershipService } from '@app/shared/shared-main'
4f5d0459 5import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '@shared/models'
17119e4a 6import { MyAcceptOwnershipComponent } from './my-accept-ownership/my-accept-ownership.component'
74d63469
GR
7
8@Component({
17119e4a
C
9 templateUrl: './my-ownership.component.html',
10 styleUrls: [ './my-ownership.component.scss' ]
74d63469 11})
17119e4a 12export class MyOwnershipComponent extends RestTable implements OnInit {
74d63469
GR
13 videoChangeOwnerships: VideoChangeOwnership[] = []
14 totalRecords = 0
74d63469
GR
15 sort: SortMeta = { field: 'createdAt', order: -1 }
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
17
17119e4a 18 @ViewChild('myAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAcceptOwnershipComponent
74d63469
GR
19
20 constructor (
f8b2c1b4
C
21 private notifier: Notifier,
22 private videoOwnershipService: VideoOwnershipService
74d63469
GR
23 ) {
24 super()
25 }
26
27 ngOnInit () {
24b9417c 28 this.initialize()
74d63469
GR
29 }
30
8e11a1b3 31 getIdentifier () {
17119e4a 32 return 'MyOwnershipComponent'
8e11a1b3
C
33 }
34
4f5d0459
RK
35 getStatusClass (status: VideoChangeOwnershipStatus) {
36 switch (status) {
37 case VideoChangeOwnershipStatus.ACCEPTED:
38 return 'badge-green'
39 case VideoChangeOwnershipStatus.REFUSED:
40 return 'badge-red'
41 default:
42 return 'badge-yellow'
43 }
44 }
45
74d63469
GR
46 openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
47 this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership)
48 }
49
50 accepted () {
2e46eb97 51 this.reloadData()
74d63469
GR
52 }
53
54 refuse (videoChangeOwnership: VideoChangeOwnership) {
55 this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id)
1378c0d3
C
56 .subscribe({
57 next: () => this.reloadData(),
58 error: err => this.notifier.error(err.message)
59 })
74d63469 60 }
dffd5d12 61
2e46eb97 62 protected reloadData () {
dffd5d12 63 return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort)
1378c0d3
C
64 .subscribe({
65 next: resultList => {
4c9e9d2e
RK
66 this.videoChangeOwnerships = resultList.data.map(change => ({
67 ...change,
68 initiatorAccount: new Account(change.initiatorAccount),
69 nextOwnerAccount: new Account(change.nextOwnerAccount)
70 }))
dffd5d12
B
71 this.totalRecords = resultList.total
72 },
73
1378c0d3
C
74 error: err => this.notifier.error(err.message)
75 })
dffd5d12 76 }
74d63469 77}