1 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { FormReactive } from '@app/shared'
3 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
4 import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service'
5 import { ServerService } from '@app/core'
6 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
7 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
8 import { ServerConfig, VideoConstant } from '../../../../../../shared'
11 selector: 'my-video-caption-add-modal',
12 styleUrls: [ './video-caption-add-modal.component.scss' ],
13 templateUrl: './video-caption-add-modal.component.html'
16 export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
17 @Input() existingCaptions: string[]
18 @Input() serverConfig: ServerConfig
20 @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
22 @ViewChild('modal', { static: true }) modal: ElementRef
24 videoCaptionLanguages: VideoConstant<string>[] = []
26 private openedModal: NgbModalRef
27 private closingModal = false
30 protected formValidatorService: FormValidatorService,
31 private modalService: NgbModal,
32 private serverService: ServerService,
33 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
38 get videoCaptionExtensions () {
39 return this.serverConfig.videoCaption.file.extensions
42 get videoCaptionMaxSize () {
43 return this.serverConfig.videoCaption.file.size.max
47 this.serverService.getVideoLanguages()
48 .subscribe(languages => this.videoCaptionLanguages = languages)
51 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
52 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
57 this.closingModal = false
59 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
63 this.closingModal = true
64 this.openedModal.close()
68 isReplacingExistingCaption () {
69 if (this.closingModal === true) return false
71 const languageId = this.form.value[ 'language' ]
73 return languageId && this.existingCaptions.indexOf(languageId) !== -1
77 const languageId = this.form.value[ 'language' ]
78 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
80 this.captionAdded.emit({
81 language: languageObject,
82 captionfile: this.form.value[ 'captionfile' ]