Commit 44054859 authored by Yogi_Wang's avatar Yogi_Wang
Browse files

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: default avatarYogi_Wang <yawang@vmware.com>
parent a7f8f531
......@@ -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()
],
......
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<any> {
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<any> {
......@@ -53,14 +52,12 @@ export class GcApiDefaultRepository extends GcApiRepository {
public getStatus(id): Observable<any> {
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<any> {
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) {
......
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) {
}
......
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<any> {
return this.http.get(`${this.config.ScanAllEndpoint}/schedule`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
.pipe(catchError(error => observableThrowError(error)));
}
}
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) {
}
......
......@@ -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;
......
......@@ -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)))
......
......@@ -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;
......
......@@ -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;
......
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();
}
......
......@@ -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<HttpResponse<AccessLogItem[]>>(
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[];
}
}
......
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<Configuration> {
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)));
}
......
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<any> {
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<any>(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<any>(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<any>(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<any>(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)));
}
}
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;
}
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<string> {
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)));
}
......
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<Label[]>(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<Label[]>(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<Label[]>(this.labelUrl, buildHttpRequestOptions(queryParams));
}
getLabels(
......@@ -149,20 +145,19 @@ export class LabelDefaultService extends LabelService {
queryParams?: RequestQueryParams
): Observable<Label[]> {
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<Label[]>(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<any>(this.labelUrl, JSON.stringify(label), HTTP_JSON_OPTIONS)
.pipe(catchError(error => observableThrowError(error)));
}
getLabel(id: number): Observable<Label> {
......@@ -182,9 +176,8 @@ export class LabelDefaultService extends LabelService {
}
let reqUrl = `${this.labelUrl}/${id}`;
return this.http
.get(reqUrl, HTTP_JSON_OPTIONS)
.pipe(map(response => response.json())
, catchError(error => observableThrowError(error)));
.get<Label>(reqUrl, HTTP_JSON_OPTIONS)
.pipe(catchError(error => observableThrowError(error)));
}
updateLabel(id: number, label: Label): Observable<any> {
......@@ -196,9 +189,8 @@ export class LabelDefaultService extends LabelService {
}
let reqUrl = `${this.labelUrl}/${id}`;
return this.http
.put(reqUrl, JSON.stringify(label), HTTP_JSON_OPTIONS)
.pipe(map(response => response.status)
, catchError(error => observableThrowError(error)));
.put<any>(reqUrl, JSON.stringify(label), HTTP_JSON_OPTIONS)
.pipe(catchError(error => observableThrowError(error)));
}
deleteLabel(id: number): Observable<any> {
......@@ -207,9 +199,8 @@ export class LabelDefaultService extends LabelService {
}
let reqUrl = `${this.labelUrl}/${id}`;
return this.http
.delete(reqUrl)