UNPKG

cronapp-framework-mobile-js

Version:
1 lines 8.16 kB
(function(){angular.module("report.services",[]).service("ReportService",["$http","$compile","$modal","$translate","$window","$rootScope","$ionicModal","$ionicLoading",function(a,b,c,d,e,f,g,h){var i=$("body"),j=angular.element(i.get(0)).scope(),k=["node_modules/cronapp-lib-js/dist/js/stimulsoft/stimulsoft-all.js","node_modules/cronapp-lib-js/dist/js/stimulsoft/stimulsoft-helper.js"],l=[];this.getReport=function(b){var c={url:window.hostApp+"api/rest/report",method:"POST",data:angular.toJson({reportName:b})};return a(c)},this.getPDFAsFile=function(b){var c={url:window.hostApp+"api/rest/report/pdfasfile",method:"POST",data:angular.toJson(b)};return a(c)},this.getContentAsString=function(b){var c={url:window.hostApp+"api/rest/report/contentasstring",method:"POST",data:angular.toJson(b)};return a(c)},this.getDataSourcesParams=function(b){var c={url:window.hostApp+"api/rest/report/getdatasourcesparams",method:"POST",data:angular.toJson(b)};return a(c)},this.openURLContent=function(a){var b=function(){var c=$("<iframe/>");c.attr("frameborder",0);var d=parseInt($(window).height());c.attr("height",d-200),c.attr("width","100%"),c.attr("src",a+"?download=false");var e=$("#reportView .modal-body");e.get(0)?(e.html(c),$("#reportViewContext .modal-dialog").css("width","95%"),setTimeout(function(){console.log("open[#reportViewContext]"),$("body").append(context),$("#reportView").modal()},100)):(console.log("wait[#reportViewContext]"),setTimeout(b,200))};setTimeout(b,200)},this.initializeStimulsoft=function(a){if(!Stimulsoft.Base.StiLicense.Key){stimulsoftHelper.setLanguage(a);var b=stimulsoftHelper.getLocalization();Stimulsoft.Base.Localization.StiLocalization.loadLocalization(b.xml),Stimulsoft.Base.Localization.StiLocalization.cultureName=b.cultureName,Stimulsoft.Base.StiLicense.Key=stimulsoftHelper.getKey()}},this.openStimulsoftReport=function(a,b,c,e,f){function g(a,b){try{window.resolveLocalFileSystemURL(cordova.file.externalApplicationStorageDirectory,function(c){f&&f(),c.getFile(a,{create:!0},function(c){c.createWriter(function(c){c.onwriteend=function(){cordova.plugins.fileOpener2.open(cordova.file.externalApplicationStorageDirectory+a,"application/pdf",{error:function(a){j.Notification.error(d.instant("General.ErrorNotSpecified"),a.message),console.log("Error status: "+a.status+" - Error message: "+a.message)}})},c.onerror=function(a){alert(a)};var e=new Blob([b],{type:"application/pdf"});c.write(e)},function(a){alert(a)})},function(a){alert(a)})},function(a){f&&f(),alert(a)})}catch(a){f&&f(),alert(a)}}var h=new Stimulsoft.Report.StiReport;h.load(a),c||(c=stimulsoftHelper.getDatasourcesInBand(h)),b&&b.forEach(function(a){c.datasources.forEach(function(b){for(var c=0;c<b.fieldParams.length;c++)if(b.fieldParams[c].param==a.originalName){b.fieldParams[c].value=a.value;break}})}),stimulsoftHelper.setParamsInFilter(h.dictionary.dataSources,c.datasources);var i=new Stimulsoft.Report.Export.StiPdfExportSettings,k=new Stimulsoft.Report.Export.StiPdfExportService,l=new Stimulsoft.System.IO.MemoryStream;h.renderAsync(function(){k.exportToAsync(function(){var b=l.toArray(),c=new Blob([new Uint8Array(b)],{type:"application/pdf"});window.resolveLocalFileSystemURL?g(a.ReportAlias+".pdf",c):(f&&f(),window.open(URL.createObjectURL(c)))},h,l,i)},!1)},this.showParameters=function(a){var b=a.parameters,c=[],d=0,e=function(a){return a.replace(/([.*+?^=!:()|\[\]\/\\])/g,"\\$1")},f=function(a,b,c){return a.replace(new RegExp(e(b),"g"),c)},i=function(){if(d<b.length){var e=b[d++];$.get("node_modules/cronapp-framework-mobile-js/components/reports/"+e.type+".parameter.html").done(function(a){c.push(f(a,"_field_",e.name)),i()})}else if(0<c.length){j.report=a,j.htmlParameters=c,j.getDescription=function(a){var b=a.name;return a.description&&(b=a.description,-1<b.indexOf("{{")&&-1<b.indexOf("}}")&&(b=b.replace("{{","").replace("}}",""),b=window.cronapi.i18n.translate(b,[]))),b},j.cloneElement=function(a){return angular.copy(a)},j.isVisibleParam=function(a){if("DATA_LIMIT"===a.name)return!1;return!(""!==a.value)||!(""!==a.value)};var k=a.reportName.match(/\/(.*?)(.*?)(\.jrxml|\.report)/);j.report.name=k[2];var l=this;j.onPrint=function(){j.report.reportName.endsWith(".report")&&(h.show({content:"Loading",animation:"fade-in",showBackdrop:!0,maxWidth:200,showDelay:0}),l.openStimulsoftReport(j.report.contentData,j.report.parameters,j.report.datasourcesInBand,void 0,j.onCancel))},j.onCancel=function(){j.ionicModal.remove(),h.hide()},g.fromTemplateUrl("node_modules/cronapp-framework-mobile-js/components/reports/reports.parameters.html",{scope:j,animation:"slide-in-up"}).then(function(a){a.scope.$parent.ionicModal=a,a.show(),$(".modal-backdrop-bg").css("opacity","0")})}}.bind(this);i()},this.mergeParam=function(a,b){var c=function(a,b){for(var c in Object.keys(b)){var d=Object.keys(b[c])[0];if(a==d)return Object.values(b[c])[0]}};for(var d in Object.keys(a)){var e=a[d].name,f=a[d].value,g=c(e,b);g&&(a[d].value=g)}return a},this.setVariablesBasedOnParams=function(a,b){for(var c in b){var d=Object.keys(b[c])[0],e=b[c][d];for(var f in a)if(a[f]&&a[f].Name&&a[f].Name===d){a[f].Value=e;break}}},this.hasParameterWithOutValue=function(a){for(var b in Object.keys(a))if(!a[b].value)return!0;return!1},this.getDatasourcesInBand=function(a){var b=new Stimulsoft.Report.StiReport;b.load(a);var c=stimulsoftHelper.getDatasourcesInBand(b);return c},this.loadSriptsStimulsoft=function(a){var b=!0,c=k.length,d=0;Pace.options.initialRate=.7,Pace.options.minTime=1750,Pace.options.maxProgressPerFrame=1,Pace.options.ghostTime=12e4,Pace.restart(),k.forEach(function(e){this.loadScript(e,function(e){d++,e||(b=!1),d==c&&(Pace.options.initialRate=.03,Pace.options.minTime=250,Pace.options.maxProgressPerFrame=20,Pace.options.ghostTime=10,Pace.stop(),a(b))})}.bind(this))},this.loadScript=function(a,b){if(0<=$.inArray(a,l))return void(b&&b(!0));if(-1!=a.indexOf(".css")){var c=document.createElement("link");c.rel="stylesheet",c.type="text/css",c.href=a,c.media="all",c.onload=function(){l.push(a),b&&b(!0)},c.onerror=function(){b&&b(!1)};try{document.getElementsByTagName("head")[0].appendChild(c)}catch(a){console.log(a)}}else{var d=document.createElement("script");d.type="text/javascript",d.readyState?d.onreadystatechange=function(){("loaded"==d.readyState||"complete"==d.readyState)&&(d.onreadystatechange=null,l.push(a),b&&b(!0))}:d.onload=function(){l.push(a),b&&b(!0)},d.src=a,document.getElementsByTagName("head")[0].appendChild(d)}},this.openReport=function(a,b,c){this.getReport(a).then(function(a){a&&a.data&&(a.data.reportName.endsWith(".report")?this.loadSriptsStimulsoft(function(e){e?(this.initializeStimulsoft(d.use()),this.getContentAsString(a.data).then(function(e){var f=this.getDatasourcesInBand(e.data);this.getDataSourcesParams(f).then(function(g){f=g.data,a.data.parameters=stimulsoftHelper.parseToGroupedParam(f.datasources),a.data.contentData=e.data,a.data.datasourcesInBand=f,b&&(a.data.parameters=this.mergeParam(a.data.parameters,b),a.data.contentData.Dictionary=a.data.contentData.Dictionary||{},this.setVariablesBasedOnParams(a.data.contentData.Dictionary.Variables,b)),this.hasParameterWithOutValue(a.data.parameters)&&!c?(a.data.parameters.forEach(function(a){a.name=d.instant(a.name)}),this.showParameters(JSON.parse(JSON.stringify(a.data)))):this.openStimulsoftReport(e.data,a.data.parameters,a.data.datasourcesInBand,c)}.bind(this))}.bind(this),function(a){var b=cronapi.internal.getErrorMessage(a,a.statusText);j.Notification.error(b)}.bind(this))):j.Notification.error("Error loading report script")}.bind(this)):0==a.data.parameters.length||1==a.data.parameters.length&&"DATA_LIMIT"==a.data.parameters[0].name?this.getPDFAsFile(a.data.reportName).then(function(a){this.openURLContent(a.data)}.bind(this),function(a){var b=cronapi.internal.getErrorMessage(a,a.statusText);j.Notification.error(b)}.bind(this)):(b&&(a.data.parameters=this.mergeParam(a.data.parameters,b)),this.hasParameterWithOutValue(a.data.parameters)?this.showParameters(JSON.parse(JSON.stringify(a.data))):this.getPDFAsFile(a.data).then(function(a){this.openURLContent(a.data)}.bind(this))))}.bind(this))}}])})(app);