diff options
Diffstat (limited to 'client/src/app/shared/shared-actor-image/actor-banner-edit.component.ts')
-rw-r--r-- | client/src/app/shared/shared-actor-image/actor-banner-edit.component.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-actor-image/actor-banner-edit.component.ts b/client/src/app/shared/shared-actor-image/actor-banner-edit.component.ts new file mode 100644 index 000000000..b92ecef4b --- /dev/null +++ b/client/src/app/shared/shared-actor-image/actor-banner-edit.component.ts | |||
@@ -0,0 +1,65 @@ | |||
1 | import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core' | ||
2 | import { Notifier, ServerService } from '@app/core' | ||
3 | import { VideoChannel } from '@app/shared/shared-main' | ||
4 | import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { getBytes } from '@root-helpers/bytes' | ||
6 | |||
7 | @Component({ | ||
8 | selector: 'my-actor-banner-edit', | ||
9 | templateUrl: './actor-banner-edit.component.html', | ||
10 | styleUrls: [ | ||
11 | './actor-image-edit.scss', | ||
12 | './actor-banner-edit.component.scss' | ||
13 | ] | ||
14 | }) | ||
15 | export class ActorBannerEditComponent implements OnInit { | ||
16 | @ViewChild('bannerfileInput') bannerfileInput: ElementRef<HTMLInputElement> | ||
17 | @ViewChild('bannerPopover') bannerPopover: NgbPopover | ||
18 | |||
19 | @Input() actor: VideoChannel | ||
20 | |||
21 | @Output() bannerChange = new EventEmitter<FormData>() | ||
22 | @Output() bannerDelete = new EventEmitter<void>() | ||
23 | |||
24 | bannerFormat = '' | ||
25 | maxBannerSize = 0 | ||
26 | bannerExtensions = '' | ||
27 | |||
28 | constructor ( | ||
29 | private serverService: ServerService, | ||
30 | private notifier: Notifier | ||
31 | ) { } | ||
32 | |||
33 | ngOnInit (): void { | ||
34 | this.serverService.getConfig() | ||
35 | .subscribe(config => { | ||
36 | this.maxBannerSize = config.banner.file.size.max | ||
37 | this.bannerExtensions = config.banner.file.extensions.join(', ') | ||
38 | |||
39 | this.bannerFormat = $localize`maxsize: ${getBytes(this.maxBannerSize)}, extensions: ${this.bannerExtensions}` | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | onBannerChange (input: HTMLInputElement) { | ||
44 | this.bannerfileInput = new ElementRef(input) | ||
45 | |||
46 | const bannerfile = this.bannerfileInput.nativeElement.files[ 0 ] | ||
47 | if (bannerfile.size > this.maxBannerSize) { | ||
48 | this.notifier.error('Error', $localize`This image is too large.`) | ||
49 | return | ||
50 | } | ||
51 | |||
52 | const formData = new FormData() | ||
53 | formData.append('bannerfile', bannerfile) | ||
54 | this.bannerPopover?.close() | ||
55 | this.bannerChange.emit(formData) | ||
56 | } | ||
57 | |||
58 | deleteBanner () { | ||
59 | this.bannerDelete.emit() | ||
60 | } | ||
61 | |||
62 | hasBanner () { | ||
63 | return !!this.actor.bannerUrl | ||
64 | } | ||
65 | } | ||