Skip to content

Commit 37bec29

Browse files
author
David Sargent
committed
More cleanup work
1 parent 8a3ad87 commit 37bec29

File tree

8 files changed

+64
-42
lines changed

8 files changed

+64
-42
lines changed

src/app/app.module.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
3-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4-
import { Routes, RouterModule } from '@angular/router';
5-
import { FeCommonModule } from './common/common.module';
6-
import { AppComponent } from './app.component';
7-
import { LoginComponent } from 'app/common/components/smart/login/login.component';
8-
import { TripPlannerComponent } from 'app/passengers/components/smart/trip-planner/trip-planner.component';
9-
import { AgmCoreModule, GoogleMapsAPIWrapper } from '@agm/core';
10-
import { PlacesAutocompleteComponent } from 'app/passengers/components/presentation/places-autocomplete/places-autocomplete.component';
11-
import { StoreModule } from '@ngrx/store';
12-
import { MatFormFieldModule, MatInputModule } from '@angular/material';
13-
import { GMapsDirectionsService } from 'app/common/states/gmaps.service';
14-
import { HttpModule } from '@angular/http';
15-
import { NotificationService } from 'app/common/states/notification.service';
16-
import { EventSourceService } from 'app/common/states/event-source.service';
1+
import {BrowserModule} from '@angular/platform-browser';
2+
import {NgModule} from '@angular/core';
3+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
4+
import {Routes, RouterModule} from '@angular/router';
5+
import {FeCommonModule} from './common/common.module';
6+
import {AppComponent} from './app.component';
7+
import {LoginComponent} from 'app/common/components/smart/login/login.component';
8+
import {TripPlannerComponent} from 'app/passengers/components/smart/trip-planner/trip-planner.component';
9+
import {AgmCoreModule, GoogleMapsAPIWrapper} from '@agm/core';
10+
import {PlacesAutocompleteComponent} from 'app/passengers/components/presentation/places-autocomplete/places-autocomplete.component';
11+
import {StoreModule} from '@ngrx/store';
12+
import {MatFormFieldModule, MatInputModule} from '@angular/material';
13+
import {GMapsDirectionsService} from 'app/common/states/gmaps.service';
14+
import {HttpModule} from '@angular/http';
15+
import {NotificationService} from 'app/common/states/notification.service';
16+
import {EventSourceService} from 'app/common/states/event-source.service';
1717
import 'rxjs/add/operator/map';
18-
import { HttpClientModule } from '@angular/common/http';
18+
import {HttpClientModule} from '@angular/common/http';
1919
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
2020
import {reducers} from './action-reducer-map';
2121
import {StoreDevtoolsModule} from '@ngrx/store-devtools';
2222
import 'rxjs/add/operator/map';
23-
import { HttpClientModule } from '@angular/common/http';
2423

2524
const routes: Routes = [
26-
{path: '', redirectTo: 'login', pathMatch: 'full'},
27-
{path: 'login', component: LoginComponent},
28-
{path: 'dashboard', component: TripPlannerComponent}
25+
{path: '', redirectTo: 'login', pathMatch: 'full'},
26+
{path: 'login', component: LoginComponent},
27+
{path: 'dashboard', component: TripPlannerComponent}
2928
];
3029

3130
@NgModule({
@@ -42,7 +41,7 @@ const routes: Routes = [
4241
libraries: ['places']
4342
}),
4443
StoreModule.forRoot(reducers),
45-
StoreDevtoolsModule.instrument({ maxAge: 25 }),
44+
StoreDevtoolsModule.instrument({maxAge: 25}),
4645
MatFormFieldModule,
4746
MatInputModule,
4847
MatProgressSpinnerModule,
@@ -54,4 +53,5 @@ const routes: Routes = [
5453
],
5554
bootstrap: [AppComponent]
5655
})
57-
export class AppModule { }
56+
export class AppModule {
57+
}

