]>
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' | |
17119e4a | 4 | import { Account, Actor, 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 | ||
4c9e9d2e RK |
46 | switchToDefaultAvatar ($event: Event) { |
47 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | |
74d63469 GR |
48 | } |
49 | ||
50 | openAcceptModal (videoChangeOwnership: VideoChangeOwnership) { | |
51 | this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership) | |
52 | } | |
53 | ||
54 | accepted () { | |
55 | this.loadData() | |
56 | } | |
57 | ||
58 | refuse (videoChangeOwnership: VideoChangeOwnership) { | |
59 | this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) | |
60 | .subscribe( | |
61 | () => this.loadData(), | |
f8b2c1b4 | 62 | err => this.notifier.error(err.message) |
74d63469 GR |
63 | ) |
64 | } | |
dffd5d12 B |
65 | |
66 | protected loadData () { | |
67 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | |
68 | .subscribe( | |
69 | resultList => { | |
4c9e9d2e RK |
70 | this.videoChangeOwnerships = resultList.data.map(change => ({ |
71 | ...change, | |
72 | initiatorAccount: new Account(change.initiatorAccount), | |
73 | nextOwnerAccount: new Account(change.nextOwnerAccount) | |
74 | })) | |
dffd5d12 B |
75 | this.totalRecords = resultList.total |
76 | }, | |
77 | ||
f8b2c1b4 | 78 | err => this.notifier.error(err.message) |
dffd5d12 B |
79 | ) |
80 | } | |
74d63469 | 81 | } |