1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { ServerService } from '../../core/server'
6 import { User } from '../../shared'
7 import { UserService } from '../../shared/users'
10 selector: 'my-account-settings',
11 templateUrl: './account-settings.component.html',
12 styleUrls: [ './account-settings.component.scss' ]
14 export class AccountSettingsComponent implements OnInit {
15 @ViewChild('avatarfileInput') avatarfileInput
19 userVideoQuotaUsed = 0
22 private userService: UserService,
23 private authService: AuthService,
24 private serverService: ServerService,
25 private notificationsService: NotificationsService
29 this.user = this.authService.getUser()
31 this.authService.userInformationLoaded.subscribe(
33 if (this.user.videoQuota !== -1) {
34 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
36 this.userVideoQuota = 'Unlimited'
41 this.userService.getMyVideoQuotaUsed()
42 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
46 return this.user.getAvatarUrl()
50 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
52 const formData = new FormData()
53 formData.append('avatarfile', avatarfile)
55 this.userService.changeAvatar(formData)
58 this.notificationsService.success('Success', 'Avatar changed.')
60 this.user.account.avatar = data.avatar
63 err => this.notificationsService.error('Error', err.message)
67 get maxAvatarSize () {
68 return this.serverService.getConfig().avatar.file.size.max
71 get avatarExtensions () {
72 return this.serverService.getConfig().avatar.file.extensions.join(',')