diff --git a/config/environment.dev.ts b/config/environment.dev.ts index 5b296ed..02880a0 100644 --- a/config/environment.dev.ts +++ b/config/environment.dev.ts @@ -1,4 +1,5 @@ export const environment = { production: false, - devHost:"http://localhost:3000" + baseApiUrl: "http://localhost:8080", + jwtEnabled: true }; diff --git a/src/app/+cart/cart.component.html b/src/app/+cart/cart.component.html index d9f17cd..2a07306 100644 --- a/src/app/+cart/cart.component.html +++ b/src/app/+cart/cart.component.html @@ -1,3 +1,8 @@

cart works! + + Click here to simulate a booking +

+
Error: {{error | json}}
+
Added: {{added | json }}
diff --git a/src/app/+cart/cart.component.ts b/src/app/+cart/cart.component.ts index f76e82b..8e35b3d 100644 --- a/src/app/+cart/cart.component.ts +++ b/src/app/+cart/cart.component.ts @@ -1,4 +1,7 @@ import { Component, OnInit } from '@angular/core'; +import { Response } from '@angular/http'; +import { AuthService, IUser, UtilityService } from '../shared'; +import { environment } from '../'; @Component({ moduleId: module.id, @@ -7,9 +10,37 @@ import { Component, OnInit } from '@angular/core'; }) export class CartComponent implements OnInit { - constructor() {} + authService: AuthService; + utility: UtilityService; + error: string; + added: Array; + + constructor(authService: AuthService, utility: UtilityService) { + this.authService = authService; + this.utility = utility; + } ngOnInit() { } + createFakeBooking() { + let flight = { + "username": this.authService.getUser(), + "flights": [ { + "name": "Fake Flight", + "date": "6/23/2016", + "sourceairport": "CDG", + "destinationairport": "SFO" + } ] + }; + return this.utility.makePostRequest(environment.baseApiUrl + "/api/user/flights", [], flight).then((response: any) => { + let result = response.data as any; + this.added = result.added; + this.error = null; + }, (error) => { + this.added = null; + this.error = error; + }); + } + } diff --git a/src/app/+hotels/hotels.component.html b/src/app/+hotels/hotels.component.html index 0c213d3..1816b6a 100644 --- a/src/app/+hotels/hotels.component.html +++ b/src/app/+hotels/hotels.component.html @@ -1,3 +1,74 @@ -

- hotels works! -

+
+
+

Find Hotels

+
+
+
+ +
+ + +
+ +
+ + +
+ + +
+
+
+ +
+
+

Matching POIs

+
+
+
+ No matching POI +
+ + + + + + + + + + + + + + + +
NameAddressDescription
{{line.name}}{{line.address}}{{line.description}}
+
+ +
+ +
+
There was an error (click for details) +
+ +
{{error | json}}
+
\ No newline at end of file diff --git a/src/app/+hotels/hotels.component.ts b/src/app/+hotels/hotels.component.ts index 85c12d4..247042e 100644 --- a/src/app/+hotels/hotels.component.ts +++ b/src/app/+hotels/hotels.component.ts @@ -1,15 +1,90 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy, Injectable, Inject } from '@angular/core'; +import { + CORE_DIRECTIVES, + FORM_DIRECTIVES, + FormBuilder, + ControlGroup, + Validators +} from '@angular/common'; +import { Response } from "@angular/http"; +import { UtilityService } from "../shared/utility.service"; +import { Narration, NarrationService } from "../shared/narration.service"; +import { environment } from "../"; +import { Observable } from 'rxjs/Rx'; @Component({ moduleId: module.id, selector: 'app-hotels', + directives: [CORE_DIRECTIVES, FORM_DIRECTIVES], templateUrl: 'hotels.component.html' }) -export class HotelsComponent implements OnInit { - constructor() {} +@Injectable() + +export class HotelsComponent implements OnInit, OnDestroy { + + hotelForm: ControlGroup; + utility: UtilityService; + private _narrations: NarrationService; + data; + error; + + constructor(fb: FormBuilder, utility: UtilityService, narrationService: NarrationService) { + this.hotelForm = fb.group({ + 'description': [''], + 'location': [''] + }); + this.utility = utility; + this._narrations = narrationService; + } ngOnInit() { + this._narrations.add("Entered Hotels component", "You navigated to the Hotels search form"); } -} + ngOnDestroy() { + this._narrations.clear(); + } + + findHotels(value: any): void { + var location = value.location; + var description = value.description; + + var url = environment.baseApiUrl + "/api/hotel/"; + var hasDescription = (description != null && description != ""); + var hasLocation = (location != null && location != ""); + if (hasDescription && hasLocation) { + url = url + description + "/" + location + "/"; + } else if (hasLocation) { + url = url + "*/" + location + "/"; + } else if (hasDescription) { + url = url + description + "/" + } + + this._narrations.addPre("GET to " + url, "The search parameters were:", JSON.stringify(value)); + + this.utility.makeGetRequestObs(url, []) + .map((response: Response) => response.json()) + .subscribe( + (val: any) => { + this.data = val.data; + + //we expect 2 context requests + if (val.context.length == 2) { + this._narrations.addPre("FTS query executed in the backend", "The following FTS query was executed in the backend:", val.context[0]); + this._narrations.addPre("Subdocument query executed in the backend", "The following subdocument fetch was executed in the backend:", val.context[1]); + this._narrations.add("SUCCESS", "Found " + this.data.length + " matching hotels"); + } else { + this._narrations.fallbackPre(2, "SUCCESS (found " + this.data.length + " matching hotels)", val.context); + } + + + }, + (error: any) => { + this.data = null; + this.error = error; + this._narrations.addPre("ERROR", "There was an error:", JSON.stringify(this.error, null, 2)); + } + ); + } +} \ No newline at end of file diff --git a/src/app/+login/login.component.html b/src/app/+login/login.component.html index d79ff36..1c0fe69 100644 --- a/src/app/+login/login.component.html +++ b/src/app/+login/login.component.html @@ -7,7 +7,7 @@
- +