@hpe/angular-toolkit
Version:
Hewlett-Packard Enterprise : Angular toolkit for rapid project development
2 lines • 10.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@hpe/angular-toolkit/model"),require("@angular/common/http"),require("@angular/platform-browser"),require("rxjs"),require("rxjs/operators"),require("primeng/components/common/messageservice"),require("@angular/common"),require("primeng/api")):"function"==typeof define&&define.amd?define("@hpe/angular-toolkit/service",["exports","@angular/core","@hpe/angular-toolkit/model","@angular/common/http","@angular/platform-browser","rxjs","rxjs/operators","primeng/components/common/messageservice","@angular/common","primeng/api"],e):e((t.hpe=t.hpe||{},t.hpe["angular-toolkit"]=t.hpe["angular-toolkit"]||{},t.hpe["angular-toolkit"].service={}),t.ng.core,t.hpe["angular-toolkit"].model,t.ng.common.http,t.ng.platformBrowser,t.rxjs,t.rxjs.operators,null,t.ng.common,null)}(this,function(t,r,i,e,o,n,s,p,u,c){"use strict";var a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function l(t,e){function o(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var h=function(){function t(t){this.eventBusService=t,this.subscriptions=[]}return t.prototype.ngOnDestroy=function(){this.subscriptions.forEach(function(t){return t.unsubscribe()})},t.prototype.subscribeToApp=function(t,e){var o=this.eventBusService.subscribeToApp(t,e);return this.subscriptions.push(o),o},t.prototype.emitToApp=function(t){this.eventBusService.emitToApp(t)},t.prototype.subscribeToError=function(t){var e=this.eventBusService.subscribeToError(t);return this.subscriptions.push(e),e},t.prototype.emitToError=function(t){this.eventBusService.emitToError(t)},t}(),f=function(){function t(){this.eventEmitterMap=new Map,this.errorEvents=new r.EventEmitter}return t.prototype.subscribeToApp=function(t,e){var o=this.eventEmitterMap.get(t);return null==o&&(o=new r.EventEmitter,this.eventEmitterMap.set(t,o)),o.subscribe(e,null,null)},t.prototype.emitToApp=function(t){var e=this.eventEmitterMap.get(t.code);null!=e?(console.log("Emitting event : "+JSON.stringify(t)),e.emit(t)):console.log("WARNING : Emitting an event without any handler : "+JSON.stringify(t)),null!=(e=this.eventEmitterMap.get(i.AppEvent.ANY))&&e.emit(t)},t.prototype.subscribeToError=function(t){return this.errorEvents.subscribe(t,null,null)},t.prototype.emitToError=function(t){console.log("Emitting error event : "+JSON.stringify(t)),this.errorEvents.emit(t)},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[]},t}(),g={LOGIN:0,LOADING:1,READY:2};g[g.LOGIN]="LOGIN",g[g.LOADING]="LOADING",g[g.READY]="READY";var v=function(o){function t(t){var e=o.call(this,t)||this;return e.status=g.LOGIN,o.prototype.subscribeToApp.call(e,i.AppEvent.LOGIN_SUCCESS,function(t){return e.onLoginSuccess(t)}),o.prototype.subscribeToApp.call(e,i.AppEvent.LOGIN_FAILED,function(t){return e.onLoginFailed(t)}),o.prototype.subscribeToApp.call(e,i.AppEvent.LOGOUT_SUCCESS,function(t){return e.onLogoutSuccess(t)}),o.prototype.subscribeToApp.call(e,i.AppEvent.LOGOUT_FAILED,function(t){return e.onLogoutFailed(t)}),o.prototype.subscribeToApp.call(e,i.AppEvent.INVALID_TOKEN,function(t){return e.onInvalidToken(t)}),o.prototype.subscribeToApp.call(e,i.AppEvent.APPLICATION_READY,function(t){return e.onApplicationReady(t)}),e}return l(t,o),t.prototype.isStatusLogin=function(){return this.status==g.LOGIN},t.prototype.isStatusLoading=function(){return this.status==g.LOADING},t.prototype.isStatusReady=function(){return this.status==g.READY},t.prototype.onLoginSuccess=function(t){this.status=g.LOADING},t.prototype.onLoginFailed=function(t){this.status=g.LOGIN},t.prototype.onLogoutSuccess=function(t){this.status=g.LOGIN},t.prototype.onLogoutFailed=function(t){this.status=g.LOGIN},t.prototype.onInvalidToken=function(t){this.status=g.LOGIN},t.prototype.onApplicationReady=function(t){this.status=g.READY},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:f}]},t}(h),y=function(){function t(t,e,o){this.httpClient=t,this.eventBusService=e,this.domSanitizer=o,this.openRequests=0}return Object.defineProperty(t.prototype,"loading",{get:function(){return 0<this.openRequests},enumerable:!0,configurable:!0}),t.prototype.getObject=function(t,e){var o=this;this.showLoader();return this.httpClient.get(t,{params:e,headers:{Pragma:"no-cache","Cache-Control":"no-cache",Expires:"0"}}).pipe(s.catchError(function(t){return o.handleError(t)}),s.finalize(function(){return o.hideLoader()}))},t.prototype.getBlob=function(t,e){var o=this;return this.showLoader(),null!=e&&(e.ts=Date.now()),this.httpClient.get(t,{params:e,responseType:"blob"}).pipe(s.map(function(t){return o.getSanitizedUrl(URL.createObjectURL(t))}),s.catchError(function(t){return o.handleError(t)}),s.finalize(function(){return o.hideLoader()}))},t.prototype.postObject=function(t,e,o){var n=this;return this.showLoader(),this.httpClient.post(t,e,o).pipe(s.catchError(function(t){return n.handleError(t)}),s.finalize(function(){return n.hideLoader()}))},t.prototype.getSanitizedUrl=function(t){return this.domSanitizer.bypassSecurityTrustResourceUrl(t)},t.prototype.handleError=function(t){var e;return console.log("Got the following HTTP error : "+JSON.stringify(t)),e=422==t.status?t.error:{code:t.status.toString(),error:t.error.toString()},this.eventBusService.emitToError(e),n.throwError(e)},t.prototype.showLoader=function(){1==++this.openRequests&&this.eventBusService.emitToApp(new i.AppEvent(i.AppEvent.SUBMIT_START))},t.prototype.hideLoader=function(){0==--this.openRequests&&this.eventBusService.emitToApp(new i.AppEvent(i.AppEvent.SUBMIT_END))},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:e.HttpClient},{type:f},{type:o.DomSanitizer}]},t}(),m=function(){function e(t){var e=this;this.httpService=t,this.languages=["en","it"],this.labelSet=new Map,this.language="en",this.languages.forEach(function(t){e.initLanguage(t)})}return e.prototype.setLanguage=function(t){this.language=t},e.prototype.getLabel=function(t,e){if(null==e)return null;var o=this.getMapping(t);if(null==o)return"?"+t+"?";var n=o[e];return null==n?t+".?"+e+"?":n},e.prototype.getMapping=function(t){var e=this.labelSet.get(this.language);return null!=e?e.get(t):null},e.prototype.initLanguage=function(t){this.loadLanguageFile(t,e.TOOLKIT_FILE),this.loadLanguageFile(t,e.APPLICATION_FILE)},e.prototype.loadLanguageFile=function(e,t){var o=this,n=t+"-"+e+".json";this.httpService.getObject("asset/lang/"+n).subscribe(function(t){return o.processFile(e,n,t)},function(t){return console.log("Cannot load labels file : "+n)})},e.prototype.processFile=function(t,e,o){console.log("Loaded labels file : "+e);var n=this.labelSet.get(t);for(var r in null==n&&(n=new Map,this.labelSet.set(t,n)),o)n.set(r,o[r])},e.TOOLKIT_FILE="toolkit",e.APPLICATION_FILE="application",e.decorators=[{type:r.Injectable}],e.ctorParameters=function(){return[{type:y}]},e}(),S=function(){function t(t){this.messageService=t}return t.prototype.showSuccess=function(t,e){this.show("success",t,e)},t.prototype.showInfo=function(t,e){this.show("info",t,e)},t.prototype.showWarn=function(t,e){this.show("warn",t,e)},t.prototype.showError=function(t,e){this.show("error",t,e)},t.prototype.show=function(t,e,o){this.messageService.add({severity:t,summary:e,detail:o})},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:p.MessageService}]},t}(),b=function(n){function t(t,e){var o=n.call(this,t)||this;return o.httpService=e,o.clearSession(),n.prototype.subscribeToApp.call(o,i.AppEvent.INVALID_TOKEN,function(t){return o.onInvalidToken(t)}),o}return l(t,n),t.prototype.login=function(t){var e=this;console.log("SessionService.login : Logging in user='"+t.username+"'"),this.httpService.postObject("/api/session/login",t).subscribe(function(t){return e.loginSuccess(t)},function(t){return e.loginError(t)})},t.prototype.logout=function(){var e=this;console.log("SessionService.logout : Logging out user='"+(this.user||"???")+"'"),this.httpService.postObject("/api/session/logout",{token:this.token}).subscribe(function(t){return e.logoutSuccess()},function(t){return e.logoutError(t)})},t.prototype.clearSession=function(){console.log("SessionService.clearSession: Resetting session..."),this.session=null,this.token=null,this.user=null,this.profile=null,this.permissions=new Map},Object.defineProperty(t.prototype,"homePage",{get:function(){return this.profile?this.profile.homePage:null},enumerable:!0,configurable:!0}),t.prototype.hasPermission=function(t){return this.permissions.get(t)},t.prototype.loginSuccess=function(t){this.session=t,this.token=t.token,this.user=t.user,this.profile=t.profile,this.permissions=this.setupPermissionMap(this.profile.permissions),n.prototype.emitToApp.call(this,new i.AppEvent(i.AppEvent.LOGIN_SUCCESS,t)),console.log("Login successful for user="+this.user.username)},t.prototype.loginError=function(t){n.prototype.emitToApp.call(this,new i.AppEvent(i.AppEvent.LOGIN_FAILED,t))},t.prototype.logoutSuccess=function(){var t=this.user.username;this.clearSession(),n.prototype.emitToApp.call(this,new i.AppEvent(i.AppEvent.LOGOUT_SUCCESS,t)),console.log("Logout successful for user="+t)},t.prototype.logoutError=function(t){this.clearSession(),n.prototype.emitToApp.call(this,new i.AppEvent(i.AppEvent.LOGOUT_FAILED))},t.prototype.setupPermissionMap=function(t){var e=new Map;return t.forEach(function(t){return e.set(t,!0)}),e},t.prototype.onInvalidToken=function(t){this.clearSession()},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:f},{type:y}]},t}(h),E=function(){function t(){}return t.decorators=[{type:r.NgModule,args:[{imports:[u.CommonModule],declarations:[],exports:[],providers:[v,f,y,m,S,b,c.MessageService]}]}],t}();t.HpeServiceModule=E,t.AbstractSubscriber=h,t.ApplicationService=v,t.EventBusService=f,t.HttpService=y,t.LabelService=m,t.NotificationService=S,t.SessionService=b,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=hpe-angular-toolkit-service.umd.min.js.map