]>
Commit | Line | Data |
---|---|---|
52d9f792 | 1 | import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core' |
52d9f792 | 2 | import { ServerService } from '../../core/server' |
52d9f792 C |
3 | import { NotificationsService } from 'angular2-notifications' |
4 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
5 | import { Account } from '@app/shared/account/account.model' | |
6 | ||
7 | @Component({ | |
8 | selector: 'my-actor-avatar-info', | |
9 | templateUrl: './actor-avatar-info.component.html', | |
10 | styleUrls: [ './actor-avatar-info.component.scss' ] | |
11 | }) | |
12 | export class ActorAvatarInfoComponent { | |
244b4ae3 | 13 | @ViewChild('avatarfileInput') avatarfileInput: any |
52d9f792 C |
14 | |
15 | @Input() actor: VideoChannel | Account | |
16 | ||
17 | @Output() avatarChange = new EventEmitter<FormData>() | |
18 | ||
19 | constructor ( | |
52d9f792 C |
20 | private serverService: ServerService, |
21 | private notificationsService: NotificationsService | |
22 | ) {} | |
23 | ||
24 | onAvatarChange () { | |
25 | const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] | |
26 | if (avatarfile.size > this.maxAvatarSize) { | |
27 | this.notificationsService.error('Error', 'This image is too large.') | |
28 | return | |
29 | } | |
30 | ||
31 | const formData = new FormData() | |
32 | formData.append('avatarfile', avatarfile) | |
33 | ||
34 | this.avatarChange.emit(formData) | |
35 | } | |
36 | ||
37 | get maxAvatarSize () { | |
38 | return this.serverService.getConfig().avatar.file.size.max | |
39 | } | |
40 | ||
41 | get avatarExtensions () { | |
42 | return this.serverService.getConfig().avatar.file.extensions.join(',') | |
43 | } | |
44 | } |