]>
Commit | Line | Data |
---|---|---|
2e7f2627 | 1 | import { Subject } from 'rxjs' |
2e7f2627 K |
2 | import { Component, Input, OnInit } from '@angular/core' |
3 | import { User, UserService } from '@app/core' | |
94676e63 | 4 | import { BytesPipe } from '../angular' |
2e7f2627 K |
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 | ||
66357162 | 24 | constructor (private userService: UserService) { } |
2e7f2627 K |
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 { | |
66357162 | 32 | this.userVideoQuota = $localize`Unlimited` |
2e7f2627 K |
33 | } |
34 | ||
35 | if (this.user.videoQuotaDaily !== -1) { | |
36 | this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString() | |
37 | } else { | |
66357162 | 38 | this.userVideoQuotaDaily = $localize`Unlimited` |
2e7f2627 K |
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 | } |