]>
Commit | Line | Data |
---|---|---|
1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | |
2 | import { ServerService } from '@app/core' | |
3 | import { VIDEO_CAPTION_FILE_VALIDATOR, VIDEO_CAPTION_LANGUAGE_VALIDATOR } from '@app/shared/form-validators/video-captions-validators' | |
4 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' | |
5 | import { VideoCaptionEdit } from '@app/shared/shared-main' | |
6 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' | |
7 | import { HTMLServerConfig, VideoConstant } from '@shared/models' | |
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 | @Input() serverConfig: HTMLServerConfig | |
18 | ||
19 | @Output() captionAdded = new EventEmitter<VideoCaptionEdit>() | |
20 | ||
21 | @ViewChild('modal', { static: true }) modal: ElementRef | |
22 | ||
23 | videoCaptionLanguages: VideoConstant<string>[] = [] | |
24 | ||
25 | private openedModal: NgbModalRef | |
26 | private closingModal = false | |
27 | ||
28 | constructor ( | |
29 | protected formReactiveService: FormReactiveService, | |
30 | private modalService: NgbModal, | |
31 | private serverService: ServerService | |
32 | ) { | |
33 | super() | |
34 | } | |
35 | ||
36 | get videoCaptionExtensions () { | |
37 | return this.serverConfig.videoCaption.file.extensions | |
38 | } | |
39 | ||
40 | get videoCaptionMaxSize () { | |
41 | return this.serverConfig.videoCaption.file.size.max | |
42 | } | |
43 | ||
44 | getReactiveFileButtonTooltip () { | |
45 | return `(extensions: ${this.videoCaptionExtensions.join(', ')})` | |
46 | } | |
47 | ||
48 | ngOnInit () { | |
49 | this.serverService.getVideoLanguages() | |
50 | .subscribe(languages => this.videoCaptionLanguages = languages) | |
51 | ||
52 | this.buildForm({ | |
53 | language: VIDEO_CAPTION_LANGUAGE_VALIDATOR, | |
54 | captionfile: VIDEO_CAPTION_FILE_VALIDATOR | |
55 | }) | |
56 | } | |
57 | ||
58 | show () { | |
59 | this.closingModal = false | |
60 | ||
61 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false }) | |
62 | } | |
63 | ||
64 | hide () { | |
65 | this.closingModal = true | |
66 | this.openedModal.close() | |
67 | this.form.reset() | |
68 | } | |
69 | ||
70 | isReplacingExistingCaption () { | |
71 | if (this.closingModal === true) return false | |
72 | ||
73 | const languageId = this.form.value['language'] | |
74 | ||
75 | return languageId && this.existingCaptions.includes(languageId) | |
76 | } | |
77 | ||
78 | addCaption () { | |
79 | const languageId = this.form.value['language'] | |
80 | const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId) | |
81 | ||
82 | this.captionAdded.emit({ | |
83 | language: languageObject, | |
84 | captionfile: this.form.value['captionfile'], | |
85 | action: 'CREATE' | |
86 | }) | |
87 | ||
88 | this.hide() | |
89 | } | |
90 | } |