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'
12 selector: 'my-signup',
13 templateUrl: './signup.component.html',
14 styleUrls: [ './signup.component.scss' ]
16 export class SignupComponent extends FormReactive implements OnInit {
18 quotaHelpIndication = ''
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,
33 get initialUserVideoQuota () {
34 return this.serverService.getConfig().user.videoQuota
38 return window.location.host
43 username: this.userValidatorsService.USER_USERNAME,
44 password: this.userValidatorsService.USER_PASSWORD,
45 email: this.userValidatorsService.USER_EMAIL,
46 terms: this.userValidatorsService.USER_TERMS
49 this.serverService.configLoaded
50 .subscribe(() => this.buildQuotaHelpIndication())
56 const userCreate: UserCreate = this.form.value
58 this.userService.signup(userCreate).subscribe(
60 this.notificationsService.success(
62 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
64 this.redirectService.redirectToHomepage()
67 err => this.error = err.message
71 private getApproximateTime (seconds: number) {
72 const hours = Math.floor(seconds / 3600)
74 if (hours > 1) pluralSuffix = 's'
75 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
77 const minutes = Math.floor(seconds % 3600 / 60)
78 if (minutes > 1) pluralSuffix = 's'
80 return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes })
83 private buildQuotaHelpIndication () {
84 if (this.initialUserVideoQuota === -1) return
86 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
91 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
92 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
93 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
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) })
101 this.quotaHelpIndication = lines.join('<br />')