com.phloxui
Version:
PhloxUI Ng2+ Framework
1,294 lines (1,288 loc) • 7.96 MB
JavaScript
import { Injectable, InjectionToken, Inject, EventEmitter, Type, Component, Input, Output, Directive, ElementRef, ViewChildren, ViewChild, ViewContainerRef, ComponentFactoryResolver, HostListener, NgZone, ApplicationRef, ChangeDetectionStrategy, Pipe, NgModule } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { __extends, __values, __decorate, __metadata } from 'tslib';
import { Response, Headers, RequestOptions, Http, HttpModule, JsonpModule } from '@angular/http';
import { Subscription, Observable } from 'rxjs';
import { UUID } from 'angular2-uuid';
import { Router, RouterModule } from '@angular/router';
import { DomSanitizer, BrowserModule } from '@angular/platform-browser';
import { FormControl, NgControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Platform } from '@angular/cdk/platform';
import { NativeDateAdapter, DateAdapter, MAT_DATE_LOCALE, MatRadioButton, MatAutocompleteModule, MatBadgeModule, MatBottomSheetModule, MatButtonModule, MatButtonToggleModule, MatCardModule, MatCheckboxModule, MatChipsModule, MatDatepickerModule, MatDialogModule, MatDividerModule, MatExpansionModule, MatGridListModule, MatIconModule, MatInputModule, MatListModule, MatMenuModule, MatNativeDateModule, MatPaginatorModule, MatProgressBarModule, MatProgressSpinnerModule, MatRadioModule, MatRippleModule, MatSelectModule, MatSidenavModule, MatSliderModule, MatSlideToggleModule, MatSnackBarModule, MatSortModule, MatStepperModule, MatTableModule, MatTabsModule, MatToolbarModule, MatTooltipModule, MatTreeModule } from '@angular/material';
import { startWith } from 'rxjs/operators';
import { NgxCroppieModule } from 'ngx-croppie';
import { Ng2GoogleChartsModule } from 'ng2-google-charts';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LoadersCssModule } from 'angular2-loaders-css';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ APP_SWITCHER_HEADER = 'App Swithcer Header';
var /** @type {?} */ APP_SWITCHER_TAGLINE = 'tagLine...';
var /** @type {?} */ DEFAULT_SCROLL_LOAD_OFF_SET = 100;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_DELAY = 100;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_COUNT = 50;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_LABEL = "Load More";
var /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_LABEL = "Press to reload";
var /** @type {?} */ DEFAULT_SCROLL_LOAD_COMPLETE_LABEL = "No more data (Press to reload)";
var /** @type {?} */ DEFAULT_SCROLL_LOAD_AUTO = true;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_AUTO = false;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_DISABLED = false;
var /** @type {?} */ DEFAULT_SCROLL_LOAD_APPEND_CLASS_WRAPPER_ICON_RELOAD = "<div class='wrapper-icon-reload'><div class='icon-reloader'><div class='reloader'></div></div></div>";
var /** @type {?} */ DEFAULT_APP_BASE_URLS = [];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* <p style="text-indent: 2em;">
* A model class representing a single <code>Phlox Application</code>. An <code>application</code> may also consist of its <code>settings</code> and
* common <code>I18N</code>. An instance of this class is usually obtained from [[PhloxAppInfoService.getAppInfo]] which may load the info from backend
* server to return the user configurations such as language settings, user preferences, etc.
* </p>
*
* @author shiorin, tee4cute
* @see [[PhloxAppInfoService]]
*/
var PhloxAppInfo = /** @class */ (function () {
function PhloxAppInfo(name, tagline, group, iconURL) {
if (name === void 0) { name = 'App Name'; }
if (tagline === void 0) { tagline = 'App Tagline'; }
this.name = name;
this.tagline = tagline;
this.iconURL = iconURL;
this.group = group;
// Init default settings
this.settings = {
RIPPLE_EFFECT_DURATION: PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_DURATION,
RIPPLE_EFFECT_WIDTH_RATIO: PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_WIDTH_RATIO,
RIPPLE_EFFECT_HEIGHT_RATIO: PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_HEIGHT_RATIO,
RIPPLE_EFFECT_REMOVE_DURATION: PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_REMOVE_DURATION,
APP_SWITCHER_POPOVER_DELAY: PhloxAppInfo.DEFAULT_APP_SWITCHER_POPOVER_DELAY,
WIZARD_HEADER_HEIGHT: PhloxAppInfo.DEFAULT_WIZARD_HEADER_HEIGHT,
WIZARD_FOOTER_HEIGHT: PhloxAppInfo.DEFAULT_WIZARD_FOOTER_HEIGHT,
OBJECT_ID_FIELD_NAME: PhloxAppInfo.DEFAULT_OBJECT_ID_FIELD_NAME,
CONNECTION_TIMEOUT: PhloxAppInfo.DEFAULT_CONNECTION_TIMEOUT,
UI_SYSTEM_CLOCK_INTERVAL: PhloxAppInfo.DEFAULT_UI_SYSTEM_CLOCK_INTERVAL,
UI_ANIMATE_INTERVAL: PhloxAppInfo.DEFAULT_UI_ANIMATE_INTERVAL,
MAX_NOTIFICATIONS: PhloxAppInfo.DEFAULT_MAX_NOTIFICATIONS,
LANGUAGE_FIELD_NAME: PhloxAppInfo.DEFAULT_LANGUAGE_FIELD_NAME,
PAGE_LOAD_TIMEOUT: PhloxAppInfo.DEFAULT_PAGE_LOAD_TIMEOUT,
SYSTEM_YEAR_OFFSET: PhloxAppInfo.DEFAULT_SYSTEM_YEAR_OFFSET,
DATE_PATTERN: PhloxAppInfo.DEFAULT_DATE_PATTERN,
YEAR_OFFSET: PhloxAppInfo.DEFAULT_YEAR_OFFSET,
TIMEZONE: PhloxAppInfo.DEFAULT_TIMEZONE,
TIME_PATTERN: PhloxAppInfo.DEFAULT_TIME_PATTERN,
DEFAULT_DATA_LANGUAGES: PhloxAppInfo.DEFAULT_DATA_LANGUAGES,
COUNTRY_CODE: PhloxAppInfo.DEFAULT_COUNTRY_CODE,
DEFAULT_TIME_OUT_LOGIN_USER_SESSION: PhloxAppInfo.DEFAULT_TIME_OUT_LOGIN_USER_SESSION
};
// init default i18n
this.i18n = {
YES: 'Yes',
NO: 'No',
OK: 'OK',
CANCEL: 'Cancel',
CLOSE: 'Close',
CONFIRM: 'Confirm',
LANG: {
EN: { iconURL: null, code: 'en', name: 'English' },
TH: { iconURL: null, code: 'th', name: 'Thailand' },
JP: { iconURL: null, code: 'ja', name: 'Japanese' },
KR: { iconURL: null, code: 'kr', name: 'Korean' }
},
INVALID_DATA: 'Invalid Data'
};
// default resources
this.resources = {
CROSS_ROUND_BTN: 'http://i249.photobucket.com/albums/gg202/sound_horizon/cross_circle.png'
};
}
/**
* @return {?}
*/
PhloxAppInfo.prototype.getName = /**
* @return {?}
*/
function () {
return this.name;
};
/**
* @param {?} name
* @return {?}
*/
PhloxAppInfo.prototype.setName = /**
* @param {?} name
* @return {?}
*/
function (name) {
this.name = name;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getTagline = /**
* @return {?}
*/
function () {
return this.tagline;
};
/**
* @param {?} tagline
* @return {?}
*/
PhloxAppInfo.prototype.setTagline = /**
* @param {?} tagline
* @return {?}
*/
function (tagline) {
this.tagline = tagline;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getSettings = /**
* @return {?}
*/
function () {
return this.settings;
};
/**
* @param {?} settings
* @return {?}
*/
PhloxAppInfo.prototype.setSettings = /**
* @param {?} settings
* @return {?}
*/
function (settings) {
this.settings = settings;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getIconURL = /**
* @return {?}
*/
function () {
return this.iconURL;
};
/**
* @param {?} iconURL
* @return {?}
*/
PhloxAppInfo.prototype.setIconURL = /**
* @param {?} iconURL
* @return {?}
*/
function (iconURL) {
this.iconURL = iconURL;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getGroup = /**
* @return {?}
*/
function () {
return this.group;
};
/**
* @param {?} group
* @return {?}
*/
PhloxAppInfo.prototype.setGroup = /**
* @param {?} group
* @return {?}
*/
function (group) {
this.group = group;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getI18n = /**
* @return {?}
*/
function () {
return this.i18n;
};
/**
* @param {?} i18n
* @return {?}
*/
PhloxAppInfo.prototype.setI18n = /**
* @param {?} i18n
* @return {?}
*/
function (i18n) {
this.i18n = i18n;
};
/**
* @return {?}
*/
PhloxAppInfo.prototype.getResources = /**
* @return {?}
*/
function () {
return this.resources;
};
/**
* @param {?} resources
* @return {?}
*/
PhloxAppInfo.prototype.setResources = /**
* @param {?} resources
* @return {?}
*/
function (resources) {
this.resources = resources;
};
PhloxAppInfo.DEFAULT_DATA_LANGUAGES = [
{ iconURL: null, code: 'th', country: 'TH', label: 'Thailand', countryCode: '+66' },
{ iconURL: null, code: 'en', country: 'EN', label: 'English', countryCode: '+44' },
{ iconURL: null, code: 'ja', country: 'JP', label: 'Japanese', countryCode: '+81' },
{ iconURL: null, code: 'kr', country: 'KR', label: 'Korean', countryCode: '+82' }
];
PhloxAppInfo.DEFAULT_COUNTRY_CODE = 'TH';
PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_DURATION = 1.5;
PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_WIDTH_RATIO = 0.5;
PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_HEIGHT_RATIO = 0.5;
PhloxAppInfo.DEFAULT_RIPPLE_EFFECT_REMOVE_DURATION = 0.8;
PhloxAppInfo.DEFAULT_APP_SWITCHER_POPOVER_DELAY = 800;
PhloxAppInfo.DEFAULT_WIZARD_HEADER_HEIGHT = 140;
PhloxAppInfo.DEFAULT_WIZARD_FOOTER_HEIGHT = 140;
PhloxAppInfo.DEFAULT_OBJECT_ID_FIELD_NAME = '_uuid';
PhloxAppInfo.DEFAULT_LANGUAGE_FIELD_NAME = '_lang';
PhloxAppInfo.DEFAULT_CONNECTION_TIMEOUT = 7000;
PhloxAppInfo.DEFAULT_UI_SYSTEM_CLOCK_INTERVAL = 20;
PhloxAppInfo.DEFAULT_UI_ANIMATE_INTERVAL = 600;
PhloxAppInfo.DEFAULT_MAX_NOTIFICATIONS = 50;
PhloxAppInfo.DEFAULT_PAGE_LOAD_TIMEOUT = 8000;
PhloxAppInfo.DEFAULT_SYSTEM_YEAR_OFFSET = 543;
PhloxAppInfo.DEFAULT_DATE_PATTERN = 'dd/MM/yyyy';
PhloxAppInfo.DEFAULT_TIME_PATTERN = 'HH:mm:ss';
PhloxAppInfo.DEFAULT_YEAR_OFFSET = 543;
PhloxAppInfo.DEFAULT_TIMEZONE = 700;
PhloxAppInfo.DEFAULT_DATA_DATE_TIME_PATTERN = 'yyyy-MM-dd HH:mm:ss';
PhloxAppInfo.DEFAULT_DATA_DATE_PATTERN = 'yyyy-MM-dd';
PhloxAppInfo.DEFAULT_DATA_TIME_PATTERN = 'HH:mm:ss';
PhloxAppInfo.DEFAULT_DATA_TIME_ZONE = 700;
PhloxAppInfo.DEFAULT_TIME_OUT_LOGIN_USER_SESSION = 10000;
return PhloxAppInfo;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ TYPE_UNDEFINED = 'undefined';
var BackgroundProcess = /** @class */ (function () {
function BackgroundProcess(process, processType, name, startTime, options) {
this.process = process;
this.type = processType;
this.name = name;
this.startTime = startTime;
this.options = options;
this.userAction = true;
if (this.type === null || typeof this.type === 'undefined') {
this.type = BackgroundProcess.TYPE_UNDEFINED;
}
if (this.name === null || typeof this.name === 'undefined') {
this.name = BackgroundProcess.TYPE_UNDEFINED;
}
if (options !== null && typeof options !== 'undefined') {
if (options.userAction !== null && typeof options.userAction !== 'undefined') {
this.userAction = options.userAction;
}
}
}
BackgroundProcess.TYPE_UNDEFINED = TYPE_UNDEFINED;
return BackgroundProcess;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* <p style="text-indent: 2em;">
* A <code>ng</code> service which is mainly responsible for providing publish/subscribe <code>Messaging API</code>. You can easily create/publish/subscribe a
* <code>message topic</code> by using this service. This service uses <code>RxJS</code>'s <code>Observable / Subject API</code> as a core engine. Neverthelss, it does not
* require you to have any background on <code>RxJS</code> since it simplifies the <code>RxJS</code>'s API by providing a new way to use it. For example, in
* <code>RxJS</code>'s normal way, you may need to keep a reference to an <code>Subject</code> object all the time in which that the <code>message topic</code>
* is still active. Moreover, if you have more <code>message topic</code>s to handle, you must keep more <code>Subject</code> instance references separately.
* In spite of that, this service diminishes those struggles by mapping each <code>Subject</code> object instance to a <code>topic name</code>. When you want
* to interact with those topics, you could simply supply the <code>topic name</code> to this service. For more information, please see methods of this class
* below.
* </p>
* <p style="text-indent: 2em;">
* If you only want to publish/subscribe to a topic. Please see [[publish]] and [[subscribe]] method below.
* </p>
*
* @author shiorin, tee4cute
*/
var ObservableManager = /** @class */ (function () {
function ObservableManager() {
this.subjects = {};
}
/**
* <p style="text-indent: 1em;">
* Get the <code>RxJS</code>'s <code>Subject</code> object bound to the given topic <code><b>name</b></code>.
* </p>
*
* @param {?} name A message topic name to get.
*
* @return {?} Returns <code>null</code> if the given topic <code><b>name</b></code> is not created yet.
*/
ObservableManager.prototype.getSubject = /**
* <p style="text-indent: 1em;">
* Get the <code>RxJS</code>'s <code>Subject</code> object bound to the given topic <code><b>name</b></code>.
* </p>
*
* @param {?} name A message topic name to get.
*
* @return {?} Returns <code>null</code> if the given topic <code><b>name</b></code> is not created yet.
*/
function (name) {
if (name === null || typeof name !== 'string') {
return null;
}
var /** @type {?} */ re = this.subjects[name];
if (typeof re === 'undefined') {
re = null;
}
return re;
};
/**
* <p style="text-indent: 1em;">
* To check that there already is <code>RxJS</code>'s <code>Subject</code> object bound to the given topic
* <code><b>name</b></code> or not.
* </p>
*
* @param {?} name A message topic name to check.
* @return {?}
*/
ObservableManager.prototype.containsSubject = /**
* <p style="text-indent: 1em;">
* To check that there already is <code>RxJS</code>'s <code>Subject</code> object bound to the given topic
* <code><b>name</b></code> or not.
* </p>
*
* @param {?} name A message topic name to check.
* @return {?}
*/
function (name) {
if (name === null || typeof name !== 'string') {
return false;
}
var /** @type {?} */ subj = this.getSubject(name);
return subj !== null && typeof subj !== 'undefined';
};
/**
* <p style="text-indent: 1em;">
* Create a new <code>Subject</code> (or topic) and map it to the given topic <code><b>name</b></code>. This method will return
* the old object instance if the given <code><b>"name"</b></code> already exists.
* </p>
*
* @param {?} name A message topic name to create <code>Subject</code>.
* @return {?}
*/
ObservableManager.prototype.createSubject = /**
* <p style="text-indent: 1em;">
* Create a new <code>Subject</code> (or topic) and map it to the given topic <code><b>name</b></code>. This method will return
* the old object instance if the given <code><b>"name"</b></code> already exists.
* </p>
*
* @param {?} name A message topic name to create <code>Subject</code>.
* @return {?}
*/
function (name) {
if (name === null || typeof name !== 'string') {
return null;
}
if (this.containsSubject(name)) {
// If the given name already exists, return the old one.
return this.getSubject(name);
}
console.debug('Obsv Mgr: Creating subject for topic "' + name + '".');
this.subjects[name] = new Subject();
return this.subjects[name];
};
/**
* <p style="text-indent: 1em;">
* Subscribe message to the given topic <code><b>name</b></code>. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name A message topic name to subscribe.
* @param {?} handler A message <code>handler function</code> which will be triggered when message arrives.
* @param {?=} errorHandler An error <code>handler function</code> which will be triggered when any error occurs on the [[Observer]].
* @param {?=} completeHandler A <code>handler function</code> which will be triggered when the topic is closed and not publishes any messages anymore.
*
* @return {?} A <code>RxJS</code>'s <code>Subscription</code> object returning from <code>Subject.subscribe()</code> method.
*/
ObservableManager.prototype.subscribe = /**
* <p style="text-indent: 1em;">
* Subscribe message to the given topic <code><b>name</b></code>. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name A message topic name to subscribe.
* @param {?} handler A message <code>handler function</code> which will be triggered when message arrives.
* @param {?=} errorHandler An error <code>handler function</code> which will be triggered when any error occurs on the [[Observer]].
* @param {?=} completeHandler A <code>handler function</code> which will be triggered when the topic is closed and not publishes any messages anymore.
*
* @return {?} A <code>RxJS</code>'s <code>Subscription</code> object returning from <code>Subject.subscribe()</code> method.
*/
function (name, handler, errorHandler, completeHandler) {
if (name === null || typeof name !== 'string') {
return null;
}
if (!this.containsSubject(name)) {
// Auto create topic if does not exist.
this.createSubject(name);
}
console.debug('Obsv Mgr: Subscribing topic "' + name + '".');
return this.subjects[name].subscribe(handler, errorHandler, completeHandler);
};
/**
* <p style="text-indent: 1em;">
* Publish a message (<code><b>data</b></code>) to the given topic <code><b>name</b></code>. The subscriber's <code>handler function</code> will be
* triggered with the given <code><b>data</b></code> passed as a parameter. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name The message topic name to publish.
* @param {?} data The message data to publish.
* @return {?}
*/
ObservableManager.prototype.publish = /**
* <p style="text-indent: 1em;">
* Publish a message (<code><b>data</b></code>) to the given topic <code><b>name</b></code>. The subscriber's <code>handler function</code> will be
* triggered with the given <code><b>data</b></code> passed as a parameter. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name The message topic name to publish.
* @param {?} data The message data to publish.
* @return {?}
*/
function (name, data) {
if (name === null || typeof name !== 'string') {
return;
}
if (!this.containsSubject(name)) {
// Auto create topic if does not exist.
this.createSubject(name);
}
console.debug('Obsv Mgr: Publishing to topic "' + name + '" [data=' + JSON.stringify(data) + '].');
this.getSubject(name).next(data);
};
/**
* <p style="text-indent: 1em;">
* Signal error message to the given topic <code><b>name</b></code>. The subscriber's <code>error function</code> will be
* triggered with the given <code><b>error</b></code> passed as a parameter. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name The message topic name to signal.
* @param {?} error The error message to signal.
* @return {?}
*/
ObservableManager.prototype.error = /**
* <p style="text-indent: 1em;">
* Signal error message to the given topic <code><b>name</b></code>. The subscriber's <code>error function</code> will be
* triggered with the given <code><b>error</b></code> passed as a parameter. This method will automatically create the topic if the given
* topic name is not created yet.
* </p>
*
* @param {?} name The message topic name to signal.
* @param {?} error The error message to signal.
* @return {?}
*/
function (name, error) {
if (name === null || typeof name !== 'string') {
return;
}
if (!this.containsSubject(name)) {
// Auto create topic if does not exist.
this.createSubject(name);
}
console.debug('Obsv Mgr: Signal error to topic "' + name + '" [error=' + JSON.stringify(error) + '].');
this.getSubject(name).error(error);
};
/**
* <p style="text-indent: 1em;">
* Close the specified topic <code><b>name</b></code>. If there is currently no <code>message topic</code> created or no one subsribing to this topic, this
* method will do nothing. Otherwise, the subscriber's <code>complete handler function</code> will be triggered. Note that, we use the method name <code>
* complete</code> instead of <code>close</code> since we try to use the same naming as <code>RxJS</code> does as much as possible.
* </p>
*
* @param {?} name The message topic name to close.
* @return {?}
*/
ObservableManager.prototype.complete = /**
* <p style="text-indent: 1em;">
* Close the specified topic <code><b>name</b></code>. If there is currently no <code>message topic</code> created or no one subsribing to this topic, this
* method will do nothing. Otherwise, the subscriber's <code>complete handler function</code> will be triggered. Note that, we use the method name <code>
* complete</code> instead of <code>close</code> since we try to use the same naming as <code>RxJS</code> does as much as possible.
* </p>
*
* @param {?} name The message topic name to close.
* @return {?}
*/
function (name) {
if (name === null || typeof name !== 'string') {
return;
}
if (!this.containsSubject(name)) {
return;
}
this.getSubject(name).complete();
delete this.subjects[name];
};
ObservableManager.decorators = [
{ type: Injectable },
];
/** @nocollapse */
ObservableManager.ctorParameters = function () { return []; };
return ObservableManager;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ PROCESS_START_TOPIC_NAME = 'bg-proc-mgr.process.start';
var /** @type {?} */ PROCESS_END_TOPIC_NAME = 'bg-proc-mgr.process.end';
var /** @type {?} */ PROCESS_ERROR_TOPIC_NAME = 'bg-proc-mgr.process.error';
/**
* <p style="text-indent: 2em;">
* A <code>ng</code> service class providing <code>background process</code> execution machanism. This class is an implementation of
* [[IBackgroundProcessManager]]. So, please see [[IBackgroundProcessManager]] for more information.
* </p>
*
* @see [[IBackgroundProcessManager]]
* @see [[BackgroundProcess]]
*
* @author shiorin, tee4cute
*/
var BackgroundProcessManager = /** @class */ (function () {
function BackgroundProcessManager(obsvMgr) {
this.processesPool = [];
this.obsvMgr = obsvMgr;
}
/**
* @param {?} processFunc
* @param {?=} processType
* @param {?=} name
* @param {?=} option
* @return {?}
*/
BackgroundProcessManager.prototype.getWrapperProcess = /**
* @param {?} processFunc
* @param {?=} processType
* @param {?=} name
* @param {?=} option
* @return {?}
*/
function (processFunc, processType, name, option) {
var /** @type {?} */ processProm = Promise.resolve(null);
if (processFunc !== null && typeof processFunc === 'function') {
var /** @type {?} */ returnVal = processFunc.call(null, null);
if (typeof returnVal === 'undefined') {
// function with no return
processProm = Promise.resolve(returnVal);
}
else if (typeof returnVal === 'object') {
if (returnVal instanceof Promise) {
processProm = returnVal;
}
else {
processProm = Promise.resolve(returnVal);
}
}
else {
processProm = Promise.resolve(returnVal);
}
}
var /** @type {?} */ result = new BackgroundProcess(processProm, processType, name, undefined, option);
return result;
};
/**
* @param {?} bgProcess
* @param {?} options
* @return {?}
*/
BackgroundProcessManager.prototype.isMatchAllOptions = /**
* @param {?} bgProcess
* @param {?} options
* @return {?}
*/
function (bgProcess, options) {
var /** @type {?} */ isMatchAll = true;
if (bgProcess !== null && bgProcess !== undefined) {
if (options !== null && options !== undefined) {
for (var /** @type {?} */ key in options) {
var /** @type {?} */ optVal = options[key];
if (bgProcess.options !== null && bgProcess.options !== undefined) {
var /** @type {?} */ bgProcVal = bgProcess.options[key];
if (optVal !== bgProcVal) {
isMatchAll = false;
break;
}
}
else {
isMatchAll = false;
break;
}
}
}
}
else {
if (options !== null && options !== undefined) {
isMatchAll = false;
}
}
return isMatchAll;
};
/**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.execute]] for more information.
* </p>
*
* @see [[IBackgroundProcessManager.execute]]
* @param {?} processFunc
* @param {?=} options
* @return {?}
*/
BackgroundProcessManager.prototype.execute = /**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.execute]] for more information.
* </p>
*
* @see [[IBackgroundProcessManager.execute]]
* @param {?} processFunc
* @param {?=} options
* @return {?}
*/
function (processFunc, options) {
var _this = this;
if (processFunc === null || typeof processFunc === 'undefined') {
return null;
}
var /** @type {?} */ processType = null;
var /** @type {?} */ name = null;
if (options !== null && typeof options !== 'undefined') {
processType = options.type;
name = options.name;
}
// return wrapper promise
var /** @type {?} */ bgProcess = this.getWrapperProcess(processFunc, processType, name, options);
if (bgProcess !== null && bgProcess.process !== null) {
this.processesPool.push(bgProcess);
// start onprocess adding
if (this.obsvMgr !== null && typeof this.obsvMgr !== 'undefined') {
this.obsvMgr.publish(BackgroundProcessManager.PROCESS_START_TOPIC_NAME, bgProcess);
}
var /** @type {?} */ wrapBgProcess = new Promise(function (resolve, reject) {
bgProcess.process.then(function (result) {
bgProcess.result = result;
resolve(result);
var /** @type {?} */ index = _this.processesPool.indexOf(bgProcess);
if (index >= 0) {
_this.processesPool.splice(index, 1);
}
if (_this.obsvMgr !== null && typeof _this.obsvMgr !== 'undefined') {
_this.obsvMgr.publish(BackgroundProcessManager.PROCESS_END_TOPIC_NAME, bgProcess);
}
}, function (error) {
bgProcess.error = error;
reject(error);
var /** @type {?} */ index = _this.processesPool.indexOf(bgProcess);
if (index >= 0) {
_this.processesPool.splice(index, 1);
}
if (_this.obsvMgr !== null && typeof _this.obsvMgr !== 'undefined') {
_this.obsvMgr.publish(BackgroundProcessManager.PROCESS_ERROR_TOPIC_NAME, bgProcess);
}
});
});
return wrapBgProcess;
}
return null;
};
/**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.getRunningProcessesCount]] for more information.
* </p>
*
* @see [[IBackgroundProcessManager.getRunningProcessesCount]]
* @param {?} typeName
* @param {?} name
* @param {?=} options
* @return {?}
*/
BackgroundProcessManager.prototype.getRunningProcessesCount = /**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.getRunningProcessesCount]] for more information.
* </p>
*
* @see [[IBackgroundProcessManager.getRunningProcessesCount]]
* @param {?} typeName
* @param {?} name
* @param {?=} options
* @return {?}
*/
function (typeName, name, options) {
return this.getRunningProcesses(typeName, name, options).length;
};
/**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.getRunningProcesses]] for more information. This method returns
* an array of process model class [[BackgroundProcess]].
* </p>
*
* @see [[IBackgroundProcessManager.getRunningProcesses]]
* @param {?} typeName
* @param {?} name
* @param {?=} options
* @return {?}
*/
BackgroundProcessManager.prototype.getRunningProcesses = /**
* <p style="text-indent: 1em;">
* Please see [[IBackgroundProcessManager.getRunningProcesses]] for more information. This method returns
* an array of process model class [[BackgroundProcess]].
* </p>
*
* @see [[IBackgroundProcessManager.getRunningProcesses]]
* @param {?} typeName
* @param {?} name
* @param {?=} options
* @return {?}
*/
function (typeName, name, options) {
if (typeName === null && name === null) {
return this.processesPool;
}
var /** @type {?} */ result = [];
try {
for (var _a = __values(this.processesPool), _b = _a.next(); !_b.done; _b = _a.next()) {
var process_1 = _b.value;
var /** @type {?} */ pType = process_1.type;
var /** @type {?} */ pName = process_1.name;
var /** @type {?} */ pUserAction = process_1.userAction;
var /** @type {?} */ allMatch = true;
if (typeName !== null && typeName !== undefined) {
if (typeName !== pType) {
allMatch = false;
}
}
if (name !== null && name !== undefined) {
if (name !== pName) {
allMatch = false;
}
}
// check more is allMatch
if (allMatch && options !== null && typeof options !== 'undefined') {
if (options.userAction !== null && typeof options.userAction !== 'undefined') {
if (pUserAction !== options.userAction) {
allMatch = false;
}
}
// check more is allMatch
if (allMatch) {
var /** @type {?} */ isMatchAllOpt = this.isMatchAllOptions(process_1, options);
if (!isMatchAllOpt) {
allMatch = false;
}
}
}
// check more is allMatch
if (allMatch) {
result.push(process_1);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
return result;
var e_1, _c;
};
BackgroundProcessManager.PROCESS_START_TOPIC_NAME = PROCESS_START_TOPIC_NAME;
BackgroundProcessManager.PROCESS_END_TOPIC_NAME = PROCESS_END_TOPIC_NAME;
BackgroundProcessManager.PROCESS_ERROR_TOPIC_NAME = PROCESS_ERROR_TOPIC_NAME;
BackgroundProcessManager.decorators = [
{ type: Injectable },
];
/** @nocollapse */
BackgroundProcessManager.ctorParameters = function () { return [
{ type: ObservableManager, },
]; };
return BackgroundProcessManager;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ GET = 'GET';
var /** @type {?} */ POST = 'POST';
var /** @type {?} */ PUT = 'PUT';
var /** @type {?} */ DELETE = 'DELETE';
var /** @type {?} */ PATCH = 'PATCH';
var /** @type {?} */ HEAD = 'HEAD';
var /** @type {?} */ OPTIONS = 'OPTIONS';
var /** @type {?} */ ROUND_ROBIN = 'ROUND_ROBIN';
var /** @type {?} */ PING = 'PING';
var /** @type {?} */ LATENCY = 'LATENCY';
var DefaultConnectionManager = /** @class */ (function () {
function DefaultConnectionManager(baseURLs, http, bgProcMgr) {
// default as round robin
this.mode = {
type: ROUND_ROBIN,
};
if (typeof baseURLs === 'string') {
this.baseURLs = [];
this.baseURLs.push(baseURLs);
}
else {
this.baseURLs = baseURLs;
}
if (this.baseURLs == null || this.baseURLs === undefined) {
this.baseURLs = [];
}
this.PROCESS_OPTIONS = { type: 'connection.data', name: '' };
this.http = http;
this.bgProcessMgr = bgProcMgr;
this.defaultHeaders = new Headers();
this.search = {};
this.params = {};
}
/**
* @return {?}
*/
DefaultConnectionManager.prototype.getMaxDurationMillisec = /**
* @return {?}
*/
function () {
var /** @type {?} */ processes = this.getRunningProcesses();
if (processes.length <= 0) {
return null;
}
var /** @type {?} */ max = 0;
try {
for (var processes_1 = __values(processes), processes_1_1 = processes_1.next(); !processes_1_1.done; processes_1_1 = processes_1.next()) {
var process_1 = processes_1_1.value;
var /** @type {?} */ startTime = process_1.startTime;
var /** @type {?} */ curTime = new Date();
if (startTime !== null && typeof startTime !== 'undefined') {
continue;
}
var /** @type {?} */ milliseconds1 = startTime.getMilliseconds();
var /** @type {?} */ milliseconds2 = curTime.getMilliseconds();
var /** @type {?} */ dif = milliseconds1 - milliseconds2;
if (dif > max) {
max = dif;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (processes_1_1 && !processes_1_1.done && (_a = processes_1.return)) _a.call(processes_1);
}
finally { if (e_1) throw e_1.error; }
}
return max;
var e_1, _a;
};
/**
* @param {?} response
* @return {?}
*/
DefaultConnectionManager.prototype.getResponseBodyAsContent = /**
* @param {?} response
* @return {?}
*/
function (response) {
if (response !== null && typeof response !== 'undefined') {
var /** @type {?} */ resHeader = response.headers;
if (resHeader !== null && typeof resHeader !== 'undefined') {
var /** @type {?} */ contentType = resHeader.get("Content-Type");
if (contentType === 'application/json') {
return response.json();
}
else {
return response.text();
}
}
}
return '';
};
/**
* @param {?} httpProm
* @return {?}
*/
DefaultConnectionManager.prototype.getResponseBodyHttpPromise = /**
* @param {?} httpProm
* @return {?}
*/
function (httpProm) {
var _this = this;
if (httpProm === null || typeof httpProm === 'undefined') {
return null;
}
return new Promise(function (resolve, reject) {
if (httpProm !== null && typeof httpProm !== 'undefined') {
// return Promise only json or text
httpProm.then(function (response) {
// if not type response always reject
if (response === null || typeof response === 'undefined' || !(response instanceof Response)) {
reject(response);
}
// check status code
if (response.status >= 200 && response.status <= 299) {
// status 2xx
resolve(_this.getResponseBodyAsContent(response));
}
else {
// if not 2xx then reject
reject(_this.getResponseBodyAsContent(response));
}
}).catch(function (error) {
if (error === null || typeof error === 'undefined' || error.constructor.name !== 'Response') {
reject(error);
}
resolve(_this.getResponseBodyAsContent(error));
});
}
});
};
/**
* @return {?}
*/
DefaultConnectionManager.prototype.loadBalanceURL = /**
* @return {?}
*/
function () {
if (this.mode.type === ROUND_ROBIN) {
if (this.mode.count === undefined || ((this.mode.count + 1) >= this.baseURLs.length)) {
this.mode.count = 0;
}
else {
++this.mode.count;
}
return this.baseURLs[this.mode.count];
}
else if (this.mode.type === PING) {
return "";
}
else if (this.mode.type === LATENCY) {
return "";
}
else {
return "";
}
};
/**
* @param {?} value
* @return {?}
*/
DefaultConnectionManager.prototype.getAppendBaseURL = /**
* @param {?} value
* @return {?}
*/
function (value) {
// baseURL
var /** @type {?} */ resultURL = value;
var /** @type {?} */ baseUrl = "";
if (this.baseURLs !== undefined && this.baseURLs !== null && this.baseURLs.length > 0) {
baseUrl = this.loadBalanceURL();
}
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
}
if (value !== null && typeof value !== 'undefined') {
if (value.startsWith("./")) {
resultURL = baseUrl + "/" + value.substring(value.indexOf("./") + 2, value.length);
}
else if (value.startsWith("/") || (value.indexOf("://") >= 0)) ;
else {
resultURL = baseUrl + "/" + value;
}
}
return resultURL;
};
/**
* @param {?} options
* @return {?}
*/
DefaultConnectionManager.prototype.addConnectionOptionsSetting = /**
* @param {?} options
* @return {?}
*/
function (options) {
// add by default
this.addRequestOptionsHeaders(options, this.defaultHeaders);
// add search
this.addRequestOptionsSearch(options, this.search);
// add param
this.addRequestOptionsParams(options, this.params);
};
/**
* @param {?} options
* @param {?} search
* @return {?}
*/
DefaultConnectionManager.prototype.addRequestOptionsSearch = /**
* @param {?} options
* @param {?} search
* @return {?}
*/
function (options, search) {
if (options === null || typeof options === 'undefined') {
return;
}
if (search === null || typeof search === 'undefined') {
return;
}
if (options.search !== null && typeof options.search !== 'undefined') {
for (var /** @type {?} */ key in search) {
if (options.search.hasOwnProperty(key)) {
// continue cause key in option has more priority
continue;
}
options.search[key] = search[key];
}
}
else {
options.search = search;
}
};
/**
* @param {?} options
* @param {?} params
* @return {?}
*/
DefaultConnectionManager.prototype.addRequestOptionsParams = /**
* @param {?} options
* @param {?} params
* @return {?}
*/
function (options, params) {
if (options === null || typeof options === 'undefined') {
return;
}
if (params === null || typeof params === 'undefined') {
return;
}
if (options.params !== null && typeof options.params !== 'undefined') {
for (var /** @type {?} */ key in params) {
if (options.params.hasOwnProperty(key)) {
// continue cause key in option has more priority
continue;
}
options.params[key] = params[key];
}
}
else {
options.params = params;
}
};
/**
* @param {?} options
* @param {?} headers
* @return {?}
*/
DefaultConnectionManager.prototype.addRequestOptionsHeaders = /**
* @param {?} options
* @param {?} headers
* @return {?}
*/
function (options, headers) {
if (options === null || typeof options === 'undefined') {
return;
}
if (headers === null || typeof headers === 'undefined') {
return;
}
if (options.headers !== null && typeof options.headers !== 'undefined') {
for (var /** @type {?} */ key in headers.keys()) {
if (options.headers.has(key)) {
// continue cause key in option has more priority
continue;
}
options.headers.append(key, headers.get(key));
}
}
else {
options.headers = headers;
}
};
/**
* @return {?}
*/
DefaultConnectionManager.prototype.getPhloxAppInfo = /**
* @return {?}
*/
function () {
return this.phloxAppInfo;
};
/**
* @param {?} phloxAppInfo
* @return {?}
*/
DefaultConnectionManager.prototype.setPhloxAppInfo = /**
* @param {?} phloxAppInfo
* @return {?}
*/
function (phloxAppInfo) {
this.phloxAppInfo = phloxAppInfo;
};
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
DefaultConnectionManager.prototype.get = /**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
function (url, requestOptionsArgs) {
var /** @type {?} */ httpProm = this.getWithHttpInfo(url, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
};
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
DefaultConnectionManager.prototype.getWithHttpInfo = /**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
function (url, requestOptionsArgs) {
var _this = this;
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
var /** @type {?} */ mergeDefaultHeader = true;
var /** @type {?} */ bgProcessOption = null;
if (typeof requestOptionsArgs === 'boolean') {
mergeDefaultHeader = requestOptionsArgs;
requestOptionsArgs = null;
}
else if (typeof requestOptionsArgs === 'object') {
if (requestOptionsArgs.constructor.name !== "RequestOptions") {
if (requestOptionsArgs.mergeDefaultHeader !== undefined && typeof requestOptionsArgs.mergeDefaultHeader === "boolean") {
mergeDefaultHeader = requestOptionsArgs.mergeDefaultHeader;
}
if (requestOptionsArgs.bgProcessOption !== undefined) {
bgProcessOption = requestOptionsArgs.bgProcessOption;
}
if (requestOptionsArgs.requestOptionsArgs !== undefined) {
requestOptionsArgs = requestOptionsArgs.requestOptionsArgs;
}
else {
requestOptionsArgs = null;
}
}
}
else {
requestOptionsArgs = null;
}
if (requestOptionsArgs === null || typeof requestOptionsArgs === 'undefined') {
requestOptionsArgs = new RequestOptions();
}
url = this.getAppendBaseURL(url);
if (url !== null && typeof url === 'string') {
if (requestOptionsArgs !== null && typeof requestOptionsArgs !== 'undefined') {
requestOptionsArgs.url = url;
}
}
requestOptionsArgs.method = GET;
var /** @type {?} */ resultProm = null;
if (mergeDefaultHeader) {
var /** @type {?} */ headers = new Headers();
var /** @type {?} */ jsonHeader = JSON.parse(JSON.stringify(this.defaultHeaders.toJSON()));
for (var /** @type {?} */ key in jsonHeader) {
headers.append(key, jsonHeader[key]);
}
if (requestOptionsArgs.headers !== null && requestOptionsArgs.headers !== undefined) {
jsonHeader = JSON.parse(JSON.stringify(requestOptionsArgs.headers.toJSON()));
for (var /** @type {?} */ key in jsonHeader) {
headers.append(key, jsonHeader[key]);
}
}
requestOptionsArgs.headers = headers;
}
//! change PROCESS_OPTIONS name to url
if (bgProcessOption !== undefined && bgProcessOption !== null) {
bgProcessOption = JSON.parse(JSON.stringify(bgProcessOption));
bgProcessOption.type = JSON.parse(JSON.stringify(this.PROCESS_OPTIONS.type));
if (bgProcessOption.name === undefined) {
bgProcessOption.name = JSON.parse(JSON.stringify(this.PROCESS_OPTIONS.name));
}
}
else {
bgProcessOption = JSON.parse(JSON.stringify(this.PROCESS_OPTIONS));
}
if (this.bgProcessMgr != null && typeof this.bgProcessMgr !== 'undefined') {
resultProm = this.bgProcessMgr.execute(function () {
var /** @type {?} */ prom = _this.http.get(url, requestOptionsArgs).toPromise();
return prom;
}, bgProcessOption);
}
if (resultProm === null || typeof resultProm === 'undefined') {
resultProm = Promise.resolve(null);
}
// wrapp prom
return resultProm;
};
/**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
DefaultConnectionManager.prototype.post = /**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
function (url, body, requestOptionsArgs) {
var /** @type {?} */ httpProm = this.postWithHttpInfo(url, body, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
};
/**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
DefaultConnectionManager.prototype.postWithHttpInfo = /**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
function (url, body, requestOptionsArgs) {
var _this = this;
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
var /** @type {?} */ mergeDefaultHeader = true;
var /** @type {?} */ bgProcessOption = null;
if (typeof requestOptionsArgs === 'boolean') {
mergeDefaultHeader = requestOptionsArgs;
requestOptionsArgs = null;
}
else if (typeof requestOptionsArgs === 'object') {
if (requestOptionsArgs.constructor.name !== "Requ