UNPKG

cronapp-framework-js

Version:
1 lines 5.36 kB
app,angular.module("dashboard.services",[]).service("DashboardService",["$http","$compile","$modal","$translate","$window","$rootScope",function(t,e,a,o,i,n){var r=$("body"),s=angular.element(r.get(0)).scope(),d=["node_modules/cronapp-lib-js/dist/js/stimulsoft/stimulsoft.vendor.css","node_modules/cronapp-lib-js/dist/js/stimulsoft/stimulsoft.vendor.js","node_modules/cronapp-lib-js/dist/js/stimulsoft/stimulsoft-helper.js"],l=[];function c(){return navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)}function h(t){window.open(t,"_blank")}this.getDashboard=function(e){var a={url:"api/rest/dashboard",method:"POST",data:angular.toJson({dashboardName:e})};return t(a)},this.getContentAsString=function(e){var a={url:"api/rest/dashboard/contentasstring",method:"POST",data:angular.toJson(e)};return t(a)},this.openURLContent=function(t){if(t&&c())h(t);else{var e=function(){var a=$("<iframe/>");a.attr("frameborder",0);var o=parseInt($(window).height());a.attr("height",o-200),a.attr("width","100%"),a.attr("src",t+"?download=false");var i=$("#reportView .modal-body");i.get(0)?(i.html(a),$("#dashboardViewContext .modal-dialog").css("width","95%"),setTimeout((function(){console.log("open[#dashboardViewContext]"),$("body").append(context),$("#reportView").modal()}),100)):(console.log("wait[#dashboardViewContext]"),setTimeout(e,200))};setTimeout(e,200)}},this.initializeStimulsoft=function(t){if(!Stimulsoft.Base.StiLicense.Key){stimulsoftHelper.setLanguage(t);var e=stimulsoftHelper.getLocalization();Stimulsoft.Base.Localization.StiLocalization.loadLocalization(e.xml),Stimulsoft.Base.Localization.StiLocalization.cultureName=e.cultureName,Stimulsoft.Base.StiLicense.Key=stimulsoftHelper.getKey()}},this.openStimulsoftDashboard=function(t,a,o,i){var n=$("#dashboardViewContext");if(!n.get(0)){var d=$('<div id="dashboardViewContext" ng-include="\'node_modules/cronapp-framework-js/components/dashboard/dashboard.view.html\'"></div>');$(r).append(d),e(d)(s),n=$("#dashboardViewContext")}var l=parseInt($(window).height())-200+"px",u="StiViewer"+app.common.generateId(),p=Stimulsoft.Report.StiReport.createNewDashboard();p.load(t);var m=()=>{var t=new Stimulsoft.Viewer.StiViewerOptions;t.toolbar.showAboutButton=!1,t.appearance.showTooltipsHelp=!1,i?(t.toolbar.showOpenButton=!1,t.exports.showExportToDocument=!1,t.toolbar.visible=i.showToolbar,t.appearance.scrollbarsMode=i.showScrollbar,null!=i.height&&(t.height=i.height+"px")):(t.appearance.scrollbarsMode=!0,t.height=l);var e=new Stimulsoft.Viewer.StiViewer(t,u,!1);return e.report=p,Stimulsoft.Viewer.StiJsViewer.prototype.IsTouchDevice()&&(e.options.appearance.interfaceType=Stimulsoft.Viewer.StiInterfaceType.Touch),e};i&&i.$element?m().renderHtml(i.$element[0]):function(t){if(t&&c())h(t);else var e=setInterval((function(){var t=$("<div/>");t.attr("id","contentDashboard"),t.attr("width","100%");var a=$("#dashboardView .modal-body");a.get(0)&&(a.html(t),$("#dashboardViewContext .modal-dialog").css("width","95%"),setTimeout((function(){console.log("open[#dashboardViewContext]"),$("body").append(n),cronapi.screen.showModal("dashboardView"),m().renderHtml("contentDashboard"),setTimeout((function(){var t,e;e=setInterval((function(){var a=$("#"+u);a.length?t||(t=a.parent(),t.parent().parent().parent().parent()):(console.log("cleared interval: "+u),clearInterval(e))}),100)}),100)}),100),clearInterval(e))}),200)}(null),$(`#${u}`).find("img").attr("alt",""),$(`#${u}`).find("input").attr("aria-label",u)},this.loadSriptsStimulsoft=function(t){var e=!0,a=d.length,o=0;Pace.options.initialRate=.7,Pace.options.minTime=1750,Pace.options.maxProgressPerFrame=1,Pace.options.ghostTime=12e4;let i=setInterval((()=>Pace.restart()),2500);d.forEach(function(n,r){this.loadScript(n,(function(n){o++,n||(e=!1),o==a&&(clearInterval(i),Pace.options.initialRate=.03,Pace.options.minTime=250,Pace.options.maxProgressPerFrame=20,Pace.options.ghostTime=10,Pace.stop(),t(e))}))}.bind(this))},this.loadScript=function(t,e){if($.inArray(t,l)>=0)e&&e(!0);else if(-1!=t.indexOf(".css")){var a=document.createElement("link");a.rel="stylesheet",a.type="text/css",a.href=t,a.media="all",a.onload=function(){l.push(t),e&&e(!0)},a.onerror=function(){e&&e(!1)};try{document.getElementsByTagName("head")[0].appendChild(a)}catch(t){console.log(t)}}else{var o=document.createElement("script");o.type="text/javascript",o.readyState?o.onreadystatechange=function(){"loaded"!=o.readyState&&"complete"!=o.readyState||(o.onreadystatechange=null,l.push(t),e&&e(!0))}:o.onload=function(){l.push(t),e&&e(!0)},o.src=t,document.getElementsByTagName("head")[0].appendChild(o)}},this.openDashboard=function(t,e,a){this.getDashboard(t).then(function(t){t&&t.data&&t.data.dashboardName.endsWith(".dashboard")&&this.loadSriptsStimulsoft(function(e){e?(this.initializeStimulsoft(o.use()),this.getContentAsString(t.data).then(function(e){this.openStimulsoftDashboard(e.data,t.data.parameters,t.data.datasourcesInBand,a)}.bind(this),function(t){var e=cronapi.internal.getErrorMessage(t,t.statusText);s.Notification.error(e)}.bind(this))):s.Notification.error("Error loading report script")}.bind(this))}.bind(this))}}]);