fix linter errors on register component

This commit is contained in:
Tom Bloor 2017-09-19 14:48:22 +01:00
parent dec53b4630
commit 61ac856cc2

View file

@ -1,6 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Validators, FormBuilder, FormGroup } from '@angular/forms'; import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { ValidationManager } from "ng2-validation-manager"; import { ValidationManager } from 'ng2-validation-manager';
import { Http, Response } from '@angular/http'; import { Http, Response } from '@angular/http';
import { ApiService } from '../providers/api-service'; import { ApiService } from '../providers/api-service';
import {Router } from '@angular/router'; import {Router } from '@angular/router';
@ -16,87 +16,87 @@ export class RegisterComponent {
organisationForm: ValidationManager; organisationForm: ValidationManager;
years: Object[]; years: Object[];
registerStatus: any; registerStatus: any;
registerStatusError: string = 'Error received, please try again.'; registerStatusError = 'Error received, please try again.';
constructor( constructor(
private http: Http, private http: Http,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private api: ApiService, private api: ApiService,
) { ) {
this.years = []; this.years = [];
let max = new Date().getFullYear() - 10, const max = new Date().getFullYear() - 10,
min = max - 140; min = max - 140;
for (let i = max; i>=min; i--){ for (let i = max; i >= min; i--) {
this.years.push(i); this.years.push(i);
} }
this.signupForm = new ValidationManager({ this.signupForm = new ValidationManager({
token: 'required', token: 'required',
usertype: 'required', usertype: 'required',
email: 'required|email', email: 'required|email',
password: 'required', password: 'required',
confirmpassword: 'required|equalTo:password' confirmpassword: 'required|equalTo:password'
}); });
this.customerForm = new ValidationManager({ this.customerForm = new ValidationManager({
display_name: 'required', display_name: 'required',
full_name: 'required', full_name: 'required',
postcode: 'required', postcode: 'required',
year_of_birth:'required', year_of_birth: 'required',
}); });
this.organisationForm = new ValidationManager({ this.organisationForm = new ValidationManager({
name: 'required', name: 'required',
sector: 'required', sector: 'required',
street_name: 'required', street_name: 'required',
town: 'required', town: 'required',
postcode: 'required', postcode: 'required',
}); });
} }
onSubmitCustomer() { onSubmitCustomer() {
console.log(this.signupForm.isValid()); console.log(this.signupForm.isValid());
if (!this.signupForm.isValid() && !this.customerForm.isValid()) { if (!this.signupForm.isValid() && !this.customerForm.isValid()) {
console.log("Not Valid!"); console.log('Not Valid!');
this.registerStatus = "validation_failed"; this.registerStatus = 'validation_failed';
console.log(this.registerStatus); console.log(this.registerStatus);
return; return;
} }
let signupForm = this.signupForm.getForm().value; const signupForm = this.signupForm.getForm().value;
let customerForm = this.customerForm.getForm().value; const customerForm = this.customerForm.getForm().value;
let data = { const data = {
token: signupForm.token, token: signupForm.token,
usertype: signupForm.usertype, usertype: signupForm.usertype,
email: signupForm.email, email: signupForm.email,
password: signupForm.password, password: signupForm.password,
display_name: customerForm.display_name, display_name: customerForm.display_name,
full_name: customerForm.full_name, full_name: customerForm.full_name,
postcode: customerForm.postcode, postcode: customerForm.postcode,
year_of_birth:customerForm.year_of_birth, year_of_birth: customerForm.year_of_birth,
}; };
console.log(data); console.log(data);
this.api this.api
.register(data) .register(data)
.subscribe( .subscribe(
result => { result => {
console.log('registered!'); console.log('registered!');
this.registerStatus = "success"; this.registerStatus = 'success';
console.log(this.registerStatus); console.log(this.registerStatus);
this.router.navigate(['/dashboard']); this.router.navigate(['/dashboard']);
}, },
error => { error => {
console.log('Register Error'); console.log('Register Error');
console.log(error); console.log(error);
try { try {
console.log(error.error); console.log(error.error);
let jsonError = error.json(); const jsonError = error.json();
console.log("boop"); console.log('boop');
this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message;
} catch(e) { } catch (e) {
this.registerStatusError = 'There was a server error, please try again later.'; this.registerStatusError = 'There was a server error, please try again later.';
} }
this.registerStatus = "send_failed"; this.registerStatus = 'send_failed';
console.log(this.registerStatus); console.log(this.registerStatus);
} }
); );
@ -104,33 +104,33 @@ export class RegisterComponent {
onSubmitOrganisation() { onSubmitOrganisation() {
console.log(this.signupForm.isValid()); console.log(this.signupForm.isValid());
if (!this.signupForm.isValid() || !this.organisationForm.isValid()) { if (!this.signupForm.isValid() || !this.organisationForm.isValid()) {
console.log("Not Valid!"); console.log('Not Valid!');
this.registerStatus = "validation_failed"; this.registerStatus = 'validation_failed';
console.log(this.registerStatus); console.log(this.registerStatus);
return; return;
} }
let signupForm = this.signupForm.getForm().value; const signupForm = this.signupForm.getForm().value;
let organisationForm = this.organisationForm.getForm().value; const organisationForm = this.organisationForm.getForm().value;
let data = { const data = {
token: signupForm.token, token: signupForm.token,
usertype: signupForm.usertype, usertype: signupForm.usertype,
email: signupForm.email, email: signupForm.email,
password: signupForm.password, password: signupForm.password,
name: organisationForm.name, name: organisationForm.name,
sector: organisationForm.sector, sector: organisationForm.sector,
street_name: organisationForm.street_name, street_name: organisationForm.street_name,
town: organisationForm.town, town: organisationForm.town,
postcode: organisationForm.postcode, postcode: organisationForm.postcode,
}; };
console.log(data); console.log(data);
this.api this.api
.register(data) .register(data)
.subscribe( .subscribe(
result => { result => {
console.log('registered!'); console.log('registered!');
this.registerStatus = "success"; this.registerStatus = 'success';
console.log(this.registerStatus); console.log(this.registerStatus);
this.router.navigate(['/dashboard']); this.router.navigate(['/dashboard']);
}, },
@ -139,13 +139,13 @@ export class RegisterComponent {
console.log(error); console.log(error);
try { try {
console.log(error.error); console.log(error.error);
let jsonError = error.json(); const jsonError = error.json();
console.log("boop"); console.log('boop');
this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message;
} catch(e) { } catch (e) {
this.registerStatusError = 'There was a server error, please try again later.'; this.registerStatusError = 'There was a server error, please try again later.';
} }
this.registerStatus = "send_failed"; this.registerStatus = 'send_failed';
console.log(this.registerStatus); console.log(this.registerStatus);
} }
); );