UNPKG

@miracledevs/paradigm-web-angular

Version:

An angular wrapper with base functionality and helper services.

1,400 lines (1,385 loc) 43.9 kB
import { __awaiter } from 'tslib'; import { Dictionary, ArrayList, Guid, ObjectExtensions, DateExtensions, StringExtensions } from '@miracledevs/paradigm-ui-web-shared'; import { Injectable, NgModule, ComponentFactoryResolver, Injector, defineInjectable, inject, 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) */ class 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 {?} */ const 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 {?} */ (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 */ class RegistrationToken { /** * Creates a new instance of \@see RegistrationToken * @param {?} messageBus a reference to the message bus. * @param {?} type the message type. */ constructor(messageBus, type) { this.messageBus = messageBus; this.innerType = type; this.innerGuid = Guid.new(); } /** * Gets the message type. * @return {?} */ get type() { return this.innerType; } /** * Gets the registration guid. * @return {?} */ get guid() { return this.innerGuid; } /** * Removes the callback from the message bus. * @return {?} */ unregister() { this.messageBus.unregister(this); } } /** * Represents a message bus callback handler. * It holds a method that must be called when certain * message is received. * @template T */ class MessageBusHandler { /** * 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. */ constructor(messageBus, type, handler) { this.innerHandler = handler; this.innerToken = new RegistrationToken(messageBus, type); } /** * Gets the registration token that identifies this handler. * @return {?} */ get token() { return this.innerToken; } /** * Gets the handler function that should be called when the message is received. * @return {?} */ get handler() { return this.innerHandler; } } class MessageBusService extends ServiceBase { /** * Creates a new instance of \@see MessageBusService */ constructor() { super(); this.handlers = new Dictionary(); } /** * Gets the amount of messages registered. * @return {?} */ count() { return this.handlers.count(); } /** * Indicates if the given message type is registered and has handlers associated to it. * @template T * @param {?} messageType the message type. * @return {?} */ isRegistered(messageType) { /** @type {?} */ const type = getMessageName(messageType); return this.handlers.containsKey(type); } /** * Gets the amount of handler or observers a given message has. * @template T * @param {?} messageType the message type. * @return {?} */ handlerCount(messageType) { /** @type {?} */ const 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. * @template T * @param {?} messageType the message type. * @param {?} handler the message handler. * @return {?} */ register(messageType, handler) { /** @type {?} */ const type = getMessageName(messageType); if (!this.handlers.containsKey(type)) { this.handlers.add(type, new ArrayList()); } /** @type {?} */ const messageBusHandler = new MessageBusHandler(this, messageType, handler); this.handlers.get(type).add(messageBusHandler); return messageBusHandler.token; } /** * Removes a handler registration from the collection. * @template T * @param {?} token the registration token. * @return {?} */ unregister(token) { /** @type {?} */ const type = getMessageName(token.type); if (!this.handlers.containsKey(type)) { throw new Error('Token has been already unregistered.'); } /** @type {?} */ const handler = this.handlers.get(type); handler.removeAll((/** * @param {?} x * @return {?} */ x => x.token.guid === token.guid)); if (!handler.any()) { this.handlers.remove(type); } } /** * Unregisters all the message handlers. * @return {?} */ unregisterAll() { this.handlers.clear(); } /** * 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 {?} */ send(message, token) { return __awaiter(this, void 0, void 0, function* () { 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 {?} */ const type = getMessageName((/** @type {?} */ (message.constructor))); if (!this.handlers.containsKey(type)) { return false; } /** @type {?} */ const handlers = this.handlers.get(type) .where((/** * @param {?} x * @return {?} */ x => token == null || token.guid === x.token.guid)) .select((/** * @param {?} x * @return {?} */ x => x.handler)); /** @type {?} */ let accepted = false; for (let i = (handlers.count() - 1); i >= 0; i--) { /** @type {?} */ const handler = handlers.get(i); accepted = true; yield handler(message); } return accepted; }); } } MessageBusService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ MessageBusService.ctorParameters = () => []; /** @nocollapse */ MessageBusService.ngInjectableDef = defineInjectable({ factory: function MessageBusService_Factory() { return new MessageBusService(); }, token: MessageBusService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const 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'; class LoggingService extends ServiceBase { /** * Creates a new instance of \@see LoggingService. */ constructor() { super(); this.logProvider = console; this.setMessageTemplateForAll('[{0}][{1}] - {3}{2}'); this.minimumLevel = LogType.Information; } /** * Sets a log provider. * By default \@see console is used as provider. * @param {?} logProvider * @return {?} */ setLogProvider(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. * @param {?} type * @param {?} message * @return {?} */ setMessageTemplate(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. * @param {?} message * @return {?} */ setMessageTemplateForAll(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. * @param {?} type * @return {?} */ setMinimumLevel(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. * @return {?} */ log(message, type = LogType.Trace, 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 {?} */ const 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. * @return {?} */ trace(message, 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. * @return {?} */ debug(message, 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. * @return {?} */ information(message, 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. * @return {?} */ warning(message, 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. * @return {?} */ error(message, 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. * @return {?} */ critical(message, 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 = () => []; /** @nocollapse */ LoggingService.ngInjectableDef = defineInjectable({ factory: function LoggingService_Factory() { return new LoggingService(); }, token: LoggingService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const 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. */ class Alert { /** * Gets the type of the alert. * @return {?} */ get type() { return this.alertType; } /** * Gets the type name. * @return {?} */ get typeName() { return AlertType[this.alertType]; } /** * Gets the alert message. * @return {?} */ get message() { return this.innerMessage; } /** * Creates a new instance of \@see Alert. * @param {?} alertType * @param {?} message */ constructor(alertType, message) { this.alertType = alertType; this.innerMessage = message; } } class AlertService extends ServiceBase { /** * Creates a new instance of \@see AlertService * @param {?} logger The current logging service. */ constructor(logger) { super(); this.logger = logger; this.alerts = new ArrayList(); } /** * Gets the equivalent \@see LogType for the specified \@see AlertType. * @param {?} alertType The specified alert type. * @return {?} the log type. */ static getLogType(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. * @return {?} */ add(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. * @return {?} */ addError(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. * @return {?} */ addWarning(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. * @return {?} */ addMessage(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. * @return {?} */ remove(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. * @return {?} */ get(index) { return this.alerts.get(index); } /** * Gets the alert collection. * @return {?} */ getAlerts() { return this.alerts; } /** * Clears the alert collection. * @return {?} */ clear() { this.alerts.clear(); } } AlertService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ AlertService.ctorParameters = () => [ { type: LoggingService } ]; /** @nocollapse */ AlertService.ngInjectableDef = defineInjectable({ factory: function AlertService_Factory() { return new AlertService(inject(LoggingService)); }, token: AlertService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class ComponentBase { /** * Creates a new instance of \@see ComponentBase * @param {?} injector reference to an injector service. */ constructor(injector) { this.injector = injector; } /** * Called when the component is initialized. * @return {?} */ ngOnInit() { } /** * Called when the component is destroyed. * @return {?} */ ngOnDestroy() { this.unregisterTokens(); } /** * Gets a reference to the message bus. * @protected * @return {?} */ getMessageBus() { 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. * @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 {?} */ registerMessage(type, handler) { /** @type {?} */ const token = this.getMessageBus().register(type, handler); this.messageTokens.add(token); } /** * Unregisters all the tokens registered within this component. * @protected * @return {?} */ unregisterTokens() { if (this.messageTokens && this.messageTokens.count() > 0) { this.messageTokens.forEach((/** * @param {?} x * @return {?} */ x => x.unregister())); this.messageTokens.clear(); } } /** * 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 {?} */ unregisterToken(type) { if (this.messageTokens && this.messageTokens.count() > 0) { /** @type {?} */ const token = this.messageTokens.firstOrDefault((/** * @param {?} x * @return {?} */ x => x.type === type)); if (token) { token.unregister(); this.messageTokens.remove(token); } } } /** * 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 {?} */ sendMessage(message, token) { return __awaiter(this, void 0, void 0, function* () { yield this.getMessageBus().send(message, token); }); } /** * Gets the alert service. * @protected * @return {?} */ getAlerts() { if (!this.alerts) { this.alerts = this.injector.get(AlertService); } return this.alerts; } /** * Adds a message in the alert service. * @protected * @param {?} message message to add. * @return {?} */ addMessage(message) { this.getAlerts().addMessage(message); } /** * Adds a warning in the alert service. * @protected * @param {?} warning warning to add. * @return {?} */ addWarning(warning) { this.getAlerts().addWarning(warning); } /** * Adds an error in the alert service. * @protected * @param {?} error error to add. * @return {?} */ addError(error) { this.getAlerts().addError(error); } /** * Handles an application error, reporting the error to the alert service. * @protected * @param {?} error the error that needs to be handled. * @return {?} */ handleError(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); } } } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @template TParameters, TResult */ class ModalComponentBase extends ComponentBase { /** * @param {?} injector */ constructor(injector) { super(injector); this.injector = injector; } /** * @param {?} modalService * @return {?} */ setModalService(modalService) { this.modalService = modalService; } /** * @param {?} parameters * @return {?} */ setParameters(parameters) { this.parameters = parameters; } /** * @param {?} modalInstance * @return {?} */ setModalInstance(modalInstance) { this.modalInstance = modalInstance; } /** * @return {?} */ ngOnDestroy() { } /** * @return {?} */ ngOnInit() { } /** * @param {?=} result * @return {?} */ resolve(result) { this.modalInstance.resolve(result); } /** * @param {?} error * @return {?} */ reject(error) { this.modalInstance.reject(error); } } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class FileService extends ServiceBase { /** * 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 {?} */ readAsBlob(file, onProgress) { return __awaiter(this, void 0, void 0, function* () { return new Blob([yield this.read(file, (/** * @param {?} fileReader * @return {?} */ fileReader => fileReader.readAsArrayBuffer(file)), onProgress)], { 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. * @return {?} */ readAsText(file, onProgress) { return __awaiter(this, void 0, void 0, function* () { return (/** @type {?} */ (yield this.read(file, (/** * @param {?} fileReader * @return {?} */ fileReader => fileReader.readAsText(file)), onProgress))); }); } /** * Reads a file as binary text. * @param {?} file the file that needs to be read. * @param {?=} onProgress A progress handler to receive progress reports. * @return {?} */ readAsBinaryString(file, onProgress) { return __awaiter(this, void 0, void 0, function* () { return (/** @type {?} */ (yield this.read(file, (/** * @param {?} fileReader * @return {?} */ fileReader => fileReader.readAsBinaryString(file)), onProgress))); }); } /** * Reads a file and handles all the events and event removing. * @private * @param {?} file the file to read. * @param {?} action the reading action. * @param {?=} progress a progress handler to report progress. * @return {?} */ read(file, action, progress) { return new Promise((/** * @param {?} resolve * @param {?} reject * @return {?} */ (resolve, reject) => { /** @type {?} */ const fileReader = new FileReader(); /** * @return {?} */ function addEventListeners() { fileReader.addEventListener('progress', onProgress); fileReader.addEventListener('loadend', onLoadEnd); fileReader.addEventListener('error', onError); } /** * @return {?} */ function removeEventListeners() { fileReader.removeEventListener('progress', onProgress); fileReader.removeEventListener('loadend', onLoadEnd); fileReader.removeEventListener('error', onError); } /** * @param {?} e * @return {?} */ function onProgress(e) { if (e.lengthComputable) { /** @type {?} */ const percentLoaded = Math.round((e.loaded / e.total) * 100); progress(percentLoaded); } } /** * @return {?} */ function onLoadEnd() { removeEventListeners(); resolve(fileReader.result); } /** * @param {?} e * @return {?} */ function onError(e) { removeEventListeners(); reject(e); } addEventListeners(); try { action(fileReader); } catch (error) { onError(error); } })); } } FileService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ FileService.ngInjectableDef = defineInjectable({ factory: function FileService_Factory() { return new FileService(); }, token: FileService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Represents a modal dialog instance. * This class lifespan depends on the modal dialog lifespan. * @template TParameters, TResult */ class ModalInstance { /** * Creates an instance of \@see ModalInstance * @param {?} type the modal component type. */ constructor(type) { this.type = type; } /** * Gets the component ref associated to the modal dialog. * @return {?} */ get componentRef() { return this.innerComponentRef; } /** * Sets the component ref reference. * @param {?} componentRef the component ref object. * @return {?} */ setComponentRef(componentRef) { this.innerComponentRef = componentRef; } } class ModalService extends ServiceBase { /** * Creates a new instance of \@see ModalService * @param {?} resolver a reference to the component factory resolver, * @param {?} injector a reference to the DI injector container */ constructor(resolver, injector) { super(); this.resolver = resolver; this.injector = injector; this.modalInstances = new ArrayList(); } /** * Sets the view container ref that will hold and contain * the modal components. * @param {?} container the view container ref. * @return {?} */ setViewContainer(container) { if (ObjectExtensions.isNull(container)) { throw new Error('The container can not be null or undefined.'); } this.viewContainer = container; } /** * Gets the stack of modal instances. * @return {?} */ getModalInstances() { return this.modalInstances; } /** * Opens a modal dialog component. * @template TParameters, TResult * @param {?} type The modal component type. * @param {?=} parameters the creation parameters to pass to the modal component. * @return {?} */ open(type, parameters) { // create modal instance. /** @type {?} */ const modalInstance = new ModalInstance(type); this.modalInstances.add(modalInstance); // setup the modal promise. /** @type {?} */ const promise = new Promise((/** * @param {?} resolve * @param {?} reject * @return {?} */ (resolve, reject) => { modalInstance.resolve = (/** * @param {?=} result * @return {?} */ (result) => { resolve(result); this.remove(modalInstance); }); modalInstance.reject = (/** * @param {?=} reason * @return {?} */ (reason) => { reject(reason); this.remove(modalInstance); }); })); // create the component. /** @type {?} */ const factory = this.resolver.resolveComponentFactory(type); /** @type {?} */ const componentRef = factory.create(this.injector); // initialize the modal and component. modalInstance.setComponentRef(componentRef); componentRef.instance.setModalService(this); componentRef.instance.setModalInstance(modalInstance); componentRef.instance.setParameters(parameters); // insert view on screen. this.viewContainer.insert(componentRef.hostView); // return the promise. return promise; } /** * Removes the modal from the stack of modal instances. * @private * @template TParameters, TResult * @param {?} modalInstance the modal that will be removed. * @return {?} */ remove(modalInstance) { this.modalInstances.remove(modalInstance); this.viewContainer.remove(this.viewContainer.indexOf(modalInstance.componentRef.hostView)); } } ModalService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ModalService.ctorParameters = () => [ { type: ComponentFactoryResolver }, { type: Injector } ]; /** @nocollapse */ ModalService.ngInjectableDef = defineInjectable({ factory: function ModalService_Factory() { return new ModalService(inject(ComponentFactoryResolver), inject(INJECTOR)); }, token: ModalService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Represents a geolocation watcher. * It listens for geolocation events. */ class GeolocationWatcher { /** * Creates a new instance of \@see GeolocationWatcher * @param {?} geolocation a reference to the geolocation service. */ constructor(geolocation) { this.geolocation = geolocation; this.watchIndex = -1; } /** * Register the watcher and stores the watch operation index. * @param {?} index the index representing this watch operation. * @return {?} */ register(index) { if (!this.isDisposed()) { throw new Error('This watcher can not be registered again.'); } this.watchIndex = index; } /** * Unregisters the watcher. * Once unregistered, the watcher does not receives any more events. * @return {?} */ unregister() { if (this.isDisposed()) { throw new Error('This watcher has not been properly registered.'); } this.beingUnregistered = true; this.geolocation.unregisterWatcher(this); this.beingUnregistered = false; this.watchIndex = -1; } /** * Gets the watch index. * @return {?} */ getWatchIndex() { return this.watchIndex; } /** * Indicates if this watcher is disposed. * @return {?} */ isDisposed() { return this.watchIndex < 0; } /** * Indicates if the watcher is being unregistered. * @return {?} */ isBeingUnregistered() { return this.beingUnregistered; } } /** * Implements the geolocation provider api using the \@see navigator.geolocation */ class NavigationGeolocationProvider { /** * Creates a new instance of \@see NavigationGeolocationProvider * @param {?=} options geolocation options. */ constructor(options) { this.options = options; } /** * Gets the current geolocation if a service geolocation service is available. * @return {?} */ getGeolocation() { if (this.isAvailable()) { return new Promise((/** * @param {?} resolve * @param {?} reject * @return {?} */ (resolve, reject) => this.getGeoLocator().getCurrentPosition((/** * @param {?} info * @return {?} */ info => resolve(info.coords)), (/** * @param {?} error * @return {?} */ error => reject(error.message)), this.options))); } return Promise.reject('The geolocation service is not available.'); } /** * Registers a geolocation watcher to lister for geolocation events. * @return {?} */ registerWatcher() { if (this.isAvailable()) { /** @type {?} */ const watcher = new GeolocationWatcher(this); watcher.register(this.getGeoLocator().watchPosition((/** * @param {?} info * @return {?} */ info => { if (watcher.onInformationReceived) { watcher.onInformationReceived(info.coords); } }), (/** * @param {?} error * @return {?} */ error => { if (watcher.onError) { watcher.onError(error.message); } }), this.options)); return watcher; } throw new Error('The geolocation service is not available.'); } /** * Unregisters the geolocation watcher. * @param {?} watcher the watcher that will be unregistered. * @return {?} */ unregisterWatcher(watcher) { if (!watcher.isBeingUnregistered()) { throw new Error('Can not call this method directly. Call GeolocationWatcher.unregister instead.'); } if (this.isAvailable()) { this.getGeoLocator().clearWatch(watcher.getWatchIndex()); } } /** * Indicates if the geolocation service is available. * @return {?} */ isAvailable() { return !ObjectExtensions.isNull(navigator.geolocation) && !ObjectExtensions.isNull(navigator.geolocation.getCurrentPosition) && !ObjectExtensions.isNull(navigator.geolocation.watchPosition) && !ObjectExtensions.isNull(navigator.geolocation.clearWatch); } /** * Gets the geolocation service. * @private * @return {?} */ getGeoLocator() { return navigator.geolocation; } } class GeolocationService extends ServiceBase { /** * Creates a new instance of \@see GeolocationService * By default \@see GeolocationService uses \@see NavigationGeolocationProvider as provider. * The provider can be changed using \@see GeolocationService.setGeolocationProvider */ constructor() { super(); this.geolocationProvider = new NavigationGeolocationProvider(); } /** * Sets the geolocation provider. * @param {?} provider geolocation provider. * @return {?} */ setGeolocationProvider(provider) { if (!provider) { throw new Error('The geolocation provider can not be null or undefined.'); } this.geolocationProvider = provider; } /** * Gets the current geolocation if a service geolocation service is available. * @return {?} */ getGeolocation() { return __awaiter(this, void 0, void 0, function* () { return yield this.geolocationProvider.getGeolocation(); }); } /** * Registers a geolocation watcher to lister for geolocation events. * @return {?} */ registerWatcher() { return this.geolocationProvider.registerWatcher(); } /** * Indicates if the geolocation service is available. * @return {?} */ isAvailable() { return this.geolocationProvider.isAvailable(); } } GeolocationService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ GeolocationService.ctorParameters = () => []; /** @nocollapse */ GeolocationService.ngInjectableDef = defineInjectable({ factory: function GeolocationService_Factory() { return new GeolocationService(); }, token: GeolocationService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class ParadigmWebAngularModule { } ParadigmWebAngularModule.decorators = [ { type: NgModule, args: [{ declarations: [], imports: [], exports: [] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { ComponentBase, ModalComponentBase, Message, getMessageName, AlertType, Alert, AlertService, FileService, LogType, LoggingService, RegistrationToken, MessageBusHandler, MessageBusService, ModalInstance, ModalService, GeolocationWatcher, NavigationGeolocationProvider, GeolocationService, ParadigmWebAngularModule, ServiceBase as ɵa }; //# sourceMappingURL=miracledevs-paradigm-web-angular.js.map