1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { ServerService } from '@app/core/server'
5 import { NotificationsService } from 'angular2-notifications'
6 import { UserCreate } from '../../../../shared'
7 import { FormReactive, USER_EMAIL, USER_PASSWORD, USER_USERNAME, UserService } from '../shared'
8 import { RedirectService } from '@app/core'
9 import { I18n } from '@ngx-translate/i18n-polyfill'
10 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
13 selector: 'my-signup',
14 templateUrl: './signup.component.html',
15 styleUrls: [ './signup.component.scss' ]
17 export class SignupComponent extends FormReactive implements OnInit {
19 quotaHelpIndication = ''
21 private static getApproximateTime (seconds: number) {
22 const hours = Math.floor(seconds / 3600)
24 if (hours > 1) pluralSuffix = 's'
25 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
27 const minutes = Math.floor(seconds % 3600 / 60)
28 if (minutes > 1) pluralSuffix = 's'
30 return `~ ${minutes} minute${pluralSuffix}`
34 protected formValidatorService: FormValidatorService,
35 private router: Router,
36 private notificationsService: NotificationsService,
37 private userService: UserService,
38 private redirectService: RedirectService,
39 private serverService: ServerService,
45 get initialUserVideoQuota () {
46 return this.serverService.getConfig().user.videoQuota
51 username: USER_USERNAME,
52 password: USER_PASSWORD,
56 this.serverService.configLoaded
57 .subscribe(() => this.buildQuotaHelpIndication())
63 const userCreate: UserCreate = this.form.value
65 this.userService.signup(userCreate).subscribe(
67 this.notificationsService.success(
69 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
71 this.redirectService.redirectToHomepage()
74 err => this.error = err.message
78 private buildQuotaHelpIndication () {
79 if (this.initialUserVideoQuota === -1) return
81 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
86 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
87 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
88 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
91 this.i18n('{{seconds}} of full HD videos', { seconds: SignupComponent.getApproximateTime(fullHdSeconds) }),
92 this.i18n('{{seconds}} of HD videos', { seconds: SignupComponent.getApproximateTime(hdSeconds) }),
93 this.i18n('{{seconds}} of average quality videos', { seconds: SignupComponent.getApproximateTime(normalSeconds) })
96 this.quotaHelpIndication = lines.join('<br />')