]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Handle overview pagination in client
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
1 import { Component, OnInit } 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
9 @Component({
10 selector: 'my-account-settings',
11 templateUrl: './my-account-settings.component.html',
12 styleUrls: [ './my-account-settings.component.scss' ]
13 })
14 export class MyAccountSettingsComponent implements OnInit {
15 user: User = null
16
17 userVideoQuota = '0'
18 userVideoQuotaUsed = 0
19
20 userVideoQuotaDaily = '0'
21 userVideoQuotaUsedDaily = 0
22
23 constructor (
24 private userService: UserService,
25 private authService: AuthService,
26 private notifier: Notifier,
27 private i18n: I18n
28 ) {}
29
30 get userInformationLoaded () {
31 return this.authService.userInformationLoaded
32 }
33
34 ngOnInit () {
35 this.user = this.authService.getUser()
36
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 {
42 this.userVideoQuota = this.i18n('Unlimited')
43 }
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 }
50 }
51 )
52
53 this.userService.getMyVideoQuotaUsed()
54 .subscribe(data => {
55 this.userVideoQuotaUsed = data.videoQuotaUsed
56 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
57 })
58 }
59
60 onAvatarChange (formData: FormData) {
61 this.userService.changeAvatar(formData)
62 .subscribe(
63 data => {
64 this.notifier.success(this.i18n('Avatar changed.'))
65
66 this.user.updateAccountAvatar(data.avatar)
67 },
68
69 err => this.notifier.error(err.message)
70 )
71 }
72
73 hasDailyQuota () {
74 return this.user.videoQuotaDaily !== -1
75 }
76 }