@miracledevs/paradigm-web-angular
Version:
An angular wrapper with base functionality and helper services.
2 lines • 17.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@miracledevs/paradigm-ui-web-shared"),require("@angular/core")):"function"==typeof define&&define.amd?define("@miracledevs/paradigm-web-angular",["exports","@miracledevs/paradigm-ui-web-shared","@angular/core"],t):t((e.miracledevs=e.miracledevs||{},e.miracledevs["paradigm-web-angular"]={}),e.paradigmUiWebShared,e.ng.core)}(this,function(e,c,i){"use strict";var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function s(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function o(t,s,a,c){return new(a||(a=Promise))(function(e,n){function r(e){try{i(c.next(e))}catch(t){n(t)}}function o(e){try{i(c["throw"](e))}catch(t){n(t)}}function i(t){t.done?e(t.value):new a(function(e){e(t.value)}).then(r,o)}i((c=c.apply(t,s||[])).next())})}function u(r,o){var i,s,a,e,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return e={next:t(0),"throw":t(1),"return":t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function n(e){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,s&&(a=2&e[0]?s["return"]:e[0]?s["throw"]||((a=s["return"])&&a.call(s),0):s.next)&&!(a=a.call(s,e[1])).done)return a;switch(s=0,a&&(e=[2&e[0],a.value]),e[0]){case 0:case 1:a=e;break;case 4:return c.label++,{value:e[1],done:!1};case 5:c.label++,s=e[1],e=[0];continue;case 7:e=c.ops.pop(),c.trys.pop();continue;default:if(!(a=0<(a=c.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){c=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){c.label=e[1];break}if(6===e[0]&&c.label<a[1]){c.label=a[1],a=e;break}if(a&&c.label<a[2]){c.label=a[2],c.ops.push(e);break}a[2]&&c.ops.pop(),c.trys.pop();continue}e=o.call(r,c)}catch(t){e=[6,t],s=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([t,e])}}}var t=function k(){},n="$messageType";function l(e){return e[n]}var a=function(){function e(e,t){this.messageBus=e,this.innerType=t,this.innerGuid=c.Guid["new"]()}return Object.defineProperty(e.prototype,"type",{get:function(){return this.innerType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"guid",{get:function(){return this.innerGuid},enumerable:!0,configurable:!0}),e.prototype.unregister=function(){this.messageBus.unregister(this)},e}(),p=function(){function e(e,t,n){this.innerHandler=n,this.innerToken=new a(e,t)}return Object.defineProperty(e.prototype,"token",{get:function(){return this.innerToken},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"handler",{get:function(){return this.innerHandler},enumerable:!0,configurable:!0}),e}(),h=function(t){function e(){var e=t.call(this)||this;return e.handlers=new c.Dictionary,e}return s(e,t),e.prototype.count=function(){return this.handlers.count()},e.prototype.isRegistered=function(e){var t=l(e);return this.handlers.containsKey(t)},e.prototype.handlerCount=function(e){var t=l(e);return this.handlers.containsKey(t)?this.handlers.get(t).count():0},e.prototype.register=function(e,t){var n=l(e);this.handlers.containsKey(n)||this.handlers.add(n,new c.ArrayList);var r=new p(this,e,t);return this.handlers.get(n).add(r),r.token},e.prototype.unregister=function(t){var e=l(t.type);if(!this.handlers.containsKey(e))throw new Error("Token has been already unregistered.");var n=this.handlers.get(e);n.removeAll(function(e){return e.token.guid===t.guid}),n.any()||this.handlers.remove(e)},e.prototype.unregisterAll=function(){this.handlers.clear()},e.prototype.send=function(s,a){return o(this,void 0,void 0,function(){var t,n,r,o,i;return u(this,function(e){switch(e.label){case 0:if(c.ObjectExtensions.isNull(s))throw new Error("Can not send a null message.");if(c.ObjectExtensions.isNull(s.constructor))throw new Error("Message does not have a constructor, and the system can not infer the type.");if(t=l(s.constructor),!this.handlers.containsKey(t))return[2,!1];n=this.handlers.get(t).where(function(e){return null==a||a.guid===e.token.guid}).select(function(e){return e.handler}),r=!1,o=n.count()-1,e.label=1;case 1:return 0<=o?(i=n.get(o),r=!0,[4,i(s)]):[3,4];case 2:e.sent(),e.label=3;case 3:return o--,[3,1];case 4:return[2,r]}})})},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=i.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(t),d={Trace:0,Debug:1,Information:2,Warning:3,Error:4,Critical:5};d[d.Trace]="Trace",d[d.Debug]="Debug",d[d.Information]="Information",d[d.Warning]="Warning",d[d.Error]="Error",d[d.Critical]="Critical";var f=function(t){function o(){var e=t.call(this)||this;return e.logProvider=console,e.setMessageTemplateForAll("[{0}][{1}] - {3}{2}"),e.minimumLevel=d.Information,e}return s(o,t),o.prototype.setLogProvider=function(e){this.logProvider=e},o.prototype.setMessageTemplate=function(e,t){if(e<0||e>=this.messageTemplates.length)throw new Error(o.typeNotRecognized);if(c.ObjectExtensions.isNull(t))throw new Error("The message template can not be null or undefined.");this.messageTemplates[e]=t},o.prototype.setMessageTemplateForAll=function(e){if(c.ObjectExtensions.isNull(e))throw new Error("The message template can not be null or undefined.");this.messageTemplates=[],this.messageTemplates.push(e),this.messageTemplates.push(e),this.messageTemplates.push(e),this.messageTemplates.push(e),this.messageTemplates.push(e),this.messageTemplates.push(e)},o.prototype.setMinimumLevel=function(e){if(e<0||e>=this.messageTemplates.length)throw new Error(o.typeNotRecognized);this.minimumLevel=e},o.prototype.log=function(e,t,n){if(void 0===t&&(t=d.Trace),void 0===n&&(n=null),t<0||t>=this.messageTemplates.length)throw new Error(o.typeNotRecognized);if(c.ObjectExtensions.isNull(e))throw new Error("The message can not be null or undefined.");if(!(t<this.minimumLevel)){var r=c.StringExtensions.format(this.messageTemplates[t],c.DateExtensions.format(new Date,"hh:mm:ss"),d[t],n,e);switch(t){case d.Trace:this.logProvider.trace(r);break;case d.Debug:this.logProvider.debug(r);break;case d.Information:this.logProvider.info(r);break;case d.Warning:this.logProvider.warn(r);break;case d.Error:this.logProvider.error(r);break;case d.Critical:this.logProvider.critical?this.logProvider.critical(r):this.logProvider.error(r)}}},o.prototype.trace=function(e,t){void 0===t&&(t=null),this.log(e,d.Trace,t)},o.prototype.debug=function(e,t){void 0===t&&(t=null),this.log(e,d.Debug,t)},o.prototype.information=function(e,t){void 0===t&&(t=null),this.log(e,d.Information,t)},o.prototype.warning=function(e,t){void 0===t&&(t=null),this.log(e,d.Warning,t)},o.prototype.error=function(e,t){void 0===t&&(t=null),this.log(e,d.Error,t)},o.prototype.critical=function(e,t){void 0===t&&(t=null),this.log(e,d.Critical,t)},o.typeNotRecognized="The provided type is not recognized as a valid log type.",o.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],o.ctorParameters=function(){return[]},o.ngInjectableDef=i.defineInjectable({factory:function(){return new o},token:o,providedIn:"root"}),o}(t),g={Message:2,Warning:3,Error:4};g[g.Message]="Message",g[g.Warning]="Warning",g[g.Error]="Error";var y=function(){function e(e,t){this.alertType=e,this.innerMessage=t}return Object.defineProperty(e.prototype,"type",{get:function(){return this.alertType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"typeName",{get:function(){return g[this.alertType]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"message",{get:function(){return this.innerMessage},enumerable:!0,configurable:!0}),e}(),v=function(n){function r(e){var t=n.call(this)||this;return t.logger=e,t.alerts=new c.ArrayList,t}return s(r,n),r.getLogType=function(e){switch(e){case g.Message:return d.Information;case g.Warning:return d.Warning;case g.Error:return d.Error}throw new Error("The alert type is not recognized.")},r.prototype.add=function(e,t){this.alerts.add(new y(e,t)),this.logger.log(t,r.getLogType(e))},r.prototype.addError=function(e){this.add(g.Error,e)},r.prototype.addWarning=function(e){this.add(g.Warning,e)},r.prototype.addMessage=function(e){this.add(g.Message,e)},r.prototype.remove=function(e){e instanceof y?this.alerts.remove(e):this.alerts.removeAt(e)},r.prototype.get=function(e){return this.alerts.get(e)},r.prototype.getAlerts=function(){return this.alerts},r.prototype.clear=function(){this.alerts.clear()},r.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],r.ctorParameters=function(){return[{type:f}]},r.ngInjectableDef=i.defineInjectable({factory:function(){return new r(i.inject(f))},token:r,providedIn:"root"}),r}(t),m=function(){function e(e){this.injector=e}return e.prototype.ngOnInit=function(){},e.prototype.ngOnDestroy=function(){this.unregisterTokens()},e.prototype.getMessageBus=function(){return this.messageBus||(this.messageBus=this.injector.get(h),this.messageTokens=new c.ArrayList),this.messageBus},e.prototype.registerMessage=function(e,t){var n=this.getMessageBus().register(e,t);this.messageTokens.add(n)},e.prototype.unregisterTokens=function(){this.messageTokens&&0<this.messageTokens.count()&&(this.messageTokens.forEach(function(e){return e.unregister()}),this.messageTokens.clear())},e.prototype.unregisterToken=function(t){if(this.messageTokens&&0<this.messageTokens.count()){var e=this.messageTokens.firstOrDefault(function(e){return e.type===t});e&&(e.unregister(),this.messageTokens.remove(e))}},e.prototype.sendMessage=function(t,n){return o(this,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,this.getMessageBus().send(t,n)];case 1:return e.sent(),[2]}})})},e.prototype.getAlerts=function(){return this.alerts||(this.alerts=this.injector.get(v)),this.alerts},e.prototype.addMessage=function(e){this.getAlerts().addMessage(e)},e.prototype.addWarning=function(e){this.getAlerts().addWarning(e)},e.prototype.addError=function(e){this.getAlerts().addError(e)},e.prototype.handleError=function(e){e&&(e.message?this.addError(e.message):e.Message?this.addError(e.Message):e.exceptionMessage?this.addError(e.exceptionMessage):e.ExceptionMessage?this.addError(e.ExceptionMessage):e.error&&e.error.message?this.addError(e.error.message):e.error&&e.error.Message&&this.addError(e.error.Message))},e}(),b=function(n){function e(e){var t=n.call(this,e)||this;return t.injector=e,t}return s(e,n),e.prototype.setModalService=function(e){this.modalService=e},e.prototype.setParameters=function(e){this.parameters=e},e.prototype.setModalInstance=function(e){this.modalInstance=e},e.prototype.ngOnDestroy=function(){},e.prototype.ngOnInit=function(){},e.prototype.resolve=function(e){this.modalInstance.resolve(e)},e.prototype.reject=function(e){this.modalInstance.reject(e)},e}(m),w=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.prototype.readAsBlob=function(n,r){return o(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return t=Blob.bind,[4,this.read(n,function(e){return e.readAsArrayBuffer(n)},r)];case 1:return[2,new(t.apply(Blob,[void 0,[e.sent()],{type:n.type}]))]}})})},t.prototype.readAsText=function(t,n){return o(this,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,this.read(t,function(e){return e.readAsText(t)},n)];case 1:return[2,e.sent()]}})})},t.prototype.readAsBinaryString=function(t,n){return o(this,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,this.read(t,function(e){return e.readAsBinaryString(t)},n)];case 1:return[2,e.sent()]}})})},t.prototype.read=function(e,u,l){return new Promise(function(e,t){var n=new FileReader;function r(){n.removeEventListener("progress",o),n.removeEventListener("loadend",i),n.removeEventListener("error",s)}function o(e){if(e.lengthComputable){var t=Math.round(e.loaded/e.total*100);l(t)}}function i(){r(),e(n.result)}function s(e){r(),t(e)}!function a(){n.addEventListener("progress",o),n.addEventListener("loadend",i),n.addEventListener("error",s)}();try{u(n)}catch(c){s(c)}})},t.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],t.ngInjectableDef=i.defineInjectable({factory:function(){return new t},token:t,providedIn:"root"}),t}(t),T=function(){function e(e){this.type=e}return Object.defineProperty(e.prototype,"componentRef",{get:function(){return this.innerComponentRef},enumerable:!0,configurable:!0}),e.prototype.setComponentRef=function(e){this.innerComponentRef=e},e}(),E=function(r){function e(e,t){var n=r.call(this)||this;return n.resolver=e,n.injector=t,n.modalInstances=new c.ArrayList,n}return s(e,r),e.prototype.setViewContainer=function(e){if(c.ObjectExtensions.isNull(e))throw new Error("The container can not be null or undefined.");this.viewContainer=e},e.prototype.getModalInstances=function(){return this.modalInstances},e.prototype.open=function(e,t){var r=this,o=new T(e);this.modalInstances.add(o);var n=new Promise(function(t,n){o.resolve=function(e){t(e),r.remove(o)},o.reject=function(e){n(e),r.remove(o)}}),i=this.resolver.resolveComponentFactory(e).create(this.injector);return o.setComponentRef(i),i.instance.setModalService(this),i.instance.setModalInstance(o),i.instance.setParameters(t),this.viewContainer.insert(i.hostView),n},e.prototype.remove=function(e){this.modalInstances.remove(e),this.viewContainer.remove(this.viewContainer.indexOf(e.componentRef.hostView))},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:i.ComponentFactoryResolver},{type:i.Injector}]},e.ngInjectableDef=i.defineInjectable({factory:function(){return new e(i.inject(i.ComponentFactoryResolver),i.inject(i.INJECTOR))},token:e,providedIn:"root"}),e}(t),I=function(){function e(e){this.geolocation=e,this.watchIndex=-1}return e.prototype.register=function(e){if(!this.isDisposed())throw new Error("This watcher can not be registered again.");this.watchIndex=e},e.prototype.unregister=function(){if(this.isDisposed())throw new Error("This watcher has not been properly registered.");this.beingUnregistered=!0,this.geolocation.unregisterWatcher(this),this.beingUnregistered=!1,this.watchIndex=-1},e.prototype.getWatchIndex=function(){return this.watchIndex},e.prototype.isDisposed=function(){return this.watchIndex<0},e.prototype.isBeingUnregistered=function(){return this.beingUnregistered},e}(),j=function(){function e(e){this.options=e}return e.prototype.getGeolocation=function(){var e=this;return this.isAvailable()?new Promise(function(t,n){return e.getGeoLocator().getCurrentPosition(function(e){return t(e.coords)},function(e){return n(e.message)},e.options)}):Promise.reject("The geolocation service is not available.")},e.prototype.registerWatcher=function(){if(this.isAvailable()){var t=new I(this);return t.register(this.getGeoLocator().watchPosition(function(e){t.onInformationReceived&&t.onInformationReceived(e.coords)},function(e){t.onError&&t.onError(e.message)},this.options)),t}throw new Error("The geolocation service is not available.")},e.prototype.unregisterWatcher=function(e){if(!e.isBeingUnregistered())throw new Error("Can not call this method directly. Call GeolocationWatcher.unregister instead.");this.isAvailable()&&this.getGeoLocator().clearWatch(e.getWatchIndex())},e.prototype.isAvailable=function(){return!(c.ObjectExtensions.isNull(navigator.geolocation)||c.ObjectExtensions.isNull(navigator.geolocation.getCurrentPosition)||c.ObjectExtensions.isNull(navigator.geolocation.watchPosition)||c.ObjectExtensions.isNull(navigator.geolocation.clearWatch))},e.prototype.getGeoLocator=function(){return navigator.geolocation},e}(),P=function(t){function e(){var e=t.call(this)||this;return e.geolocationProvider=new j,e}return s(e,t),e.prototype.setGeolocationProvider=function(e){if(!e)throw new Error("The geolocation provider can not be null or undefined.");this.geolocationProvider=e},e.prototype.getGeolocation=function(){return o(this,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,this.geolocationProvider.getGeolocation()];case 1:return[2,e.sent()]}})})},e.prototype.registerWatcher=function(){return this.geolocationProvider.registerWatcher()},e.prototype.isAvailable=function(){return this.geolocationProvider.isAvailable()},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=i.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(t),M=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{declarations:[],imports:[],exports:[]}]}],e}();e.ComponentBase=m,e.ModalComponentBase=b,e.Message=function x(t){return function(e){e[n]=t}},e.getMessageName=l,e.AlertType=g,e.Alert=y,e.AlertService=v,e.FileService=w,e.LogType=d,e.LoggingService=f,e.RegistrationToken=a,e.MessageBusHandler=p,e.MessageBusService=h,e.ModalInstance=T,e.ModalService=E,e.GeolocationWatcher=I,e.NavigationGeolocationProvider=j,e.GeolocationService=P,e.ParadigmWebAngularModule=M,e.ɵa=t,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=miracledevs-paradigm-web-angular.umd.min.js.map