Skip to content

Commit 9fbee39

Browse files
ghillertoodamien
authored andcommitted
gh-536 Replace HttpModule with HttpClientModule
* Update Tests (Refactoring of HttpClient mocks) * Ensure that lint warnings related to Http module are fixed * Minor fix to make bundle analyzer work: Update `webpack-bundle-analyzer` to `2.13.1` * Fix RxJS lint warnings due to deprecation * Start to Remove unused imports * Fix Lint errors
1 parent b533b54 commit 9fbee39

File tree

65 files changed

+858
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+858
-716
lines changed

ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"@types/d3-dsv": "1.0.31",
8383
"browserstack-local": "1.3.3",
8484
"napa": "3.0.0",
85-
"webpack-bundle-analyzer": "2.9.0",
85+
"webpack-bundle-analyzer": "2.13.1",
8686
"protractor-docker-plugin": "./protractor-docker-plugin"
8787
},
8888
"napa-config": {

ui/src/app/about/about.service.spec.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AboutService } from './about.service';
22
import { Observable } from 'rxjs/Observable';
33
import { ErrorHandler } from '../shared/model/error-handler';
4-
import { Response, ResponseOptions } from '@angular/http';
54
import { SharedAboutService } from '../shared/services/shared-about.service';
65
import { BusyService } from '../shared/services/busy.service';
76

