diff options
Diffstat (limited to 'client/src/app/+my-library/my-ownership/my-ownership.component.ts')
-rw-r--r-- | client/src/app/+my-library/my-ownership/my-ownership.component.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/client/src/app/+my-library/my-ownership/my-ownership.component.ts b/client/src/app/+my-library/my-ownership/my-ownership.component.ts new file mode 100644 index 000000000..e1aca65f6 --- /dev/null +++ b/client/src/app/+my-library/my-ownership/my-ownership.component.ts | |||
@@ -0,0 +1,81 @@ | |||
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, Actor, 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 | switchToDefaultAvatar ($event: Event) { | ||
47 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | ||
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(), | ||
62 | err => this.notifier.error(err.message) | ||
63 | ) | ||
64 | } | ||
65 | |||
66 | protected loadData () { | ||
67 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | ||
68 | .subscribe( | ||
69 | resultList => { | ||
70 | this.videoChangeOwnerships = resultList.data.map(change => ({ | ||
71 | ...change, | ||
72 | initiatorAccount: new Account(change.initiatorAccount), | ||
73 | nextOwnerAccount: new Account(change.nextOwnerAccount) | ||
74 | })) | ||
75 | this.totalRecords = resultList.total | ||
76 | }, | ||
77 | |||
78 | err => this.notifier.error(err.message) | ||
79 | ) | ||
80 | } | ||
81 | } | ||