Skip to content

Commit e1fc2b0

Browse files
committed
ApiGatewayService- added service and updated trip planner
1 parent 7c0351e commit e1fc2b0

File tree

8 files changed

+80
-8
lines changed

8 files changed

+80
-8
lines changed

src/app/app.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
44
import { Routes, RouterModule } from '@angular/router';
5+
import { HttpModule } from '@angular/http';
56
import { FeCommonModule } from './common/common.module';
67
import { AppComponent } from './app.component';
78
import { LoginComponent } from 'app/common/components/smart/login/login.component';
89
import { TripPlannerComponent } from 'app/passengers/components/smart/trip-planner/trip-planner.component';
910
import { AgmCoreModule, GoogleMapsAPIWrapper } from '@agm/core';
11+
import { APIGatewayService } from 'app/common/services/api-gateway.service';
1012

1113
const routes:Routes = [
1214
{path: '', redirectTo: 'login', pathMatch: 'full'},
@@ -26,10 +28,11 @@ const routes:Routes = [
2628
AgmCoreModule.forRoot({
2729
apiKey: 'AIzaSyDPs_IyBxZNsYKEh8JplMe8a91URajuqic',
2830
libraries: ['places']
29-
})
31+
}),
32+
HttpModule
3033
],
3134
providers: [
32-
GoogleMapsAPIWrapper
35+
GoogleMapsAPIWrapper, APIGatewayService
3336
],
3437
bootstrap: [AppComponent]
3538
})

src/app/common/common.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ToolbarComponent } from './components/presentation/toolbar/toolbar.comp
1010
import { RaisedButtonComponent } from './components/presentation/raised-button/raised-button.component';
1111
import { BasicButtonComponent } from './components/presentation/basic-button/basic-button.component';
1212
import { IconButtonComponent } from './components/presentation/icon-button/icon-button.component';
13-
import { GMapsDirectionsService} from './states/gmaps.service';
13+
import { GMapsDirectionsService} from './services/gmaps.service';
1414
import { MatToolbarModule, MatCheckboxModule, MatButtonModule, MatFormFieldModule, MatFormFieldControl, MatInputModule, MatIconModule, MatCardModule, MatAutocompleteModule } from '@angular/material';
1515
import { HeaderComponent } from './components/presentation/header/header.component';
1616

@@ -48,7 +48,9 @@ import { HeaderComponent } from './components/presentation/header/header.compone
4848
ReactiveFormsModule,
4949
MatAutocompleteModule,
5050
GMapsDirectionsService,
51-
HeaderComponent
51+
HeaderComponent,
52+
TextBoxComponent,
53+
FormsModule
5254
],
5355
})
5456

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Injectable } from '@angular/core';
2+
import { Http } from '@angular/http';
3+
4+
@Injectable()
5+
export class APIGatewayService {
6+
7+
private http:Http;
8+
private apiUrl = "http://10.55.13.61:8081/api/";
9+
10+
constructor(http:Http) {
11+
this.http = http;
12+
}
13+
14+
// Trip Management
15+
16+
getDirections(originAddress:string, destinationAddress:string, directionsDisplay:any) {
17+
let postUrl = this.apiUrl.concat("trips/directions");
18+
this.http.post(postUrl, {
19+
"origin": originAddress,
20+
"destination": destinationAddress
21+
}).subscribe(result => {
22+
let body = result.json();
23+
//directionsDisplay.set(body["routes"]);
24+
console.log("Result of getDirections: ");
25+
console.log(body);
26+
return result;
27+
})
28+
}
29+
30+
getTrip(passenger:string, driver:string, car:string, originAddress:string, destinationAddress:string) {
31+
let postUrl = this.apiUrl.concat(passenger, "/", driver, "/", car, "/", originAddress, "/", destinationAddress);
32+
this.http.post(postUrl, {}).subscribe(result => {
33+
console.log("Result of getTrip: ");
34+
console.log(result);
35+
})
36+
}
37+
38+
}
File renamed without changes.

