1 import { Component, OnInit, AfterViewChecked } 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'
8 import { ViewportScroller } from '@angular/common'
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, AfterViewChecked {
19 userVideoQuotaUsed = 0
20 userVideoQuotaPercentage = 15
22 userVideoQuotaDaily = '0'
23 userVideoQuotaUsedDaily = 0
24 userVideoQuotaDailyPercentage = 15
27 private viewportScroller: ViewportScroller,
28 private userService: UserService,
29 private authService: AuthService,
30 private notifier: Notifier,
34 get userInformationLoaded () {
35 return this.authService.userInformationLoaded
39 this.user = this.authService.getUser()
41 this.authService.userInformationLoaded.subscribe(
43 if (this.user.videoQuota !== -1) {
44 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
45 this.userVideoQuotaPercentage = this.user.videoQuota * 100 / this.userVideoQuotaUsed
47 this.userVideoQuota = this.i18n('Unlimited')
50 if (this.user.videoQuotaDaily !== -1) {
51 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
52 this.userVideoQuotaDailyPercentage = this.user.videoQuotaDaily * 100 / this.userVideoQuotaUsedDaily
54 this.userVideoQuotaDaily = this.i18n('Unlimited')
59 this.userService.getMyVideoQuotaUsed()
61 this.userVideoQuotaUsed = data.videoQuotaUsed
62 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
66 ngAfterViewChecked () {
67 if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
70 onAvatarChange (formData: FormData) {
71 this.userService.changeAvatar(formData)
74 this.notifier.success(this.i18n('Avatar changed.'))
76 this.user.updateAccountAvatar(data.avatar)
79 err => this.notifier.error(err.message)
84 return this.user.videoQuotaDaily !== -1