1 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { AuthService, Notifier } from '@app/core'
3 import { FormReactive, FormValidatorService, VideoAcceptOwnershipValidatorsService } from '@app/shared/shared-forms'
4 import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { VideoChangeOwnership, VideoChannel } from '@shared/models'
10 selector: 'my-account-accept-ownership',
11 templateUrl: './my-account-accept-ownership.component.html',
12 styleUrls: [ './my-account-accept-ownership.component.scss' ]
14 export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
15 @Output() accepted = new EventEmitter<void>()
17 @ViewChild('modal', { static: true }) modal: ElementRef
19 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
21 videoChannels: VideoChannel[]
26 protected formValidatorService: FormValidatorService,
27 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
28 private videoOwnershipService: VideoOwnershipService,
29 private notifier: Notifier,
30 private authService: AuthService,
31 private videoChannelService: VideoChannelService,
32 private modalService: NgbModal,
39 this.videoChannels = []
41 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
42 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
45 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
49 show (videoChangeOwnership: VideoChangeOwnership) {
50 this.videoChangeOwnership = videoChangeOwnership
52 .open(this.modal, { centered: true })
54 .then(() => this.acceptOwnership())
55 .catch(() => this.videoChangeOwnership = undefined)
59 const channel = this.form.value['channel']
61 const videoChangeOwnership = this.videoChangeOwnership
62 this.videoOwnershipService
63 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
66 this.notifier.success(this.i18n('Ownership accepted'))
67 if (this.accepted) this.accepted.emit()
68 this.videoChangeOwnership = undefined
71 err => this.notifier.error(err.message)