]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance-features-table.component.ts
Support ICU in TS components
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-instance / instance-features-table.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { ServerService } from '@app/core'
3 import { prepareIcu } from '@app/helpers'
4 import { ServerConfig } from '@shared/models'
5 import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service'
6
7 @Component({
8 selector: 'my-instance-features-table',
9 templateUrl: './instance-features-table.component.html',
10 styleUrls: [ './instance-features-table.component.scss' ]
11 })
12 export class InstanceFeaturesTableComponent implements OnInit {
13 quotaHelpIndication = ''
14 serverConfig: ServerConfig
15
16 constructor (
17 private serverService: ServerService,
18 private modalService: PeertubeModalService
19 ) { }
20
21 get initialUserVideoQuota () {
22 return this.serverConfig.user.videoQuota
23 }
24
25 get dailyUserVideoQuota () {
26 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
27 }
28
29 get maxInstanceLives () {
30 const value = this.serverConfig.live.maxInstanceLives
31 if (value === -1) return $localize`Unlimited`
32
33 return value
34 }
35
36 get maxUserLives () {
37 const value = this.serverConfig.live.maxUserLives
38 if (value === -1) return $localize`Unlimited`
39
40 return value
41 }
42
43 ngOnInit () {
44 this.serverService.getConfig()
45 .subscribe(config => {
46 this.serverConfig = config
47 this.buildQuotaHelpIndication()
48 })
49 }
50
51 buildNSFWLabel () {
52 const policy = this.serverConfig.instance.defaultNSFWPolicy
53
54 if (policy === 'do_not_list') return $localize`Hidden`
55 if (policy === 'blur') return $localize`Blurred with confirmation request`
56 if (policy === 'display') return $localize`Displayed`
57 }
58
59 getServerVersionAndCommit () {
60 return this.serverService.getServerVersionAndCommit()
61 }
62
63 openQuickSettingsHighlight () {
64 this.modalService.openQuickSettingsSubject.next()
65 }
66
67 private getApproximateTime (seconds: number) {
68 const hours = Math.floor(seconds / 3600)
69
70 if (hours !== 0) {
71 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
72 { hours },
73 $localize`~ ${hours} hours`
74 )
75 }
76
77 const minutes = Math.floor(seconds % 3600 / 60)
78
79 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
80 { minutes },
81 $localize`~ ${minutes} minutes`
82 )
83 }
84
85 private buildQuotaHelpIndication () {
86 if (this.initialUserVideoQuota === -1) return
87
88 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
89
90 // 1080p: ~ 6Mbps
91 // 720p: ~ 4Mbps
92 // 360p: ~ 1.5Mbps
93 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
94 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
95 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
96
97 const lines = [
98 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
99 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
100 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
101 ]
102
103 this.quotaHelpIndication = lines.join('<br />')
104 }
105 }