@miracledevs/paradigm-web-angular
Version:
An angular wrapper with base functionality and helper services.
1,541 lines (1,532 loc) • 74.1 kB
JavaScript
import { __extends, __awaiter, __generator } from 'tslib';
import { Dictionary, ArrayList, Guid, ObjectExtensions, DateExtensions, StringExtensions } from '@miracledevs/paradigm-ui-web-shared';
import { Injectable, NgModule, defineInjectable, inject, ComponentFactoryResolver, Injector, INJECTOR } from '@angular/core';
/**
* @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 = 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 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 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 (ObjectExtensions.isNull(message)) {
throw new Error('Can not send a null message.');
}
if (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: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
MessageBusService.ctorParameters = function () { return []; };
/** @nocollapse */ MessageBusService.ngInjectableDef = 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 (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 (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 (ObjectExtensions.isNull(message)) {
throw new Error('The message can not be null or undefined.');
}
if (type < this.minimumLevel) {
return;
}
/** @type {?} */
var formattedMessage = StringExtensions.format(this.messageTemplates[type], 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: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
LoggingService.ctorParameters = function () { return []; };
/** @nocollapse */ LoggingService.ngInjectableDef = 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 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: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
AlertService.ctorParameters = function () { return [
{ type: LoggingService }
]; };
/** @nocollapse */ AlertService.ngInjectableDef = defineInjectable({ factory: function AlertService_Factory() { return new AlertService(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 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 {?}
*/
function () {
if (this.messageTokens && this.messageTokens.count() > 0) {
this.messageTokens.forEach((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.unregister(); }));
this.messageTokens.clear();
}
};
/**
* Unregisters a particular token.
* If no unregister take place, the component will unregister all the tokens
* on @see ngOnDestroy
* @param type the type of message to unregister
*/
/**
* Unregisters a particular token.
* If no unregister take place, the component will unregister all the tokens
* on \@see ngOnDestroy
* @protected
* @template T
* @param {?} type the type of message to unregister
* @return {?}
*/
ComponentBase.prototype.unregisterToken = /**
* Unregisters a particular token.
* If no unregister take place, the component will unregister all the tokens
* on \@see ngOnDestroy
* @protected
* @template T
* @param {?} type the type of message to unregister
* @return {?}
*/
function (type) {
if (this.messageTokens && this.messageTokens.count() > 0) {
/** @type {?} */
var token = this.messageTokens.firstOrDefault((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.type === type; }));
if (token) {
token.unregister();
this.messageTokens.remove(token);
}
}
};
/**
* Sends a message using the message bus.
* @param message The message instance to send using the message bus.
* @param token if specified, the component can target one specific registration token and handler;
* if not, all the handlers registered for this message type, will receive the message.
*/
/**
* Sends a message using the message bus.
* @protected
* @template T
* @param {?} message The message instance to send using the message bus.
* @param {?=} token if specified, the component can target one specific registration token and handler;
* if not, all the handlers registered for this message type, will receive the message.
* @return {?}
*/
ComponentBase.prototype.sendMessage = /**
* Sends a message using the message bus.
* @protected
* @template T
* @param {?} message The message instance to send using the message bus.
* @param {?=} token if specified, the component can target one specific registration token and handler;
* if not, all the handlers registered for this message type, will receive the message.
* @return {?}
*/
function (message, token) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getMessageBus().send(message, token)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/**
* Gets the alert service.
*/
/**
* Gets the alert service.
* @protected
* @return {?}
*/
ComponentBase.prototype.getAlerts = /**
* Gets the alert service.
* @protected
* @return {?}
*/
function () {
if (!this.alerts) {
this.alerts = this.injector.get(AlertService);
}
return this.alerts;
};
/**
* Adds a message in the alert service.
* @param message message to add.
*/
/**
* Adds a message in the alert service.
* @protected
* @param {?} message message to add.
* @return {?}
*/
ComponentBase.prototype.addMessage = /**
* Adds a message in the alert service.
* @protected
* @param {?} message message to add.
* @return {?}
*/
function (message) {
this.getAlerts().addMessage(message);
};
/**
* Adds a warning in the alert service.
* @param warning warning to add.
*/
/**
* Adds a warning in the alert service.
* @protected
* @param {?} warning warning to add.
* @return {?}
*/
ComponentBase.prototype.addWarning = /**
* Adds a warning in the alert service.
* @protected
* @param {?} warning warning to add.
* @return {?}
*/
function (warning) {
this.getAlerts().addWarning(warning);
};
/**
* Adds an error in the alert service.
* @param error error to add.
*/
/**
* Adds an error in the alert service.
* @protected
* @param {?} error error to add.
* @return {?}
*/
ComponentBase.prototype.addError = /**
* Adds an error in the alert service.
* @protected
* @param {?} error error to add.
* @return {?}
*/
function (error) {
this.getAlerts().addError(error);
};
/**
* Handles an application error, reporting the error to the alert service.
* @param error the error that needs to be handled.
*/
/**
* Handles an application error, reporting the error to the alert service.
* @protected
* @param {?} error the error that needs to be handled.
* @return {?}
*/
ComponentBase.prototype.handleError = /**
* Handles an application error, reporting the error to the alert service.
* @protected
* @param {?} error the error that needs to be handled.
* @return {?}
*/
function (error) {
if (!error) {
return;
}
if (error.message) {
this.addError(error.message);
}
else if (error.Message) {
this.addError(error.Message);
}
else if (error.exceptionMessage) {
this.addError(error.exceptionMessage);
}
else if (error.ExceptionMessage) {
this.addError(error.ExceptionMessage);
}
else if (error.error && error.error.message) {
this.addError(error.error.message);
}
else if (error.error && error.error.Message) {
this.addError(error.error.Message);
}
};
return ComponentBase;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template TParameters, TResult
*/
var /**
* @template TParameters, TResult
*/
ModalComponentBase = /** @class */ (function (_super) {
__extends(ModalComponentBase, _super);
function ModalComponentBase(injector) {
var _this = _super.call(this, injector) || this;
_this.injector = injector;
return _this;
}
/**
* @param {?} modalService
* @return {?}
*/
ModalComponentBase.prototype.setModalService = /**
* @param {?} modalService
* @return {?}
*/
function (modalService) {
this.modalService = modalService;
};
/**
* @param {?} parameters
* @return {?}
*/
ModalComponentBase.prototype.setParameters = /**
* @param {?} parameters
* @return {?}
*/
function (parameters) {
this.parameters = parameters;
};
/**
* @param {?} modalInstance
* @return {?}
*/
ModalComponentBase.prototype.setModalInstance = /**
* @param {?} modalInstance
* @return {?}
*/
function (modalInstance) {
this.modalInstance = modalInstance;
};
/**
* @return {?}
*/
ModalComponentBase.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
};
/**
* @return {?}
*/
ModalComponentBase.prototype.ngOnInit = /**
* @return {?}
*/
function () {
};
/**
* @param {?=} result
* @return {?}
*/
ModalComponentBase.prototype.resolve = /**
* @param {?=} result
* @return {?}
*/
function (result) {
this.modalInstance.resolve(result);
};
/**
* @param {?} error
* @return {?}
*/
ModalComponentBase.prototype.reject = /**
* @param {?} error
* @return {?}
*/
function (error) {
this.modalInstance.reject(error);
};
return ModalComponentBase;
}(ComponentBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FileService = /** @class */ (function (_super) {
__extends(FileService, _super);
function FileService() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Reads a file as a blog.
* @param file the file that needs to be read.
* @param onProgress A progress handler to receive progress reports.
*/
/**
* Reads a file as a blog.
* @param {?} file the file that needs to be read.
* @param {?=} onProgress A progress handler to receive progress reports.
* @return {?}
*/
FileService.prototype.readAsBlob = /**
* Reads a file as a blog.
* @param {?} file the file that needs to be read.
* @param {?=} onProgress A progress handler to receive progress reports.
* @return {?}
*/
function (file, onProgress) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = Blob.bind;
return [4 /*yield*/, this.read(file, (/**
* @param {?} fileReader
* @return {?}
*/
function (fileReader) { return fileReader.readAsArrayBuffer(file); }), onProgress)];
case 1: return [2 /*return*/, new (_a.apply(Blob, [void 0, [_b.sent()], { type: file.type }]))()];
}
});
});
};
/**
* Reads a file as text.
* @param file the file that needs to be read.
* @param onProgress A progress handler to receive progress reports.
*/
/**
* Reads a file as text.
* @param {?} file the file that needs to be read.
* @param {?=} onProgress A progress handler to receive progress reports.
* @return {?}
*/
FileService.prototype.readAsText = /**
* Reads a file as text.
* @param {?} file the file that needs to be read.
* @param {?=} onProgress A progress handler to receive progress reports.
* @return {?}
*/
function (file, onProgress) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.read(file, (/**
* @param {?} fileReader
* @return {?}
*/
function (fileReader) { return fileReader.readAsText(file); }), onProgress)];
case 1: return [2 /*return*/, (/** @type {?} */ (_a.sent()))];
}
});