@helgoland/core
Version:
1,435 lines (1,413 loc) • 267 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('rxjs'), require('@angular/common'), require('@ngx-translate/core'), require('moment'), require('class-transformer'), require('rxjs/operators')) :
typeof define === 'function' && define.amd ? define('@helgoland/core', ['exports', '@angular/core', '@angular/common/http', 'rxjs', '@angular/common', '@ngx-translate/core', 'moment', 'class-transformer', 'rxjs/operators'], factory) :
(factory((global.helgoland = global.helgoland || {}, global.helgoland.core = {}),global.ng.core,global.ng.common.http,global.rxjs,global.ng.common,null,null,null,global.rxjs.operators));
}(this, (function (exports,core,http,rxjs,common,core$1,moment,classTransformer,operators) { 'use strict';
moment = moment && moment.hasOwnProperty('default') ? moment['default'] : moment;
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var ColorService = (function () {
function ColorService() {
}
/**
* Creates a random color and return it as a hex string.
* @return {?}
*/
ColorService.prototype.getColor = /**
* Creates a random color and return it as a hex string.
* @return {?}
*/
function () {
return this.getRandomColor();
};
/**
* Converts a hex string and opacity in percent to RGBA color as string.
* @param {?} hex
* @param {?} opacity
* @return {?}
*/
ColorService.prototype.convertHexToRGBA = /**
* Converts a hex string and opacity in percent to RGBA color as string.
* @param {?} hex
* @param {?} opacity
* @return {?}
*/
function (hex, opacity) {
hex = hex.replace('#', '');
/** @type {?} */
var r = parseInt(hex.substring(0, 2), 16);
/** @type {?} */
var g = parseInt(hex.substring(2, 4), 16);
/** @type {?} */
var b = parseInt(hex.substring(4, 6), 16);
return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity / 100 + ')';
};
/**
* @return {?}
*/
ColorService.prototype.getRandomColor = /**
* @return {?}
*/
function () {
/** @type {?} */
var letters = '0123456789ABCDEF';
/** @type {?} */
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
ColorService.decorators = [
{ type: core.Injectable },
];
return ColorService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @enum {number} */
var DatasetApiVersion = {
V1: 0,
V2: 1,
};
DatasetApiVersion[DatasetApiVersion.V1] = 'V1';
DatasetApiVersion[DatasetApiVersion.V2] = 'V2';
var DatasetApiMapping = (function () {
function DatasetApiMapping(http$$1) {
this.http = http$$1;
this.cache = new Map();
}
/**
* @param {?} apiUrl
* @return {?}
*/
DatasetApiMapping.prototype.getApiVersion = /**
* @param {?} apiUrl
* @return {?}
*/
function (apiUrl) {
var _this = this;
return new rxjs.Observable(function (observer) {
if (_this.cache.has(apiUrl)) {
_this.confirmVersion(observer, _this.cache.get(apiUrl));
}
else {
_this.http.get(apiUrl).subscribe(function (result) {
/** @type {?} */
var version = DatasetApiVersion.V1;
result.forEach(function (entry) {
if (entry.id === 'platforms') {
version = DatasetApiVersion.V2;
}
});
_this.cache.set(apiUrl, version);
_this.confirmVersion(observer, version);
});
}
});
};
/**
* @param {?} observer
* @param {?} version
* @return {?}
*/
DatasetApiMapping.prototype.confirmVersion = /**
* @param {?} observer
* @param {?} version
* @return {?}
*/
function (observer, version) {
observer.next(version);
observer.complete();
};
DatasetApiMapping.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
DatasetApiMapping.ctorParameters = function () {
return [
{ type: http.HttpClient }
];
};
return DatasetApiMapping;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var StatusIntervalResolverService = (function () {
function StatusIntervalResolverService() {
}
/**
* @param {?} value
* @param {?} statusIntervals
* @return {?}
*/
StatusIntervalResolverService.prototype.getMatchingInterval = /**
* @param {?} value
* @param {?} statusIntervals
* @return {?}
*/
function (value, statusIntervals) {
if (value && statusIntervals) {
return statusIntervals.find(function (interval) {
/** @type {?} */
var upper = interval.upper ? parseFloat(interval.upper) : Number.MAX_VALUE;
/** @type {?} */
var lower = interval.lower ? parseFloat(interval.lower) : Number.MIN_VALUE;
if (lower <= value && value < upper) {
return true;
}
});
}
};
StatusIntervalResolverService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
StatusIntervalResolverService.ctorParameters = function () { return []; };
return StatusIntervalResolverService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var HTTP_SERVICE_INTERCEPTORS = new core.InjectionToken('HTTP_SERVICE_INTERCEPTORS');
var HttpService = (function () {
function HttpService(httpHandler, interceptors) {
this.httpHandler = httpHandler;
/** @type {?} */
var handler = {
handle: function (req, options) { return httpHandler.handle(req); }
};
if (interceptors) {
handler = interceptors.reduceRight(function (next, interceptor) {
return ({
handle: function (req, options) { return interceptor.intercept(req, options, next); }
});
}, handler);
}
this.handler = handler;
}
/**
* @param {?=} options
* @return {?}
*/
HttpService.prototype.client = /**
* @param {?=} options
* @return {?}
*/
function (options) {
var _this = this;
if (options === void 0) {
options = {};
}
return new http.HttpClient({
handle: function (req) { return _this.handler.handle(req, options); }
});
};
HttpService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
HttpService.ctorParameters = function () {
return [
{ type: http.HttpHandler },
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [HTTP_SERVICE_INTERCEPTORS,] }] }
];
};
return HttpService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var INTERNAL_ID_SEPERATOR = '__';
/**
* Service to generate or resolve internal dataset IDs
*/
var InternalIdHandler = (function () {
function InternalIdHandler() {
}
/**
* Generates an internal id for the given dataset.
* @param {?} dataset The dataset for which the internal id will be generated and saved.
* @return {?}
*/
InternalIdHandler.prototype.generateInternalId = /**
* Generates an internal id for the given dataset.
* @param {?} dataset The dataset for which the internal id will be generated and saved.
* @return {?}
*/
function (dataset) {
dataset.internalId = dataset.url + INTERNAL_ID_SEPERATOR + dataset.id;
};
/**
* Resolves the internal ID to the url and the API specific dataset id.
* @param {?} internalId The internal id as string
* @return {?} Construct of url and API id
*/
InternalIdHandler.prototype.resolveInternalId = /**
* Resolves the internal ID to the url and the API specific dataset id.
* @param {?} internalId The internal id as string
* @return {?} Construct of url and API id
*/
function (internalId) {
/** @type {?} */
var split = internalId.split(INTERNAL_ID_SEPERATOR);
if (split.length !== 2) {
console.error('InternalID ' + internalId + ' is not resolvable');
}
else {
return {
url: split[0],
id: split[1]
};
}
};
InternalIdHandler.decorators = [
{ type: core.Injectable },
];
return InternalIdHandler;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* LocalStorage save objects with a given key
*
* @export
*/
var LocalStorage = (function () {
function LocalStorage() {
this.localStorageEnabled = false;
if (typeof (Storage) !== 'undefined') {
this.localStorageEnabled = true;
}
}
/**
* Saves the object with the key in the local storage
*
* \@memberof LocalStorage
* @param {?} key
* @param {?} object
* @return {?} successfull saving
*/
LocalStorage.prototype.save = /**
* Saves the object with the key in the local storage
*
* \@memberof LocalStorage
* @param {?} key
* @param {?} object
* @return {?} successfull saving
*/
function (key, object) {
if (this.localStorageEnabled) {
localStorage.setItem(key, JSON.stringify(object));
return true;
}
return false;
};
/**
* loads the object with for the key
*
* \@memberof LocalStorage
* @template T
* @param {?} key
* @return {?} the object if exists, else null
*/
LocalStorage.prototype.load = /**
* loads the object with for the key
*
* \@memberof LocalStorage
* @template T
* @param {?} key
* @return {?} the object if exists, else null
*/
function (key) {
if (this.localStorageEnabled) {
/** @type {?} */
var result = localStorage.getItem(key);
if (result) {
return JSON.parse(result);
}
return null;
}
};
/**
* loads an array of objects for the key
*
* \@memberof LocalStorage
* @template T
* @param {?} key
* @return {?} the array of objects if exists, else null
*/
LocalStorage.prototype.loadArray = /**
* loads an array of objects for the key
*
* \@memberof LocalStorage
* @template T
* @param {?} key
* @return {?} the array of objects if exists, else null
*/
function (key) {
if (this.localStorageEnabled) {
/** @type {?} */
var result = localStorage.getItem(key);
if (result) {
return JSON.parse(result);
}
return null;
}
};
/**
* load a textual string for the given key
*
* \@memberof LocalStorage
* @param {?} key
* @return {?} the string if exists, else null
*/
LocalStorage.prototype.loadTextual = /**
* load a textual string for the given key
*
* \@memberof LocalStorage
* @param {?} key
* @return {?} the string if exists, else null
*/
function (key) {
if (this.localStorageEnabled) {
/** @type {?} */
var result = localStorage.getItem(key);
if (result) {
return result;
}
}
return null;
};
LocalStorage.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
LocalStorage.ctorParameters = function () { return []; };
return LocalStorage;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var ID = 'helgoland-notifier';
/** @type {?} */
var TIME_IN_MS = 3000;
var NotifierService = (function () {
function NotifierService() {
/** @type {?} */
var notifierElement = document.getElementById(ID);
if (!notifierElement) {
/** @type {?} */
var node = document.createElement('div');
node.id = ID;
node.className = 'hide';
/** @type {?} */
var textNode = document.createTextNode('');
node.appendChild(textNode);
document.body.appendChild(node);
}
}
/**
* @param {?} text
* @return {?}
*/
NotifierService.prototype.notify = /**
* @param {?} text
* @return {?}
*/
function (text) {
clearTimeout(this.notifierTimeout);
/** @type {?} */
var notifierElement = document.getElementById(ID);
notifierElement.innerHTML = text;
notifierElement.className = notifierElement.className.replace('hide', 'show');
this.notifierTimeout = setTimeout(function () {
notifierElement.className = notifierElement.className.replace('show', 'hide');
}, TIME_IN_MS);
};
NotifierService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
NotifierService.ctorParameters = function () { return []; };
return NotifierService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var DateProxyPipe = (function () {
function DateProxyPipe(translate) {
this.translate = translate;
}
/**
* @param {?} value
* @param {?=} pattern
* @return {?}
*/
DateProxyPipe.prototype.transform = /**
* @param {?} value
* @param {?=} pattern
* @return {?}
*/
function (value, pattern) {
if (pattern === void 0) {
pattern = 'mediumDate';
}
/** @type {?} */
var builtinDatePipe = new common.DatePipe(this.translate.currentLang || 'en');
try {
return builtinDatePipe.transform(value, pattern);
}
catch (error) {
console.error(error);
return new common.DatePipe('en').transform(value, pattern);
}
};
DateProxyPipe.decorators = [
{ type: core.Pipe, args: [{
name: 'dateI18n',
pure: false
},] },
];
/** @nocollapse */
DateProxyPipe.ctorParameters = function () {
return [
{ type: core$1.TranslateService }
];
};
return DateProxyPipe;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var SumValuesService = (function () {
function SumValuesService() {
}
/**
* @param {?} startOf
* @param {?} period
* @param {?} data
* @return {?}
*/
SumValuesService.prototype.sum = /**
* @param {?} startOf
* @param {?} period
* @param {?} data
* @return {?}
*/
function (startOf, period, data) {
/** @type {?} */
var result = [];
if (data.length === 0) {
return result;
}
/** @type {?} */
var currentBucketStart = moment(data[0][0]).startOf(startOf);
/** @type {?} */
var currentBucketEnd = moment(currentBucketStart).add(period).subtract(1, 'millisecond');
/** @type {?} */
var bucketVals = [];
for (var i = 0; i < data.length; i++) {
/** @type {?} */
var time = moment(data[i][0]);
/** @type {?} */
var value = data[i][1];
var _loop_1 = function () {
if (bucketVals.length > 0) {
/** @type {?} */
var sum_1 = 0;
/** @type {?} */
var hasValues_1 = false;
bucketVals.forEach(function (e) {
if (typeof e === 'number') {
sum_1 += e;
hasValues_1 = true;
}
});
result.push([currentBucketStart.unix() * 1000, hasValues_1 ? sum_1 : 'NaN']);
}
else {
result.push([currentBucketStart.unix() * 1000, 'NaN']);
}
bucketVals = [];
currentBucketStart = currentBucketStart.add(period);
currentBucketEnd = currentBucketEnd.add(period);
};
while (!(currentBucketStart.isSameOrBefore(time) && currentBucketEnd.isSameOrAfter(time))) {
_loop_1();
}
bucketVals.push(value);
}
return result;
};
SumValuesService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
SumValuesService.ctorParameters = function () { return []; };
return SumValuesService;
}());
/*! *****************************************************************************
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 __());
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/ TimeInterval = (function () {
function TimeInterval() {
}
return TimeInterval;
}());
var Timespan = (function (_super) {
__extends(Timespan, _super);
function Timespan(from, to) {
var _this = _super.call(this) || this;
_this.from = from;
if (to) {
_this.to = to;
}
else {
_this.to = from;
}
return _this;
}
return Timespan;
}(TimeInterval));
var BufferedTime = (function (_super) {
__extends(BufferedTime, _super);
function BufferedTime(timestamp, bufferInterval) {
var _this = _super.call(this) || this;
_this.timestamp = timestamp;
_this.bufferInterval = bufferInterval;
return _this;
}
return BufferedTime;
}(TimeInterval));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @enum {string} */
var DefinedTimespan = {
LASTHOUR: 'last_hour',
TODAY: 'today',
YESTERDAY: 'yesterday',
TODAY_YESTERDAY: 'today_yesterday',
CURRENT_WEEK: 'current_week',
LAST_WEEK: 'last_week',
CURRENT_MONTH: 'current_month',
LAST_MONTH: 'last_month',
CURRENT_YEAR: 'current_year',
LAST_YEAR: 'last_year',
};
var DefinedTimespanService = (function () {
function DefinedTimespanService() {
this.intervals = new Map();
this.intervals.set(DefinedTimespan.LASTHOUR, function () {
/** @type {?} */
var from = moment().subtract(1, 'hours').unix() * 1000;
/** @type {?} */
var to = moment().unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.TODAY, function () {
/** @type {?} */
var from = moment().startOf('day').unix() * 1000;
/** @type {?} */
var to = moment().endOf('day').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.YESTERDAY, function () {
/** @type {?} */
var from = moment().subtract(1, 'days').startOf('day').unix() * 1000;
/** @type {?} */
var to = moment().subtract(1, 'days').endOf('day').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.TODAY_YESTERDAY, function () {
/** @type {?} */
var from = moment().subtract(1, 'days').startOf('day').unix() * 1000;
/** @type {?} */
var to = moment().endOf('day').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.CURRENT_WEEK, function () {
/** @type {?} */
var from = moment().startOf('isoWeek').unix() * 1000;
/** @type {?} */
var to = moment().endOf('isoWeek').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.LAST_WEEK, function () {
/** @type {?} */
var from = moment().subtract(1, 'weeks').startOf('isoWeek').unix() * 1000;
/** @type {?} */
var to = moment().subtract(1, 'weeks').endOf('isoWeek').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.CURRENT_MONTH, function () {
/** @type {?} */
var from = moment().startOf('month').unix() * 1000;
/** @type {?} */
var to = moment().endOf('month').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.LAST_MONTH, function () {
/** @type {?} */
var from = moment().subtract(1, 'months').startOf('month').unix() * 1000;
/** @type {?} */
var to = moment().subtract(1, 'months').endOf('month').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.CURRENT_YEAR, function () {
/** @type {?} */
var from = moment().startOf('year').unix() * 1000;
/** @type {?} */
var to = moment().endOf('year').unix() * 1000;
return new Timespan(from, to);
});
this.intervals.set(DefinedTimespan.LAST_YEAR, function () {
/** @type {?} */
var from = moment().subtract(1, 'years').startOf('year').unix() * 1000;
/** @type {?} */
var to = moment().subtract(1, 'years').endOf('year').unix() * 1000;
return new Timespan(from, to);
});
}
/**
* @param {?} intervalDescriber
* @return {?}
*/
DefinedTimespanService.prototype.getInterval = /**
* @param {?} intervalDescriber
* @return {?}
*/
function (intervalDescriber) {
if (this.intervals.has(intervalDescriber)) {
return this.intervals.get(intervalDescriber)();
}
};
DefinedTimespanService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
DefinedTimespanService.ctorParameters = function () { return []; };
return DefinedTimespanService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var Time = (function () {
function Time(localStorage) {
this.localStorage = localStorage;
}
/**
* @param {?} timespan
* @param {?} date
* @return {?}
*/
Time.prototype.centerTimespan = /**
* @param {?} timespan
* @param {?} date
* @return {?}
*/
function (timespan, date) {
/** @type {?} */
var halfduration = this.getDuration(timespan).asMilliseconds() / 2;
/** @type {?} */
var from = moment(date).subtract(halfduration).unix() * 1000;
/** @type {?} */
var to = moment(date).add(halfduration).unix() * 1000;
return new Timespan(from, to);
};
/**
* @param {?} timespan
* @param {?} duration
* @return {?}
*/
Time.prototype.centerTimespanWithDuration = /**
* @param {?} timespan
* @param {?} duration
* @return {?}
*/
function (timespan, duration) {
/** @type {?} */
var half = duration.asMilliseconds() / 2;
/** @type {?} */
var center = this.getCenterOfTimespan(timespan);
return new Timespan(center - half, center + half);
};
/**
* @param {?} timespan
* @return {?}
*/
Time.prototype.getCenterOfTimespan = /**
* @param {?} timespan
* @return {?}
*/
function (timespan) {
return timespan.from + (timespan.to - timespan.from) / 2;
};
/**
* @param {?} timespan
* @return {?}
*/
Time.prototype.stepBack = /**
* @param {?} timespan
* @return {?}
*/
function (timespan) {
/** @type {?} */
var duration = this.getDuration(timespan);
/** @type {?} */
var from = moment(timespan.from).subtract(duration).unix() * 1000;
/** @type {?} */
var to = moment(timespan.to).subtract(duration).unix() * 1000;
return new Timespan(from, to);
};
/**
* @param {?} timespan
* @return {?}
*/
Time.prototype.stepForward = /**
* @param {?} timespan
* @return {?}
*/
function (timespan) {
/** @type {?} */
var duration = this.getDuration(timespan);
/** @type {?} */
var from = moment(timespan.from).add(duration).unix() * 1000;
/** @type {?} */
var to = moment(timespan.to).add(duration).unix() * 1000;
return new Timespan(from, to);
};
/**
* @param {?} timeInterval
* @param {?} from
* @param {?} to
* @return {?}
*/
Time.prototype.overlaps = /**
* @param {?} timeInterval
* @param {?} from
* @param {?} to
* @return {?}
*/
function (timeInterval, from, to) {
/** @type {?} */
var timespan = this.createTimespanOfInterval(timeInterval);
if (timespan.from <= to && timespan.to >= from) {
return true;
}
return false;
};
/**
* @param {?} timeInterval
* @return {?}
*/
Time.prototype.createTimespanOfInterval = /**
* @param {?} timeInterval
* @return {?}
*/
function (timeInterval) {
if (timeInterval instanceof Timespan) {
return timeInterval;
}
else if (timeInterval instanceof BufferedTime) {
/** @type {?} */
var duration = moment.duration(timeInterval.bufferInterval / 2);
/** @type {?} */
var from = moment(timeInterval.timestamp).subtract(duration).unix() * 1000;
/** @type {?} */
var to = moment(timeInterval.timestamp).add(duration).unix() * 1000;
return new Timespan(from, to);
}
else {
console.error('Wrong time interval!');
}
};
/**
* @param {?} timespan
* @param {?} factor
* @return {?}
*/
Time.prototype.getBufferedTimespan = /**
* @param {?} timespan
* @param {?} factor
* @return {?}
*/
function (timespan, factor) {
/** @type {?} */
var durationMillis = this.getDuration(timespan).asMilliseconds();
/** @type {?} */
var from = moment(timespan.from).subtract(durationMillis * factor).unix() * 1000;
/** @type {?} */
var to = moment(timespan.to).add(durationMillis * factor).unix() * 1000;
return new Timespan(from, to);
};
/**
* @param {?} param
* @param {?} timespan
* @return {?}
*/
Time.prototype.saveTimespan = /**
* @param {?} param
* @param {?} timespan
* @return {?}
*/
function (param, timespan) {
this.localStorage.save(param, timespan);
};
/**
* @param {?} param
* @return {?}
*/
Time.prototype.loadTimespan = /**
* @param {?} param
* @return {?}
*/
function (param) {
/** @type {?} */
var json = this.localStorage.load(param);
if (json) {
return classTransformer.plainToClass(Timespan, json);
}
return null;
};
/**
* @return {?}
*/
Time.prototype.initTimespan = /**
* @return {?}
*/
function () {
/** @type {?} */
var now = new Date();
/** @type {?} */
var start = moment(now).startOf('day').unix() * 1000;
/** @type {?} */
var end = moment(now).endOf('day').unix() * 1000;
return new Timespan(start, end);
};
/**
* @param {?} timespan
* @return {?}
*/
Time.prototype.getDuration = /**
* @param {?} timespan
* @return {?}
*/
function (timespan) {
/** @type {?} */
var from = moment(timespan.from);
/** @type {?} */
var to = moment(timespan.to);
return moment.duration(to.diff(from));
};
Time.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
Time.ctorParameters = function () {
return [
{ type: LocalStorage }
];
};
return Time;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var HelgolandCoreModule = (function () {
function HelgolandCoreModule() {
}
HelgolandCoreModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [
DateProxyPipe
],
imports: [
http.HttpClientModule
],
exports: [
DateProxyPipe
],
providers: [
ColorService,
DatasetApiMapping,
DefinedTimespanService,
InternalIdHandler,
LocalStorage,
NotifierService,
StatusIntervalResolverService,
SumValuesService,
HttpService,
Time
]
},] },
];
return HelgolandCoreModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/ ApiInterface = (function () {
function ApiInterface() {
}
/**
* @param {?} apiUrl
* @param {?} endpoint
* @param {?=} id
* @return {?}
*/
ApiInterface.prototype.createRequestUrl = /**
* @param {?} apiUrl
* @param {?} endpoint
* @param {?=} id
* @return {?}
*/
function (apiUrl, endpoint, id) {
/** @type {?} */
var requestUrl = apiUrl + endpoint;
if (id) {
requestUrl += '/' + id;
}
return requestUrl;
};
/**
* @param {?} timespan
* @return {?}
*/
ApiInterface.prototype.createRequestTimespan = /**
* @param {?} timespan
* @return {?}
*/
function (timespan) {
return encodeURI(moment(timespan.from).format() + '/' + moment(timespan.to).format());
};
/**
* @param {?} token
* @return {?}
*/
ApiInterface.prototype.createBasicAuthHeader = /**
* @param {?} token
* @return {?}
*/
function (token) {
/** @type {?} */
var headers = new http.HttpHeaders();
if (token) {
return headers.set('Authorization', token);
}
return headers;
};
return ApiInterface;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
// unsupported: template constraints.
/**
* @abstract
* @template T
*/
var
// unsupported: template constraints.
/**
* @abstract
* @template T
*/
DatasetService = (function () {
function DatasetService() {
this.datasetIds = [];
this.datasetOptions = new Map();
this.datasetIdsChanged = new core.EventEmitter();
}
/**
* Adds the dataset to the selection
*
* @param {?} internalId
* @param {?=} options
* @return {?} Successfull added the dataset.
*/
DatasetService.prototype.addDataset = /**
* Adds the dataset to the selection
*
* @param {?} internalId
* @param {?=} options
* @return {?} Successfull added the dataset.
*/
function (internalId, options) {
if (this.datasetIds.indexOf(internalId) < 0) {
this.datasetIds.push(internalId);
if (options) {
this.datasetOptions.set(internalId, options);
}
else {
this.datasetOptions.set(internalId, this.createStyles(internalId));
}
this.saveState();
}
else if (options instanceof Array) {
/** @type {?} */
var temp_1 = ((this.datasetOptions.get(internalId)));
options.forEach(function (e) { return temp_1.push(e); });
this.saveState();
}
this.datasetIdsChanged.emit(this.datasetIds);
return rxjs.of(true);
};
/**
* @return {?}
*/
DatasetService.prototype.removeAllDatasets = /**
* @return {?}
*/
function () {
this.datasetIds.length = 0;
this.datasetOptions.clear();
this.datasetIdsChanged.emit(this.datasetIds);
this.saveState();
};
/**
* @param {?} internalId
* @return {?}
*/
DatasetService.prototype.removeDataset = /**
* @param {?} internalId
* @return {?}
*/
function (internalId) {
/** @type {?} */
var datasetIdx = this.datasetIds.indexOf(internalId);
if (datasetIdx > -1) {
this.datasetIds.splice(datasetIdx, 1);
this.datasetOptions.delete(internalId);
}
this.datasetIdsChanged.emit(this.datasetIds);
this.saveState();
};
/**
* @return {?}
*/
DatasetService.prototype.hasDatasets = /**
* @return {?}
*/
function () {
return this.datasetIds.length > 0;
};
/**
* @param {?} id
* @return {?}
*/
DatasetService.prototype.hasDataset = /**
* @param {?} id
* @return {?}
*/
function (id) {
return this.datasetIds.indexOf(id) >= 0;
};
/**
* @param {?} options
* @param {?} internalId
* @return {?}
*/
DatasetService.prototype.updateDatasetOptions = /**
* @param {?} options
* @param {?} internalId
* @return {?}
*/
function (options, internalId) {
this.datasetOptions.set(internalId, options);
this.saveState();
};
return DatasetService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
// unsupported: template constraints.
/**
* @abstract
* @template T
*/
var
// unsupported: template constraints.
/**
* @abstract
* @template T
*/
RenderingHintsDatasetService = (function (_super) {
__extends(RenderingHintsDatasetService, _super);
function RenderingHintsDatasetService(api) {
var _this = _super.call(this) || this;
_this.api = api;
return _this;
}
/**
* @param {?} internalId
* @param {?=} options
* @return {?}
*/
RenderingHintsDatasetService.prototype.addDataset = /**
* @param {?} internalId
* @param {?=} options
* @return {?}
*/
function (internalId, options) {
var _this = this;
return new rxjs.Observable(function (observer) {
if (options) {
_this.datasetIds.push(internalId);
_this.datasetOptions.set(internalId, options);
observer.next(true);
observer.complete();
_this.datasetIdsChanged.emit(_this.datasetIds);
}
else if (_this.datasetIds.indexOf(internalId) < 0) {
_this.api.getSingleTimeseriesByInternalId(internalId).subscribe(function (timeseries) { return _this.addLoadedDataset(timeseries, observer); }, function (error) {
_this.api.getDatasetByInternalId(internalId).subscribe(function (dataset) { return _this.addLoadedDataset(dataset, observer); });
});
}
});
};
/**
* @param {?} dataset
* @param {?} observer
* @return {?}
*/
RenderingHintsDatasetService.prototype.addLoadedDataset = /**
* @param {?} dataset
* @param {?} observer
* @return {?}
*/
function (dataset, observer) {
this.datasetIds.push(dataset.internalId);
this.datasetOptions.set(dataset.internalId, this.createOptionsOfRenderingHints(dataset));
observer.next(true);
observer.complete();
this.datasetIdsChanged.emit(this.datasetIds);
this.saveState();
};
/**
* @param {?} dataset
* @return {?}
*/
RenderingHintsDatasetService.prototype.createOptionsOfRenderingHints = /**
* @param {?} dataset
* @return {?}
*/
function (dataset) {
/** @type {?} */
var options = (this.createStyles(dataset.internalId));
if (dataset.renderingHints) {
if (dataset.renderingHints.properties && dataset.renderingHints.properties.color) {
options.color = dataset.renderingHints.properties.color;
}
switch (dataset.renderingHints.chartType) {
case 'line':
this.handleLineRenderingHints(/** @type {?} */ (dataset.renderingHints), options);
break;
case 'bar':
this.handleBarRenderingHints(/** @type {?} */ (dataset.renderingHints), options);
break;
default:
break;
}
}
return /** @type {?} */ (options);
};
/**
* @param {?} lineHints
* @param {?} options
* @return {?}
*/
RenderingHintsDatasetService.prototype.handleLineRenderingHints = /**
* @param {?} lineHints
* @param {?} options
* @return {?}
*/
function (lineHints, options) {
if (lineHints.properties.width) {
options.lineWidth = Math.round(parseFloat(lineHints.properties.width));
}
};
/**
* @param {?} barHints
* @param {?} options
* @return {?}
*/
RenderingHintsDatasetService.prototype.handleBarRenderingHints = /**
* @param {?} barHints
* @param {?} options
* @return {?}
*/
function (barHints, options) {
if (barHints.properties.width) {
options.lineWidth = Math.round(parseFloat(barHints.properties.width));
}
};
return RenderingHintsDatasetService;
}(DatasetService));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var UriParameterCoder = (function () {
function UriParameterCoder() {
}
/**
* @param {?} key
* @return {?}
*/
UriParameterCoder.prototype.encodeKey = /**
* @param {?} key
* @return {?}
*/
function (key) {
return encodeURIComponent(key);
};
/**
* @param {?} value
* @return {?}
*/
UriParameterCoder.prototype.encodeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
return encodeURIComponent(value);
};
/**
* @param {?} key
* @return {?}
*/
UriParameterCoder.prototype.decodeKey = /**
* @param {?} key
* @return {?}
*/
function (key) {
return key;
};
/**
* @param {?} value
* @return {?}
*/
UriParameterCoder.prototype.decodeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
return value;
};
return UriParameterCoder;
}());
/**
* @abstract
*/
var /**
* @abstract
*/ DatasetApiInterface = (function (_super) {
__extends(DatasetApiInterface, _super);
function DatasetApiInterface(httpService, translate) {
var _this = _super.call(this) || this;
_this.httpService = httpService;
_this.translate = translate;
return _this;
}
/**
* @template T
* @param {?} url
* @param {?=} params
* @param {?=} options
* @return {?}
*/
DatasetApiInterface.prototype.requestApi = /**
* @template T
* @param {?} url
* @param {?=} params
* @param {?=} options
* @return {?}
*/
function (url, params, options) {
if (params === void 0) {
params = {};
}
if (options === void 0) {
options = {};
}
return this.httpService.client(options).get(url, {
params: this.prepareParams(params),
headers: this.createBasicAuthHeader(options.basicAuthToken)
});
};
/**
* @param {?} params
* @return {?}
*/
DatasetApiInterface.prototype.prepareParams = /**
* @param {?} params
* @return {?}
*/
function (params) {
if (this.translate && this.translate.currentLang) {
params["locale"] = this.translate.currentLang;
}
/** @type {?} */
var httpParams = new http.HttpParams({