]>
Commit | Line | Data |
---|---|---|
f77eb73b | 1 | import { SortMeta } from 'primeng/api' |
67ed6552 C |
2 | import { Component, OnInit, ViewChild } from '@angular/core' |
3 | import { Notifier, RestPagination, RestTable } from '@app/core' | |
c418d483 | 4 | import { Account, VideoOwnershipService } from '@app/shared/shared-main' |
4f5d0459 | 5 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '@shared/models' |
17119e4a | 6 | import { 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 | 12 | export 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 () { | |
51 | this.loadData() | |
52 | } | |
53 | ||
54 | refuse (videoChangeOwnership: VideoChangeOwnership) { | |
55 | this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) | |
56 | .subscribe( | |
57 | () => this.loadData(), | |
f8b2c1b4 | 58 | err => this.notifier.error(err.message) |
74d63469 GR |
59 | ) |
60 | } | |
dffd5d12 B |
61 | |
62 | protected loadData () { | |
63 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | |
64 | .subscribe( | |
65 | 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 | ||
f8b2c1b4 | 74 | err => this.notifier.error(err.message) |
dffd5d12 B |
75 | ) |
76 | } | |
74d63469 | 77 | } |