aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/forms/reactive-file.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-12 19:02:00 +0200
committerChocobozzz <me@florianbigard.com>2018-07-16 11:50:08 +0200
commit40e87e9ecc54e3513fb586928330a7855eb192c6 (patch)
treeaf1111ecba85f9cd8286811ff332a67cf21be2f6 /client/src/app/shared/forms/reactive-file.component.ts
parentd4557fd3ecc8d4ed4fb0e5c868929bc36c959ed2 (diff)
downloadPeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.gz
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.zst
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.zip
Implement captions/subtitles
Diffstat (limited to 'client/src/app/shared/forms/reactive-file.component.ts')
-rw-r--r--client/src/app/shared/forms/reactive-file.component.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/client/src/app/shared/forms/reactive-file.component.ts b/client/src/app/shared/forms/reactive-file.component.ts
new file mode 100644
index 000000000..f5758b643
--- /dev/null
+++ b/client/src/app/shared/forms/reactive-file.component.ts
@@ -0,0 +1,75 @@
1import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { NotificationsService } from 'angular2-notifications'
4import { I18n } from '@ngx-translate/i18n-polyfill'
5
6@Component({
7 selector: 'my-reactive-file',
8 styleUrls: [ './reactive-file.component.scss' ],
9 templateUrl: './reactive-file.component.html',
10 providers: [
11 {
12 provide: NG_VALUE_ACCESSOR,
13 useExisting: forwardRef(() => ReactiveFileComponent),
14 multi: true
15 }
16 ]
17})
18export class ReactiveFileComponent implements OnInit, ControlValueAccessor {
19 @Input() inputLabel: string
20 @Input() inputName: string
21 @Input() extensions: string[] = []
22 @Input() maxFileSize: number
23 @Input() displayFilename = false
24
25 @Output() fileChanged = new EventEmitter<Blob>()
26
27 allowedExtensionsMessage = ''
28
29 private file: File
30
31 constructor (
32 private notificationsService: NotificationsService,
33 private i18n: I18n
34 ) {}
35
36 get filename () {
37 if (!this.file) return ''
38
39 return this.file.name
40 }
41
42 ngOnInit () {
43 this.allowedExtensionsMessage = this.extensions.join(', ')
44 }
45
46 fileChange (event: any) {
47 if (event.target.files && event.target.files.length) {
48 const [ file ] = event.target.files
49
50 if (file.size > this.maxFileSize) {
51 this.notificationsService.error(this.i18n('Error'), this.i18n('This file is too large.'))
52 return
53 }
54
55 this.file = file
56
57 this.propagateChange(this.file)
58 this.fileChanged.emit(this.file)
59 }
60 }
61
62 propagateChange = (_: any) => { /* empty */ }
63
64 writeValue (file: any) {
65 this.file = file
66 }
67
68 registerOnChange (fn: (_: any) => void) {
69 this.propagateChange = fn
70 }
71
72 registerOnTouched () {
73 // Unused
74 }
75}