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