]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/signup/signup.component.ts
Fix dev locale
[github/Chocobozzz/PeerTube.git] / client / src / app / signup / signup.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { ServerService } from '@app/core/server'
4 import { NotificationsService } from 'angular2-notifications'
5 import { UserCreate } from '../../../../shared'
6 import { FormReactive, UserService, UserValidatorsService } from '../shared'
7 import { RedirectService } from '@app/core'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
10
11 @Component({
12 selector: 'my-signup',
13 templateUrl: './signup.component.html',
14 styleUrls: [ './signup.component.scss' ]
15 })
16 export class SignupComponent extends FormReactive implements OnInit {
17 error: string = null
18 quotaHelpIndication = ''
19
20 constructor (
21 protected formValidatorService: FormValidatorService,
22 private userValidatorsService: UserValidatorsService,
23 private router: Router,
24 private notificationsService: NotificationsService,
25 private userService: UserService,
26 private redirectService: RedirectService,
27 private serverService: ServerService,
28 private i18n: I18n
29 ) {
30 super()
31 }
32
33 get initialUserVideoQuota () {
34 return this.serverService.getConfig().user.videoQuota
35 }
36
37 ngOnInit () {
38 this.buildForm({
39 username: this.userValidatorsService.USER_USERNAME,
40 password: this.userValidatorsService.USER_PASSWORD,
41 email: this.userValidatorsService.USER_EMAIL,
42 terms: this.userValidatorsService.USER_TERMS
43 })
44
45 this.serverService.configLoaded
46 .subscribe(() => this.buildQuotaHelpIndication())
47 }
48
49 signup () {
50 this.error = null
51
52 const userCreate: UserCreate = this.form.value
53
54 this.userService.signup(userCreate).subscribe(
55 () => {
56 this.notificationsService.success(
57 this.i18n('Success'),
58 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
59 )
60 this.redirectService.redirectToHomepage()
61 },
62
63 err => this.error = err.message
64 )
65 }
66
67 private getApproximateTime (seconds: number) {
68 const hours = Math.floor(seconds / 3600)
69 let pluralSuffix = ''
70 if (hours > 1) pluralSuffix = 's'
71 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
72
73 const minutes = Math.floor(seconds % 3600 / 60)
74 if (minutes > 1) pluralSuffix = 's'
75
76 return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes })
77 }
78
79 private buildQuotaHelpIndication () {
80 if (this.initialUserVideoQuota === -1) return
81
82 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
83
84 // 1080p: ~ 6Mbps
85 // 720p: ~ 4Mbps
86 // 360p: ~ 1.5Mbps
87 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
88 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
89 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
90
91 const lines = [
92 this.i18n('{{seconds}} of full HD videos', { seconds: this.getApproximateTime(fullHdSeconds) }),
93 this.i18n('{{seconds}} of HD videos', { seconds: this.getApproximateTime(hdSeconds) }),
94 this.i18n('{{seconds}} of average quality videos', { seconds: this.getApproximateTime(normalSeconds) })
95 ]
96
97 this.quotaHelpIndication = lines.join('<br />')
98 }
99 }