1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { User } from '../../shared'
6 import { UserService } from '../../shared/users'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
10 selector: 'my-account-settings',
11 templateUrl: './my-account-settings.component.html',
12 styleUrls: [ './my-account-settings.component.scss' ]
14 export class MyAccountSettingsComponent implements OnInit {
18 userVideoQuotaUsed = 0
20 userVideoQuotaDaily = '0'
21 userVideoQuotaUsedDaily = 0
24 private userService: UserService,
25 private authService: AuthService,
26 private notifier: Notifier,
30 get userInformationLoaded () {
31 return this.authService.userInformationLoaded
35 this.user = this.authService.getUser()
37 this.authService.userInformationLoaded.subscribe(
39 if (this.user.videoQuota !== -1) {
40 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
42 this.userVideoQuota = this.i18n('Unlimited')
45 if (this.user.videoQuotaDaily !== -1) {
46 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
48 this.userVideoQuotaDaily = this.i18n('Unlimited')
53 this.userService.getMyVideoQuotaUsed()
55 this.userVideoQuotaUsed = data.videoQuotaUsed
56 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
60 onAvatarChange (formData: FormData) {
61 this.userService.changeAvatar(formData)
64 this.notifier.success(this.i18n('Avatar changed.'))
66 this.user.updateAccountAvatar(data.avatar)
69 err => this.notifier.error(err.message)
74 return this.user.videoQuotaDaily !== -1