]>
Commit | Line | Data |
---|---|---|
45e0d669 | 1 | import { Component, OnInit, AfterViewChecked } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
234b535d | 3 | import { BytesPipe } from 'ngx-pipes' |
c30745f3 | 4 | import { AuthService } from '../../core' |
01de67b9 | 5 | import { User } from '../../shared' |
c5911fd3 | 6 | import { UserService } from '../../shared/users' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
45e0d669 | 8 | import { 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 | 15 | export 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 | |
64e0f8cf C |
26 | private lastScrollHash: string |
27 | ||
c5911fd3 | 28 | constructor ( |
45e0d669 | 29 | private viewportScroller: ViewportScroller, |
c5911fd3 C |
30 | private userService: UserService, |
31 | private authService: AuthService, | |
f8b2c1b4 | 32 | private notifier: Notifier, |
b1d40cff | 33 | private i18n: I18n |
c5911fd3 | 34 | ) {} |
c30745f3 | 35 | |
d18d6478 C |
36 | get userInformationLoaded () { |
37 | return this.authService.userInformationLoaded | |
38 | } | |
39 | ||
c30745f3 C |
40 | ngOnInit () { |
41 | this.user = this.authService.getUser() | |
ce5496d6 | 42 | |
234b535d C |
43 | this.authService.userInformationLoaded.subscribe( |
44 | () => { | |
45 | if (this.user.videoQuota !== -1) { | |
46 | this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString() | |
df8914c9 | 47 | this.userVideoQuotaPercentage = this.user.videoQuota * 100 / this.userVideoQuotaUsed |
234b535d | 48 | } else { |
b1d40cff | 49 | this.userVideoQuota = this.i18n('Unlimited') |
234b535d | 50 | } |
66fd1516 C |
51 | |
52 | if (this.user.videoQuotaDaily !== -1) { | |
53 | this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString() | |
df8914c9 | 54 | this.userVideoQuotaDailyPercentage = this.user.videoQuotaDaily * 100 / this.userVideoQuotaUsedDaily |
66fd1516 C |
55 | } else { |
56 | this.userVideoQuotaDaily = this.i18n('Unlimited') | |
57 | } | |
234b535d C |
58 | } |
59 | ) | |
60 | ||
ce5496d6 | 61 | this.userService.getMyVideoQuotaUsed() |
66fd1516 C |
62 | .subscribe(data => { |
63 | this.userVideoQuotaUsed = data.videoQuotaUsed | |
64 | this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily | |
65 | }) | |
c30745f3 | 66 | } |
2295ce6c | 67 | |
45e0d669 | 68 | ngAfterViewChecked () { |
64e0f8cf C |
69 | if (window.location.hash && window.location.hash !== this.lastScrollHash) { |
70 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) | |
71 | ||
72 | this.lastScrollHash = window.location.hash | |
73 | } | |
45e0d669 RK |
74 | } |
75 | ||
52d9f792 | 76 | onAvatarChange (formData: FormData) { |
c5911fd3 C |
77 | this.userService.changeAvatar(formData) |
78 | .subscribe( | |
79 | data => { | |
f8b2c1b4 | 80 | this.notifier.success(this.i18n('Avatar changed.')) |
c5911fd3 | 81 | |
0c237b19 | 82 | this.user.updateAccountAvatar(data.avatar) |
c5911fd3 C |
83 | }, |
84 | ||
f8b2c1b4 | 85 | err => this.notifier.error(err.message) |
c5911fd3 | 86 | ) |
2295ce6c | 87 | } |
66fd1516 C |
88 | |
89 | hasDailyQuota () { | |
90 | return this.user.videoQuotaDaily !== -1 | |
91 | } | |
c30745f3 | 92 | } |