@@ -102,19 +101,22 @@ describe('AboutService', () => {
102101
};
103102

104103
beforeEach(() => {
105-
this.mockHttp = jasmine.createSpyObj('mockHttp', ['get']);
106-
const mockResponse = new Response(new ResponseOptions({
107-
body: JSON.stringify(jsonData)
108-
}));
109-
this.mockHttp.get.and.returnValue(Observable.of(mockResponse));
104+
this.mockHttp = {
105+
get: jasmine.createSpy('get'),
106+
};
107+
this.mockHttp.get.and.returnValue(Observable.of(jsonData));
110108
const errorHandler = new ErrorHandler();
111109
this.sharedAboutService = new SharedAboutService(new BusyService(), this.mockHttp, errorHandler);
112-
this.aboutService = new AboutService(this.sharedAboutService, this.mockHttp, errorHandler);
110+
this.aboutService = new AboutService(this.sharedAboutService);
113111
});
114112

115113
it('should call the about service with the right url', () => {
116114
this.aboutService.getAboutInfo(true);
117-
expect(this.mockHttp.get).toHaveBeenCalledWith('/about');
115+
116+
const httpUri = this.mockHttp.get.calls.mostRecent().args[0];
117+
const headerArgs = this.mockHttp.get.calls.mostRecent().args[1];
118+
expect(httpUri).toEqual('/about');
119+
expect(headerArgs).toBeUndefined();
118120
});
119121

120122
it('should return the correct json data', () => {

ui/src/app/about/about.service.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { Injectable } from '@angular/core';
2-
import { Http, Response } from '@angular/http';
32
import { Observable } from 'rxjs/Observable';
43
import { Subject } from 'rxjs/Subject';
54

65
import 'rxjs/add/operator/catch';
76
import 'rxjs/add/operator/map';
8-
import { ErrorHandler } from '../shared/model/error-handler';
97

108
import { SharedAboutService } from '../shared/services/shared-about.service';
119
import { FeatureInfo } from '../shared/model/about/feature-info.model';
@@ -18,12 +16,8 @@ export class AboutService {
1816
* Constructor
1917
*
2018
* @param {SharedAboutService} sharedAboutService
21-
* @param {Http} http
22-
* @param {ErrorHandler} errorHandler
2319
*/
24-
constructor(private sharedAboutService: SharedAboutService,
25-
private http: Http,
26-
private errorHandler: ErrorHandler) {
20+
constructor(private sharedAboutService: SharedAboutService) {
2721
}
2822

2923
/**

ui/src/app/about/about/about.component.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ export class AboutComponent implements OnInit {
3131
* Constructor
3232
*
3333
* @param {AboutService} aboutService
34-
* @param {Router} router
3534
*/
36-
constructor(private aboutService: AboutService,
37-
private router: Router) {
35+
constructor(private aboutService: AboutService) {
3836
}
3937

4038
/**

ui/src/app/analytics/analytics.service.ts

+35-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { Http, Response, RequestOptionsArgs, URLSearchParams } from '@angular/http';
2+
import { HttpClient, HttpParams } from '@angular/common/http';
33
import { Observable } from 'rxjs/Observable';
44
import { Subscription } from 'rxjs/Subscription';
55
import 'rxjs/add/operator/catch';
@@ -43,7 +43,7 @@ export class AnalyticsService {
4343
private rowId = 1; // For Dashboard
4444
public dashboardItems: DashboardItem[];
4545

46-
constructor(private http: Http,
46+
constructor(private httpClient: HttpClient,
4747
private errorHandler: ErrorHandler,
4848
private loggerService: LoggerService,
4949
private notificationService: NotificationService) {
@@ -119,14 +119,16 @@ export class AnalyticsService {
119119
}
120120

121121
const params = HttpUtils.getPaginationParams(this.counters.pageNumber, this.counters.pageSize);
122-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
122+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
123123

124124
if (detailed) {
125125
params.append('detailed', detailed.toString());
126126
}
127127

128-
requestOptionsArgs.search = params;
129-
return this.http.get(this.metricsCountersUrl, requestOptionsArgs)
128+
return this.httpClient.get<any>(this.metricsCountersUrl, {
129+
headers: httpHeaders,
130+
params: params
131+
})
130132
.map(response => this.extractData(response, detailed))
131133
.catch(this.errorHandler.handleError) as Observable<Page<Counter>>;
132134
}
@@ -136,10 +138,12 @@ export class AnalyticsService {
136138
*/
137139
private getAllFieldValueCounters(): Observable<Page<FieldValueCounter>> {
138140
const params = HttpUtils.getPaginationParams(0, 100);
139-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
141+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
140142

141-
requestOptionsArgs.search = params;
142-
return this.http.get(this.metricsFieldValueCountersUrl, requestOptionsArgs)
143+
return this.httpClient.get<any>(this.metricsFieldValueCountersUrl, {
144+
params: params,
145+
headers: httpHeaders
146+
})
143147
.map(response => this.extractData(response, false))
144148
.catch(this.errorHandler.handleError) as Observable<Page<FieldValueCounter>>;
145149
}
@@ -149,16 +153,17 @@ export class AnalyticsService {
149153
*/
150154
private getAllAggregateCounters(): Observable<Page<AggregateCounter>> {
151155
const params = HttpUtils.getPaginationParams(0, 100);
152-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
156+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
153157

154-
requestOptionsArgs.search = params;
155-
return this.http.get(this.metricsAggregateCountersUrl, requestOptionsArgs)
158+
return this.httpClient.get<any>(this.metricsAggregateCountersUrl, {
159+
params: params,
160+
headers: httpHeaders
161+
})
156162
.map(response => this.extractData(response, false))
157163
.catch(this.errorHandler.handleError) as Observable<Page<AggregateCounter>>;
158164
}
159165

160-
private extractData(response: Response, handleRates: boolean): Page<BaseCounter> {
161-
const body = response.json();
166+
private extractData(body, handleRates: boolean): Page<BaseCounter> {
162167
const items: BaseCounter[] = [];
163168
const cache: BaseCounter[] = [];
164169

@@ -374,10 +379,11 @@ export class AnalyticsService {
374379
* @param counterName Name of the counter for which to retrieve details
375380
*/
376381
private getSingleCounter(counterName: string): Observable<Counter> {
377-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
378-
return this.http.get(this.metricsCountersUrl + '/' + counterName, requestOptionsArgs)
379-
.map(response => {
380-
const body = response.json();
382+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
383+
return this.httpClient.get<any>(this.metricsCountersUrl + '/' + counterName, {
384+
headers: httpHeaders
385+
})
386+
.map(body => {
381387
this.loggerService.log('body', body);
382388
return new Counter().deserialize(body);
383389
})
@@ -390,10 +396,11 @@ export class AnalyticsService {
390396
* @param counterName Name of the counter for which to retrieve details
391397
*/
392398
private getSingleFieldValueCounter(counterName: string): Observable<FieldValueCounter> {
393-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
394-
return this.http.get(this.metricsFieldValueCountersUrl + '/' + counterName, requestOptionsArgs)
395-
.map(response => {
396-
const body = response.json();
399+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
400+
return this.httpClient.get<any>(this.metricsFieldValueCountersUrl + '/' + counterName, {
401+
headers: httpHeaders
402+
})
403+
.map(body => {
397404
return new FieldValueCounter().deserialize(body);
398405
})
399406
.catch(this.errorHandler.handleError);
@@ -405,16 +412,16 @@ export class AnalyticsService {
405412
* @param counterName Name of the counter for which to retrieve details
406413
*/
407414
private getSingleAggregateCounter(counter: AggregateCounter): Observable<AggregateCounter> {
408-
const requestOptionsArgs: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
409-
const params = new URLSearchParams();
410-
411-
requestOptionsArgs.params = params;
415+
const httpHeaders = HttpUtils.getDefaultHttpHeaders();
416+
const params = new HttpParams();
412417

413418
params.append('resolution', counter.resolutionType.name.toLowerCase());
414419

415-
return this.http.get(this.metricsAggregateCountersUrl + '/' + counter.name, requestOptionsArgs)
416-
.map(response => {
417-
const body = response.json();
420+
return this.httpClient.get<any>(this.metricsAggregateCountersUrl + '/' + counter.name, {
421+
headers: httpHeaders,
422+
params: params
423+
})
424+
.map(body => {
418425
return new AggregateCounter().deserialize(body);
419426
})
420427
.catch(this.errorHandler.handleError);

ui/src/app/analytics/charts/bar-chart/bar-chart.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
OnChanges, ChangeDetectionStrategy, Component,
2+
OnChanges, Component,
33
OnInit, HostListener, ViewChild,
44
ElementRef, Input, ViewEncapsulation } from '@angular/core';
55
import * as d3 from 'd3';

ui/src/app/analytics/charts/bubble-chart/bubble-chart.component.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
OnChanges, ChangeDetectionStrategy, Component,
3-
OnInit, DoCheck, HostListener, ViewChild, ElementRef,
2+
OnChanges, Component,
3+
OnInit, HostListener, ViewChild, ElementRef,
44
Input, ViewEncapsulation } from '@angular/core';
55

66
import * as d3 from 'd3';
@@ -32,9 +32,6 @@ export class BubbleChartComponent implements OnInit, OnChanges {
3232
private chartDataToUse: FieldValueCounterValue[];
3333

3434
private chart: any;
35-
private xScale: any;
36-
private yScale: any;
37-
private xAxis: any;
3835

3936
/**
4037
* Initialize the component and trigger the rendering of the chart.
@@ -129,8 +126,6 @@ export class BubbleChartComponent implements OnInit, OnChanges {
129126

130127
const localThis = this;
131128

132-
const radius = Math.min(widthToUse, heightToUse) / 2;
133-
134129
if (!localThis.chartDataToUse) {
135130
return;
136131
} else {
@@ -182,6 +177,4 @@ export class BubbleChartComponent implements OnInit, OnChanges {
182177
});
183178
}
184179

185-
private updateChart() {
186-
}
187180
}

ui/src/app/analytics/charts/graph-chart/graph-chart.component.ts

-19
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,6 @@ export class GraphChartComponent implements OnInit, DoCheck {
197197
})
198198
.curve(d3.curveBasis);
199199

200-
const xAxisGroup = svg
201-
.append('g')
202-
.attr('class', 'x axis')
203-
.attr('transform', 'translate(0,' + (height - margin.bottom) + ')')
204-
.attr('fill', 'none')
205-
.attr('stroke', '#777')
206-
.attr('opacity', 1.0)
207-
.attr('shape-rendering', 'crispEdges')
208-
.call(xAxis);
209-
210-
const yAxisGroup = svg.append('g')
211-
.attr('class', 'y axis')
212-
.attr('transform', 'translate(' + (margin.left) + ',0)')
213-
.attr('fill', 'none')
214-
.attr('stroke', '#777')
215-
.attr('opacity', 1.0)
216-
.attr('shape-rendering', 'crispEdges')
217-
.call(yAxis);
218-
219200
svg.append('path')
220201
.datum(dataItemsToUse)
221202
.attr('d', lineGen)

ui/src/app/analytics/charts/pie-chart/pie-chart.component.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
OnChanges, ChangeDetectionStrategy, Component,
3-
OnInit, DoCheck, HostListener, ViewChild,
2+
OnChanges, Component,
3+
OnInit, HostListener, ViewChild,
44
ElementRef, Input, ViewEncapsulation } from '@angular/core';
55

66
import * as d3 from 'd3';
@@ -252,8 +252,4 @@ export class PieChartComponent implements OnInit, OnChanges {
252252
return localThis.chartDataToUse[i].key;
253253
});
254254
}
255-
256-
private updateChart() {
257-
const localThis = this;
258-
}
259255
}

ui/src/app/analytics/counters/counters.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22

33
import { AnalyticsService } from '../analytics.service';
4-
import { Counter } from '../model/counter.model';
54
import { LoggerService } from '../../shared/services/logger.service';
65

76
/**

ui/src/app/analytics/dashboard/dashboard.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { AnalyticsService } from '../analytics.service';
3-
import { AggregateCounter, AggregateCounterResolutionType, DashboardItem, MetricType } from '../model';
3+
import { AggregateCounterResolutionType, DashboardItem, MetricType } from '../model';
44
import { takeUntil } from 'rxjs/operators';
55
import { Subject } from 'rxjs/Subject';
66
import { NotificationService } from '../../shared/services/notification.service';

ui/src/app/analytics/model/aggregate-counter-resolution-type.model.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Serializable } from '../../shared/model';
2-
31
/**
42
* Mimics the corresponding AggregateCounterResolution class from the
53
* server-side. Represents a time-resolution supported by the

ui/src/app/analytics/model/aggregate-counter.model.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ describe('AggregateCounter', () => {
6868
const values = counter.getValues();
6969

7070
expect(values.length).toBe(4);
71-
72-
const expectedTime0: Moment = moment('2017-09-27T00:03:58.378Z');
73-
const expectedTime1: Moment = moment('2017-09-27T00:04:58.378Z');
74-
7571
expect(values[0]).toBe(654);
7672
expect(values[1]).toBe(861);
7773
});

ui/src/app/app.module.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule, APP_INITIALIZER } from '@angular/core';
3-
import { RequestOptions } from '@angular/http';
4-
import { SecurityAwareRequestOptions } from './auth/support/security-aware-request-options';
53

64
/* Feature Modules */
75
import { AboutModule } from './about/about.module';
@@ -67,10 +65,6 @@ export function init(authService: AuthService, sharedAboutService: SharedAboutSe
6765
'useFactory': init,
6866
'deps': [ AuthService, SharedAboutService ],
6967
'multi': true
70-
},
71-
{
72-
'provide': RequestOptions,
73-
'useClass': SecurityAwareRequestOptions
7468
}
7569
],
7670
bootstrap: [ AppComponent ]

ui/src/app/apps/app-details/app-details.component.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
2-
import { Router, ActivatedRoute, Params } from '@angular/router';
2+
import { ActivatedRoute, Params } from '@angular/router';
33
import { AppsService } from '../apps.service';
44
import { ApplicationType, DetailedAppRegistration } from '../../shared/model';
5-
import { Subscription } from 'rxjs/Subscription';
65
import { SharedAboutService } from '../../shared/services/shared-about.service';
76
import { AppRegistration } from '../../shared/model/app-registration.model';
87
import { FeatureInfo } from '../../shared/model/about/feature-info.model';
98
import { AppVersionsComponent } from '../app-versions/app-versions.component';
109
import { BsModalService } from 'ngx-bootstrap';
1110
import { SortParams } from '../../shared/components/shared.interface';
12-
import { combineLatest } from 'rxjs/operators/combineLatest';
11+
import { combineLatest } from 'rxjs';
1312
import { Subject } from 'rxjs/Subject';
1413
import { takeUntil } from 'rxjs/operators';
1514
import { BusyService } from '../../shared/services/busy.service';
@@ -97,8 +96,9 @@ export class AppDetailsComponent implements OnInit, OnDestroy {
9796
*/
9897
ngOnInit() {
9998
this.loggerService.log('App Service Details');
100-
this.sharedAboutService.getFeatureInfo()
101-
.pipe(combineLatest(this.route.params))
99+
const featureInfo$ = this.sharedAboutService.getFeatureInfo();
100+
101+
combineLatest(featureInfo$, this.route.params)
102102
.subscribe((data: any[]) => {
103103
const featureInfo = data[0] as FeatureInfo;
104104
const params = data[1] as Params;

ui/src/app/apps/apps-bulk-import/apps-bulk-import.validator.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {FormControl, FormGroup} from '@angular/forms';
2-
import {AppsBulkImportComponent} from './apps-bulk-import.component';
32

43
/**
54
* Validators for Bulk Import Form

0 commit comments

Comments
 (0)