From 52de477cc2d87949f7a91a5551b39e224dfb9e5f Mon Sep 17 00:00:00 2001 From: piratefinn Date: Wed, 30 Aug 2017 16:09:57 +0100 Subject: [PATCH] Fully working table org search and better error --- src/app/dashboard/add-data.component.html | 2 +- src/app/dashboard/add-data.component.ts | 32 ++++++++++++----------- src/app/dashboard/dashboard.module.ts | 2 ++ src/app/shared/org-result.component.html | 4 +++ src/app/shared/org-result.component.ts | 26 +++++++++++++----- src/app/shared/org-table.component.html | 19 ++++++++++++++ src/app/shared/org-table.component.ts | 23 ++++++++++++++++ 7 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 src/app/shared/org-result.component.html create mode 100644 src/app/shared/org-table.component.html create mode 100644 src/app/shared/org-table.component.ts diff --git a/src/app/dashboard/add-data.component.html b/src/app/dashboard/add-data.component.html index b05dda8..60ab424 100644 --- a/src/app/dashboard/add-data.component.html +++ b/src/app/dashboard/add-data.component.html @@ -30,8 +30,8 @@ This is a help text - +
diff --git a/src/app/dashboard/add-data.component.ts b/src/app/dashboard/add-data.component.ts index 335227e..2ed1e54 100644 --- a/src/app/dashboard/add-data.component.ts +++ b/src/app/dashboard/add-data.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Validators, FormBuilder, FormGroup } from '@angular/forms'; import { Http, Response } from '@angular/http'; import { ApiService } from '../providers/api-service'; -import { OrgResultComponent } from '../shared/org-result.component'; +import { OrgTableComponent } from '../shared/org-table.component'; import * as moment from 'moment'; import 'rxjs/add/operator/map'; @@ -22,7 +22,7 @@ export class AddDataComponent { employeeFormStatus: any; transactionFormStatus: any; transactionFormStatusError: string = 'Error received, please try again.'; - + submitOrg = { name: '', street_name: '', @@ -45,7 +45,7 @@ export class AddDataComponent { private http: Http, private formBuilder: FormBuilder, private api: ApiService, - ) { + ) { this.payrollForm = this.formBuilder.group({ entryperiod: ['', [Validators.required]], employeeamount: ['', [Validators.required]], @@ -81,7 +81,7 @@ export class AddDataComponent { this.myDate = moment().format('YYYY-MM-DD[T]HH:mm'); // this.myDate = new Date().toISOString().slice(0, 16); } - + ngOnInit(): void { this.getMinDate(); } @@ -98,7 +98,7 @@ export class AddDataComponent { this.minDate = aprilDate.subtract(1, 'years').format('YYYY-MM-DD'); } } - + initializeItems() { // Dont bother searching for an empty or undefined string if ( this.submitOrg.name == '' ) { @@ -229,8 +229,10 @@ export class AddDataComponent { console.log('Upload Error'); console.log(error); try { - let jsonError = JSON.parse(error.body); - this.transactionFormStatusError = JSON.stringify(jsonError.status) + 'Error, ' + JSON.stringify(jsonError.message); + console.log(error.error); + let jsonError = error.json(); + console.log("boop"); + this.transactionFormStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; } catch(e) { this.transactionFormStatusError = 'There was a server error, please try again later.'; } @@ -251,10 +253,10 @@ export class AddDataComponent { this.amount = null; this.transactionFormInvalid = true; } - + onSubmitPayroll() { console.log(this.payrollForm.value); - + this.api .login(this.payrollForm.value) .subscribe( @@ -270,10 +272,10 @@ export class AddDataComponent { } ); } - + onSubmitSuppliers() { console.log(this.suppliersForm.value); - + this.api .login(this.suppliersForm.value) .subscribe( @@ -289,10 +291,10 @@ export class AddDataComponent { } ); } - + onSubmitSingleSupplier() { console.log(this.singleSupplierForm.value); - + this.api .login(this.singleSupplierForm.value) .subscribe( @@ -308,10 +310,10 @@ export class AddDataComponent { } ); } - + onSubmitEmployee() { console.log(this.employeeForm.value); - + this.api .login(this.employeeForm.value) .subscribe( diff --git a/src/app/dashboard/dashboard.module.ts b/src/app/dashboard/dashboard.module.ts index 8e52b2c..9a2adae 100644 --- a/src/app/dashboard/dashboard.module.ts +++ b/src/app/dashboard/dashboard.module.ts @@ -11,6 +11,7 @@ import { AddDataComponent } from './add-data.component'; import { DashboardRoutingModule } from './dashboard.routing'; import { OrgResultComponent } from '../shared/org-result.component'; +import { OrgTableComponent } from '../shared/org-table.component'; @NgModule({ imports: [ @@ -28,6 +29,7 @@ import { OrgResultComponent } from '../shared/org-result.component'; AccountEditComponent, AddDataComponent, OrgResultComponent, + OrgTableComponent, ] }) export class DashboardModule { } diff --git a/src/app/shared/org-result.component.html b/src/app/shared/org-result.component.html new file mode 100644 index 0000000..bd7a172 --- /dev/null +++ b/src/app/shared/org-result.component.html @@ -0,0 +1,4 @@ +{{org.name}} +{{org.street_name}} +{{org.town}} +{{org.postcode}} diff --git a/src/app/shared/org-result.component.ts b/src/app/shared/org-result.component.ts index eccc092..d7c599f 100644 --- a/src/app/shared/org-result.component.ts +++ b/src/app/shared/org-result.component.ts @@ -1,10 +1,24 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, Output, EventEmitter } from '@angular/core'; + +interface OrgData { + id: number; + name: string; + street_name: string; + town: string; + postcode: string; +} @Component({ - selector: 'org-result', - template:'banana {{ organisation }}', + selector: '[org-result]', + templateUrl: 'org-result.component.html', }) export class OrgResultComponent { - @Input() organisation: any; - -} \ No newline at end of file + @Input() public org: OrgData; + @Output() public onClick = new EventEmitter(); + + public orgClick(): void { + this.onClick.emit( + this.org + ) + } +} diff --git a/src/app/shared/org-table.component.html b/src/app/shared/org-table.component.html new file mode 100644 index 0000000..6d9a627 --- /dev/null +++ b/src/app/shared/org-table.component.html @@ -0,0 +1,19 @@ +
+ +
+ Select an Organisation from the table below + + + + + + + + + + + + +
Organisation NameStreet NameTownPostcode
+
+
diff --git a/src/app/shared/org-table.component.ts b/src/app/shared/org-table.component.ts new file mode 100644 index 0000000..8e0979d --- /dev/null +++ b/src/app/shared/org-table.component.ts @@ -0,0 +1,23 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { OrgResultComponent } from '../shared/org-result.component'; + +interface OrgData { + id: number; + name: string; + street_name: string; + town: string; + postcode: string; +} + +@Component({ + selector: 'org-table', + templateUrl: 'org-table.component.html', +}) +export class OrgTableComponent { + @Input() public orgList: Array; + @Output() public onClick = new EventEmitter(); + + public orgClick(event: any): void { + this.onClick.emit( event ); + } +}