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