com.phloxui
Version:
PhloxUI Ng2+ Framework
1,272 lines (1,266 loc) • 7.25 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 { Response, Headers, RequestOptions, Http, HttpModule, JsonpModule } from '@angular/http';
import { __decorate, __metadata } from 'tslib';
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
*/
const /** @type {?} */ APP_SWITCHER_HEADER = 'App Swithcer Header';
const /** @type {?} */ APP_SWITCHER_TAGLINE = 'tagLine...';
const /** @type {?} */ DEFAULT_SCROLL_LOAD_OFF_SET = 100;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_DELAY = 100;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_COUNT = 50;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_LABEL = "Load More";
const /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_LABEL = "Press to reload";
const /** @type {?} */ DEFAULT_SCROLL_LOAD_COMPLETE_LABEL = "No more data (Press to reload)";
const /** @type {?} */ DEFAULT_SCROLL_LOAD_AUTO = true;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_AUTO = false;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_RELOAD_DISABLED = false;
const /** @type {?} */ DEFAULT_SCROLL_LOAD_APPEND_CLASS_WRAPPER_ICON_RELOAD = "<div class='wrapper-icon-reload'><div class='icon-reloader'><div class='reloader'></div></div></div>";
const /** @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]]
*/
class PhloxAppInfo {
/**
* @param {?=} name
* @param {?=} tagline
* @param {?=} group
* @param {?=} iconURL
*/
constructor(name = 'App Name', tagline = 'App Tagline', group, iconURL) {
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 {?}
*/
getName() {
return this.name;
}
/**
* @param {?} name
* @return {?}
*/
setName(name) {
this.name = name;
}
/**
* @return {?}
*/
getTagline() {
return this.tagline;
}
/**
* @param {?} tagline
* @return {?}
*/
setTagline(tagline) {
this.tagline = tagline;
}
/**
* @return {?}
*/
getSettings() {
return this.settings;
}
/**
* @param {?} settings
* @return {?}
*/
setSettings(settings) {
this.settings = settings;
}
/**
* @return {?}
*/
getIconURL() {
return this.iconURL;
}
/**
* @param {?} iconURL
* @return {?}
*/
setIconURL(iconURL) {
this.iconURL = iconURL;
}
/**
* @return {?}
*/
getGroup() {
return this.group;
}
/**
* @param {?} group
* @return {?}
*/
setGroup(group) {
this.group = group;
}
/**
* @return {?}
*/
getI18n() {
return this.i18n;
}
/**
* @param {?} i18n
* @return {?}
*/
setI18n(i18n) {
this.i18n = i18n;
}
/**
* @return {?}
*/
getResources() {
return this.resources;
}
/**
* @param {?} resources
* @return {?}
*/
setResources(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;
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
const /** @type {?} */ TYPE_UNDEFINED = 'undefined';
class BackgroundProcess {
/**
* @param {?} process
* @param {?} processType
* @param {?} name
* @param {?=} startTime
* @param {?=} options
*/
constructor(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;
/**
* @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
*/
class ObservableManager {
constructor() {
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.
*/
getSubject(name) {
if (name === null || typeof name !== 'string') {
return null;
}
let /** @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 {?}
*/
containsSubject(name) {
if (name === null || typeof name !== 'string') {
return false;
}
let /** @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 {?}
*/
createSubject(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.
*/
subscribe(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 {?}
*/
publish(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 {?}
*/
error(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 {?}
*/
complete(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 = () => [];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
const /** @type {?} */ PROCESS_START_TOPIC_NAME = 'bg-proc-mgr.process.start';
const /** @type {?} */ PROCESS_END_TOPIC_NAME = 'bg-proc-mgr.process.end';
const /** @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
*/
class BackgroundProcessManager {
/**
* @param {?} obsvMgr
*/
constructor(obsvMgr) {
this.processesPool = [];
this.obsvMgr = obsvMgr;
}
/**
* @param {?} processFunc
* @param {?=} processType
* @param {?=} name
* @param {?=} option
* @return {?}
*/
getWrapperProcess(processFunc, processType, name, option) {
let /** @type {?} */ processProm = Promise.resolve(null);
if (processFunc !== null && typeof processFunc === 'function') {
let /** @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);
}
}
let /** @type {?} */ result = new BackgroundProcess(processProm, processType, name, undefined, option);
return result;
}
/**
* @param {?} bgProcess
* @param {?} options
* @return {?}
*/
isMatchAllOptions(bgProcess, options) {
let /** @type {?} */ isMatchAll = true;
if (bgProcess !== null && bgProcess !== undefined) {
if (options !== null && options !== undefined) {
for (let /** @type {?} */ key in options) {
let /** @type {?} */ optVal = options[key];
if (bgProcess.options !== null && bgProcess.options !== undefined) {
let /** @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 {?}
*/
execute(processFunc, options) {
if (processFunc === null || typeof processFunc === 'undefined') {
return null;
}
let /** @type {?} */ processType = null;
let /** @type {?} */ name = null;
if (options !== null && typeof options !== 'undefined') {
processType = options.type;
name = options.name;
}
// return wrapper promise
let /** @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);
}
let /** @type {?} */ wrapBgProcess = new Promise((resolve, reject) => {
bgProcess.process.then((result) => {
bgProcess.result = result;
resolve(result);
let /** @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);
}
}, (error) => {
bgProcess.error = error;
reject(error);
let /** @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 {?}
*/
getRunningProcessesCount(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 {?}
*/
getRunningProcesses(typeName, name, options) {
if (typeName === null && name === null) {
return this.processesPool;
}
let /** @type {?} */ result = [];
for (let /** @type {?} */ process of this.processesPool) {
let /** @type {?} */ pType = process.type;
let /** @type {?} */ pName = process.name;
let /** @type {?} */ pUserAction = process.userAction;
let /** @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) {
let /** @type {?} */ isMatchAllOpt = this.isMatchAllOptions(process, options);
if (!isMatchAllOpt) {
allMatch = false;
}
}
}
// check more is allMatch
if (allMatch) {
result.push(process);
}
}
return result;
}
}
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 = () => [
{ type: ObservableManager, },
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
const /** @type {?} */ GET = 'GET';
const /** @type {?} */ POST = 'POST';
const /** @type {?} */ PUT = 'PUT';
const /** @type {?} */ DELETE = 'DELETE';
const /** @type {?} */ PATCH = 'PATCH';
const /** @type {?} */ HEAD = 'HEAD';
const /** @type {?} */ OPTIONS = 'OPTIONS';
const /** @type {?} */ ROUND_ROBIN = 'ROUND_ROBIN';
const /** @type {?} */ PING = 'PING';
const /** @type {?} */ LATENCY = 'LATENCY';
class DefaultConnectionManager {
/**
* @param {?} baseURLs
* @param {?} http
* @param {?} bgProcMgr
*/
constructor(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 {?}
*/
getMaxDurationMillisec() {
let /** @type {?} */ processes = this.getRunningProcesses();
if (processes.length <= 0) {
return null;
}
let /** @type {?} */ max = 0;
for (let /** @type {?} */ process of processes) {
let /** @type {?} */ startTime = process.startTime;
let /** @type {?} */ curTime = new Date();
if (startTime !== null && typeof startTime !== 'undefined') {
continue;
}
let /** @type {?} */ milliseconds1 = startTime.getMilliseconds();
let /** @type {?} */ milliseconds2 = curTime.getMilliseconds();
let /** @type {?} */ dif = milliseconds1 - milliseconds2;
if (dif > max) {
max = dif;
}
}
return max;
}
/**
* @param {?} response
* @return {?}
*/
getResponseBodyAsContent(response) {
if (response !== null && typeof response !== 'undefined') {
let /** @type {?} */ resHeader = response.headers;
if (resHeader !== null && typeof resHeader !== 'undefined') {
let /** @type {?} */ contentType = resHeader.get("Content-Type");
if (contentType === 'application/json') {
return response.json();
}
else {
return response.text();
}
}
}
return '';
}
/**
* @param {?} httpProm
* @return {?}
*/
getResponseBodyHttpPromise(httpProm) {
if (httpProm === null || typeof httpProm === 'undefined') {
return null;
}
return new Promise((resolve, reject) => {
if (httpProm !== null && typeof httpProm !== 'undefined') {
// return Promise only json or text
httpProm.then((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((error) => {
if (error === null || typeof error === 'undefined' || error.constructor.name !== 'Response') {
reject(error);
}
resolve(this.getResponseBodyAsContent(error));
});
}
});
}
/**
* @return {?}
*/
loadBalanceURL() {
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 {?}
*/
getAppendBaseURL(value) {
// baseURL
let /** @type {?} */ resultURL = value;
let /** @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 {?}
*/
addConnectionOptionsSetting(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 {?}
*/
addRequestOptionsSearch(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 (let /** @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 {?}
*/
addRequestOptionsParams(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 (let /** @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 {?}
*/
addRequestOptionsHeaders(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 (let /** @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 {?}
*/
getPhloxAppInfo() {
return this.phloxAppInfo;
}
/**
* @param {?} phloxAppInfo
* @return {?}
*/
setPhloxAppInfo(phloxAppInfo) {
this.phloxAppInfo = phloxAppInfo;
}
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
get(url, requestOptionsArgs) {
let /** @type {?} */ httpProm = this.getWithHttpInfo(url, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
}
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
getWithHttpInfo(url, requestOptionsArgs) {
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
let /** @type {?} */ mergeDefaultHeader = true;
let /** @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;
let /** @type {?} */ resultProm = null;
if (mergeDefaultHeader) {
let /** @type {?} */ headers = new Headers();
let /** @type {?} */ jsonHeader = JSON.parse(JSON.stringify(this.defaultHeaders.toJSON()));
for (let /** @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 (let /** @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(() => {
let /** @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 {?}
*/
post(url, body, requestOptionsArgs) {
let /** @type {?} */ httpProm = this.postWithHttpInfo(url, body, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
}
/**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
postWithHttpInfo(url, body, requestOptionsArgs) {
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
let /** @type {?} */ mergeDefaultHeader = true;
let /** @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 = POST;
let /** @type {?} */ resultProm = Promise.resolve(null);
if (mergeDefaultHeader) {
let /** @type {?} */ headers = new Headers();
let /** @type {?} */ jsonHeader = JSON.parse(JSON.stringify(this.defaultHeaders.toJSON()));
for (let /** @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 (let /** @type {?} */ key in jsonHeader) {
if (headers.has(key)) {
// continue cause key in jsonHeader has more headers
continue;
}
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(() => {
let /** @type {?} */ prom = this.http.post(url, body, 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 {?}
*/
put(url, body, requestOptionsArgs) {
let /** @type {?} */ httpProm = this.putWithHttpInfo(url, body, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
}
/**
* @param {?} url
* @param {?} body
* @param {?} requestOptionsArgs
* @return {?}
*/
putWithHttpInfo(url, body, requestOptionsArgs) {
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
let /** @type {?} */ mergeDefaultHeader = true;
let /** @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 = PUT;
let /** @type {?} */ resultProm = Promise.resolve(null);
if (mergeDefaultHeader) {
let /** @type {?} */ headers = new Headers();
let /** @type {?} */ jsonHeader = JSON.parse(JSON.stringify(this.defaultHeaders.toJSON()));
for (let /** @type {?} */ key in jsonHeader) {
if (!headers.has(key)) {
headers.append(key, jsonHeader[key]);
}
// headers.append(key, jsonHeader[key]);
}
if (requestOptionsArgs.headers !== null && requestOptionsArgs.headers !== undefined) {
jsonHeader = JSON.parse(JSON.stringify(requestOptionsArgs.headers.toJSON()));
for (let /** @type {?} */ key in jsonHeader) {
if (!headers.has(key)) {
headers.append(key, jsonHeader[key]);
}
// 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(() => {
let /** @type {?} */ prom = this.http.put(url, body, requestOptionsArgs).toPromise();
return prom;
}, bgProcessOption);
}
if (resultProm === null || typeof resultProm === 'undefined') {
resultProm = Promise.resolve(null);
}
// wrapp prom
return resultProm;
}
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
delete(url, requestOptionsArgs) {
let /** @type {?} */ httpProm = this.deleteWithHttpInfo(url, requestOptionsArgs);
return this.getResponseBodyHttpPromise(httpProm);
}
/**
* @param {?} url
* @param {?} requestOptionsArgs
* @return {?}
*/
deleteWithHttpInfo(url, requestOptionsArgs) {
if (this.http === null || typeof this.http === 'undefined') {
return null;
}
let /** @type {?} */ mergeDefaultHeader = true;
let /** @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;
}
}
requ