]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/users/user-quota.component.ts
Remove angular pipes module
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-quota.component.ts
1 import { Subject } from 'rxjs'
2 import { Component, Input, OnInit } from '@angular/core'
3 import { User, UserService } from '@app/core'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { BytesPipe } from '../angular'
6
7 @Component({
8 selector: 'my-user-quota',
9 templateUrl: './user-quota.component.html',
10 styleUrls: ['./user-quota.component.scss']
11 })
12
13 export class UserQuotaComponent implements OnInit {
14 @Input() user: User = null
15 @Input() userInformationLoaded: Subject<any>
16
17 userVideoQuota = '0'
18 userVideoQuotaUsed = 0
19 userVideoQuotaPercentage = 15
20
21 userVideoQuotaDaily = '0'
22 userVideoQuotaUsedDaily = 0
23 userVideoQuotaDailyPercentage = 15
24
25 constructor (
26 private userService: UserService,
27 private i18n: I18n
28 ) { }
29
30 ngOnInit () {
31 this.userInformationLoaded.subscribe(
32 () => {
33 if (this.user.videoQuota !== -1) {
34 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
35 } else {
36 this.userVideoQuota = this.i18n('Unlimited')
37 }
38
39 if (this.user.videoQuotaDaily !== -1) {
40 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
41 } else {
42 this.userVideoQuotaDaily = this.i18n('Unlimited')
43 }
44 }
45 )
46
47 this.userService.getMyVideoQuotaUsed()
48 .subscribe(data => {
49 this.userVideoQuotaUsed = data.videoQuotaUsed
50 this.userVideoQuotaPercentage = this.userVideoQuotaUsed * 100 / this.user.videoQuota
51
52 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
53 this.userVideoQuotaDailyPercentage = this.userVideoQuotaUsedDaily * 100 / this.user.videoQuotaDaily
54 })
55 }
56
57 hasDailyQuota () {
58 return this.user.videoQuotaDaily !== -1
59 }
60
61 titleVideoQuota () {
62 return `${new BytesPipe().transform(this.userVideoQuotaUsed, 0).toString()} / ${this.userVideoQuota}`
63 }
64
65 titleVideoQuotaDaily () {
66 return `${new BytesPipe().transform(this.userVideoQuotaUsedDaily, 0).toString()} / ${this.userVideoQuotaDaily}`
67 }
68 }