src/app/common/common.module.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { AgmCoreModule } from '@agm/core'
3+
import { AgmCoreModule } from '@agm/core';
44
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5-
import { Routes, RouterModule } from '@angular/router';
5+
import { RouterModule } from '@angular/router';
66
import { TextBoxComponent } from './components/presentation/text-box/text-box.component';
77
import { LoginComponent } from './components/smart/login/login.component';
88
import { CheckBoxComponent } from './components/presentation/check-box/check-box.component';
@@ -11,8 +11,17 @@ import { RaisedButtonComponent } from './components/presentation/raised-button/r
1111
import { BasicButtonComponent } from './components/presentation/basic-button/basic-button.component';
1212
import { IconButtonComponent } from './components/presentation/icon-button/icon-button.component';
1313
import { GMapsDirectionsService} from './states/gmaps.service';
14-
import { MatToolbarModule, MatCheckboxModule, MatButtonModule, MatFormFieldModule, MatFormFieldControl, MatInputModule, MatIconModule, MatCardModule, MatAutocompleteModule,
15-
MatProgressSpinnerModule } from '@angular/material';
14+
import {
15+
MatToolbarModule,
16+
MatCheckboxModule,
17+
MatButtonModule,
18+
MatFormFieldModule,
19+
MatInputModule,
20+
MatIconModule,
21+
MatCardModule,
22+
MatAutocompleteModule,
23+
MatProgressSpinnerModule
24+
} from '@angular/material';
1625
import { HeaderComponent } from './components/presentation/header/header.component';
1726
import { GetEstimateButtonComponent } from './components/presentation/get-estimate-button/get-estimate-button.component';
1827

