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
21 userVideoQuotaDaily = '0'
22 userVideoQuotaUsedDaily = 0
25 private viewportScroller: ViewportScroller,
26 private userService: UserService,
27 private authService: AuthService,
28 private notifier: Notifier,
32 get userInformationLoaded () {
33 return this.authService.userInformationLoaded
37 this.user = this.authService.getUser()
39 this.authService.userInformationLoaded.subscribe(
41 if (this.user.videoQuota !== -1) {
42 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
44 this.userVideoQuota = this.i18n('Unlimited')
47 if (this.user.videoQuotaDaily !== -1) {
48 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
50 this.userVideoQuotaDaily = this.i18n('Unlimited')
55 this.userService.getMyVideoQuotaUsed()
57 this.userVideoQuotaUsed = data.videoQuotaUsed
58 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
62 ngAfterViewChecked () {
63 if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
66 onAvatarChange (formData: FormData) {
67 this.userService.changeAvatar(formData)
70 this.notifier.success(this.i18n('Avatar changed.'))
72 this.user.updateAccountAvatar(data.avatar)
75 err => this.notifier.error(err.message)
80 return this.user.videoQuotaDaily !== -1