]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts
Handle .srt subtitles
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / shared / video-caption-add-modal.component.ts
1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { ModalDirective } from 'ngx-bootstrap/modal'
3 import { FormReactive } from '@app/shared'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service'
6 import { ServerService } from '@app/core'
7 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
8
9 @Component({
10 selector: 'my-video-caption-add-modal',
11 styleUrls: [ './video-caption-add-modal.component.scss' ],
12 templateUrl: './video-caption-add-modal.component.html'
13 })
14
15 export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
16 @Input() existingCaptions: string[]
17
18 @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
19
20 @ViewChild('modal') modal: ModalDirective
21
22 videoCaptionLanguages = []
23
24 private closingModal = false
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 private serverService: ServerService,
29 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
30 ) {
31 super()
32 }
33
34 get videoCaptionExtensions () {
35 return this.serverService.getConfig().videoCaption.file.extensions
36 }
37
38 get videoCaptionMaxSize () {
39 return this.serverService.getConfig().videoCaption.file.size.max
40 }
41
42 ngOnInit () {
43 this.videoCaptionLanguages = this.serverService.getVideoLanguages()
44
45 this.buildForm({
46 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
47 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
48 })
49 }
50
51 show () {
52 this.closingModal = false
53
54 this.modal.show()
55 }
56
57 hide () {
58 this.closingModal = true
59
60 this.modal.hide()
61 }
62
63 isReplacingExistingCaption () {
64 if (this.closingModal === true) return false
65
66 const languageId = this.form.value[ 'language' ]
67
68 return languageId && this.existingCaptions.indexOf(languageId) !== -1
69 }
70
71 async addCaption () {
72 this.hide()
73
74 const languageId = this.form.value[ 'language' ]
75 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
76
77 this.captionAdded.emit({
78 language: languageObject,
79 captionfile: this.form.value['captionfile']
80 })
81 //
82 // this.form.patchValue({
83 // language: null,
84 // captionfile: null
85 // })
86
87 this.form.reset()
88 }
89 }