1 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { AuthService, Notifier } from '@app/core'
3 import { FormReactive } from '@app/shared'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { VideoOwnershipService } from '@app/shared/video-ownership'
6 import { VideoChangeOwnership } from '../../../../../../shared/models/videos'
7 import { VideoAcceptOwnershipValidatorsService } from '@app/shared/forms/form-validators'
8 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
10 import { I18n } from '@ngx-translate/i18n-polyfill'
11 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
14 selector: 'my-account-accept-ownership',
15 templateUrl: './my-account-accept-ownership.component.html',
16 styleUrls: [ './my-account-accept-ownership.component.scss' ]
18 export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
19 @Output() accepted = new EventEmitter<void>()
21 @ViewChild('modal', { static: true }) modal: ElementRef
23 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
25 videoChannels: VideoChannel[]
30 protected formValidatorService: FormValidatorService,
31 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
32 private videoOwnershipService: VideoOwnershipService,
33 private notifier: Notifier,
34 private authService: AuthService,
35 private videoChannelService: VideoChannelService,
36 private modalService: NgbModal,
43 this.videoChannels = []
45 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
46 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
49 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
53 show (videoChangeOwnership: VideoChangeOwnership) {
54 this.videoChangeOwnership = videoChangeOwnership
58 .then(() => this.acceptOwnership())
59 .catch(() => this.videoChangeOwnership = undefined)
63 const channel = this.form.value['channel']
65 const videoChangeOwnership = this.videoChangeOwnership
66 this.videoOwnershipService
67 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
70 this.notifier.success(this.i18n('Ownership accepted'))
71 if (this.accepted) this.accepted.emit()
72 this.videoChangeOwnership = undefined
75 err => this.notifier.error(err.message)