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

Commit 373cb80

Browse files
committed
feat(http): upgrade angular http to httpClient
1 parent 211cece commit 373cb80

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/app/app.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
44
import { FormsModule } from '@angular/forms';
5-
import { HttpModule } from '@angular/http';
5+
import { HttpClientModule } from '@angular/common/http';
66

77
// App components
88
import { AppComponent } from './app.component';
@@ -22,7 +22,8 @@ import { SlideOutExampleModule } from './slide-out-panel/examples/slide-out-exam
2222
BrowserAnimationsModule,
2323
BrowserModule,
2424
FormsModule,
25-
HttpModule,
25+
// import HttpClientModule after BrowserModule.
26+
HttpClientModule,
2627
GitHubLinkAreaExampleModule,
2728
HomeModule,
2829
MarkdownExampleModule,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import (reference) '../../assets/stylesheets/ngx-widgets.less';
2+
3+
.gh-link-open { color: @color-pf-red; }
4+
.gh-link-closed { color: @color-pf-green; }
5+
.gh-link-error { color: @color-pf-orange; }

src/app/github-link-area/github-link-area.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ import { GitHubLinkService } from './github-link.service';
2222
@Component({
2323
encapsulation: ViewEncapsulation.None,
2424
selector: 'github-link-area',
25-
styles: [ `
26-
.gh-link-open { color: @color-pf-red; }
27-
.gh-link-closed { color: @color-pf-green; }
28-
.gh-link-error { color: @color-pf-orange; }
29-
`],
25+
styleUrls: [ './github-link-area.component.less'],
3026
templateUrl: './github-link-area.component.html'
3127
})
3228
export class GitHubLinkAreaComponent implements OnChanges, AfterViewChecked {

src/app/github-link-area/github-link.service.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import {
77
import { Observable, of } from 'rxjs';
88
import { catchError } from 'rxjs/operators';
99

10+
/**
11+
* This is the Type used for the data returned from Github
12+
*/
13+
export interface Gh_issue {
14+
match: string;
15+
org: string;
16+
repo: string;
17+
issue: string;
18+
state?: string;
19+
url?: string;
20+
}
1021

1122
/**
1223
* This provides a very simple retrieval of issue information from
@@ -17,7 +28,7 @@ import { catchError } from 'rxjs/operators';
1728
@Injectable()
1829
export class GitHubLinkService {
1930

20-
private linkCache: any[] = [];
31+
private linkCache: Gh_issue[] = [];
2132

2233
constructor(private http: HttpClient) {}
2334

@@ -28,18 +39,19 @@ export class GitHubLinkService {
2839
* once for every GitHub issue for the entire runtime of the service. This is needed
2940
* because GitHub is enforcing a strict rate limiting.
3041
*/
31-
getIssue(linkData: any): Observable<any> {
42+
getIssue(linkData: Gh_issue): Observable<Gh_issue> {
3243
let cachedData = this.findInCache(linkData);
3344
if (cachedData) {
3445
return of(cachedData);
3546
} else {
36-
let query: Observable<any> = this.http.get(
47+
let query: Observable<Gh_issue> = this.http.get<Gh_issue>(
3748
'https://api.github.com/repos/' +
3849
linkData.org + '/' +
3950
linkData.repo +
4051
'/issues/' + linkData.issue)
4152
.pipe(catchError((error: any) => {
42-
return of({state: 'error'});
53+
linkData.state = 'error';
54+
return of(linkData);
4355
}));
4456
query.subscribe(data => {
4557
this.linkCache.push(data);
@@ -48,7 +60,7 @@ export class GitHubLinkService {
4860
}
4961
}
5062

51-
private findInCache(linkData: any): any {
63+
private findInCache(linkData: Gh_issue): any {
5264
for (let i = 0; i < this.linkCache.length; i++) {
5365
let link = this.linkCache[i];
5466
if (link.url === 'https://api.github.com/repos/' +

0 commit comments

Comments
 (0)