@harbor/ui
Version:
Harbor shared UI components based on Clarity and Angular6
1,448 lines (1,435 loc) • 1.71 MB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('@angular/http'), require('rxjs/operators'), require('rxjs/index'), require('@ngx-translate/core'), require('@angular/forms'), require('@angular/router'), require('@angular/animations'), require('@angular/platform-browser'), require('@angular/common'), require('@angular/common/http'), require('@clr/angular'), require('ngx-cookie'), require('ngx-markdown'), require('@ngx-translate/http-loader')) :
typeof define === 'function' && define.amd ? define('@harbor/ui', ['exports', '@angular/core', 'rxjs', '@angular/http', 'rxjs/operators', 'rxjs/index', '@ngx-translate/core', '@angular/forms', '@angular/router', '@angular/animations', '@angular/platform-browser', '@angular/common', '@angular/common/http', '@clr/angular', 'ngx-cookie', 'ngx-markdown', '@ngx-translate/http-loader'], factory) :
(factory((global.harbor = global.harbor || {}, global.harbor.ui = {}),global.ng.core,global.rxjs,global.ng.http,global.rxjs.operators,global.rxjs.index,global.core$1,global.ng.forms,global.ng.router,global.ng.animations,global.ng.platformBrowser,global.ng.common,global.ng.common.http,global.angular,global.ngxCookie,global.ngxMarkdown,global.httpLoader));
}(this, (function (exports,core,rxjs,http,operators,index,core$1,forms,router,animations,platformBrowser,common,http$1,angular,ngxCookie,ngxMarkdown,httpLoader) { 'use strict';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var Filter = /** @class */ (function () {
function Filter(kind, pattern) {
this.kind = kind;
this.pattern = pattern;
}
return Filter;
}());
var Trigger = /** @class */ (function () {
function Trigger(kind, param) {
this.kind = kind;
this.schedule_param = param;
}
return Trigger;
}());
/** @enum {number} */
var VulnerabilitySeverity = {
_SEVERITY: 0,
NONE: 1,
UNKNOWN: 2,
LOW: 3,
MEDIUM: 4,
HIGH: 5,
};
VulnerabilitySeverity[VulnerabilitySeverity._SEVERITY] = '_SEVERITY';
VulnerabilitySeverity[VulnerabilitySeverity.NONE] = 'NONE';
VulnerabilitySeverity[VulnerabilitySeverity.UNKNOWN] = 'UNKNOWN';
VulnerabilitySeverity[VulnerabilitySeverity.LOW] = 'LOW';
VulnerabilitySeverity[VulnerabilitySeverity.MEDIUM] = 'MEDIUM';
VulnerabilitySeverity[VulnerabilitySeverity.HIGH] = 'HIGH';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m)
return m.call(o);
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var SERVICE_CONFIG = new core.InjectionToken("service.config");
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Convert the different async channels to the Promise<T> type.
*
* *
* template T
* ** deprecated param {(Observable<T> | Promise<T> | T)} async
* returns {Promise<T>}
* @template T
* @param {?} async
* @return {?}
*/
function toPromise(async) {
if (!async) {
return Promise.reject("Bad argument");
}
if (async instanceof rxjs.Observable) {
/** @type {?} */
var obs = async;
return obs.toPromise();
}
else {
return Promise.resolve(async);
}
}
/** *
* The default cookie key used to store current used language preference.
@type {?} */
var DEFAULT_LANG_COOKIE_KEY = 'harbor-lang';
/** *
* Declare what languages are supported now.
@type {?} */
var DEFAULT_SUPPORTING_LANGS = ['en-us', 'zh-cn', 'es-es', 'fr-fr', 'pt-br'];
/** *
* The default language.
@type {?} */
var DEFAULT_LANG = 'en-us';
/** @type {?} */
var HTTP_JSON_OPTIONS = new http.RequestOptions({
headers: new http.Headers({
"Content-Type": 'application/json',
"Accept": 'application/json'
})
});
/** @type {?} */
var HTTP_GET_OPTIONS = new http.RequestOptions({
headers: new http.Headers({
"Content-Type": 'application/json',
"Accept": 'application/json',
"Cache-Control": 'no-cache',
"Pragma": 'no-cache'
})
});
/** @type {?} */
var FILE_UPLOAD_OPTION = new http.RequestOptions({
headers: new http.Headers({
"Content-Type": 'multipart/form-data',
})
});
/**
* Build http request options
*
* *
* ** deprecated param {RequestQueryParams} params
* returns {RequestOptions}
* @param {?} params
* @return {?}
*/
function buildHttpRequestOptions(params) {
/** @type {?} */
var reqOptions = new http.RequestOptions({
headers: new http.Headers({
"Content-Type": 'application/json',
"Accept": 'application/json',
"Cache-Control": 'no-cache',
"Pragma": 'no-cache'
})
});
if (params) {
reqOptions.search = params;
}
return reqOptions;
}
/** *
* Button events to pass to `DebugElement.triggerEventHandler` for RouterLink event handler
@type {?} */
var ButtonClickEvents = {
left: { button: 0 },
right: { button: 2 }
};
/**
* Simulate element click. Defaults to mouse left-button click event.
* @param {?} el
* @param {?=} eventObj
* @return {?}
*/
function click(el, eventObj) {
if (eventObj === void 0) {
eventObj = ButtonClickEvents.left;
}
if (el instanceof HTMLElement) {
el.click();
}
else {
el.triggerEventHandler('click', eventObj);
}
}
/**
* Comparator for fields with specific type.
*
* @template T
*/
var /**
* Comparator for fields with specific type.
*
* @template T
*/ CustomComparator = /** @class */ (function () {
function CustomComparator(fieldName, type) {
this.fieldName = fieldName;
this.type = type;
}
/**
* @param {?} a
* @param {?} b
* @return {?}
*/
CustomComparator.prototype.compare = /**
* @param {?} a
* @param {?} b
* @return {?}
*/
function (a, b) {
/** @type {?} */
var comp = 0;
if (a && b) {
/** @type {?} */
var fieldA = a[this.fieldName];
/** @type {?} */
var fieldB = b[this.fieldName];
switch (this.type) {
case "number":
comp = fieldB - fieldA;
break;
case "date":
comp = new Date(fieldB).getTime() - new Date(fieldA).getTime();
break;
}
}
return comp;
};
return CustomComparator;
}());
/** *
* The default page size
@type {?} */
var DEFAULT_PAGE_SIZE = 15;
/** *
* The state of vulnerability scanning
@type {?} */
var VULNERABILITY_SCAN_STATUS = {
unknown: "n/a",
pending: "pending",
running: "running",
error: "error",
stopped: "stopped",
finished: "finished"
};
/**
* Calculate page number by state
* @param {?} state
* @return {?}
*/
function calculatePage(state) {
if (!state || !state.page) {
return 1;
}
return Math.ceil((state.page.to + 1) / state.page.size);
}
/**
* Filter columns via RegExp
*
* *
* ** deprecated param {State} state
* returns {void}
* @template T
* @param {?} items
* @param {?} state
* @return {?}
*/
function doFiltering(items, state) {
if (!items || items.length === 0) {
return items;
}
if (!state || !state.filters || state.filters.length === 0) {
return items;
}
state.filters.forEach(function (filter) {
items = items.filter(function (item) {
if (filter['property'].indexOf('.') !== -1) {
/** @type {?} */
var arr_1 = filter['property'].split('.');
if (Array.isArray(item[arr_1[0]]) && item[arr_1[0]].length) {
return item[arr_1[0]].some(function (data) {
return filter['value'] === data[arr_1[1]];
});
}
}
else {
return regexpFilter(filter['value'], item[filter['property']]);
}
});
});
return items;
}
/**
* Match items via RegExp
*
* *
* ** deprecated param {string} terms
* ** deprecated param {*} testedValue
* returns {boolean}
* @param {?} terms
* @param {?} testedValue
* @return {?}
*/
function regexpFilter(terms, testedValue) {
/** @type {?} */
var reg = new RegExp('.*' + terms + '.*', 'i');
return reg.test(testedValue);
}
/**
* Sorting the data by column
*
* *
* template T
* ** deprecated param {T[]} items
* ** deprecated param {State} state
* returns {T[]}
* @template T
* @param {?} items
* @param {?} state
* @return {?}
*/
function doSorting(items, state) {
if (!items || items.length === 0) {
return items;
}
if (!state || !state.sort) {
return items;
}
return items.sort(function (a, b) {
/** @type {?} */
var comp = 0;
if (typeof state.sort.by !== "string") {
comp = state.sort.by.compare(a, b);
}
else {
/** @type {?} */
var propA = a[state.sort.by.toString()];
/** @type {?} */
var propB = b[state.sort.by.toString()];
if (typeof propA === "string") {
comp = propA.localeCompare(propB);
}
else {
if (propA > propB) {
comp = 1;
}
else if (propA < propB) {
comp = -1;
}
}
}
if (state.sort.reverse) {
comp = -comp;
}
return comp;
});
}
/**
* Compare the two objects to adjust if they're equal
*
* *
* ** deprecated param {*} a
* ** deprecated param {*} b
* returns {boolean}
* @param {?} a
* @param {?} b
* @return {?}
*/
function compareValue(a, b) {
if ((a && !b) || (!a && b)) {
return false;
}
if (!a && !b) {
return true;
}
return JSON.stringify(a) === JSON.stringify(b);
}
/**
* Check if the object is null or empty '{}'
*
* *
* ** deprecated param {*} obj
* returns {boolean}
* @param {?} obj
* @return {?}
*/
function isEmptyObject(obj) {
return !obj || JSON.stringify(obj) === "{}";
}
/**
* Deeper clone all
*
* *
* ** deprecated param {*} srcObj
* returns {*}
* @param {?} srcObj
* @return {?}
*/
function clone(srcObj) {
if (!srcObj) {
return null;
}
return JSON.parse(JSON.stringify(srcObj));
}
/**
* @param {?} obj
* @return {?}
*/
function isEmpty(obj) {
return !obj || JSON.stringify(obj) === '{}';
}
/**
* @param {?} fileData
* @return {?}
*/
function downloadFile(fileData) {
/** @type {?} */
var url = window.URL.createObjectURL(fileData.data);
/** @type {?} */
var a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("style", "display: none");
a.href = url;
a.download = fileData.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove();
}
/**
* @param {?} original
* @param {?} afterChange
* @return {?}
*/
function getChanges(original, afterChange) {
var e_1, _a;
/** @type {?} */
var changes = {};
if (!afterChange || !original) {
return changes;
}
try {
for (var _b = __values(Object.keys(afterChange)), _c = _b.next(); !_c.done; _c = _b.next()) {
var prop = _c.value;
/** @type {?} */
var field = original[prop];
if (field && field.editable) {
if (!compareValue(field.value, afterChange[prop].value)) {
changes[prop] = afterChange[prop].value;
// Number
if (typeof field.value === 'number') {
changes[prop] = +changes[prop];
}
// Trim string value
if (typeof field.value === 'string') {
changes[prop] = ('' + changes[prop]).trim();
}
}
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return changes;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Get System information about current backend server.
* @abstract
* class
* @abstract
*/
var /**
* Get System information about current backend server.
* @abstract
* class
* @abstract
*/ SystemInfoService = /** @class */ (function () {
function SystemInfoService() {
}
return SystemInfoService;
}());
var SystemInfoDefaultService = /** @class */ (function (_super) {
__extends(SystemInfoDefaultService, _super);
function SystemInfoDefaultService(config, http$$1) {
var _this = _super.call(this) || this;
_this.config = config;
_this.http = http$$1;
return _this;
}
/**
* @return {?}
*/
SystemInfoDefaultService.prototype.getSystemInfo = /**
* @return {?}
*/
function () {
/** @type {?} */
var url = this.config.systemInfoEndpoint ? this.config.systemInfoEndpoint : '/api/systeminfo';
return this.http.get(url, HTTP_GET_OPTIONS)
.toPromise()
.then(function (systemInfo) { return (systemInfo.json()); })
.catch(function (error) { return Promise.reject(error); });
};
SystemInfoDefaultService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
SystemInfoDefaultService.ctorParameters = function () {
return [
{ type: undefined, decorators: [{ type: core.Inject, args: [SERVICE_CONFIG,] }] },
{ type: http.Http }
];
};
return SystemInfoDefaultService;
}(SystemInfoService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Define service methods to handle the access log related things.
*
* *
* @abstract
* class AccessLogService
* @abstract
*/
var /**
* Define service methods to handle the access log related things.
*
* *
* @abstract
* class AccessLogService
* @abstract
*/ AccessLogService = /** @class */ (function () {
function AccessLogService() {
}
return AccessLogService;
}());
/**
* Implement a default service for access log.
*
* *
* class AccessLogDefaultService
* extends {AccessLogService}
*/
var AccessLogDefaultService = /** @class */ (function (_super) {
__extends(AccessLogDefaultService, _super);
function AccessLogDefaultService(http$$1, config) {
var _this = _super.call(this) || this;
_this.http = http$$1;
_this.config = config;
return _this;
}
/**
* @param {?} projectId
* @param {?=} queryParams
* @return {?}
*/
AccessLogDefaultService.prototype.getAuditLogs = /**
* @param {?} projectId
* @param {?=} queryParams
* @return {?}
*/
function (projectId, queryParams) {
return rxjs.of(/** @type {?} */ ({}));
};
/**
* @param {?=} queryParams
* @return {?}
*/
AccessLogDefaultService.prototype.getRecentLogs = /**
* @param {?=} queryParams
* @return {?}
*/
function (queryParams) {
/** @type {?} */
var url = this.config.logBaseEndpoint
? this.config.logBaseEndpoint
: "";
if (url === "") {
url = "/api/logs";
}
return this.http
.get(url, queryParams ? buildHttpRequestOptions(queryParams) : HTTP_GET_OPTIONS)
.toPromise()
.then(function (response) {
/** @type {?} */
var result = {
metadata: {
xTotalCount: 0
},
data: []
};
/** @type {?} */
var xHeader = "0";
if (response && response.headers) {
xHeader = response.headers.get("X-Total-Count");
}
if (result && result.metadata) {
result.metadata.xTotalCount = parseInt(xHeader ? xHeader : "0", 0);
if (result.metadata.xTotalCount > 0) {
result.data = /** @type {?} */ (response.json());
}
}
return result;
})
.catch(function (error) { return Promise.reject(error); });
};
AccessLogDefaultService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
AccessLogDefaultService.ctorParameters = function () {
return [
{ type: http.Http },
{ type: undefined, decorators: [{ type: core.Inject, args: [SERVICE_CONFIG,] }] }
];
};
return AccessLogDefaultService;
}(AccessLogService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Wrap the class 'URLSearchParams' for future extending requirements.
* Currently no extra methods provided.
*
* *
* class RequestQueryParams
* extends {URLSearchParams}
*/
var /**
* Wrap the class 'URLSearchParams' for future extending requirements.
* Currently no extra methods provided.
*
* *
* class RequestQueryParams
* extends {URLSearchParams}
*/ RequestQueryParams = /** @class */ (function (_super) {
__extends(RequestQueryParams, _super);
function RequestQueryParams() {
return _super.call(this) || this;
}
return RequestQueryParams;
}(http.URLSearchParams));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Define the service methods to handle the endpoint related things.
*
* *
* @abstract
* class EndpointService
* @abstract
*/
var /**
* Define the service methods to handle the endpoint related things.
*
* *
* @abstract
* class EndpointService
* @abstract
*/ EndpointService = /** @class */ (function () {
function EndpointService() {
}
return EndpointService;
}());
/**
* Implement default service for endpoint.
*
* *
* class EndpointDefaultService
* extends {EndpointService}
*/
var EndpointDefaultService = /** @class */ (function (_super) {
__extends(EndpointDefaultService, _super);
function EndpointDefaultService(config, http$$1) {
var _this = _super.call(this) || this;
_this.http = http$$1;
_this._endpointUrl = config.targetBaseEndpoint
? config.targetBaseEndpoint
: "/api/targets";
return _this;
}
/**
* @param {?=} endpointName
* @param {?=} queryParams
* @return {?}
*/
EndpointDefaultService.prototype.getEndpoints = /**
* @param {?=} endpointName
* @param {?=} queryParams
* @return {?}
*/
function (endpointName, queryParams) {
if (!queryParams) {
queryParams = new RequestQueryParams();
}
if (endpointName) {
queryParams.set("name", endpointName);
}
/** @type {?} */
var requestUrl = "" + this._endpointUrl;
return this.http
.get(requestUrl, buildHttpRequestOptions(queryParams))
.toPromise()
.then(function (response) { return response.json(); })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpointId
* @return {?}
*/
EndpointDefaultService.prototype.getEndpoint = /**
* @param {?} endpointId
* @return {?}
*/
function (endpointId) {
if (!endpointId || endpointId <= 0) {
return Promise.reject("Bad request argument.");
}
/** @type {?} */
var requestUrl = this._endpointUrl + "/" + endpointId;
return this.http
.get(requestUrl, HTTP_GET_OPTIONS)
.toPromise()
.then(function (response) { return (response.json()); })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpoint
* @return {?}
*/
EndpointDefaultService.prototype.createEndpoint = /**
* @param {?} endpoint
* @return {?}
*/
function (endpoint) {
if (!endpoint) {
return Promise.reject("Invalid endpoint.");
}
/** @type {?} */
var requestUrl = "" + this._endpointUrl;
return this.http
.post(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response.status; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpointId
* @param {?} endpoint
* @return {?}
*/
EndpointDefaultService.prototype.updateEndpoint = /**
* @param {?} endpointId
* @param {?} endpoint
* @return {?}
*/
function (endpointId, endpoint) {
if (!endpointId || endpointId <= 0) {
return Promise.reject("Bad request argument.");
}
if (!endpoint) {
return Promise.reject("Invalid endpoint.");
}
/** @type {?} */
var requestUrl = this._endpointUrl + "/" + endpointId;
return this.http
.put(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response.status; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpointId
* @return {?}
*/
EndpointDefaultService.prototype.deleteEndpoint = /**
* @param {?} endpointId
* @return {?}
*/
function (endpointId) {
if (!endpointId || endpointId <= 0) {
return Promise.reject("Bad request argument.");
}
/** @type {?} */
var requestUrl = this._endpointUrl + "/" + endpointId;
return this.http
.delete(requestUrl)
.toPromise()
.then(function (response) { return response.status; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpoint
* @return {?}
*/
EndpointDefaultService.prototype.pingEndpoint = /**
* @param {?} endpoint
* @return {?}
*/
function (endpoint) {
if (!endpoint) {
return Promise.reject("Invalid endpoint.");
}
/** @type {?} */
var requestUrl = this._endpointUrl + "/ping";
return this.http
.post(requestUrl, endpoint, HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response.status; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} endpointId
* @return {?}
*/
EndpointDefaultService.prototype.getEndpointWithReplicationRules = /**
* @param {?} endpointId
* @return {?}
*/
function (endpointId) {
if (!endpointId || endpointId <= 0) {
return Promise.reject("Bad request argument.");
}
/** @type {?} */
var requestUrl = this._endpointUrl + "/" + endpointId + "/policies";
return this.http
.get(requestUrl, HTTP_GET_OPTIONS)
.toPromise()
.then(function (response) { return (response.json()); })
.catch(function (error) { return Promise.reject(error); });
};
EndpointDefaultService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
EndpointDefaultService.ctorParameters = function () {
return [
{ type: undefined, decorators: [{ type: core.Inject, args: [SERVICE_CONFIG,] }] },
{ type: http.Http }
];
};
return EndpointDefaultService;
}(EndpointService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Define the service methods to handle the replication (rule and job) related things.
*
* *
* @abstract
* class ReplicationService
* @abstract
*/
var /**
* Define the service methods to handle the replication (rule and job) related things.
*
* *
* @abstract
* class ReplicationService
* @abstract
*/ ReplicationService = /** @class */ (function () {
function ReplicationService() {
}
return ReplicationService;
}());
/**
* Implement default service for replication rule and job.
*
* *
* class ReplicationDefaultService
* extends {ReplicationService}
*/
var ReplicationDefaultService = /** @class */ (function (_super) {
__extends(ReplicationDefaultService, _super);
function ReplicationDefaultService(http$$1, config) {
var _this = _super.call(this) || this;
_this.http = http$$1;
_this._ruleBaseUrl = config.replicationRuleEndpoint
? config.replicationRuleEndpoint
: "/api/policies/replication";
_this._jobBaseUrl = config.replicationJobEndpoint
? config.replicationJobEndpoint
: "/api/jobs/replication";
_this._replicateUrl = config.replicationBaseEndpoint
? config.replicationBaseEndpoint
: "/api/replications";
return _this;
}
// Private methods
// Check if the rule object is valid
/**
* @param {?} rule
* @return {?}
*/
ReplicationDefaultService.prototype._isValidRule = /**
* @param {?} rule
* @return {?}
*/
function (rule) {
return (rule !== undefined &&
rule != null &&
rule.name !== undefined &&
rule.name.trim() !== "" &&
rule.targets.length !== 0);
};
/**
* @return {?}
*/
ReplicationDefaultService.prototype.getJobBaseUrl = /**
* @return {?}
*/
function () {
return this._jobBaseUrl;
};
/**
* @param {?=} projectId
* @param {?=} ruleName
* @param {?=} queryParams
* @return {?}
*/
ReplicationDefaultService.prototype.getReplicationRules = /**
* @param {?=} projectId
* @param {?=} ruleName
* @param {?=} queryParams
* @return {?}
*/
function (projectId, ruleName, queryParams) {
if (!queryParams) {
queryParams = new RequestQueryParams();
}
if (projectId) {
queryParams.set("project_id", "" + projectId);
}
if (ruleName) {
queryParams.set("name", ruleName);
}
return this.http
.get(this._ruleBaseUrl, buildHttpRequestOptions(queryParams))
.toPromise()
.then(function (response) { return (response.json()); })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @return {?}
*/
ReplicationDefaultService.prototype.getReplicationRule = /**
* @param {?} ruleId
* @return {?}
*/
function (ruleId) {
if (!ruleId) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = this._ruleBaseUrl + "/" + ruleId;
return this.http
.get(url, HTTP_GET_OPTIONS)
.toPromise()
.then(function (response) { return (response.json()); })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} replicationRule
* @return {?}
*/
ReplicationDefaultService.prototype.createReplicationRule = /**
* @param {?} replicationRule
* @return {?}
*/
function (replicationRule) {
if (!this._isValidRule(replicationRule)) {
return Promise.reject("Bad argument");
}
return this.http
.post(this._ruleBaseUrl, JSON.stringify(replicationRule), HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} id
* @param {?} rep
* @return {?}
*/
ReplicationDefaultService.prototype.updateReplicationRule = /**
* @param {?} id
* @param {?} rep
* @return {?}
*/
function (id, rep) {
if (!this._isValidRule(rep)) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = this._ruleBaseUrl + "/" + id;
return this.http
.put(url, JSON.stringify(rep), HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @return {?}
*/
ReplicationDefaultService.prototype.deleteReplicationRule = /**
* @param {?} ruleId
* @return {?}
*/
function (ruleId) {
if (!ruleId || ruleId <= 0) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = this._ruleBaseUrl + "/" + ruleId;
return this.http
.delete(url, HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @return {?}
*/
ReplicationDefaultService.prototype.replicateRule = /**
* @param {?} ruleId
* @return {?}
*/
function (ruleId) {
if (!ruleId) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = "" + this._replicateUrl;
return this.http
.post(url, { policy_id: ruleId }, HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @param {?} enablement
* @return {?}
*/
ReplicationDefaultService.prototype.enableReplicationRule = /**
* @param {?} ruleId
* @param {?} enablement
* @return {?}
*/
function (ruleId, enablement) {
if (!ruleId || ruleId <= 0) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = this._ruleBaseUrl + "/" + ruleId + "/enablement";
return this.http
.put(url, { enabled: enablement }, HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @return {?}
*/
ReplicationDefaultService.prototype.disableReplicationRule = /**
* @param {?} ruleId
* @return {?}
*/
function (ruleId) {
if (!ruleId || ruleId <= 0) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var url = this._ruleBaseUrl + "/" + ruleId + "/enablement";
return this.http
.put(url, { enabled: 0 }, HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} ruleId
* @param {?=} queryParams
* @return {?}
*/
ReplicationDefaultService.prototype.getJobs = /**
* @param {?} ruleId
* @param {?=} queryParams
* @return {?}
*/
function (ruleId, queryParams) {
if (!ruleId || ruleId <= 0) {
return Promise.reject("Bad argument");
}
if (!queryParams) {
queryParams = new RequestQueryParams();
}
queryParams.set("policy_id", "" + ruleId);
return this.http
.get(this._jobBaseUrl, buildHttpRequestOptions(queryParams))
.toPromise()
.then(function (response) {
/** @type {?} */
var result = {
metadata: {
xTotalCount: 0
},
data: []
};
if (response && response.headers) {
/** @type {?} */
var xHeader = response.headers.get("X-Total-Count");
if (xHeader) {
result.metadata.xTotalCount = parseInt(xHeader, 0);
}
}
result.data = /** @type {?} */ (response.json());
if (result.metadata.xTotalCount === 0) {
if (result.data && result.data.length > 0) {
result.metadata.xTotalCount = result.data.length;
}
}
return result;
})
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} jobId
* @return {?}
*/
ReplicationDefaultService.prototype.getJobLog = /**
* @param {?} jobId
* @return {?}
*/
function (jobId) {
if (!jobId || jobId <= 0) {
return Promise.reject("Bad argument");
}
/** @type {?} */
var logUrl = this._jobBaseUrl + "/" + jobId + "/log";
return this.http
.get(logUrl, HTTP_GET_OPTIONS)
.toPromise()
.then(function (response) { return response.text(); })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} jobId
* @return {?}
*/
ReplicationDefaultService.prototype.stopJobs = /**
* @param {?} jobId
* @return {?}
*/
function (jobId) {
return this.http
.put(this._jobBaseUrl, JSON.stringify({ policy_id: jobId, status: "stop" }), HTTP_JSON_OPTIONS)
.toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
ReplicationDefaultService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
ReplicationDefaultService.ctorParameters = function () {
return [
{ type: http.Http },
{ type: undefined, decorators: [{ type: core.Inject, args: [SERVICE_CONFIG,] }] }
];
};
return ReplicationDefaultService;
}(ReplicationService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* Define service methods for handling the repository related things.
* Loose couple with project module.
*
* *
* @abstract
* class RepositoryService
* @abstract
*/
var /**
* Define service methods for handling the repository related things.
* Loose couple with project module.
*
* *
* @abstract
* class RepositoryService
* @abstract
*/ RepositoryService = /** @class */ (function () {
function RepositoryService() {
}
return RepositoryService;
}());
/**
* Implement default service for repository.
*
* *
* class RepositoryDefaultService
* extends {RepositoryService}
*/
var RepositoryDefaultService = /** @class */ (function (_super) {
__extends(RepositoryDefaultService, _super);
function RepositoryDefaultService(http$$1, config) {
var _this = _super.call(this) || this;
_this.http = http$$1;
_this.config = config;
return _this;
}
/**
* @param {?} projectId
* @param {?=} repositoryName
* @param {?=} queryParams
* @return {?}
*/
RepositoryDefaultService.prototype.getRepositories = /**
* @param {?} projectId
* @param {?=} repositoryName
* @param {?=} queryParams
* @return {?}
*/
function (projectId, repositoryName, queryParams) {
if (!projectId) {
return Promise.reject('Bad argument');
}
if (!queryParams) {
queryParams = new RequestQueryParams();
}
queryParams.set('project_id', '' + projectId);
if (repositoryName && repositoryName.trim() !== '') {
queryParams.set('q', repositoryName);
}
/** @type {?} */
var url = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories';
return this.http.get(url, buildHttpRequestOptions(queryParams)).toPromise()
.then(function (response) {
/** @type {?} */
var result = {
metadata: { xTotalCount: 0 },
data: []
};
if (response && response.headers) {
/** @type {?} */
var xHeader = response.headers.get('X-Total-Count');
if (xHeader) {
result.metadata.xTotalCount = parseInt(xHeader, 0);
}
}
result.data = /** @type {?} */ (response.json());
if (result.metadata.xTotalCount === 0) {
if (result.data && result.data.length > 0) {
result.metadata.xTotalCount = result.data.length;
}
}
return result;
})
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} repositoryName
* @param {?} description
* @param {?=} queryParams
* @return {?}
*/
RepositoryDefaultService.prototype.updateRepositoryDescription = /**
* @param {?} repositoryName
* @param {?} description
* @param {?=} queryParams
* @return {?}
*/
function (repositoryName, description, queryParams) {
if (!queryParams) {
queryParams = new RequestQueryParams();
}
/** @type {?} */
var baseUrl = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories';
/** @type {?} */
var url = baseUrl + "/" + repositoryName;
return this.http.put(url, { 'description': description }, HTTP_JSON_OPTIONS).toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
/**
* @param {?} repositoryName
* @return {?}
*/
RepositoryDefaultService.prototype.deleteRepository = /**
* @param {?} repositoryName
* @return {?}
*/
function (repositoryName) {
if (!repositoryName) {
return Promise.reject('Bad argument');
}
/** @type {?} */
var url = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories';
url = url + "/" + repositoryName;
return this.http.delete(url, HTTP_JSON_OPTIONS).toPromise()
.then(function (response) { return response; })
.catch(function (error) { return Promise.reject(error); });
};
RepositoryDefaultService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
RepositoryDefaultService.ctorParameters = function () {
return [
{ type: http.Http },
{ type: undefined, decorators: [{ type: core.Inject, args: [SERVICE_CONFIG,] }] }
];
};
return RepositoryDefaultService;
}(RepositoryService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* For getting tag signatures.
* This is temporary, will be removed in future.
*
* *
* class VerifiedSignature
*/
var /**
* For getting tag signatures.
* This is temporary, will be removed in future.
*
* *
* class VerifiedSignature
*/ VerifiedSignature = /** @class */ (function () {
function VerifiedSignature() {
}
return VerifiedSignature;
}());
/**
* Define the service methods to handle the repository tag related things.
*
* *
* @abstract
* class TagService
* @abstract
*/
var /**
* Define the service methods to handle the repository tag related things.
*
* *
* @abstract
* class TagService
* @abstract
*/ TagService = /** @class */ (function () {
function TagService() {
}
return TagService;
}());
/**
* Implement default service for tag.
*
* *
* class TagDefaultService
* extends {TagService}
*/
var TagDefaultService = /** @class */ (function (_super) {
__extends(TagDefaultService, _super);
function TagDefaultService(http$$1, config) {
var _this = _super.call(this) || this;
_this.http = http$$