diff options
Diffstat (limited to 'client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts')
-rw-r--r-- | client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts b/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts new file mode 100644 index 000000000..587a455f0 --- /dev/null +++ b/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts | |||
@@ -0,0 +1,72 @@ | |||
1 | import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { AuthService, Notifier } from '@app/core' | ||
3 | import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators' | ||
4 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | ||
5 | import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main' | ||
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
7 | import { VideoChangeOwnership, VideoChannel } from '@shared/models' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-accept-ownership', | ||
11 | templateUrl: './my-accept-ownership.component.html', | ||
12 | styleUrls: [ './my-accept-ownership.component.scss' ] | ||
13 | }) | ||
14 | export class MyAcceptOwnershipComponent extends FormReactive implements OnInit { | ||
15 | @Output() accepted = new EventEmitter<void>() | ||
16 | |||
17 | @ViewChild('modal', { static: true }) modal: ElementRef | ||
18 | |||
19 | videoChangeOwnership: VideoChangeOwnership | undefined = undefined | ||
20 | |||
21 | videoChannels: VideoChannel[] | ||
22 | |||
23 | error: string = null | ||
24 | |||
25 | constructor ( | ||
26 | protected formValidatorService: FormValidatorService, | ||
27 | private videoOwnershipService: VideoOwnershipService, | ||
28 | private notifier: Notifier, | ||
29 | private authService: AuthService, | ||
30 | private videoChannelService: VideoChannelService, | ||
31 | private modalService: NgbModal | ||
32 | ) { | ||
33 | super() | ||
34 | } | ||
35 | |||
36 | ngOnInit () { | ||
37 | this.videoChannels = [] | ||
38 | |||
39 | this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account) | ||
40 | .subscribe(videoChannels => this.videoChannels = videoChannels.data) | ||
41 | |||
42 | this.buildForm({ | ||
43 | channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | show (videoChangeOwnership: VideoChangeOwnership) { | ||
48 | this.videoChangeOwnership = videoChangeOwnership | ||
49 | this.modalService | ||
50 | .open(this.modal, { centered: true }) | ||
51 | .result | ||
52 | .then(() => this.acceptOwnership()) | ||
53 | .catch(() => this.videoChangeOwnership = undefined) | ||
54 | } | ||
55 | |||
56 | acceptOwnership () { | ||
57 | const channel = this.form.value['channel'] | ||
58 | |||
59 | const videoChangeOwnership = this.videoChangeOwnership | ||
60 | this.videoOwnershipService | ||
61 | .acceptOwnership(videoChangeOwnership.id, { channelId: channel }) | ||
62 | .subscribe( | ||
63 | () => { | ||
64 | this.notifier.success($localize`Ownership accepted`) | ||
65 | if (this.accepted) this.accepted.emit() | ||
66 | this.videoChangeOwnership = undefined | ||
67 | }, | ||
68 | |||
69 | err => this.notifier.error(err.message) | ||
70 | ) | ||
71 | } | ||
72 | } | ||