]>
Commit | Line | Data |
---|---|---|
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' | |
7 | ||
8 | @Component({ | |
9 | templateUrl: './my-ownership.component.html', | |
10 | styleUrls: [ './my-ownership.component.scss' ] | |
11 | }) | |
12 | export class MyOwnershipComponent extends RestTable implements OnInit { | |
13 | videoChangeOwnerships: VideoChangeOwnership[] = [] | |
14 | totalRecords = 0 | |
15 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
16 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
17 | ||
18 | @ViewChild('myAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAcceptOwnershipComponent | |
19 | ||
20 | constructor ( | |
21 | private notifier: Notifier, | |
22 | private videoOwnershipService: VideoOwnershipService | |
23 | ) { | |
24 | super() | |
25 | } | |
26 | ||
27 | ngOnInit () { | |
28 | this.initialize() | |
29 | } | |
30 | ||
31 | getIdentifier () { | |
32 | return 'MyOwnershipComponent' | |
33 | } | |
34 | ||
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 | ||
46 | openAcceptModal (videoChangeOwnership: VideoChangeOwnership) { | |
47 | this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership) | |
48 | } | |
49 | ||
50 | accepted () { | |
51 | this.reloadData() | |
52 | } | |
53 | ||
54 | refuse (videoChangeOwnership: VideoChangeOwnership) { | |
55 | this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) | |
56 | .subscribe( | |
57 | () => this.reloadData(), | |
58 | err => this.notifier.error(err.message) | |
59 | ) | |
60 | } | |
61 | ||
62 | protected reloadData () { | |
63 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | |
64 | .subscribe( | |
65 | resultList => { | |
66 | this.videoChangeOwnerships = resultList.data.map(change => ({ | |
67 | ...change, | |
68 | initiatorAccount: new Account(change.initiatorAccount), | |
69 | nextOwnerAccount: new Account(change.nextOwnerAccount) | |
70 | })) | |
71 | this.totalRecords = resultList.total | |
72 | }, | |
73 | ||
74 | err => this.notifier.error(err.message) | |
75 | ) | |
76 | } | |
77 | } |