]>
Commit | Line | Data |
---|---|---|
74d63469 | 1 | import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { AuthService, Notifier } from '@app/core' |
7ed1edbb C |
3 | import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators' |
4 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
67ed6552 | 5 | import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main' |
74d63469 | 6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
67ed6552 | 7 | import { VideoChangeOwnership, VideoChannel } from '@shared/models' |
74d63469 GR |
8 | |
9 | @Component({ | |
17119e4a C |
10 | selector: 'my-accept-ownership', |
11 | templateUrl: './my-accept-ownership.component.html', | |
12 | styleUrls: [ './my-accept-ownership.component.scss' ] | |
74d63469 | 13 | }) |
17119e4a | 14 | export class MyAcceptOwnershipComponent extends FormReactive implements OnInit { |
74d63469 GR |
15 | @Output() accepted = new EventEmitter<void>() |
16 | ||
f36da21e | 17 | @ViewChild('modal', { static: true }) modal: ElementRef |
74d63469 GR |
18 | |
19 | videoChangeOwnership: VideoChangeOwnership | undefined = undefined | |
20 | ||
21 | videoChannels: VideoChannel[] | |
22 | ||
23 | error: string = null | |
24 | ||
25 | constructor ( | |
26 | protected formValidatorService: FormValidatorService, | |
74d63469 | 27 | private videoOwnershipService: VideoOwnershipService, |
f8b2c1b4 | 28 | private notifier: Notifier, |
74d63469 GR |
29 | private authService: AuthService, |
30 | private videoChannelService: VideoChannelService, | |
66357162 C |
31 | private modalService: NgbModal |
32 | ) { | |
74d63469 GR |
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({ | |
7ed1edbb | 43 | channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR |
74d63469 GR |
44 | }) |
45 | } | |
46 | ||
47 | show (videoChangeOwnership: VideoChangeOwnership) { | |
48 | this.videoChangeOwnership = videoChangeOwnership | |
49 | this.modalService | |
24e7916c | 50 | .open(this.modal, { centered: true }) |
74d63469 GR |
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 | () => { | |
66357162 | 64 | this.notifier.success($localize`Ownership accepted`) |
74d63469 GR |
65 | if (this.accepted) this.accepted.emit() |
66 | this.videoChangeOwnership = undefined | |
67 | }, | |
68 | ||
f8b2c1b4 | 69 | err => this.notifier.error(err.message) |
74d63469 GR |
70 | ) |
71 | } | |
72 | } |