1 import { BytesPipe } from 'ngx-pipes'
2 import { ViewportScroller } from '@angular/common'
3 import { AfterViewChecked, Component, OnInit } from '@angular/core'
4 import { AuthService, Notifier, User, UserService } from '@app/core'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
8 selector: 'my-account-settings',
9 templateUrl: './my-account-settings.component.html',
10 styleUrls: [ './my-account-settings.component.scss' ]
12 export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
16 userVideoQuotaUsed = 0
17 userVideoQuotaPercentage = 15
19 userVideoQuotaDaily = '0'
20 userVideoQuotaUsedDaily = 0
21 userVideoQuotaDailyPercentage = 15
23 private lastScrollHash: string
26 private viewportScroller: ViewportScroller,
27 private userService: UserService,
28 private authService: AuthService,
29 private notifier: Notifier,
33 get userInformationLoaded () {
34 return this.authService.userInformationLoaded
38 this.user = this.authService.getUser()
40 this.authService.userInformationLoaded.subscribe(
42 if (this.user.videoQuota !== -1) {
43 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
44 this.userVideoQuotaPercentage = this.user.videoQuota * 100 / this.userVideoQuotaUsed
46 this.userVideoQuota = this.i18n('Unlimited')
49 if (this.user.videoQuotaDaily !== -1) {
50 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
51 this.userVideoQuotaDailyPercentage = this.user.videoQuotaDaily * 100 / this.userVideoQuotaUsedDaily
53 this.userVideoQuotaDaily = this.i18n('Unlimited')
58 this.userService.getMyVideoQuotaUsed()
60 this.userVideoQuotaUsed = data.videoQuotaUsed
61 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
65 ngAfterViewChecked () {
66 if (window.location.hash && window.location.hash !== this.lastScrollHash) {
67 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
69 this.lastScrollHash = window.location.hash
73 onAvatarChange (formData: FormData) {
74 this.userService.changeAvatar(formData)
77 this.notifier.success(this.i18n('Avatar changed.'))
79 this.user.updateAccountAvatar(data.avatar)
82 err => this.notifier.error(err.message)
87 return this.user.videoQuotaDaily !== -1