1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { AuthService } from '../../core'
4 import { ServerService } from '../../core/server'
5 import { User } from '../../shared'
6 import { UserService } from '../../shared/users'
9 selector: 'my-account-settings',
10 templateUrl: './account-settings.component.html',
11 styleUrls: [ './account-settings.component.scss' ]
13 export class AccountSettingsComponent implements OnInit {
14 @ViewChild('avatarfileInput') avatarfileInput
17 userVideoQuotaUsed = 0
20 private userService: UserService,
21 private authService: AuthService,
22 private serverService: ServerService,
23 private notificationsService: NotificationsService
27 this.user = this.authService.getUser()
29 this.userService.getMyVideoQuotaUsed()
30 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
34 return this.user.getAvatarUrl()
38 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
40 const formData = new FormData()
41 formData.append('avatarfile', avatarfile)
43 this.userService.changeAvatar(formData)
46 this.notificationsService.success('Success', 'Avatar changed.')
48 this.user.account.avatar = data.avatar
51 err => this.notificationsService.error('Error', err.message)
55 get maxAvatarSize () {
56 return this.serverService.getConfig().avatar.file.size.max
59 get avatarExtensions () {
60 return this.serverService.getConfig().avatar.file.extensions.join(',')