@miracledevs/paradigm-web-angular
Version:
An angular wrapper with base functionality and helper services.
1,299 lines (1,290 loc) • 92 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@miracledevs/paradigm-ui-web-shared'), require('@angular/core')) :
typeof define === 'function' && define.amd ? define('@miracledevs/paradigm-web-angular', ['exports', '@miracledevs/paradigm-ui-web-shared', '@angular/core'], factory) :
(factory((global.miracledevs = global.miracledevs || {}, global.miracledevs['paradigm-web-angular'] = {}),global.paradigmUiWebShared,global.ng.core));
}(this, (function (exports,paradigmUiWebShared,i0) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*!
* Paradigm Framework - Angular Wrapper
* Copyright (c) 2017 Miracle Devs, Inc
* Licensed under MIT (https://github.com/MiracleDevs/Paradigm.Web.Shared/blob/master/LICENSE)
*/
var ServiceBase = /** @class */ (function () {
function ServiceBase() {
}
return ServiceBase;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*!
* Paradigm Framework - Angular Wrapper
* Copyright (c) 2017 Miracle Devs, Inc
* Licensed under MIT (https://github.com/MiracleDevs/Paradigm.Web.Angular/blob/master/LICENSE)
*/
/** @type {?} */
var messageNameKey = '$messageType';
/**
* Decorates a class that needs to be marked as a message to use in conjunction
* with the \@see MessageBusService
* @param {?} name the name of the message.
* @return {?}
*/
function Message(name) {
return ( /**
* @template T
* @param {?} messageType
* @return {?}
*/function (messageType) {
messageType[messageNameKey] = name;
});
}
/**
* Gets the message name from a given message type.
* The message type needs to be decorated with \@see Message
* @template T
* @param {?} type the type of a message.
* @return {?}
*/
function getMessageName(type) {
return type[messageNameKey];
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Represents a message bus registration token.
* @template T
*/
var /**
* Represents a message bus registration token.
* @template T
*/ RegistrationToken = /** @class */ (function () {
/**
* Creates a new instance of @see RegistrationToken
* @param messageBus a reference to the message bus.
* @param type the message type.
*/
function RegistrationToken(messageBus, type) {
this.messageBus = messageBus;
this.innerType = type;
this.innerGuid = paradigmUiWebShared.Guid.new();
}
Object.defineProperty(RegistrationToken.prototype, "type", {
/**
* Gets the message type.
*/
get: /**
* Gets the message type.
* @return {?}
*/ function () {
return this.innerType;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RegistrationToken.prototype, "guid", {
/**
* Gets the registration guid.
*/
get: /**
* Gets the registration guid.
* @return {?}
*/ function () {
return this.innerGuid;
},
enumerable: true,
configurable: true
});
/**
* Removes the callback from the message bus.
*/
/**
* Removes the callback from the message bus.
* @return {?}
*/
RegistrationToken.prototype.unregister = /**
* Removes the callback from the message bus.
* @return {?}
*/
function () {
this.messageBus.unregister(this);
};
return RegistrationToken;
}());
/**
* Represents a message bus callback handler.
* It holds a method that must be called when certain
* message is received.
* @template T
*/
var /**
* Represents a message bus callback handler.
* It holds a method that must be called when certain
* message is received.
* @template T
*/ MessageBusHandler = /** @class */ (function () {
/**
* Creates a new instance of @see MessageBusHandler
* @param messageBus a reference to the message bus.
* @param type the message type.
* @param handler the message handler.
*/
function MessageBusHandler(messageBus, type, handler) {
this.innerHandler = handler;
this.innerToken = new RegistrationToken(messageBus, type);
}
Object.defineProperty(MessageBusHandler.prototype, "token", {
/**
* Gets the registration token that identifies this handler.
*/
get: /**
* Gets the registration token that identifies this handler.
* @return {?}
*/ function () { return this.innerToken; },
enumerable: true,
configurable: true
});
Object.defineProperty(MessageBusHandler.prototype, "handler", {
/**
* Gets the handler function that should be called when the message is received.
*/
get: /**
* Gets the handler function that should be called when the message is received.
* @return {?}
*/ function () { return this.innerHandler; },
enumerable: true,
configurable: true
});
return MessageBusHandler;
}());
var MessageBusService = /** @class */ (function (_super) {
__extends(MessageBusService, _super);
/**
* Creates a new instance of @see MessageBusService
*/
function MessageBusService() {
var _this = _super.call(this) || this;
_this.handlers = new paradigmUiWebShared.Dictionary();
return _this;
}
/**
* Gets the amount of messages registered.
*/
/**
* Gets the amount of messages registered.
* @return {?}
*/
MessageBusService.prototype.count = /**
* Gets the amount of messages registered.
* @return {?}
*/
function () {
return this.handlers.count();
};
/**
* Indicates if the given message type is registered and has handlers associated to it.
* @param messageType the message type.
*/
/**
* Indicates if the given message type is registered and has handlers associated to it.
* @template T
* @param {?} messageType the message type.
* @return {?}
*/
MessageBusService.prototype.isRegistered = /**
* Indicates if the given message type is registered and has handlers associated to it.
* @template T
* @param {?} messageType the message type.
* @return {?}
*/
function (messageType) {
/** @type {?} */
var type = getMessageName(messageType);
return this.handlers.containsKey(type);
};
/**
* Gets the amount of handler or observers a given message has.
* @param messageType the message type.
*/
/**
* Gets the amount of handler or observers a given message has.
* @template T
* @param {?} messageType the message type.
* @return {?}
*/
MessageBusService.prototype.handlerCount = /**
* Gets the amount of handler or observers a given message has.
* @template T
* @param {?} messageType the message type.
* @return {?}
*/
function (messageType) {
/** @type {?} */
var type = getMessageName(messageType);
if (!this.handlers.containsKey(type)) {
return 0;
}
return this.handlers.get(type).count();
};
/**
* Registers a new message handler.
* The handler will be called every time a message of @see messageType is called.
* @param messageType the message type.
* @param handler the message handler.
*/
/**
* Registers a new message handler.
* The handler will be called every time a message of \@see messageType is called.
* @template T
* @param {?} messageType the message type.
* @param {?} handler the message handler.
* @return {?}
*/
MessageBusService.prototype.register = /**
* Registers a new message handler.
* The handler will be called every time a message of \@see messageType is called.
* @template T
* @param {?} messageType the message type.
* @param {?} handler the message handler.
* @return {?}
*/
function (messageType, handler) {
/** @type {?} */
var type = getMessageName(messageType);
if (!this.handlers.containsKey(type)) {
this.handlers.add(type, new paradigmUiWebShared.ArrayList());
}
/** @type {?} */
var messageBusHandler = new MessageBusHandler(this, messageType, handler);
this.handlers.get(type).add(messageBusHandler);
return messageBusHandler.token;
};
/**
* Removes a handler registration from the collection.
* @param token the registration token.
*/
/**
* Removes a handler registration from the collection.
* @template T
* @param {?} token the registration token.
* @return {?}
*/
MessageBusService.prototype.unregister = /**
* Removes a handler registration from the collection.
* @template T
* @param {?} token the registration token.
* @return {?}
*/
function (token) {
/** @type {?} */
var type = getMessageName(token.type);
if (!this.handlers.containsKey(type)) {
throw new Error('Token has been already unregistered.');
}
/** @type {?} */
var handler = this.handlers.get(type);
handler.removeAll(( /**
* @param {?} x
* @return {?}
*/function (x) { return x.token.guid === token.guid; }));
if (!handler.any()) {
this.handlers.remove(type);
}
};
/**
* Unregisters all the message handlers.
*/
/**
* Unregisters all the message handlers.
* @return {?}
*/
MessageBusService.prototype.unregisterAll = /**
* Unregisters all the message handlers.
* @return {?}
*/
function () {
this.handlers.clear();
};
/**
* Sends a message to all the registered handlers.
* @param message the message to be sent.
* @param token if specified, the message will be sent only to one handler.
*/
/**
* Sends a message to all the registered handlers.
* @template T
* @param {?} message the message to be sent.
* @param {?=} token if specified, the message will be sent only to one handler.
* @return {?}
*/
MessageBusService.prototype.send = /**
* Sends a message to all the registered handlers.
* @template T
* @param {?} message the message to be sent.
* @param {?=} token if specified, the message will be sent only to one handler.
* @return {?}
*/
function (message, token) {
return __awaiter(this, void 0, void 0, function () {
var type, handlers, accepted, i, handler;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (paradigmUiWebShared.ObjectExtensions.isNull(message)) {
throw new Error('Can not send a null message.');
}
if (paradigmUiWebShared.ObjectExtensions.isNull(message.constructor)) {
throw new Error('Message does not have a constructor, and the system can not infer the type.');
}
type = getMessageName(( /** @type {?} */(message.constructor)));
if (!this.handlers.containsKey(type)) {
return [2 /*return*/, false];
}
handlers = this.handlers.get(type)
.where(( /**
* @param {?} x
* @return {?}
*/function (x) { return token == null || token.guid === x.token.guid; }))
.select(( /**
* @param {?} x
* @return {?}
*/function (x) { return x.handler; }));
accepted = false;
i = (handlers.count() - 1);
_a.label = 1;
case 1:
if (!(i >= 0))
return [3 /*break*/, 4];
handler = handlers.get(i);
accepted = true;
return [4 /*yield*/, handler(message)];
case 2:
_a.sent();
_a.label = 3;
case 3:
i--;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, accepted];
}
});
});
};
MessageBusService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
MessageBusService.ctorParameters = function () { return []; };
/** @nocollapse */ MessageBusService.ngInjectableDef = i0.defineInjectable({ factory: function MessageBusService_Factory() { return new MessageBusService(); }, token: MessageBusService, providedIn: "root" });
return MessageBusService;
}(ServiceBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var LogType = {
/**
* Represents a trace log.
*/
Trace: 0,
/**
* Represents a debug log.
*/
Debug: 1,
/**
* Represents an information log.
*/
Information: 2,
/**
* Represents a warning log.
*/
Warning: 3,
/**
* Represents an error log.
*/
Error: 4,
/**
* Represents a critical error log.
*/
Critical: 5,
};
LogType[LogType.Trace] = 'Trace';
LogType[LogType.Debug] = 'Debug';
LogType[LogType.Information] = 'Information';
LogType[LogType.Warning] = 'Warning';
LogType[LogType.Error] = 'Error';
LogType[LogType.Critical] = 'Critical';
var LoggingService = /** @class */ (function (_super) {
__extends(LoggingService, _super);
/**
* Creates a new instance of @see LoggingService.
*/
function LoggingService() {
var _this = _super.call(this) || this;
_this.logProvider = console;
_this.setMessageTemplateForAll('[{0}][{1}] - {3}{2}');
_this.minimumLevel = LogType.Information;
return _this;
}
/**
* Sets a log provider.
* By default @see console is used as provider.
*/
/**
* Sets a log provider.
* By default \@see console is used as provider.
* @param {?} logProvider
* @return {?}
*/
LoggingService.prototype.setLogProvider = /**
* Sets a log provider.
* By default \@see console is used as provider.
* @param {?} logProvider
* @return {?}
*/
function (logProvider) {
this.logProvider = logProvider;
};
/**
* Sets the message template for a given log type.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
*/
/**
* Sets the message template for a given log type.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
* @param {?} type
* @param {?} message
* @return {?}
*/
LoggingService.prototype.setMessageTemplate = /**
* Sets the message template for a given log type.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
* @param {?} type
* @param {?} message
* @return {?}
*/
function (type, message) {
if (type < 0 || type >= this.messageTemplates.length) {
throw new Error(LoggingService.typeNotRecognized);
}
if (paradigmUiWebShared.ObjectExtensions.isNull(message)) {
throw new Error('The message template can not be null or undefined.');
}
this.messageTemplates[type] = message;
};
/**
* Sets the message template for all the types.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
*/
/**
* Sets the message template for all the types.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
* @param {?} message
* @return {?}
*/
LoggingService.prototype.setMessageTemplateForAll = /**
* Sets the message template for all the types.
* There are some predefined content placeholders the user can utilize
* to configure the custom messages:
*
* {0}: The time when the log was added.
*
* {1}: The type of the log (Trace, Debug , Information, etc)
*
* {2}: A custom tag value provided by the user.
*
* {3}: The log message.
* @param {?} message
* @return {?}
*/
function (message) {
if (paradigmUiWebShared.ObjectExtensions.isNull(message)) {
throw new Error('The message template can not be null or undefined.');
}
this.messageTemplates = [];
this.messageTemplates.push(message);
this.messageTemplates.push(message);
this.messageTemplates.push(message);
this.messageTemplates.push(message);
this.messageTemplates.push(message);
this.messageTemplates.push(message);
};
/**
* Sets the minimum log level.
* Log types smaller than this value will be ignored.
*/
/**
* Sets the minimum log level.
* Log types smaller than this value will be ignored.
* @param {?} type
* @return {?}
*/
LoggingService.prototype.setMinimumLevel = /**
* Sets the minimum log level.
* Log types smaller than this value will be ignored.
* @param {?} type
* @return {?}
*/
function (type) {
if (type < 0 || type >= this.messageTemplates.length) {
throw new Error(LoggingService.typeNotRecognized);
}
this.minimumLevel = type;
};
/**
* Logs the specified message.
* @param message the message to be logged.
* @param type the type of log entry.
* @param tag a tag value used for further analysis.
*/
/**
* Logs the specified message.
* @param {?} message the message to be logged.
* @param {?=} type the type of log entry.
* @param {?=} tag a tag value used for further analysis.
* @return {?}
*/
LoggingService.prototype.log = /**
* Logs the specified message.
* @param {?} message the message to be logged.
* @param {?=} type the type of log entry.
* @param {?=} tag a tag value used for further analysis.
* @return {?}
*/
function (message, type, tag) {
if (type === void 0) {
type = LogType.Trace;
}
if (tag === void 0) {
tag = null;
}
if (type < 0 || type >= this.messageTemplates.length) {
throw new Error(LoggingService.typeNotRecognized);
}
if (paradigmUiWebShared.ObjectExtensions.isNull(message)) {
throw new Error('The message can not be null or undefined.');
}
if (type < this.minimumLevel) {
return;
}
/** @type {?} */
var formattedMessage = paradigmUiWebShared.StringExtensions.format(this.messageTemplates[type], paradigmUiWebShared.DateExtensions.format(new Date(), 'hh:mm:ss'), LogType[type], tag, message);
switch (type) {
case LogType.Trace:
this.logProvider.trace(formattedMessage);
break;
case LogType.Debug:
this.logProvider.debug(formattedMessage);
break;
case LogType.Information:
this.logProvider.info(formattedMessage);
break;
case LogType.Warning:
this.logProvider.warn(formattedMessage);
break;
case LogType.Error:
this.logProvider.error(formattedMessage);
break;
case LogType.Critical:
if (this.logProvider.critical) {
this.logProvider.critical(formattedMessage);
}
else {
this.logProvider.error(formattedMessage);
}
break;
}
};
/**
* Adds a trace log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds a trace log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.trace = /**
* Adds a trace log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Trace, tag);
};
/**
* Adds a debug log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds a debug log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.debug = /**
* Adds a debug log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Debug, tag);
};
/**
* Adds an information log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds an information log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.information = /**
* Adds an information log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Information, tag);
};
/**
* Adds a warning log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds a warning log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.warning = /**
* Adds a warning log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Warning, tag);
};
/**
* Adds an error log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds an error log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.error = /**
* Adds an error log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Error, tag);
};
/**
* Adds a critical error log entry.
* @param message the message to be logged.
* @param tag a tag value for the entry.
*/
/**
* Adds a critical error log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
LoggingService.prototype.critical = /**
* Adds a critical error log entry.
* @param {?} message the message to be logged.
* @param {?=} tag a tag value for the entry.
* @return {?}
*/
function (message, tag) {
if (tag === void 0) {
tag = null;
}
this.log(message, LogType.Critical, tag);
};
/**
* Error message.
*/
LoggingService.typeNotRecognized = 'The provided type is not recognized as a valid log type.';
LoggingService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
LoggingService.ctorParameters = function () { return []; };
/** @nocollapse */ LoggingService.ngInjectableDef = i0.defineInjectable({ factory: function LoggingService_Factory() { return new LoggingService(); }, token: LoggingService, providedIn: "root" });
return LoggingService;
}(ServiceBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var AlertType = {
/**
* Represents a message alert.
* It's the equivalent of @see LogType.Information
*/
Message: 2,
/**
* Represents a warning alert.
* It's the equivalent of @see LogType.Warning
*/
Warning: 3,
/**
* Represents an error alert.
* It's the equivalent of @see LogType.Error
*/
Error: 4,
};
AlertType[AlertType.Message] = 'Message';
AlertType[AlertType.Warning] = 'Warning';
AlertType[AlertType.Error] = 'Error';
/**
* Represents an alert thrown by the system.
*/
var /**
* Represents an alert thrown by the system.
*/ Alert = /** @class */ (function () {
/**
* Creates a new instance of @see Alert.
*/
function Alert(alertType, message) {
this.alertType = alertType;
this.innerMessage = message;
}
Object.defineProperty(Alert.prototype, "type", {
/**
* Gets the type of the alert.
*/
get: /**
* Gets the type of the alert.
* @return {?}
*/ function () { return this.alertType; },
enumerable: true,
configurable: true
});
Object.defineProperty(Alert.prototype, "typeName", {
/**
* Gets the type name.
*/
get: /**
* Gets the type name.
* @return {?}
*/ function () { return AlertType[this.alertType]; },
enumerable: true,
configurable: true
});
Object.defineProperty(Alert.prototype, "message", {
/**
* Gets the alert message.
*/
get: /**
* Gets the alert message.
* @return {?}
*/ function () { return this.innerMessage; },
enumerable: true,
configurable: true
});
return Alert;
}());
var AlertService = /** @class */ (function (_super) {
__extends(AlertService, _super);
/**
* Creates a new instance of @see AlertService
* @param logger The current logging service.
*/
function AlertService(logger) {
var _this = _super.call(this) || this;
_this.logger = logger;
_this.alerts = new paradigmUiWebShared.ArrayList();
return _this;
}
/**
* Gets the equivalent @see LogType for the specified @see AlertType.
* @param alertType The specified alert type.
* @returns the log type.
*/
/**
* Gets the equivalent \@see LogType for the specified \@see AlertType.
* @param {?} alertType The specified alert type.
* @return {?} the log type.
*/
AlertService.getLogType = /**
* Gets the equivalent \@see LogType for the specified \@see AlertType.
* @param {?} alertType The specified alert type.
* @return {?} the log type.
*/
function (alertType) {
switch (alertType) {
case AlertType.Message:
return LogType.Information;
case AlertType.Warning:
return LogType.Warning;
case AlertType.Error:
return LogType.Error;
}
throw new Error('The alert type is not recognized.');
};
/**
* Adds a new alert.
* The alert service will also notify the @see LoggingService.
* @param alertType the alert type.
* @param message the alert message.
*/
/**
* Adds a new alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} alertType the alert type.
* @param {?} message the alert message.
* @return {?}
*/
AlertService.prototype.add = /**
* Adds a new alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} alertType the alert type.
* @param {?} message the alert message.
* @return {?}
*/
function (alertType, message) {
this.alerts.add(new Alert(alertType, message));
this.logger.log(message, AlertService.getLogType(alertType));
};
/**
* Adds a new error alert.
* The alert service will also notify the @see LoggingService.
* @param message the error message.
*/
/**
* Adds a new error alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
AlertService.prototype.addError = /**
* Adds a new error alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
function (message) {
this.add(AlertType.Error, message);
};
/**
* Adds a new warning alert.
* The alert service will also notify the @see LoggingService.
* @param message the error message.
*/
/**
* Adds a new warning alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
AlertService.prototype.addWarning = /**
* Adds a new warning alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
function (message) {
this.add(AlertType.Warning, message);
};
/**
* Adds a new message alert.
* The alert service will also notify the @see LoggingService.
* @param message the error message.
*/
/**
* Adds a new message alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
AlertService.prototype.addMessage = /**
* Adds a new message alert.
* The alert service will also notify the \@see LoggingService.
* @param {?} message the error message.
* @return {?}
*/
function (message) {
this.add(AlertType.Message, message);
};
/**
* Removes one of the alerts from the alerts collection.
* @param index The index of the alert, or the alert that needs to be removed.
*/
/**
* Removes one of the alerts from the alerts collection.
* @param {?} index The index of the alert, or the alert that needs to be removed.
* @return {?}
*/
AlertService.prototype.remove = /**
* Removes one of the alerts from the alerts collection.
* @param {?} index The index of the alert, or the alert that needs to be removed.
* @return {?}
*/
function (index) {
if (index instanceof Alert) {
this.alerts.remove(index);
}
else {
this.alerts.removeAt(( /** @type {?} */(index)));
}
};
/**
* Gets the specified alert by its index.
* @param index the alert index.
*/
/**
* Gets the specified alert by its index.
* @param {?} index the alert index.
* @return {?}
*/
AlertService.prototype.get = /**
* Gets the specified alert by its index.
* @param {?} index the alert index.
* @return {?}
*/
function (index) {
return this.alerts.get(index);
};
/**
* Gets the alert collection.
*/
/**
* Gets the alert collection.
* @return {?}
*/
AlertService.prototype.getAlerts = /**
* Gets the alert collection.
* @return {?}
*/
function () {
return this.alerts;
};
/**
* Clears the alert collection.
*/
/**
* Clears the alert collection.
* @return {?}
*/
AlertService.prototype.clear = /**
* Clears the alert collection.
* @return {?}
*/
function () {
this.alerts.clear();
};
AlertService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
AlertService.ctorParameters = function () {
return [
{ type: LoggingService }
];
};
/** @nocollapse */ AlertService.ngInjectableDef = i0.defineInjectable({ factory: function AlertService_Factory() { return new AlertService(i0.inject(LoggingService)); }, token: AlertService, providedIn: "root" });
return AlertService;
}(ServiceBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ComponentBase = /** @class */ (function () {
/**
* Creates a new instance of @see ComponentBase
* @param injector reference to an injector service.
*/
function ComponentBase(injector) {
this.injector = injector;
}
/**
* Called when the component is initialized.
*/
/**
* Called when the component is initialized.
* @return {?}
*/
ComponentBase.prototype.ngOnInit = /**
* Called when the component is initialized.
* @return {?}
*/
function () {
};
/**
* Called when the component is destroyed.
*/
/**
* Called when the component is destroyed.
* @return {?}
*/
ComponentBase.prototype.ngOnDestroy = /**
* Called when the component is destroyed.
* @return {?}
*/
function () {
this.unregisterTokens();
};
/**
* Gets a reference to the message bus.
*/
/**
* Gets a reference to the message bus.
* @protected
* @return {?}
*/
ComponentBase.prototype.getMessageBus = /**
* Gets a reference to the message bus.
* @protected
* @return {?}
*/
function () {
if (!this.messageBus) {
this.messageBus = this.injector.get(MessageBusService);
this.messageTokens = new paradigmUiWebShared.ArrayList();
}
return this.messageBus;
};
/**
* Registers a message handler for a given message type.
* @param type the message type.
* @param handler the message handler to process when some part of the application sends a message of type @see type
*/
/**
* Registers a message handler for a given message type.
* @protected
* @template T
* @param {?} type the message type.
* @param {?} handler the message handler to process when some part of the application sends a message of type \@see type
* @return {?}
*/
ComponentBase.prototype.registerMessage = /**
* Registers a message handler for a given message type.
* @protected
* @template T
* @param {?} type the message type.
* @param {?} handler the message handler to process when some part of the application sends a message of type \@see type
* @return {?}
*/
function (type, handler) {
/** @type {?} */
var token = this.getMessageBus().register(type, handler);
this.messageTokens.add(token);
};
/**
* Unregisters all the tokens registered within this component.
*/
/**
* Unregisters all the tokens registered within this component.
* @protected
* @return {?}
*/
ComponentBase.prototype.unregisterTokens = /**
* Unregisters all the tokens registered within this component.
* @protected
* @return {?}
*/
fun