]>
Commit | Line | Data |
---|---|---|
7cd4d2ba | 1 | import { Component, OnInit } 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' |
c30745f3 C |
8 | |
9 | @Component({ | |
10 | selector: 'my-account-settings', | |
4bb6886d C |
11 | templateUrl: './my-account-settings.component.html', |
12 | styleUrls: [ './my-account-settings.component.scss' ] | |
c30745f3 | 13 | }) |
4bb6886d | 14 | export class MyAccountSettingsComponent implements OnInit { |
c30745f3 | 15 | user: User = null |
66fd1516 | 16 | |
234b535d | 17 | userVideoQuota = '0' |
ce5496d6 | 18 | userVideoQuotaUsed = 0 |
c30745f3 | 19 | |
66fd1516 C |
20 | userVideoQuotaDaily = '0' |
21 | userVideoQuotaUsedDaily = 0 | |
22 | ||
c5911fd3 C |
23 | constructor ( |
24 | private userService: UserService, | |
25 | private authService: AuthService, | |
f8b2c1b4 | 26 | private notifier: Notifier, |
b1d40cff | 27 | private i18n: I18n |
c5911fd3 | 28 | ) {} |
c30745f3 | 29 | |
d18d6478 C |
30 | get userInformationLoaded () { |
31 | return this.authService.userInformationLoaded | |
32 | } | |
33 | ||
c30745f3 C |
34 | ngOnInit () { |
35 | this.user = this.authService.getUser() | |
ce5496d6 | 36 | |
234b535d C |
37 | this.authService.userInformationLoaded.subscribe( |
38 | () => { | |
39 | if (this.user.videoQuota !== -1) { | |
40 | this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString() | |
41 | } else { | |
b1d40cff | 42 | this.userVideoQuota = this.i18n('Unlimited') |
234b535d | 43 | } |
66fd1516 C |
44 | |
45 | if (this.user.videoQuotaDaily !== -1) { | |
46 | this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString() | |
47 | } else { | |
48 | this.userVideoQuotaDaily = this.i18n('Unlimited') | |
49 | } | |
234b535d C |
50 | } |
51 | ) | |
52 | ||
ce5496d6 | 53 | this.userService.getMyVideoQuotaUsed() |
66fd1516 C |
54 | .subscribe(data => { |
55 | this.userVideoQuotaUsed = data.videoQuotaUsed | |
56 | this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily | |
57 | }) | |
c30745f3 | 58 | } |
2295ce6c | 59 | |
52d9f792 | 60 | onAvatarChange (formData: FormData) { |
c5911fd3 C |
61 | this.userService.changeAvatar(formData) |
62 | .subscribe( | |
63 | data => { | |
f8b2c1b4 | 64 | this.notifier.success(this.i18n('Avatar changed.')) |
c5911fd3 | 65 | |
0c237b19 | 66 | this.user.updateAccountAvatar(data.avatar) |
c5911fd3 C |
67 | }, |
68 | ||
f8b2c1b4 | 69 | err => this.notifier.error(err.message) |
c5911fd3 | 70 | ) |
2295ce6c | 71 | } |
66fd1516 C |
72 | |
73 | hasDailyQuota () { | |
74 | return this.user.videoQuotaDaily !== -1 | |
75 | } | |
c30745f3 | 76 | } |