@dotgov/core
Version:
DGS core.
16 lines (14 loc) • 17 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common/http"),require("@angular/common"),require("@ngx-translate/core")):"function"==typeof define&&define.amd?define("@dotgov/core",["exports","@angular/core","@angular/common/http","@angular/common","@ngx-translate/core"],e):e(((t=t||self).dotgov=t.dotgov||{},t.dotgov.core={}),t.ng.core,t.ng.common.http,t.ng.common,t.ngxt)}(this,(function(t,e,r,o,n){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};Object.create;function a(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return a}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(a(arguments[e]));return t}Object.create;var u=function(){function t(){this._storage={},this._inProgress={}}return t.prototype.get=function(t){return this._storage[t]},t.prototype.set=function(t,e){this._storage[t]=e},t.prototype.remove=function(t,e){var r=this._storage[t];if(e&&r&&Array.isArray(r)){var o=r.findIndex((function(t){return t.taskId===e}));if(!(o>-1))return r;if(r.splice(o,1),r.length>0)return void(this._storage[t]=r)}delete this._storage[t]},t.prototype.removeMatched=function(t){var e=this;Object.keys(this._storage).forEach((function(r){-1!==r.indexOf(t)&&e.remove(r)})),Object.keys(this._inProgress).forEach((function(r){-1!==r.indexOf(t)&&e.deleteProgress(r)}))},t.prototype.clearCache=function(){this._inProgress={},this._storage={}},t.prototype.getProgress=function(t){return this._inProgress[t]},t.prototype.deleteProgress=function(t){delete this._inProgress[t]},t.prototype.setProgress=function(t){this._inProgress[t]=new e.EventEmitter},t}();u.decorators=[{type:e.Injectable}],u.ctorParameters=function(){return[]};var c=function(){};c.samlRequestIdKey="EP_samlRequestID_key",c.samlRelayStateKey="RelayState",c.samlResponsePrefixKey="SAMLResponse_",c.samlResponsePartsCountKey="SAMLResponsePartsCount",c.externalSessionIndexKey="externalSessionIndex",c.userContext="userContext",c.activeRole="activeRole";var p=function(){function t(){}return t.prototype.init=function(t){var e=!0===t.debug;this._environment=t,this._buttonsDebug=e||t.debug&&!0===t.debug.buttons,this._missingFieldsDebug=e||t.debug&&!0===t.debug.missingFields},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.action.apply(this,s(["log"],t))},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.action.apply(this,s(["warn"],t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.action.apply(this,s(["error"],t))},t.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.action.apply(this,s(["info"],t))},t.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.action.apply(this,s(["debug"],t))},t.prototype.action=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];var o=!0===window.dgs_debug,n=this._environment.debug;if(n&&("object"==typeof n||"boolean"==typeof n)){var i=!0===n||!0===n.logs||n.logs&&!0===n.logs[t];(i||o)&&console[t].apply(console,s(e))}},t}(),l=function(){function t(){}return t.validValue=function(t){var e=typeof t;return void 0!==t&&("string"===e?""!==t:"number"!==e||Number.isFinite(t))},t.formatDate=function(e,r,o){if(void 0===r&&(r=!0),void 0===o&&(o=!1),e){var n=t.convertToDate(e),i=function(t){return t<=9?"0"+t:t},a=" "+i(n.getHours())+":"+i(n.getMinutes())+":"+i(n.getSeconds());return o?(i(n.getDate())+"/"+i(n.getMonth()+1)+"/"+n.getFullYear()+(r?a:"")).trim():(i(n.getMonth()+1)+"/"+i(n.getDate())+"/"+n.getFullYear()+(r?a:"")).trim()}},t.stringToDate=function(t,e){var r,o;void 0===e&&(e=!1);var n=t.match(/\d+/gim).map((function(t){return Number(t)})),i=a(n,6),s=i[0],u=i[1],c=i[2],p=i[3],l=i[4],f=i[5];e?(u=(r=a(n,3))[0],s=r[1],c=r[2]):s>12&&(c=(o=a(n,3))[0],s=o[1],u=o[2]);var d=function(t){return void 0!==t?t:0};return new Date(d(c),d(Number(s)-1),d(u),d(p),d(l),d(f))},t.convertToDate=function(e){if(null==e)return NaN;var r=e.constructor===Date,o=e.constructor===Array,n=e.constructor===Number,i=e.constructor===String,a="object"==typeof e;return r&&e||o&&new Date(e[0],e[1],e[2])||n&&new Date(e)||i&&t.stringToDate(e)||a&&new Date(e.year,e.month,e.date)||NaN},t.camelize=function(t){var e=t.toLowerCase().replace(/[^A-Za-z0-9]/g," ").split(" ").reduce((function(t,e){return t+((r=e.toLowerCase()).charAt(0).toUpperCase()+r.toLowerCase().slice(1));var r}));return e.charAt(0).toLowerCase()+e.slice(1)},t.isValidUrl=function(t){try{new URL(t)}catch(t){return!1}return!0},t}(),f=function(){function t(t){this.environment=t}return t.prototype.load=function(){var e=this,r=this.environment.settingsUrl;return new Promise((function(o,n){fetch(r).then((function(t){return t.json()})).then((function(r){t.settings=r,l.isValidUrl(t.settings.apiUrl)||e.setEnvironmentAPIURI(),o()})).catch((function(t){n("Could not load file '"+r+"': "+JSON.stringify(t))}))}))},t.prototype.setEnvironmentAPIURI=function(){t.settings.apiUrl=this.environment.apiUrl},t}();f.settings={},f.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new f(e.ɵɵinject("environment"))},token:f,providedIn:"platform"}),f.decorators=[{type:e.Injectable,args:[{providedIn:"platform"}]}],f.ctorParameters=function(){return[{type:void 0,decorators:[{type:e.Inject,args:["environment"]}]}]};var d=function(t,e){this.data=t,this.error=e},g=function(t){function e(e,r,o,n){var i=t.call(this)||this;return i.httpClient=e,i.appConfig=r,i.customAuthenticator=o,i.environment=n,i.sanitizeMark="___mk___",i}return function(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e.prototype.get=function(t,e,r,o){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),this.request.apply(this,s(["GET",t,r,o,void 0],e))},e.prototype.delete=function(t,e,r,o,n){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),void 0===n&&(n={}),this.request.apply(this,s(["DELETE",t,r,o,n],e))},e.prototype.options=function(t,e,r,o){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),this.request.apply(this,s(["OPTIONS",t,r,o,void 0],e))},e.prototype.post=function(t,e,r,o,n){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),void 0===n&&(n={}),this.request.apply(this,s(["POST",t,r,n,o],e))},e.prototype.patch=function(t,e,r,o,n){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),void 0===n&&(n={}),this.request.apply(this,s(["PATCH",t,r,n,o],e))},e.prototype.put=function(t,e,r,o,n){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),void 0===n&&(n={}),this.request.apply(this,s(["PUT",t,r,n,o],e))},e.prototype.getURL=function(t,e,r,o,n){return void 0===e&&(e=[]),void 0===r&&(r={}),void 0===o&&(o={}),void 0===n&&(n={}),this.request.apply(this,s(["getURL",t,r,n,o],e))},Object.defineProperty(e.prototype,"apiRenameList",{get:function(){return["Name","Title"]},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"API",{get:function(){return f.settings.apiUrl},enumerable:!1,configurable:!0}),e.prototype.rename=function(t,e){this.languages.forEach((function(r){var o=t+"_"+r,n=""+t;e||e.hasOwnProperty(o)&&!e.hasOwnProperty(n)&&(e[n]=e[o],delete e[o])}))},e.prototype.generateUrl=function(t,e){for(var r=this,o=[],n=2;n<arguments.length;n++)o[n-2]=arguments[n];var i=t+(o.length?"/"+o.join("/"):""),a=Object.keys(e).map((function(t){return t+"="+r.sanitize(e[t])})).join("&");return i+(a?"?"+a:"")},e.prototype.sanitize=function(t){return null!=t?t.constructor===String?t.trim():function(t){return t.constructor===Number}(t)?t:(t&&Array.isArray(t)&&(t=t.map((function(t){return t?(t.hasOwnProperty("value")&&(t.value=t.value?t.value.toString():null),t):t}))),JSON.stringify(t)):t},e.prototype.resolve=function(t){var e,r=this;return t&&t.data&&Array.isArray(t.data)&&t.data.forEach((function(t){r.apiRenameList.forEach((function(e){r.rename(e,t)}))})),t&&t.hasOwnProperty(this.sanitizeMark)?t:((e={data:t,error:null})[this.sanitizeMark]=!0,e)},e.prototype.request=function(e,o,n,i,a){var u=this;void 0===a&&(a=null);for(var c=[],p=5;p<arguments.length;p++)c[p-5]=arguments[p];if(e){var l=this.API,f=new RegExp("^(?:[a-z]+:)?//","i");f.test(o)&&(l=""),e=e.toLowerCase();var d=this.generateUrl.apply(this,s([(i.apiUrl||l)+o,n],c));if("geturl"===e)return d;var g=d+"|"+e;return new Promise((function(o){var n,c=t.prototype.get.call(u,g),p=t.prototype.getProgress.call(u,g),l=i.skipCache||!1;if(c&&!0!==l)return o(c);if(p&&!0!==l)p.subscribe((function(e){t.prototype.deleteProgress.call(u,g);var r=u.resolve(e);return o(r)}));else{var f="get"===e||"options"===e,v=[],y=Object.assign({Pragma:"no-cache","Cache-control":-1,"ngsw-bypass":""},i.headers||{});u.authenticator(y,i),i.headers=new r.HttpHeaders(u.cleanHeaders(y)),f?(v=[d,i],t.prototype.setProgress.call(u,g)):v="delete"===e?[d,i,a||{}]:[d,a||{},i],(n=u.httpClient)[e].apply(n,s(v)).toPromise().then((function(e){var r=u.resolve(e);f&&t.prototype.set.call(u,g,r);var n=t.prototype.getProgress.call(u,g);return n&&(n.emit(r),t.prototype.deleteProgress.call(u,g)),o(r)})).catch((function(e){var r={data:null,error:e},n=t.prototype.getProgress.call(u,g);return n&&(n.emit(r),t.prototype.deleteProgress.call(u,g)),o(r)}))}}))}console.warn("Something went wrong with API service.")},e.prototype.authenticator=function(t,e){return this.customAuthenticator?this.customAuthenticator(t,e):this.defaultAuthenticator(t,e)},e.prototype.defaultAuthenticator=function(t,e){var r=JSON.parse(localStorage.getItem("auth")),o=JSON.parse(localStorage.getItem(c.externalSessionIndexKey));r&&!t.hasOwnProperty("Authorization")&&(t.Authorization=r.tokenType+" "+r.token),o&&!t.hasOwnProperty(c.externalSessionIndexKey)&&(t["x-"+c.externalSessionIndexKey]=""+o);var n=localStorage.getItem(c.userContext),i=localStorage.getItem(c.activeRole)||(n&&"undefined"!==n&&"null"!==n?JSON.parse(n):{}).role;!e.skipRole&&i&&(t["x-Current-Role"]=""+i)},e.prototype.cleanHeaders=function(t){var e={};return Object.keys(t).forEach((function(r){var o=t[r];null!=o&&(e[r]=o)})),e},Object.defineProperty(e.prototype,"languages",{get:function(){return["en","ro","ru"]},enumerable:!1,configurable:!0}),e}(u);g.decorators=[{type:e.Injectable}],g.ctorParameters=function(){return[{type:r.HttpClient},{type:f},{type:void 0,decorators:[{type:e.Inject,args:["authenticator"]}]},{type:void 0,decorators:[{type:e.Inject,args:["environment"]}]}]};var v=function(){function t(t,e){void 0===e&&(e={}),this.resolver=t,this.environment=e,this.debug=Boolean(this.environment.debug)}return t.prototype.componentByName=function(t,e,r){var o=Array.from(this.resolver._factories.keys()).find((function(e){return e.name===t}));if(o)return this.createComponent(o,r,e);this.debug&&console.warn("Could not load "+t)},t.prototype.componentbySelector=function(e,r,o,n){var i,a=this;return void 0===n&&(n={}),e?(r.forEach((function(t){t&&t.selector===e&&(i=a.createComponent(t.factoryClass,n,o))})),i?i.create?i:t.HAS_ROUTE:(this.debug&&console.warn("Could not load "+e),t.NOT_FOUND)):(this.debug&&console.warn("Started client-control with no target component."),t.NOT_FOUND)},t.prototype.createComponent=function(r,o,n){if(!n||!n.insert)return this.debug&&console.warn("Could not get target for ",r,"|",n),t.NOT_FOUND;if(!r)return this.debug&&console.warn("Could not load factory class"),t.NOT_FOUND;var i=Object.keys(o).map((function(t){return{provide:t,useValue:o[t]}})),a=e.ReflectiveInjector.resolve(i),s=e.ReflectiveInjector.fromResolvedProviders(a,n.parentInjector),u=this.resolver.resolveComponentFactory(r).create(s);return n.insert(u.hostView),Object.keys(o).forEach((function(t){u.instance[t]=o[t]})),u},t}();v.HAS_ROUTE=null,v.NOT_FOUND=void 0,v.decorators=[{type:e.Injectable}],v.ctorParameters=function(){return[{type:e.ComponentFactoryResolver},{type:void 0,decorators:[{type:e.Inject,args:["environment"]}]}]};var y=function(){function t(){this.notifyEvent=new e.EventEmitter}return t.prototype.error=function(t,e){this.emit({type:"error",message:t,title:e})},t.prototype.info=function(t,e){this.emit({type:"info",message:t,title:e})},t.prototype.success=function(t,e){this.emit({type:"success",message:t,title:e})},t.prototype.warning=function(t,e){this.emit({type:"warning",message:t,title:e})},t.prototype.subscription=function(t){return this.notifyEvent.subscribe(t)},t.prototype.emit=function(t){this.notifyEvent.emit(t)},t}();y.decorators=[{type:e.Injectable}];var h=function(){function t(t,e){this.translate=t,this._ref=e,this.translatePipe=new n.TranslatePipe(this.translate,this._ref)}return t.prototype.transform=function(t){var e;void 0===t&&(t="");for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];var n="string"==typeof t,i=t;n&&(i=t.toLowerCase()||" ");var a=(e=this.translatePipe).transform.apply(e,s([i],r));return a===i&&n?t:a},t}();function m(t){return function(){return t.load()}}h.decorators=[{type:e.Pipe,args:[{name:"ltranslate",pure:!1}]}],h.ctorParameters=function(){return[{type:n.TranslateService},{type:e.ChangeDetectorRef}]};var b=function(){function t(){}return t.forRoot=function(r,o){return{ngModule:t,providers:[f,{provide:e.APP_INITIALIZER,useFactory:m,deps:[f],multi:!0},g,u,v,y,{provide:"environment",useValue:r},{provide:"authenticator",useValue:o}]}},t}();b.decorators=[{type:e.NgModule,args:[{declarations:[h],imports:[o.CommonModule,r.HttpClientModule],exports:[h],providers:[],schemas:[e.CUSTOM_ELEMENTS_SCHEMA]}]}];var P=function(t,e,r){void 0===r&&(r="fa fa-globe"),this.Name=t,this.Code=e,this.Icon=r},_=function(){function t(t,e,r,o,n,i,a){this.expires=t,this.expiresIn=e,this.issued=r,this.token=o,this.tokenType=n,this.role=i,this.username=a}return t.fromResponse=function(e){return new t(e[".expires"],e.expires_in,e[".issued"],e.access_token,e.token_type,e.role,e.userName)},t}(),O=function(){function t(){}return Object.defineProperty(t.prototype,"loading",{get:function(){return this._loading},set:function(t){this._loading=t},enumerable:!1,configurable:!0}),t}();O.decorators=[{type:e.Component,args:[{selector:"dgs-loading",template:'<div *ngIf="loading" class="loading">\r\n <div class="spinner-border text-primary loading__element" role="status">\r\n <span class="sr-only">Loading...</span>\r\n </div>\r\n</div>\r\n',styles:[".loadingContainer{bottom:0;left:0;position:fixed;right:0;top:0;z-index:99999}.loadingBack{background-color:#fff;bottom:0;left:0;opacity:.5;position:absolute;right:0;top:0;z-index:99}.spinner{left:50%;position:relative;top:50%;z-index:999}"]}]}],O.propDecorators={loading:[{type:e.Input}]};var w=function(){function t(t){this.noValidate=!1,this.elemenet=t.nativeElement}return t.prototype.ngOnInit=function(){var t=this,e=[69,187,188,189];this.elemenet.addEventListener("keydown",(function(r){t.noValidate||-1!==e.indexOf(r.keyCode)&&r.preventDefault()})),this.elemenet.addEventListener("paste",(function(e){setTimeout((function(){!t.noValidate&&t&&e&&e.target&&e.target.value&&(e.target.value||(e.target.value=""))}))}))},t}();w.decorators=[{type:e.Directive,args:[{selector:"[type='number']"}]}],w.ctorParameters=function(){return[{type:e.ElementRef}]},w.propDecorators={noValidate:[{type:e.Input}]};var I=[O],C=function(){};C.decorators=[{type:e.NgModule,args:[{declarations:s(I,[w]),imports:[o.CommonModule],exports:s(I,[w]),providers:[]}]}],t.ApiResponse=d,t.ApiService=g,t.AppConfigService=f,t.Auth=_,t.DGSCoreModule=b,t.DGSLoadingComponent=O,t.DGSLowerTranslatePipe=h,t.DGSNotificationService=y,t.DGSUICoreModule=C,t.Debugger=p,t.FactoryService=v,t.Helper=l,t.Lang=P,t.LoginMetadata=c,t.StorageService=u,t.ɵa=m,t.ɵb=h,t.ɵc=f,t.ɵe=g,t.ɵf=u,t.ɵg=v,t.ɵh=y,t.ɵi=O,t.ɵj=w,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=dotgov-core.umd.min.js.map