]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Fix getSubs import
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
CommitLineData
45e0d669 1import { Component, OnInit, AfterViewChecked } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
234b535d 3import { BytesPipe } from 'ngx-pipes'
c30745f3 4import { AuthService } from '../../core'
01de67b9 5import { User } from '../../shared'
c5911fd3 6import { UserService } from '../../shared/users'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
45e0d669 8import { ViewportScroller } from '@angular/common'
c30745f3
C
9
10@Component({
11 selector: 'my-account-settings',
4bb6886d
C
12 templateUrl: './my-account-settings.component.html',
13 styleUrls: [ './my-account-settings.component.scss' ]
c30745f3 14})
45e0d669 15export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
c30745f3 16 user: User = null
66fd1516 17
234b535d 18 userVideoQuota = '0'
ce5496d6 19 userVideoQuotaUsed = 0
df8914c9 20 userVideoQuotaPercentage = 15
c30745f3 21
66fd1516
C
22 userVideoQuotaDaily = '0'
23 userVideoQuotaUsedDaily = 0
df8914c9 24 userVideoQuotaDailyPercentage = 15
66fd1516 25
c5911fd3 26 constructor (
45e0d669 27 private viewportScroller: ViewportScroller,
c5911fd3
C
28 private userService: UserService,
29 private authService: AuthService,
f8b2c1b4 30 private notifier: Notifier,
b1d40cff 31 private i18n: I18n
c5911fd3 32 ) {}
c30745f3 33
d18d6478
C
34 get userInformationLoaded () {
35 return this.authService.userInformationLoaded
36 }
37
c30745f3
C
38 ngOnInit () {
39 this.user = this.authService.getUser()
ce5496d6 40
234b535d
C
41 this.authService.userInformationLoaded.subscribe(
42 () => {
43 if (this.user.videoQuota !== -1) {
44 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
df8914c9 45 this.userVideoQuotaPercentage = this.user.videoQuota * 100 / this.userVideoQuotaUsed
234b535d 46 } else {
b1d40cff 47 this.userVideoQuota = this.i18n('Unlimited')
234b535d 48 }
66fd1516
C
49
50 if (this.user.videoQuotaDaily !== -1) {
51 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
df8914c9 52 this.userVideoQuotaDailyPercentage = this.user.videoQuotaDaily * 100 / this.userVideoQuotaUsedDaily
66fd1516
C
53 } else {
54 this.userVideoQuotaDaily = this.i18n('Unlimited')
55 }
234b535d
C
56 }
57 )
58
ce5496d6 59 this.userService.getMyVideoQuotaUsed()
66fd1516
C
60 .subscribe(data => {
61 this.userVideoQuotaUsed = data.videoQuotaUsed
62 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
63 })
c30745f3 64 }
2295ce6c 65
45e0d669
RK
66 ngAfterViewChecked () {
67 if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
68 }
69
52d9f792 70 onAvatarChange (formData: FormData) {
c5911fd3
C
71 this.userService.changeAvatar(formData)
72 .subscribe(
73 data => {
f8b2c1b4 74 this.notifier.success(this.i18n('Avatar changed.'))
c5911fd3 75
0c237b19 76 this.user.updateAccountAvatar(data.avatar)
c5911fd3
C
77 },
78
f8b2c1b4 79 err => this.notifier.error(err.message)
c5911fd3 80 )
2295ce6c 81 }
66fd1516
C
82
83 hasDailyQuota () {
84 return this.user.videoQuotaDaily !== -1
85 }
c30745f3 86}