]>
Commit | Line | Data |
---|---|---|
2989628b | 1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
27ec473f | 2 | import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser' |
cdeddff1 C |
3 | import { Notifier, ServerService } from '@app/core' |
4 | import { VideoChannel } from '@app/shared/shared-main' | |
5 | import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' | |
6 | import { getBytes } from '@root-helpers/bytes' | |
7 | ||
8 | @Component({ | |
9 | selector: 'my-actor-banner-edit', | |
10 | templateUrl: './actor-banner-edit.component.html', | |
11 | styleUrls: [ | |
12 | './actor-image-edit.scss', | |
13 | './actor-banner-edit.component.scss' | |
14 | ] | |
15 | }) | |
16 | export class ActorBannerEditComponent implements OnInit { | |
17 | @ViewChild('bannerfileInput') bannerfileInput: ElementRef<HTMLInputElement> | |
18 | @ViewChild('bannerPopover') bannerPopover: NgbPopover | |
19 | ||
20 | @Input() actor: VideoChannel | |
27ec473f | 21 | @Input() previewImage = false |
cdeddff1 C |
22 | |
23 | @Output() bannerChange = new EventEmitter<FormData>() | |
24 | @Output() bannerDelete = new EventEmitter<void>() | |
25 | ||
26 | bannerFormat = '' | |
27 | maxBannerSize = 0 | |
28 | bannerExtensions = '' | |
29 | ||
27ec473f C |
30 | preview: SafeResourceUrl |
31 | ||
cdeddff1 | 32 | constructor ( |
27ec473f | 33 | private sanitizer: DomSanitizer, |
cdeddff1 C |
34 | private serverService: ServerService, |
35 | private notifier: Notifier | |
36 | ) { } | |
37 | ||
38 | ngOnInit (): void { | |
2989628b C |
39 | const config = this.serverService.getHTMLConfig() |
40 | this.maxBannerSize = config.banner.file.size.max | |
41 | this.bannerExtensions = config.banner.file.extensions.join(', ') | |
cdeddff1 | 42 | |
2989628b C |
43 | // tslint:disable:max-line-length |
44 | this.bannerFormat = $localize`ratio 6/1, recommended size: 1920x317, max size: ${getBytes(this.maxBannerSize)}, extensions: ${this.bannerExtensions}` | |
cdeddff1 C |
45 | } |
46 | ||
47 | onBannerChange (input: HTMLInputElement) { | |
48 | this.bannerfileInput = new ElementRef(input) | |
49 | ||
50 | const bannerfile = this.bannerfileInput.nativeElement.files[ 0 ] | |
51 | if (bannerfile.size > this.maxBannerSize) { | |
52 | this.notifier.error('Error', $localize`This image is too large.`) | |
53 | return | |
54 | } | |
55 | ||
56 | const formData = new FormData() | |
57 | formData.append('bannerfile', bannerfile) | |
58 | this.bannerPopover?.close() | |
59 | this.bannerChange.emit(formData) | |
27ec473f C |
60 | |
61 | if (this.previewImage) { | |
62 | this.preview = this.sanitizer.bypassSecurityTrustResourceUrl(URL.createObjectURL(bannerfile)) | |
63 | } | |
cdeddff1 C |
64 | } |
65 | ||
66 | deleteBanner () { | |
27ec473f | 67 | this.preview = undefined |
cdeddff1 C |
68 | this.bannerDelete.emit() |
69 | } | |
70 | ||
71 | hasBanner () { | |
27ec473f | 72 | return !!this.preview || !!this.actor.bannerUrl |
cdeddff1 C |
73 | } |
74 | } |