Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 8 deletions
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 35 additions & 28 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 9 deletions
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

Lines changed: 0 additions & 19 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 0 additions & 1 deletion
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
/**

0 commit comments

Comments
 (0)