From 44054859b9bee942d5717d5fdb99f92221818e1e Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Tue, 21 May 2019 13:43:27 +0800 Subject: [PATCH] Change http to httpClient of all Api in harbor change http to httpClient of all Api in harbor because since Angular 4.3, Angular has abandoned HTTP and used HTTP Client instead. Signed-off-by: Yogi_Wang --- src/portal/lib/src/app.module.ts | 2 - .../lib/src/config/gc/gc.api.repository.ts | 13 +-- src/portal/lib/src/config/gc/gc.service.ts | 3 +- .../vulnerability/scanAll.api.repository.ts | 7 +- .../config/vulnerability/scanAll.service.ts | 3 +- .../lib/src/log/recent-log.component.ts | 6 +- .../replication-tasks.component.ts | 2 +- .../src/replication/replication.component.ts | 7 +- .../repository-gridview.component.ts | 8 +- .../lib/src/service/RequestQueryParams.ts | 4 +- .../lib/src/service/access-log.service.ts | 12 +- .../lib/src/service/configuration.service.ts | 6 +- .../lib/src/service/endpoint.service.ts | 35 +++--- src/portal/lib/src/service/interface.ts | 27 +++++ src/portal/lib/src/service/job-log.service.ts | 10 +- src/portal/lib/src/service/label.service.ts | 74 ++++++------ src/portal/lib/src/service/project.service.ts | 20 ++-- .../lib/src/service/replication.service.ts | 38 +++---- .../lib/src/service/repository.service.ts | 36 +++--- .../lib/src/service/resource-label.service.ts | 49 ++++---- src/portal/lib/src/service/retag.service.ts | 4 +- .../lib/src/service/scanning.service.ts | 6 +- .../lib/src/service/system-info.service.ts | 8 +- src/portal/lib/src/service/tag.service.ts | 22 ++-- src/portal/lib/src/shared/shared.module.ts | 3 - src/portal/lib/src/shared/shared.utils.ts | 16 +-- src/portal/lib/src/tag/tag.component.ts | 3 +- src/portal/lib/src/utils.ts | 105 +++++++++++++----- .../account-settings-modal-service.service.ts | 4 +- .../account-settings-modal.component.ts | 3 +- .../password-setting.component.ts | 2 +- .../password-setting.service.ts | 12 +- src/portal/src/app/app-config.service.ts | 9 +- .../global-search/global-search.service.ts | 8 +- .../app/config/auth/config-auth.component.ts | 2 +- src/portal/src/app/config/config.service.ts | 8 +- .../config/email/config-email.component.ts | 2 +- src/portal/src/app/core/core.module.ts | 3 - .../app/dev-center/dev-center.component.ts | 10 +- src/portal/src/app/group/group.service.ts | 37 ++---- src/portal/src/app/log/audit-log.component.ts | 2 +- src/portal/src/app/log/audit-log.service.ts | 30 +++-- .../app/oidc-onboard/oidc-onboard.service.ts | 4 +- .../create-project.component.ts | 1 - .../project/helm-chart/helm-chart.service.ts | 39 +++---- .../list-project/list-project.component.ts | 2 +- .../member/add-member/add-member.component.ts | 18 +-- .../src/app/project/member/member.service.ts | 18 ++- src/portal/src/app/project/project.service.ts | 29 ++--- .../robot-account/robot-account.service.ts | 4 +- .../robot-account/robot.api.repository.ts | 10 +- .../replication/replication-page.component.ts | 2 +- .../top-repo/top-repository.service.ts | 8 +- .../list-chart-version-ro.component.ts | 3 +- src/portal/src/app/shared/session.service.ts | 27 ++--- src/portal/src/app/shared/shared.utils.ts | 62 +---------- .../shared/statictics/statistics.service.ts | 10 +- .../src/app/sign-in/sign-in.component.ts | 4 +- src/portal/src/app/sign-in/sign-in.service.ts | 16 +-- src/portal/src/app/skinable-config.service.ts | 6 +- src/portal/src/app/user/user.service.ts | 14 +-- 61 files changed, 430 insertions(+), 508 deletions(-) diff --git a/src/portal/lib/src/app.module.ts b/src/portal/lib/src/app.module.ts index c6e476eb9..e98f493d4 100644 --- a/src/portal/lib/src/app.module.ts +++ b/src/portal/lib/src/app.module.ts @@ -2,7 +2,6 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { HttpModule } from '@angular/http'; import { ClarityModule } from '@clr/angular'; import { HarborLibraryModule } from './harbor-library.module'; @@ -12,7 +11,6 @@ import { HarborLibraryModule } from './harbor-library.module'; BrowserAnimationsModule, BrowserModule, FormsModule, - HttpModule, ClarityModule, HarborLibraryModule.forRoot() ], diff --git a/src/portal/lib/src/config/gc/gc.api.repository.ts b/src/portal/lib/src/config/gc/gc.api.repository.ts index 5cf1b64c7..3d6dd7ae9 100644 --- a/src/portal/lib/src/config/gc/gc.api.repository.ts +++ b/src/portal/lib/src/config/gc/gc.api.repository.ts @@ -1,6 +1,6 @@ import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; +import { HttpClient } from '@angular/common/http'; import { throwError as observableThrowError, Observable } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { SERVICE_CONFIG, IServiceConfig } from "../../service.config"; @@ -24,7 +24,7 @@ export abstract class GcApiRepository { @Injectable() export class GcApiDefaultRepository extends GcApiRepository { constructor( - private http: Http, + private http: HttpClient, @Inject(SERVICE_CONFIG) private config: IServiceConfig ) { super(); @@ -42,8 +42,7 @@ export class GcApiDefaultRepository extends GcApiRepository { public getSchedule(): Observable { return this.http.get(`${this.config.gcEndpoint}/schedule`) - .pipe(catchError(error => observableThrowError(error))) - .pipe(map(response => response.json())); + .pipe(catchError(error => observableThrowError(error))); } public getLog(id): Observable { @@ -53,14 +52,12 @@ export class GcApiDefaultRepository extends GcApiRepository { public getStatus(id): Observable { return this.http.get(`${this.config.gcEndpoint}/id`) - .pipe(catchError(error => observableThrowError(error))) - .pipe(map(response => response.json())); + .pipe(catchError(error => observableThrowError(error))); } public getJobs(): Observable { return this.http.get(`${this.config.gcEndpoint}`) - .pipe(catchError(error => observableThrowError(error))) - .pipe(map(response => response.json())); + .pipe(catchError(error => observableThrowError(error))); } public getLogLink(id) { diff --git a/src/portal/lib/src/config/gc/gc.service.ts b/src/portal/lib/src/config/gc/gc.service.ts index b04232377..d3abedee7 100644 --- a/src/portal/lib/src/config/gc/gc.service.ts +++ b/src/portal/lib/src/config/gc/gc.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@angular/core'; -import { Http } from '@angular/http'; import { Observable, Subscription, Subject, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { GcApiRepository } from './gc.api.repository'; @@ -10,7 +9,7 @@ import { GcJobData } from './gcLog'; @Injectable() export class GcRepoService { - constructor(private http: Http, + constructor( private gcApiRepository: GcApiRepository, private errorHandler: ErrorHandler) { } diff --git a/src/portal/lib/src/config/vulnerability/scanAll.api.repository.ts b/src/portal/lib/src/config/vulnerability/scanAll.api.repository.ts index 1657a9319..bf0dad5e3 100644 --- a/src/portal/lib/src/config/vulnerability/scanAll.api.repository.ts +++ b/src/portal/lib/src/config/vulnerability/scanAll.api.repository.ts @@ -1,6 +1,6 @@ import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; +import { HttpClient } from '@angular/common/http'; import { throwError as observableThrowError, Observable } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { SERVICE_CONFIG, IServiceConfig } from "../../service.config"; @@ -17,7 +17,7 @@ export abstract class ScanApiRepository { @Injectable() export class ScanApiDefaultRepository extends ScanApiRepository { constructor( - private http: Http, + private http: HttpClient, @Inject(SERVICE_CONFIG) private config: IServiceConfig ) { super(); @@ -35,8 +35,7 @@ export class ScanApiDefaultRepository extends ScanApiRepository { public getSchedule(): Observable { return this.http.get(`${this.config.ScanAllEndpoint}/schedule`) - .pipe(catchError(error => observableThrowError(error))) - .pipe(map(response => response.json())); + .pipe(catchError(error => observableThrowError(error))); } } diff --git a/src/portal/lib/src/config/vulnerability/scanAll.service.ts b/src/portal/lib/src/config/vulnerability/scanAll.service.ts index f69f7a473..66da5db29 100644 --- a/src/portal/lib/src/config/vulnerability/scanAll.service.ts +++ b/src/portal/lib/src/config/vulnerability/scanAll.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@angular/core'; -import { Http } from '@angular/http'; import { Observable } from 'rxjs'; import { ScanApiRepository } from './scanAll.api.repository'; import { ErrorHandler } from '../../error-handler/index'; @@ -8,7 +7,7 @@ import { ErrorHandler } from '../../error-handler/index'; @Injectable() export class ScanAllRepoService { - constructor(private http: Http, + constructor( private scanApiRepository: ScanApiRepository, private errorHandler: ErrorHandler) { } diff --git a/src/portal/lib/src/log/recent-log.component.ts b/src/portal/lib/src/log/recent-log.component.ts index e5d50ec76..b791e7bfb 100644 --- a/src/portal/lib/src/log/recent-log.component.ts +++ b/src/portal/lib/src/log/recent-log.component.ts @@ -119,11 +119,9 @@ export class RecentLogComponent implements OnInit { let pageNumber: number = calculatePage(state); if (pageNumber !== this.currentPagePvt) { // load data - let params: RequestQueryParams = new RequestQueryParams(); - params.set("page", '' + pageNumber); - params.set("page_size", '' + this.pageSize); + let params: RequestQueryParams = new RequestQueryParams().set("page", '' + pageNumber).set("page_size", '' + this.pageSize); if (this.currentTerm && this.currentTerm !== "") { - params.set(this.defaultFilter, this.currentTerm); + params = params.set(this.defaultFilter, this.currentTerm); } this.loading = true; diff --git a/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.ts b/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.ts index bc5623101..a9984d47f 100644 --- a/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.ts +++ b/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.ts @@ -140,7 +140,7 @@ export class ReplicationTasksComponent implements OnInit, OnDestroy { this.loading = true; let params: RequestQueryParams = new RequestQueryParams(); if (this.searchTask && this.searchTask !== "") { - params.set(this.defaultFilter, this.searchTask); + params = params.set(this.defaultFilter, this.searchTask); } this.replicationService.getReplicationTasks(this.executionId, params) .pipe(finalize(() => (this.loading = false))) diff --git a/src/portal/lib/src/replication/replication.component.ts b/src/portal/lib/src/replication/replication.component.ts index daab204d4..e211af9ea 100644 --- a/src/portal/lib/src/replication/replication.component.ts +++ b/src/portal/lib/src/replication/replication.component.ts @@ -201,13 +201,10 @@ export class ReplicationComponent implements OnInit, OnDestroy { pageNumber = 1; } - let params: RequestQueryParams = new RequestQueryParams(); - // Pagination - params.set("page", "" + pageNumber); - params.set("page_size", "" + this.pageSize); + let params: RequestQueryParams = new RequestQueryParams().set("page", "" + pageNumber).set("page_size", "" + this.pageSize); if (this.currentTerm && this.currentTerm !== "") { - params.set(this.defaultFilter, this.currentTerm); + params = params.set(this.defaultFilter, this.currentTerm); } this.jobsLoading = true; diff --git a/src/portal/lib/src/repository-gridview/repository-gridview.component.ts b/src/portal/lib/src/repository-gridview/repository-gridview.component.ts index 074bea76e..fe533195b 100644 --- a/src/portal/lib/src/repository-gridview/repository-gridview.component.ts +++ b/src/portal/lib/src/repository-gridview/repository-gridview.component.ts @@ -348,9 +348,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit { loadNextPage() { this.currentPage = this.currentPage + 1; // Pagination - let params: RequestQueryParams = new RequestQueryParams(); - params.set("page", "" + this.currentPage); - params.set("page_size", "" + this.pageSize); + let params: RequestQueryParams = new RequestQueryParams().set("page", "" + this.currentPage).set("page_size", "" + this.pageSize); this.loading = true; this.repositoryService.getRepositories( @@ -395,9 +393,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit { } // Pagination - let params: RequestQueryParams = new RequestQueryParams(); - params.set("page", "" + pageNumber); - params.set("page_size", "" + this.pageSize); + let params: RequestQueryParams = new RequestQueryParams().set("page", "" + pageNumber).set("page_size", "" + this.pageSize); this.loading = true; diff --git a/src/portal/lib/src/service/RequestQueryParams.ts b/src/portal/lib/src/service/RequestQueryParams.ts index d60a5f1a7..cb09be5a9 100644 --- a/src/portal/lib/src/service/RequestQueryParams.ts +++ b/src/portal/lib/src/service/RequestQueryParams.ts @@ -1,4 +1,4 @@ -import { URLSearchParams } from "@angular/http"; +import { HttpParams } from "@angular/common/http"; /** * Wrap the class 'URLSearchParams' for future extending requirements. @@ -8,7 +8,7 @@ import { URLSearchParams } from "@angular/http"; * class RequestQueryParams * extends {URLSearchParams} */ -export class RequestQueryParams extends URLSearchParams { +export class RequestQueryParams extends HttpParams { constructor() { super(); } diff --git a/src/portal/lib/src/service/access-log.service.ts b/src/portal/lib/src/service/access-log.service.ts index eea64bee1..e91ef3e2d 100644 --- a/src/portal/lib/src/service/access-log.service.ts +++ b/src/portal/lib/src/service/access-log.service.ts @@ -3,8 +3,8 @@ import { RequestQueryParams } from "./RequestQueryParams"; import { AccessLog, AccessLogItem } from "./interface"; import { Injectable, Inject } from "@angular/core"; import { SERVICE_CONFIG, IServiceConfig } from "../service.config"; -import { Http } from "@angular/http"; -import { buildHttpRequestOptions, HTTP_GET_OPTIONS } from "../utils"; +import { HttpClient, HttpResponse } from "@angular/common/http"; +import { buildHttpRequestOptionsWithObserveResponse, HTTP_GET_OPTIONS_OBSERVE_RESPONSE } from "../utils"; import { map, catchError } from "rxjs/operators"; /** @@ -57,7 +57,7 @@ export abstract class AccessLogService { @Injectable() export class AccessLogDefaultService extends AccessLogService { constructor( - private http: Http, + private http: HttpClient, @Inject(SERVICE_CONFIG) private config: IServiceConfig ) { super(); @@ -81,9 +81,9 @@ export class AccessLogDefaultService extends AccessLogService { } return this.http - .get( + .get>( url, - queryParams ? buildHttpRequestOptions(queryParams) : HTTP_GET_OPTIONS + queryParams ? buildHttpRequestOptionsWithObserveResponse(queryParams) : HTTP_GET_OPTIONS_OBSERVE_RESPONSE ) .pipe(map(response => { let result: AccessLog = { @@ -100,7 +100,7 @@ export class AccessLogDefaultService extends AccessLogService { if (result && result.metadata) { result.metadata.xTotalCount = parseInt(xHeader ? xHeader : "0", 0); if (result.metadata.xTotalCount > 0) { - result.data = response.json() as AccessLogItem[]; + result.data = response.body as AccessLogItem[]; } } diff --git a/src/portal/lib/src/service/configuration.service.ts b/src/portal/lib/src/service/configuration.service.ts index 9338edac8..4f1e868cf 100644 --- a/src/portal/lib/src/service/configuration.service.ts +++ b/src/portal/lib/src/service/configuration.service.ts @@ -1,5 +1,5 @@ import { Injectable, Inject } from "@angular/core"; -import { Http } from "@angular/http"; +import { HttpClient } from "@angular/common/http"; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; @@ -44,7 +44,7 @@ export class ConfigurationDefaultService extends ConfigurationService { _baseUrl: string; constructor( - private http: Http, + private http: HttpClient, @Inject(SERVICE_CONFIG) private config: IServiceConfig ) { super(); @@ -59,7 +59,7 @@ export class ConfigurationDefaultService extends ConfigurationService { | Observable { return this.http .get(this._baseUrl, HTTP_GET_OPTIONS) - .pipe(map(response => response.json() as Configuration) + .pipe(map(response => response as Configuration) , catchError(error => observableThrowError(error))); } diff --git a/src/portal/lib/src/service/endpoint.service.ts b/src/portal/lib/src/service/endpoint.service.ts index a736089d0..075e23084 100644 --- a/src/portal/lib/src/service/endpoint.service.ts +++ b/src/portal/lib/src/service/endpoint.service.ts @@ -1,5 +1,5 @@ import { Injectable, Inject } from "@angular/core"; -import { Http } from "@angular/http"; +import { HttpClient } from "@angular/common/http"; import { Observable, throwError as observableThrowError } from "rxjs"; import { IServiceConfig, SERVICE_CONFIG } from "../service.config"; @@ -140,7 +140,7 @@ export class EndpointDefaultService extends EndpointService { constructor( @Inject(SERVICE_CONFIG) config: IServiceConfig, - private http: Http + private http: HttpClient ) { super(); this._endpointUrl = config.targetBaseEndpoint @@ -156,12 +156,12 @@ export class EndpointDefaultService extends EndpointService { queryParams = new RequestQueryParams(); } if (endpointName) { - queryParams.set("name", endpointName); + queryParams = queryParams.set("name", endpointName); } let requestUrl: string = `${this._endpointUrl}`; return this.http .get(requestUrl, buildHttpRequestOptions(queryParams)) - .pipe(map(response => response.json()) + .pipe(map(response => response as Endpoint[]) , catchError(error => observableThrowError(error))); } @@ -174,15 +174,14 @@ export class EndpointDefaultService extends EndpointService { let requestUrl: string = `${this._endpointUrl}/${endpointId}`; return this.http .get(requestUrl, HTTP_GET_OPTIONS) - .pipe(map(response => response.json() as Endpoint) + .pipe(map(response => response as Endpoint) , catchError(error => observableThrowError(error))); } public getAdapters(): Observable { return this.http .get(`/api/replication/adapters`) - .pipe(map(response => response.json()) - , catchError(error => observableThrowError(error))); + .pipe(catchError(error => observableThrowError(error))); } public createEndpoint( @@ -193,9 +192,8 @@ export class EndpointDefaultService extends EndpointService { } let requestUrl: string = `${this._endpointUrl}`; return this.http - .post(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) - .pipe(map(response => response.status) - , catchError(error => observableThrowError(error))); + .post(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) + .pipe(catchError(error => observableThrowError(error))); } public updateEndpoint( @@ -210,9 +208,8 @@ export class EndpointDefaultService extends EndpointService { } let requestUrl: string = `${this._endpointUrl}/${endpointId}`; return this.http - .put(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) - .pipe(map(response => response.status) - , catchError(error => observableThrowError(error))); + .put(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) + .pipe(catchError(error => observableThrowError(error))); } public deleteEndpoint( @@ -223,9 +220,8 @@ export class EndpointDefaultService extends EndpointService { } let requestUrl: string = `${this._endpointUrl}/${endpointId}`; return this.http - .delete(requestUrl) - .pipe(map(response => response.status) - , catchError(error => observableThrowError(error))); + .delete(requestUrl) + .pipe(catchError(error => observableThrowError(error))); } public pingEndpoint( @@ -236,9 +232,8 @@ export class EndpointDefaultService extends EndpointService { } let requestUrl: string = `${this._endpointUrl}/ping`; return this.http - .post(requestUrl, endpoint, HTTP_JSON_OPTIONS) - .pipe(map(response => response.status) - , catchError(error => observableThrowError(error))); + .post(requestUrl, endpoint, HTTP_JSON_OPTIONS) + .pipe(catchError(error => observableThrowError(error))); } public getEndpointWithReplicationRules( @@ -250,7 +245,7 @@ export class EndpointDefaultService extends EndpointService { let requestUrl: string = `${this._endpointUrl}/${endpointId}/policies`; return this.http .get(requestUrl, HTTP_GET_OPTIONS) - .pipe(map(response => response.json() as ReplicationRule[]) + .pipe(map(response => response as ReplicationRule[]) , catchError(error => observableThrowError(error))); } } diff --git a/src/portal/lib/src/service/interface.ts b/src/portal/lib/src/service/interface.ts index 2b9417abd..be56b4707 100644 --- a/src/portal/lib/src/service/interface.ts +++ b/src/portal/lib/src/service/interface.ts @@ -1,6 +1,7 @@ import { Project } from "../project-policy-config/project"; import { Observable } from 'rxjs'; import { ClrModal } from '@clr/angular'; +import { HttpHeaders, HttpParams } from '@angular/common/http'; /** * The base interface contains the general properties @@ -407,3 +408,29 @@ export class OriginCron { cron: string; } +export interface HttpOptionInterface { + headers?: HttpHeaders | { + [header: string]: string | string[]; + }; + observe?: 'body'; + params?: HttpParams | { + [param: string]: string | string[]; + }; + reportProgress?: boolean; + responseType: 'json'; + withCredentials?: boolean; +} + +export interface HttpOptionTextInterface { + headers?: HttpHeaders | { + [header: string]: string | string[]; + }; + observe?: 'body'; + params?: HttpParams | { + [param: string]: string | string[]; + }; + reportProgress?: boolean; + responseType: 'text'; + withCredentials?: boolean; +} + diff --git a/src/portal/lib/src/service/job-log.service.ts b/src/portal/lib/src/service/job-log.service.ts index f11ba6bd7..cde8b50cd 100644 --- a/src/portal/lib/src/service/job-log.service.ts +++ b/src/portal/lib/src/service/job-log.service.ts @@ -1,7 +1,7 @@ import { Injectable, Inject } from "@angular/core"; -import { Http } from "@angular/http"; +import { HttpClient } from "@angular/common/http"; import { SERVICE_CONFIG, IServiceConfig } from "../service.config"; -import { HTTP_GET_OPTIONS } from "../utils"; +import { HTTP_GET_OPTIONS, HTTP_GET_OPTIONS_TEXT } from "../utils"; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; /** @@ -43,7 +43,7 @@ export class JobLogDefaultService extends JobLogService { _supportedJobTypes: string[]; constructor( - private http: Http, + private http: HttpClient, @Inject(SERVICE_CONFIG) config: IServiceConfig ) { super(); @@ -58,8 +58,8 @@ export class JobLogDefaultService extends JobLogService { _getJobLog(logUrl: string): Observable { return this.http - .get(logUrl, HTTP_GET_OPTIONS) - .pipe(map(response => response.text()) + .get(logUrl, HTTP_GET_OPTIONS_TEXT) + .pipe(map(response => response) , catchError(error => observableThrowError(error))); } diff --git a/src/portal/lib/src/service/label.service.ts b/src/portal/lib/src/service/label.service.ts index 6e73c2096..e4f1fcc50 100644 --- a/src/portal/lib/src/service/label.service.ts +++ b/src/portal/lib/src/service/label.service.ts @@ -1,5 +1,5 @@ import { Inject, Injectable } from "@angular/core"; -import { Http } from "@angular/http"; +import { HttpClient } from "@angular/common/http"; import { map, catchError} from "rxjs/operators"; import { RequestQueryParams } from "./RequestQueryParams"; @@ -7,7 +7,6 @@ import { Label } from "./interface"; import { IServiceConfig, SERVICE_CONFIG } from "../service.config"; import { buildHttpRequestOptions, HTTP_JSON_OPTIONS } from "../utils"; -import { extractJson } from "../shared/shared.utils"; import { Observable, throwError as observableThrowError } from "rxjs"; export abstract class LabelService { @@ -76,7 +75,7 @@ export class LabelDefaultService extends LabelService { constructor( @Inject(SERVICE_CONFIG) config: IServiceConfig, - private http: Http + private http: HttpClient ) { super(); this.labelUrl = config.labelEndpoint ? config.labelEndpoint : "/api/labels"; @@ -91,15 +90,14 @@ export class LabelDefaultService extends LabelService { if (!queryParams) { queryParams = new RequestQueryParams(); } - queryParams.set("scope", "g"); + queryParams = queryParams.set("scope", "g"); if (name) { - queryParams.set("name", "" + name); + queryParams = queryParams.set("name", "" + name); } return this.http - .get(this.labelUrl, buildHttpRequestOptions(queryParams)) - .pipe(map(response => response.json()) - , catchError(error => observableThrowError(error))); + .get(this.labelUrl, buildHttpRequestOptions(queryParams)) + .pipe(catchError(error => observableThrowError(error))); } getPLabels( @@ -110,17 +108,16 @@ export class LabelDefaultService extends LabelService { if (!queryParams) { queryParams = new RequestQueryParams(); } - queryParams.set("scope", "p"); + queryParams = queryParams.set("scope", "p"); if (projectId) { - queryParams.set("project_id", "" + projectId); + queryParams = queryParams.set("project_id", "" + projectId); } if (name) { - queryParams.set("name", "" + name); + queryParams = queryParams.set("name", "" + name); } return this.http - .get(this.labelUrl, buildHttpRequestOptions(queryParams)) - .pipe(map(response => response.json()) - , catchError(error => observableThrowError(error))); + .get(this.labelUrl, buildHttpRequestOptions(queryParams)) + .pipe(catchError(error => observableThrowError(error))); } getProjectLabels( @@ -131,15 +128,14 @@ export class LabelDefaultService extends LabelService { if (!queryParams) { queryParams = new RequestQueryParams(); } - queryParams.set("scope", "p"); + queryParams = queryParams.set("scope", "p"); if (projectId) { - queryParams.set("project_id", "" + projectId); + queryParams = queryParams.set("project_id", "" + projectId); } if (name) { - queryParams.set("name", "" + name); + queryParams = queryParams.set("name", "" + name); } - return this.http.get(this.labelUrl, buildHttpRequestOptions(queryParams)) - .pipe(map( res => extractJson(res))); + return this.http.get(this.labelUrl, buildHttpRequestOptions(queryParams)); } getLabels( @@ -149,20 +145,19 @@ export class LabelDefaultService extends LabelService { queryParams?: RequestQueryParams ): Observable { if (!queryParams) { - queryParams = new RequestQueryParams(); + queryParams = queryParams = new RequestQueryParams(); } if (scope) { - queryParams.set("scope", scope); + queryParams = queryParams.set("scope", scope); } if (projectId) { - queryParams.set("project_id", "" + projectId); + queryParams = queryParams.set("project_id", "" + projectId); } if (name) { - queryParams.set("name", "" + name); + queryParams = queryParams.set("name", "" + name); } return this.http - .get(this.labelUrl, buildHttpRequestOptions(queryParams)) - .pipe(map(response => response.json())) + .get(this.labelUrl, buildHttpRequestOptions(queryParams)) .pipe(catchError(error => observableThrowError(error))); } @@ -171,9 +166,8 @@ export class LabelDefaultService extends LabelService { return observableThrowError("Invalid label."); } return this.http - .post(this.labelUrl, JSON.stringify(label), HTTP_JSON_OPTIONS) - .pipe(map(response => response.status) - , catchError(error => observableThrowError(error))); + .post(this.labelUrl, JSON.stringify(label), HTTP_JSON_OPTIONS) + .pipe(catchError(error => observableThrowError(error))); } getLabel(id: number): Observable