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'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
11 selector: 'my-account-settings',
12 templateUrl: './my-account-settings.component.html',
13 styleUrls: [ './my-account-settings.component.scss' ]
15 export class MyAccountSettingsComponent implements OnInit {
18 userVideoQuotaUsed = 0
21 private userService: UserService,
22 private authService: AuthService,
23 private serverService: ServerService,
24 private notificationsService: NotificationsService,
28 get userInformationLoaded () {
29 return this.authService.userInformationLoaded
33 this.user = this.authService.getUser()
35 this.authService.userInformationLoaded.subscribe(
37 if (this.user.videoQuota !== -1) {
38 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
40 this.userVideoQuota = this.i18n('Unlimited')
45 this.userService.getMyVideoQuotaUsed()
46 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
49 onAvatarChange (formData: FormData) {
50 this.userService.changeAvatar(formData)
53 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
55 this.user.updateAccountAvatar(data.avatar)
58 err => this.notificationsService.error(this.i18n('Error'), err.message)