src/app/passengers/components/smart/trip-planner/trip-planner.component.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@ <h1>{{ title }}</h1>
55
<directions-service></directions-service>
66
</agm-map>
77
</div>
8+
<div class="material-trip-inputs">
9+
<app-text-box placeholder="Enter your pickup location."
10+
icon="my_location"
11+
ngDefaultControl
12+
[(ngModel)]="pickupTextboxValue"
13+
(ngModelChange)="onPickupTextChange($event)">
14+
</app-text-box>
15+
<app-text-box placeholder="Enter your destination."
16+
icon="place"
17+
ngDefaultControl
18+
[(ngModel)]="destinationTextboxValue"
19+
(ngModelChange)="onDestinationTextChange($event)">>
20+
</app-text-box>
21+
</div>
22+
823
<div class="trip-inputs">
924
<input placeholder="Enter your pickup location." autocorrect="off" autocapitalize="off" spellcheck="off" type="text" class="form-control"
1025
#pickupInput [formControl]="destinationInput" size="55">
1126
<input placeholder="Enter your destination." autocorrect="off" autocapitalize="off" spellcheck="off" type="text" class="form-control"
1227
#pickupOutput [formControl]="destinationOutput" size="55">
1328
</div>
14-
<app-raised-button label="Find Your Ride" color="primary"></app-raised-button>
29+
<app-raised-button label="Find Your Ride" color="primary" (click)="onFindRideClick($event)"></app-raised-button>
1530
</mat-card>

src/app/passengers/components/smart/trip-planner/trip-planner.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit, Input, ElementRef, NgZone, ViewChild } from '@angular/core';
22
import { FormControl, ReactiveFormsModule } from '@angular/forms';
3-
import { GMapsDirectionsService } from 'app/common/states/gmaps.service';
3+
import { GMapsDirectionsService } from 'app/common/services/gmaps.service';
4+
import { APIGatewayService } from 'app/common/services/api-gateway.service';
45
import { } from '@types/googlemaps';
56
import { GoogleMapsAPIWrapper, MapsAPILoader } from '@agm/core';
67
import { error } from 'util';
@@ -25,6 +26,9 @@ export class TripPlannerComponent implements OnInit {
2526
@Input() private estimatedDistance: any;
2627
@Input() private initialLat: number;
2728
@Input() private initialLng: number;
29+
@Input() private pickupTextboxValue: any;
30+
@Input() private destinationTextboxValue: any;
31+
private directionsDisplay;
2832

2933
@ViewChild('pickupInput')
3034
public pickupInputElementRef: ElementRef;
@@ -38,7 +42,8 @@ export class TripPlannerComponent implements OnInit {
3842
private ngZone: NgZone,
3943
private mapsAPILoader: MapsAPILoader,
4044
private gmapsApi: GoogleMapsAPIWrapper,
41-
private _elementRef: ElementRef) {
45+
private _elementRef: ElementRef,
46+
private apiGatewayService: APIGatewayService) {
4247
}
4348

4449
ngOnInit() {
@@ -72,6 +77,14 @@ export class TripPlannerComponent implements OnInit {
7277
});
7378
}
7479

80+
onFindRideClick(event) {
81+
this.apiGatewayService.getDirections(this.pickupTextboxValue, this.destinationTextboxValue, this.directionsDisplay);
82+
}
83+
84+
onPickupTextChange(event) {}
85+
86+
onDestinationTextChange(event) {}
87+
7588
setCurrentPosition() {
7689
if ('geolocation' in navigator) {
7790
navigator.geolocation.getCurrentPosition((position) => {

src/app/passengers/passengers.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3+
import { FeCommonModule } from 'app/common/common.module';
34

45
@NgModule({
56
imports: [
6-
CommonModule
7+
CommonModule, FeCommonModule
78
],
89
declarations: []
910
})

0 commit comments

Comments
 (0)