1 import { SelectChannelItem } from 'src/types/select-options-item.model'
2 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
3 import { AuthService, Notifier } from '@app/core'
4 import { listUserChannelsForSelect } from '@app/helpers'
5 import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
7 import { VideoOwnershipService } from '@app/shared/shared-main'
8 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
9 import { VideoChangeOwnership } from '@shared/models'
12 selector: 'my-accept-ownership',
13 templateUrl: './my-accept-ownership.component.html',
14 styleUrls: [ './my-accept-ownership.component.scss' ]
16 export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
17 @Output() accepted = new EventEmitter<void>()
19 @ViewChild('modal', { static: true }) modal: ElementRef
21 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
22 videoChannels: SelectChannelItem[]
27 protected formValidatorService: FormValidatorService,
28 private videoOwnershipService: VideoOwnershipService,
29 private notifier: Notifier,
30 private authService: AuthService,
31 private modalService: NgbModal
37 this.videoChannels = []
39 listUserChannelsForSelect(this.authService)
40 .subscribe(channels => this.videoChannels = channels)
43 channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR
47 show (videoChangeOwnership: VideoChangeOwnership) {
48 // Select the first available channel by default
49 this.form.patchValue({
50 channel: this.videoChannels[0].id
53 this.videoChangeOwnership = videoChangeOwnership
55 .open(this.modal, { centered: true })
57 .then(() => this.acceptOwnership())
58 .catch(() => this.videoChangeOwnership = undefined)
62 const channel = this.form.value['channel']
64 const videoChangeOwnership = this.videoChangeOwnership
65 this.videoOwnershipService
66 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
69 this.notifier.success($localize`Ownership accepted`)
70 if (this.accepted) this.accepted.emit()
71 this.videoChangeOwnership = undefined
74 error: err => this.notifier.error(err.message)