Fix linter errors in add-data component

This commit is contained in:
Tom Bloor 2017-09-19 14:53:25 +01:00
parent 61ac856cc2
commit f6c0583481

View file

@ -9,7 +9,7 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'add-data.component.html', templateUrl: 'add-data.component.html',
}) })
export class AddDataComponent { export class AddDataComponent implements OnInit {
payrollForm: FormGroup; payrollForm: FormGroup;
singleSupplierForm: FormGroup; singleSupplierForm: FormGroup;
employeeForm: FormGroup; employeeForm: FormGroup;
@ -18,7 +18,7 @@ export class AddDataComponent {
singleSupplierFormStatus: any; singleSupplierFormStatus: any;
employeeFormStatus: any; employeeFormStatus: any;
transactionFormStatus: any; transactionFormStatus: any;
transactionFormStatusError: string = 'Error received, please try again.'; transactionFormStatusError = 'Error received, please try again.';
accountType: any; accountType: any;
submitOrg = { submitOrg = {
@ -73,13 +73,13 @@ export class AddDataComponent {
this.accountType = localStorage.getItem('usertype'); this.accountType = localStorage.getItem('usertype');
} }
getMinDate(){ getMinDate() {
// gets the April 1st date of the current year // gets the April 1st date of the current year
let aprilDate = moment().month(3).date(1); const aprilDate = moment().month(3).date(1);
let now = moment(); const now = moment();
// Checks if current time is before April 1st, if so returns true // Checks if current time is before April 1st, if so returns true
let beforeApril = now.isBefore(aprilDate); const beforeApril = now.isBefore(aprilDate);
if ( beforeApril == true ) { if ( beforeApril === true ) {
this.minDate = aprilDate.subtract(2, 'years').format('YYYY-MM-DD'); this.minDate = aprilDate.subtract(2, 'years').format('YYYY-MM-DD');
} else { } else {
this.minDate = aprilDate.subtract(1, 'years').format('YYYY-MM-DD'); this.minDate = aprilDate.subtract(1, 'years').format('YYYY-MM-DD');
@ -88,16 +88,16 @@ export class AddDataComponent {
initializeItems() { initializeItems() {
// Dont bother searching for an empty or undefined string // Dont bother searching for an empty or undefined string
if ( this.submitOrg.name == '' ) { if ( this.submitOrg.name === '' ) {
return; return;
} }
var searchData = { const searchData = {
search_name: this.submitOrg.name, search_name: this.submitOrg.name,
}; };
this.api.search(searchData).subscribe( this.api.search(searchData).subscribe(
data => { data => {
if(data.validated.length > 0) { if (data.validated.length > 0) {
this.storeList = data.validated; this.storeList = data.validated;
this.showAddStore = false; this.showAddStore = false;
this.transactionAdditionType = 1; this.transactionAdditionType = 1;
@ -107,7 +107,7 @@ export class AddDataComponent {
this.transactionAdditionType = 2; this.transactionAdditionType = 2;
} }
// handle the case when the storelist is empty // handle the case when the storelist is empty
if(this.storeList.length < 1 ) { if (this.storeList.length < 1) {
this.storeList = null; this.storeList = null;
this.showAddStore = true; this.showAddStore = true;
this.transactionAdditionType = 3; this.transactionAdditionType = 3;
@ -120,7 +120,7 @@ export class AddDataComponent {
} }
// if user select a item from the list // if user select a item from the list
addStore(store){ addStore(store) {
this.submitOrg = store; this.submitOrg = store;
this.transactionFormValidate(); this.transactionFormValidate();
this.organisationId = store.id; this.organisationId = store.id;
@ -132,40 +132,40 @@ export class AddDataComponent {
this.initializeItems(); this.initializeItems();
// set val to the value of the searchbar // set val to the value of the searchbar
let val = ev.target.value; const val = ev.target.value;
// Filter the store list so search seems quicker // Filter the store list so search seems quicker
if (val && val.trim() != '' && this.storeList != null) { if (val && val.trim() !== '' && this.storeList !== null) {
this.storeList = this.storeList.filter( this.storeList = this.storeList.filter(
(item) => { (item) => {
return ( item.name.toLowerCase().indexOf( val.toLowerCase() ) > -1 ); return ( item.name.toLowerCase().indexOf( val.toLowerCase() ) > -1 );
} }
) );
} }
// if nothing is found // if nothing is found
if(!this.storeList === null){ if (!this.storeList === null) {
// display add new store button // display add new store button
this.showAddStore = true; this.showAddStore = true;
} }
} }
transactionFormValidate() { transactionFormValidate() {
if( this.submitOrg.name.length == 0 || if (this.submitOrg.name.length === 0 ||
this.submitOrg.town.length == 0 || this.submitOrg.town.length === 0 ||
this.amount == 0 ) { this.amount === 0 ) {
this.transactionFormInvalid = true; this.transactionFormInvalid = true;
}else{ } else {
this.transactionFormInvalid = false; this.transactionFormInvalid = false;
} }
} }
public postTransaction() { public postTransaction() {
var myParams: any; let myParams: any;
let purchaseTime: string; let purchaseTime: string;
purchaseTime = moment(this.myDate, 'YYYY-MM-DD[T]HH:mm').local().format('YYYY-MM-DD[T]HH:mm:ss.SSSZ'); purchaseTime = moment(this.myDate, 'YYYY-MM-DD[T]HH:mm').local().format('YYYY-MM-DD[T]HH:mm:ss.SSSZ');
switch(this.transactionAdditionType){ switch (this.transactionAdditionType) {
case 1: case 1:
myParams = { myParams = {
transaction_type : this.transactionAdditionType, transaction_type : this.transactionAdditionType,
@ -200,16 +200,16 @@ export class AddDataComponent {
.upload(myParams) .upload(myParams)
.subscribe( .subscribe(
result => { result => {
if ( result.success == true ) { if ( result.success === true ) {
console.log('Successful Upload'); console.log('Successful Upload');
console.log(result); console.log(result);
this.transactionFormStatus = "success"; this.transactionFormStatus = 'success';
console.log(this.transactionFormStatus); console.log(this.transactionFormStatus);
this.resetForm(); this.resetForm();
} else { } else {
console.log('Upload Error'); console.log('Upload Error');
this.transactionFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message); this.transactionFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message);
this.transactionFormStatus = "send_failed"; this.transactionFormStatus = 'send_failed';
console.log(this.transactionFormStatus); console.log(this.transactionFormStatus);
} }
}, },
@ -218,13 +218,13 @@ export class AddDataComponent {
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.transactionFormStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; this.transactionFormStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message;
} catch(e) { } catch (e) {
this.transactionFormStatusError = 'There was a server error, please try again later.'; this.transactionFormStatusError = 'There was a server error, please try again later.';
} }
this.transactionFormStatus = "send_failed"; this.transactionFormStatus = 'send_failed';
console.log(this.transactionFormStatus); console.log(this.transactionFormStatus);
} }
); );
@ -251,12 +251,12 @@ export class AddDataComponent {
.subscribe( .subscribe(
result => { result => {
console.log('data submitted!'); console.log('data submitted!');
this.payrollFormStatus = "success"; this.payrollFormStatus = 'success';
console.log(this.payrollFormStatus); console.log(this.payrollFormStatus);
}, },
error => { error => {
console.log( error._body ); console.log( error._body );
this.payrollFormStatus = "send_failed"; this.payrollFormStatus = 'send_failed';
console.log(this.payrollFormStatus); console.log(this.payrollFormStatus);
} }
); );
@ -270,12 +270,12 @@ export class AddDataComponent {
.subscribe( .subscribe(
result => { result => {
console.log('data submitted!'); console.log('data submitted!');
this.singleSupplierFormStatus = "success"; this.singleSupplierFormStatus = 'success';
console.log(this.singleSupplierFormStatus); console.log(this.singleSupplierFormStatus);
}, },
error => { error => {
console.log( error._body ); console.log( error._body );
this.singleSupplierFormStatus = "send_failed"; this.singleSupplierFormStatus = 'send_failed';
console.log(this.singleSupplierFormStatus); console.log(this.singleSupplierFormStatus);
} }
); );
@ -289,12 +289,12 @@ export class AddDataComponent {
.subscribe( .subscribe(
result => { result => {
console.log('data submitted!'); console.log('data submitted!');
this.employeeFormStatus = "success"; this.employeeFormStatus = 'success';
console.log(this.employeeFormStatus); console.log(this.employeeFormStatus);
}, },
error => { error => {
console.log( error._body ); console.log( error._body );
this.employeeFormStatus = "send_failed"; this.employeeFormStatus = 'send_failed';
console.log(this.employeeFormStatus); console.log(this.employeeFormStatus);
} }
); );