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