src/app/common/states/event-source.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ export class EventSourceService {
99
constructor() { }
1010

1111
forUrl(url: string, err: (EventSource) => void): EventSource {
12-
if (!isNullOrUndefined(this.connections[url]) && (this.connections[url].conn.readyState !== 2 && this.connections[url].err !== null)) return this.connections[url];
13-
let newCon = this.createEventStreamConnection(url, err);
12+
if (!isNullOrUndefined(this.connections[url]) && (this.connections[url].conn.readyState !== 2 && this.connections[url].err !== null)) {
13+
return this.connections[url];
14+
}
15+
16+
const newCon = this.createEventStreamConnection(url, err);
1417
this.connections[url] = newCon;
1518
return newCon.conn;
1619
}
1720

1821
private createEventStreamConnection(url: string, err: (EventSource) => void) {
19-
let newCon = {
22+
const newCon = {
2023
conn: new this.EventSource(url),
2124
errorHandler: err,
2225
errorHandlerCalled: false

src/app/common/states/notification.service.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { TestBed, inject } from '@angular/core/testing';
22
import EventSourceMock, { sources } from 'eventsourcemock';
33
import { NotificationService } from './notification.service';
44
import {EventSourceService} from './event-source.service';
5+
import {StoreModule} from '@ngrx/store';
6+
import {reducers} from '../../action-reducer-map';
57

68
describe('NotificationService', () => {
79
let uri: string;
@@ -11,6 +13,9 @@ describe('NotificationService', () => {
1113
const mockEventSource = new EventSourceMock(uri);
1214

1315
TestBed.configureTestingModule({
16+
imports: [
17+
StoreModule.forRoot({reducers})
18+
],
1419
providers: [NotificationService, EventSourceService]
1520
});
1621
const eventSourceService = TestBed.get(EventSourceService);

src/app/common/states/notification.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ export class NotificationService {
4141

4242
onInit(): void {
4343
const currNotificationService = this;
44-
this.bindToNotificationEventSource(this.eventSourceService.forUrl(`http://localhost:32700/events?stream=${this.userId()}`, eventSource => {
45-
this.bindToNotificationEventSource.call(currNotificationService, eventSource);
46-
}));
44+
this.bindToNotificationEventSource(this.eventSourceService.forUrl(`http://localhost:32700/events?stream=${this.userId()}`,
45+
eventSource => this.bindToNotificationEventSource.call(currNotificationService, eventSource)));
4746
this.listenForRouteUpdates();
4847
}
4948

src/app/common/states/reducers/notification.reducer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ initialState.duration = 0;
99
export function notificationReducer(state: Route = initialState, action: PlannedRouteAction): Route {
1010
switch (action.type) {
1111
case 'UPDATE_ROUTE':
12-
let action1 = (action as UpdatePlannedRoute);
13-
return action1.data;
12+
return (action as UpdatePlannedRoute).data;
1413

1514
default:
1615
return state;

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface AppState {
3939
})
4040
export class TripPlannerComponent implements OnInit {
4141

42-
title: string = 'Trip Planner';
42+
title = 'Trip Planner';
4343

4444
@Input() private latitude: number;
4545
@Input() private longitude: number;
@@ -218,7 +218,9 @@ export class TripPlannerComponent implements OnInit {
218218
}
219219

220220
onFindRideClick(event) {
221-
if (this.findYourRideButtonDisabled) return;
221+
if (this.findYourRideButtonDisabled) {
222+
return;
223+
}
222224

223225
const pickupAddress = this.pickupTextboxValue;
224226
const destinationAddress = this.destinationTextboxValue;
@@ -238,7 +240,9 @@ export class TripPlannerComponent implements OnInit {
238240
// Until user-service is configured we will have to hit directly user service to get JWT token to contact edge-service
239241
const authPort = '32942';
240242
// To-Do: Disable "Find Ride" until inputs are validated
241-
if (this.tripEstimateButtonDisabled) return;
243+
if (this.tripEstimateButtonDisabled) {
244+
return;
245+
}
242246

243247
const headers = new HttpHeaders({
244248
'Content-Type': 'application/x-www-form-urlencoded',
@@ -266,7 +270,7 @@ export class TripPlannerComponent implements OnInit {
266270

267271
// Request to communicate with calculation service via JWT token
268272
postToCalculationService() {
269-
const headers = this.requestHeaders("application/json", "Bearer");
273+
const headers = this.requestHeaders('application/json', 'Bearer');
270274
const resOptions = {
271275
headers,
272276
withCredentials: true,
@@ -286,7 +290,7 @@ export class TripPlannerComponent implements OnInit {
286290
}
287291

288292
requestHeaders(contentType, authorization: string): HttpHeaders {
289-
const token = localStorage.getItem("accessToken");
293+
const token = localStorage.getItem('accessToken');
290294
return new HttpHeaders({
291295
'Content-Type': contentType,
292296
'Authorization': `${authorization} ${token}`

src/app/passengers/reducers/trip-planner.reducer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
USER_LOCATION_INPUT_REQUIRED
66
} from '../actions/trip-planner.action';
77

8-
export function tripPlannerStateReducer(state: TripPlannerState = USER_LOCATION_INPUT_REQUIRED, action: TripPlannerAction): TripPlannerState {
8+
export function tripPlannerStateReducer(
9+
state: TripPlannerState = USER_LOCATION_INPUT_REQUIRED, action: TripPlannerAction): TripPlannerState {
910
switch (action.type) {
1011
case USER_LOCATION_INPUT_REQUIRED:
1112
case PRICE_CALCULATION_REQUIRED:
@@ -15,7 +16,9 @@ export function tripPlannerStateReducer(state: TripPlannerState = USER_LOCATION_
1516

1617
case FINDING_RIDE_REQUIRED: {
1718
// Workaround for TOOL-7543
18-
if (state === USER_LOCATION_INPUT_REQUIRED) return state;
19+
if (state === USER_LOCATION_INPUT_REQUIRED) {
20+
return state;
21+
}
1922
return action.type as TripPlannerState;
2023
}
2124

0 commit comments

Comments
 (0)