fng-reports 0.12.0-beta.31 → 0.12.0-beta.310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +1 -1
- package/dist/fng-reports.js +1087 -739
- package/dist/fng-reports.min.js +3 -3
- package/dist/index.d.ts +45 -0
- package/index.d.ts +45 -0
- package/package.json +30 -24
- package/readme.md +1 -1
- package/src/fng-reports.js +498 -234
- package/src/plugins/jsPDF/jspdf-plugin.cell.js +441 -441
- package/src/plugins/ng-grid/ng-grid-csv-export.js +69 -41
- package/src/plugins/ng-grid/ng-grid-pdf-export.js +76 -20
- package/test/karma.conf.js +3 -1
- package/test/specs/reportSpec.js +4 -3
package/dist/fng-reports.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! forms-angular
|
|
2
|
-
|
|
3
|
-
"use strict";formsAngular.controller("AnalysisCtrl",["$filter","$scope","$http","$location","cssFrameworkService","routingService",function(o,l,r,s,c,t){var g=!0,e=new ngGridPdfExportPlugin({inhibitButton:!0}),n=new ngGridCsvExportPlugin({inhibitButton:!0});if(angular.extend(l,t.parsePathFunc()(s.$$path)),l.reportSchema={columnDefs:[]},l.gridOptions={data:"report",columnDefs:l.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,showFilter:!0,showFooter:!0,reallyShowFooter:!0,showTotals:!0,enableColumnResize:!0,footerRowHeight:65,multiSelect:!1,plugins:[e,n],onRegisterApi:function(e){(l.gridApi=e).selection.on.rowSelectionChanged(l,function(i){var e=l.reportSchema.drilldown;e&&(e=t.buildUrl(e.replace(/\|.+?\|/g,function(e){var t=e.slice(1,-1),n=/\((.+)\)/.exec(t);return n?l.reportSchema.params[n[1]].value:i.entity[t]})),window.location=e)})},footerTemplate:'<div ng-show="gridOptions.reallyShowFooter" class="ngFooterPanel" ng-class="{\'ui-widget-content\': jqueryUITheme, \'ui-corner-bottom\': jqueryUITheme}" ng-style="footerStyle()"><div ng-show="gridOptions.showTotals" ng-style="{height: rowHeight+3}"><div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell ngTotalCell {{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }"> </div><div ng-total-cell></div> </div></div><div class="ngTotalSelectContainer" ><div class="ngFooterTotalItems" ng-class="{\'ngNoMultiSelect\': !multiSelect}" ><span class="ngLabel">{{i18n.ngTotalItemsLabel}} {{maxRows()}}</span><span ng-show="filterText.length > 0" class="ngLabel">({{i18n.ngShowingItemsLabel}} {{totalFilteredItemsLength()}})</span></div><div class="ngFooterSelectedItems" ng-show="multiSelect"> <span class="ngLabel">{{i18n.ngSelectedItemsLabel}} {{selectedItems.length}}</span></div></div><div class="ngPagerContainer" style="float: right; margin-top: 10px;" ng-show="enablePaging" ng-class="{\'ngNoMultiSelect\': !multiSelect}"><div style="float:left; margin-right: 10px;" class="ngRowCountPicker"><span style="float: left; margin-top: 3px;" class="ngLabel">{{i18n.ngPageSizeLabel}}</span><select style="float: left;height: 27px; width: 100px" ng-model="pagingOptions.pageSize" ><option ng-repeat="size in pagingOptions.pageSizes">{{size}}</option></select></div><div style="float:left; margin-right: 10px; line-height:25px;" class="ngPagerControl" style="float: left; min-width: 135px;"><button class="ngPagerButton" ng-click="pageToFirst()" ng-disabled="cantPageBackward()" title="{{i18n.ngPagerFirstTitle}}"><div class="ngPagerFirstTriangle"><div class="ngPagerFirstBar"></div></div></button><button class="ngPagerButton" ng-click="pageBackward()" ng-disabled="cantPageBackward()" title="{{i18n.ngPagerPrevTitle}}"><div class="ngPagerFirstTriangle ngPagerPrevTriangle"></div></button><input class="ngPagerCurrent" min="1" max="{{maxPages()}}" type="number" style="width:50px; height: 24px; margin-top: 1px; padding: 0 4px;" ng-model="pagingOptions.currentPage"/><button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="{{i18n.ngPagerNextTitle}}"><div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button><button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageToLast()" title="{{i18n.ngPagerLastTitle}}"><div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button></div></div></div>'},l.report=[],!l.reportSchemaName&&s.$$search.r)switch(s.$$search.r.slice(0,1)){case"[":l.reportSchema.pipeline=JSON.parse(s.$$search.r);break;case"{":angular.extend(l.reportSchema,JSON.parse(s.$$search.r));break;default:throw new Error("No report instructions specified")}l.getTotalVal=function(t,e){var n="",i=_.find(l.reportSchema.columnDefs,function(e){return e.field===t});if(i)switch(i.totalsRow){case void 0:break;case"$SUM":for(var a=0,r=0;r<l.report.length;r++)a+=l.report[r][t];n=a,e&&(n=o(e)(n));break;default:n=i.totalsRow}return n},l.$on("exportToPDF",function(){e.createPDF()}),l.$on("exportToCSV",function(){n.createCSV()}),l.refreshQuery=function(){var e="/api/report/"+l.modelName,t="?";if(l.reportSchemaName&&(e+="/"+l.reportSchemaName),l.paramSchema){for(var n in l.record)if(l.record.hasOwnProperty(n)){var i=l.reportSchema.params[n];if(l.record[n]&&""!==l.record[n])l.param=l.record[n],i.conversionExpression&&(l.param=l.$eval(i.conversionExpression)),e+=t+n+"="+l.param,t="&";else if(i.required)return}}else{var a=s.$$url.match(/\?.*/);a&&(e+=t+a[0].slice(1))}r.get(e).then(function(e){var t=e.data;if(t.success){if(l.report=t.report,l.reportSchema=t.schema,l.reportSchema.title=l.reportSchema.title||l.modelName,l.reportSchema.title=l.reportSchema.title.replace(/\|.+?\|/g,function(e){var t=e.slice(1,-1),n=/\((.+)\)/.exec(t);return n?l.reportSchema.params[n[1]].value:""}),g&&(g=!1,l.$watch("reportSchema.columnDefs",function(e){var t=!1;if(e){for(var n=0;n<e.length;n++)if(e[n].totalsRow&&(t=!0),e[n].align){var i="fng-"+e[n].align;e[n].cellClass=e[n].cellClass||"",-1===e[n].cellClass.indexOf(i)&&(e[n].cellClass=e[n].cellClass+" "+i)}e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),l.gridOptions.columnDefs=e}l.gridOptions.showTotals=t,l.gridOptions.reallyShowFooter=t,l.gridOptions.footerRowHeight=55+(t?10:0)},!0),!l.paramSchema&&t.schema.params)){for(var n in l.paramSchema=[],l.record={},t.schema.params)if(t.schema.params.hasOwnProperty(n)){var i=t.schema.params[n];if(!i.noInput){var a=l.paramSchema.push({name:n,id:"fp_"+n,label:i.label||o("titleCase")(n),type:i.type||"text",required:!0,add:i.add||void 0,size:i.size||("bs3"===c.frameWork?"large":"medium")});"select"===i.type&&(l[n+"_Opts"]=i.enum,l.paramSchema[a-1].options=n+"_Opts")}var r=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(i.value);r&&(i.value=moment(r[1]).format("YYYY-MM-DDTHH:mm:ss.SSS")+"Z"),l.record[n]=i.value}l.$watch("record",function(e,t){t!==e&&l.refreshQuery()},!0)}}else console.log(JSON.stringify(t)),l.reportSchema.title="Error - see console log"},function(e){console.log(JSON.stringify(e)),s.path("/404")})},l.refreshQuery()}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(a){var r=this;r.grid=null,r.scope=null,r.init=function(n,e,t){function i(){var e=angular.element("h1").parent(),t=angular.element("#csv-data-link");null!=t&&t.remove();var n='<button id="csv-data-link" class="btn"><a href="data:text/csv;charset=UTF-8,';n+=encodeURIComponent(r.prepareCSV()),n+='" download="Export.csv">CSV Export</button>',e.append(n)}r.grid=e,r.scope=n,a.inhibitButton||(setTimeout(i,0),n.catHashKeys=function(){var e="";for(var t in n.renderedRows)e+=n.renderedRows[t].$$hashKey;return e},n.$watch("catHashKeys()",i))},r.createCSV=function(){window.open("data:text/csv;charset=UTF-8,"+encodeURIComponent(r.prepareCSV()))},r.prepareCSV=function(){function n(e){return null==e?"":"number"==typeof e?""+e:"boolean"==typeof e?e?"TRUE":"FALSE":"string"==typeof e?e.replace(/"/g,'""'):JSON.stringify(e).replace(/"/g,'""')}function e(e){return e.substr(0,e.length-1)+"\n"}var i="";return angular.forEach(r.scope.columns,function(e){e.visible&&(void 0===e.width||0<e.width)&&(i+='"'+n(e.displayName)+'",')}),i=e(i),angular.forEach(r.grid.filteredRows,function(t){angular.forEach(r.scope.columns,function(e){e.visible&&(i+='"'+n(t.entity[e.field])+'",')}),i=e(i)}),i}}function ngGridPdfExportPlugin(r){var o=this;o.grid=null,o.scope=null,o.services=null,o.options=r,o.init=function(e,t,n){if(o.grid=t,o.scope=e,o.services=n,!r.inhibitButton){var i=t.$root.find(".ngFooterPanel"),a=t.$root.find(".ngFooterPanel .pdf-data-link-span");null!=a&&a.remove();i.append('<button class="pdf-data-link-span">PDF Export</button>'),i.on("click",function(){o.createPDF()})}},o.createPDF=function(){var t=[],n=[],i={},a=o.scope.totalRowWidth();angular.forEach(o.scope.columns,function(e){e.visible&&(void 0===e.width||0<e.width)&&(t.push({name:e.field,prompt:e.displayName,width:e.width*(185/a),align:e.colDef.align||"left"}),e.colDef.totalsRow&&(i[e.field]=o.scope.getTotalVal(e.field,e.filter).toString()))}),angular.forEach(o.grid.filteredRows,function(e){n.push(angular.copy(e.entity))});var e=new jsPDF("landscape","mm","a4");e.setFontStyle("bold"),e.setFontSize(24),e.text(o.scope.reportSchema.title,15,15),e.setFontStyle("normal"),e.setFontSize(12),e.cellInitialize(),e.table(15,24,n,{headers:t,footers:i,printHeaders:!0,autoSize:!1,margins:{left:15,top:15,bottom:15,width:e.internal.pageSize-15}}),e.output("dataurlnewwindow")}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(o,n){return{scope:!1,compile:function(){return{pre:function(e,t){var n,i,a=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/);i=a?e.col.cellTemplate.replace("COL_FIELD |"+a[1],'getTotalVal("'+e.col.field+'","'+a[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),n=e.col.enableCellEdit?(n=(n=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,i)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):i;var r=o(n)(e);e.enableCellSelection&&-1===r[0].className.indexOf("ngSelectionCell")&&(r[0].setAttribute("tabindex",0),r.addClass("ngCellElement")),t.append(r)},post:function(e,t){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,t),e.$on("ngGridEventDigestCell",function(){n.digest(e)})}}}}}]),function(E){var a,r,o,s,R={x:void 0,y:void 0,w:void 0,h:void 0,ln:void 0},D=1,d=function(e,t,n,i,a){R={x:e,y:t,w:n,h:i,ln:a}},h=function(){return R};E.setHeaderFunction=function(e){s=e},E.getTextDimensions=function(e){a=this.internal.getFont().fontName,r=this.table_font_size||this.internal.getFontSize(),o=this.internal.getFont().fontStyle;var t,n,i=19.049976/25.4;return(n=document.createElement("font")).id="jsPDFCell",n.style.fontStyle=o,n.style.fontName=a,n.style.fontSize=r+"pt",n.innerText=e,document.body.appendChild(n),t={w:(n.offsetWidth+1)*i,h:(n.offsetHeight+1)*i},document.body.removeChild(n),t},E.cellAddPage=function(){this.addPage(),d(this.margins.left,this.margins.top,void 0,void 0),D+=1},E.cellInitialize=function(){R={x:void 0,y:void 0,w:void 0,h:void 0,ln:void 0},D=1},E.cell=function(e,t,n,i,a,r,o){var l,s=h();if(void 0!==s.ln&&(t=s.ln===r?(e=s.x+s.w,s.y):(s.y+s.h+i+13>=this.internal.pageSize.height-this.margins.bottom&&(this.cellAddPage(),this.printHeaders&&this.tableHeaderRow&&this.printHeaderRow(r,!0)),h().y+h().h)),void 0!==a[0])if(this.printingHeaderRow?this.rect(e,t,n,i,"FD"):this.rect(e,t,n,i),"right"===o)if(a instanceof Array)for(var c=0;c<a.length;c++){var g=a[c];l=this.getStringUnitWidth(g)*this.internal.getFontSize()/2.8125,this.text(g,e+n-l-3,t+this.internal.getLineHeight()*(c+1))}else l=this.getStringUnitWidth(a)*this.internal.getFontSize()/2.8125,this.text(a,e+n-l-3,t+this.internal.getLineHeight());else this.text(a,e+3,t+this.internal.getLineHeight());return d(e,t,n,i,r),this},E.getKeys="function"==typeof Object.keys?function(e){return e?Object.keys(e):[]}:function(e){var t,n=[];for(t in e)e.hasOwnProperty(t)&&n.push(t);return n},E.arrayMax=function(e,t){var n,i,a,r=e[0];for(n=0,i=e.length;n<i;n+=1)a=e[n],t?-1===t(r,a)&&(r=a):r<a&&(r=a);return r},E.table=function(e,t,n,i){if(!n)throw"No data for PDF table";var a,r,o,l,s,c,g,d,h,p,u=[],f=[],m={},v={},w=[],S=[],b=[],y=!1,x=!0,P=12,T=null,F=null,C={left:0,top:0,bottom:0,width:this.internal.pageSize.width};if(i&&(!0===i.autoSize&&(y=!0),!1===i.printHeaders&&(x=!1),i.fontSize&&(P=i.fontSize),i.margins&&(C=i.margins),i.headers&&(T=i.headers),i.footers&&(F=i.footers)),this.lnMod=0,R={x:void 0,y:void 0,w:void 0,h:void 0,ln:void 0},D=1,this.printHeaders=x,this.margins=C,this.setFontSize(P),this.table_font_size=P,null==T)u=this.getKeys(n[0]);else if(T[0]&&"string"!=typeof T[0]){for(r=0,o=T.length;r<o;r+=1)a=T[r],u.push(a.name),f.push(a.prompt),v[a.name]=1.5*a.width,S[a.name]=a.align}else u=T;if(y)for(p=function(e){return e[a]},r=0,o=u.length;r<o;r+=1){for(m[a=u[r]]=n.map(p),w.push(this.getTextDimensions(f[r]||a).w),g=0,l=(c=m[a]).length;g<l;g+=1)s=c[g],w.push(this.getTextDimensions(s).w);F&&w.push(this.getTextDimensions(F[r]).w),v[a]=E.arrayMax(w)}if(x){var L=this.calculateLineHeight(u,v,f.length?f:u);for(r=0,o=u.length;r<o;r+=1)a=u[r],b.push([e,t,v[a],L,String(f.length?f[r]:a),0,S[a]]);this.setTableHeaderRow(b),this.printHeaderRow(1,!1)}for(r=0,o=n.length;r<o;r+=1){for(d=n[r],L=this.calculateLineHeight(u,v,d),g=0,h=u.length;g<h;g+=1)a=u[g],this.cell(e,t,v[a],L,d[a],r+2,S[a])}if(F){for(var H=0;H<u.length;H++)a=u[H],b[H][4]=F[a]||" ";this.printHeaderRow(r+2,!1)}return this.table_x=e,this.table_y=t,this},E.calculateLineHeight=function(e,t,n){for(var i,a=0,r=0;r<e.length;r++){n[i=e[r]]=this.splitTextToSize(String(n[i]),t[i]-3);var o=this.internal.getLineHeight()*n[i].length+3;a<o&&(a=o)}return a},E.setTableHeaderRow=function(e){this.tableHeaderRow=e},E.printHeaderRow=function(e,t){if(!this.tableHeaderRow)throw"Property tableHeaderRow does not exist.";var n,i,a,r;if(this.printingHeaderRow=!0,void 0!==s){var o=s(this,D);d(o[0],o[1],o[2],o[3],-1)}this.setFontStyle("bold");var l=[];for(a=0,r=this.tableHeaderRow.length;a<r;a+=1)this.setFillColor(200,200,200),n=this.tableHeaderRow[a],t&&(n[1]=this.margins.top,l.push(n)),(i=[].concat(n))[5]=e,this.cell.apply(this,i);0<l.length&&this.setTableHeaderRow(l),this.setFontStyle("normal"),this.printingHeaderRow=!1}}(jsPDF.API);
|
|
1
|
+
/*! forms-angular 2025-02-09 */
|
|
2
|
+
"use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$q","$filter","$scope","$http","$location","CssFrameworkService","RoutingService","uiGridConstants",function($rootScope,$window,$q,$filter,$scope,$http,$location,CssFrameworkService,RoutingService,uiGridConstants){var firstTime=!0,pdfPlugIn=new ngGridPdfExportPlugin({inhibitButton:!0}),csvPlugIn=new ngGridCsvExportPlugin({inhibitButton:!0});function parseAndHandleError(r){try{return JSON.parse(r)}catch(e){throw new Error(`Invalid JSON ${r}
|
|
3
|
+
`+e.message)}}if(angular.extend($scope,RoutingService.parsePathFunc()($location.$$path)),$scope.reportSchema={},$scope.gridOptions={enableFiltering:!1,data:"report",columnDefs:$scope.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[pdfPlugIn,csvPlugIn],onRegisterApi:function(r){$scope.gridApi=r,$scope.gridOptions.plugins.forEach(function(e){e.init($scope,r.grid,null)}),r.selection.on.rowSelectionChanged($scope,function(t,o){var a=$scope.reportSchema.drilldown;if(a)if("string"==typeof a){let e="A"===o.target.tagName,r=o.target;for(;r=r.parentElement,e=r&&"A"===r.tagName,r&&!e&&r!==t;);e||(a=RoutingService.buildUrl(a.replace(/\|.+?\|/g,function(e){var r,e=e.slice(1,-1),o=/\((.+)\)/.exec(e);return o?(r=$scope.reportSchema.params[o[1]])&&$scope.record?($scope.param=$scope.record[o[1]],r.conversionExpression?$scope.$eval(r.conversionExpression):r.value):$scope.reportSchema.params[o[1]]?$scope.reportSchema.params[o[1]].value||"":(console.error("No value for "+o[1]),"ERR"):t.entity[e]})),window.location=a)}else console.error("Was expecting drilldown to be string but it was "+typeof a+" ("+a+")")})},appScopeProvider:{http:function(r,e,o){r.currentTarget.getAttributeNames().forEach(e=>{e.startsWith("data-")&&(o=o.replace(":"+e.slice(5),r.currentTarget.getAttribute(e)))});var t=r.currentTarget.getAttribute("data-disable-button"),t=(t&&(r.currentTarget.setAttribute("disabled","disabled"),"true"!==t)&&(r.currentTarget.innerText=t),{method:e,url:o});-1!==["POST","PUT","PATCH"].indexOf(e)&&(t.data={val:r.currentTarget.getAttribute("data-data")||{}}),$http(t).then(function(e){200!==e.status&&$scope.showError(e.statusText,"Error")}),r.stopPropagation()}}},$scope.report=[],!$scope.reportSchemaName&&$location.$$search.r)switch($location.$$search.r.slice(0,1)){case"[":$scope.reportSchema.pipeline=parseAndHandleError($location.$$search.r);break;case"{":angular.extend($scope.reportSchema,parseAndHandleError($location.$$search.r));break;default:throw new Error("No report instructions specified")}function setupParamsForm(e){for(var r in $scope.paramSchema=[],$scope.record={},e){var o,t;e.hasOwnProperty(r)&&((o=e[r]).noInput||(t=$scope.paramSchema.push({name:r,id:"fp_"+r,label:o.label||$filter("titleCase")(r),type:o.type||"text",required:!0,add:o.add||void 0,size:o.size||("bs3"===CssFrameworkService.frameWork?"large":"medium")}),"select"===o.type&&($scope[r+"_Opts"]=o.enum,$scope.paramSchema[t-1].options=r+"_Opts")),(t=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(o.value))&&(o.value=new Date(t[0])),$scope.record[r]=o.value)}$scope.$watch("record",function(e,r){r!==e&&$scope.refreshQuery()},!0)}$scope.getTotalVal=function(r,e){var o="",t=_.find($scope.reportSchema.columnDefs,function(e){return e.field===r});if(t)switch(t.totalsRow){case void 0:break;case"$SUM":for(var a=0,n=0;n<$scope.report.length;n++)a+=$scope.report[n][r];o=a,e&&(o=$filter(e)(o));break;default:o=t.totalsRow}return o},$scope.$on("exportToPDF",function(){pdfPlugIn.createPDF()}),$scope.$on("exportToCSV",function(){csvPlugIn.createCSV()}),$scope.extractFilter=function(e,r){var o,t,a;e.cellFilter&&(-1===(a=e.cellFilter.indexOf(":"))?o=e.cellFilter:(o=e.cellFilter.slice(0,a).trim(),"'"!==(t=e.cellFilter.slice(a+1,999).trim())[0]&&'"'!==t[0]||(t=t.slice(1,-1))),a=angular.element(document.body).injector().get("$filter")(o.trim()),r[e.field]={filter:a,filterParam:t})};var container=document.querySelector("div.report-grow"),margin,topOffset,header,headerHeight,availRows,navScope=(container&&(margin=container.offsetLeft,topOffset=container.offsetTop+margin,header=document.querySelector("div.ui-grid-header"),headerHeight=header?header.clientHeight:31,availRows=Math.floor(($window.innerHeight-topOffset-headerHeight-margin)/30),angular.element(container).css("height",30*availRows+"px")),$rootScope.navScope);navScope.items=[{fn:pdfPlugIn.createPDF,text:"Save as PDF"},{fn:csvPlugIn.createCSV,text:"Export as CSV"}],navScope.contextMenu="Report",navScope.contextMenuId="reportMenu",$scope.titleWithSubstitutions=$scope.reportSchema.title,$scope.inhibitRefresh||($scope.refreshQuery=function(){function substituteParams(t){function c(e,r){let o;return e instanceof Date||"string"==typeof e&&e.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} \d{4}/)&&(e=new Date(e.replace(" ","+"))),e instanceof Date?o=r?($scope.param=e,$scope.$eval(r)):e.toISOString():e}return $q(function(e){let s=[];t.replace(/\|.+?\|/g,function(e){var r=e.slice(1,-1),o=/(.*)\((.+)\)/.exec(r);let t;if(o)try{var a=$scope.reportSchema.params[o[2]],n=a.value;(t=2<o.length&&""!==o[1]?$http.get(`/api/${o[1]}/${n}/list`).then(function(e){return e&&200===e.status&&e.data?e.data.list:""}):t)?s.push(t):s.push(Promise.resolve(c(n,a.conversionExpression)))}catch(e){console.error(e),s.push("Error in fng-reports: "+e.message)}else{o=$scope.reportSchema.params[r];o?s.push(Promise.resolve(c(o.value,o.conversionExpression))):(console.log("Cannot find param "+r),s.push(Promise.resolve("ERR")))}return e}),Promise.all(s).then(function(r){let o=0;e(t.replace(/\|.+?\|/g,function(){var e=r[o];return o+=1,e}))})})}var apiCall="/api/report/"+$scope.modelName,connector="?",haveUrlParams=!1,query=$location.$$url.match(/\?.*/);if($scope.reportSchemaName?apiCall+="/"+$scope.reportSchemaName:query&&(firstTime&&($scope.paramSchema=JSON.parse($location.search().r).params,setupParamsForm($scope.paramSchema)),apiCall+=connector+query[0].slice(1),connector="&",haveUrlParams=!0),$scope.paramSchema){for(var paramVal in $scope.record)if($scope.record.hasOwnProperty(paramVal)){var instructions=$scope.reportSchema.params[paramVal];if($scope.record[paramVal]&&""!==$scope.record[paramVal])$scope.param=$scope.record[paramVal],instructions.conversionExpression&&($scope.param=$scope.$eval(instructions.conversionExpression)),apiCall+=connector+paramVal+"="+$scope.param,connector="&";else if(instructions.required)return}}else!haveUrlParams&&query&&(apiCall+=connector+query[0].slice(1),connector="&");return $http.get(apiCall).then(function(response){if(response&&response.data&&response.data.success){var data=response.data,alignClass;if($scope.report=data.report,$scope.reportSchema=data.schema,firstTime){if(firstTime=!1,data.schema.columnDefs&&0<data.schema.columnDefs.length)for(const colDef of data.schema.columnDefs){colDef.align&&(alignClass="fng-"+colDef.align,colDef.cellClass=colDef.cellClass||"",-1===colDef.cellClass.indexOf(alignClass))&&(colDef.cellClass=colDef.cellClass+" "+alignClass),colDef.aggregationTypeStr&&($scope.gridOptions.showColumnFooter=!0,colDef.aggregationType=uiGridConstants.aggregationTypes[colDef.aggregationTypeStr],colDef.aggregationType||(colDef.aggregationType=function(){return eval(colDef.aggregationTypeStr)}),colDef.aggregationHideLabel="sum"===colDef.aggregationTypeStr,colDef.footerCellFilter=colDef.cellFilter,colDef.footerCellClass=colDef.cellClass),$scope.gridOptions.columnDefs.push(colDef),colDef.width&&"string"==typeof colDef.width&&-1!==colDef.width.indexOf("px")&&(colDef.width=parseInt(colDef.width.slice(0,-2)))}else{var allFields=new Set;data.report.forEach(function(e){for(var r in e)allFields.add(r)}),data.schema.columnDefs=Array.from(allFields).map(function(e){e={name:e};return $scope.gridOptions.columnDefs.push(e),e})}!$scope.paramSchema&&data.schema.params&&"1"!==$location.$$search.noinput&&setupParamsForm(data.schema.params)}$scope.reportSchema.title=$scope.reportSchema.title||$scope.modelName,substituteParams($scope.reportSchema.title).then(function(e){$scope.titleWithSubstitutions=e}),$scope.gridOptions.enableFiltering=!!$scope.reportSchema.filter,navScope&&navScope.items&&(navScope.items.length=2,$scope.reportSchema.menu)&&$scope.reportSchema.menu.forEach(function(e){substituteParams(JSON.stringify(e)).then(function(e){navScope.items.push(JSON.parse(e))})})}else $scope.showError(JSON.stringify(response.data.error),"Invalid Response Error"),$scope.reportSchema.title="Error - see console log"},function(e){let r,o;o=403===e.status?(r="You do not have permission to run this report (permission to GET all "+$scope.modelName+" records is required)","Permission denied"):(r="The server could not process the request<br />Details:<br />"+e.data,"Error"),$scope.showError(r,o)})},$scope.refreshQuery()),$scope.showsContent=function(e,r){return!!/{{[\s]*COL_FIELD[\s]*}}/.test(e.replace(/(<([^>]+)>)/gi,""))||(-1!==e.indexOf('ng-bind-html="row.entity.'+r)?"HTML":void 0)},$scope.$on("$locationChangeStart",function(){navScope.clearContextMenu()}),$scope.showError=function(r,e){if($scope.alertTitle=e||"Error!","string"==typeof r)$scope.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)$scope.errorMessage=r.message;else if(r.data&&r.data.message)$scope.errorMessage=r.data.message;else try{$scope.errorMessage=JSON.stringify(r)}catch(e){$scope.errorMessage=r}else $scope.errorMessage="An error occurred - that's all we got. Sorry.";$scope.errorHideTimer=window.setTimeout(function(){$scope.dismissError(),$scope.$digest()},3500+1e3*($scope.alertTitle+$scope.errorMessage).length/50),$scope.errorVisible=!0,window.setTimeout(()=>{$scope.$digest()})},$scope.clearTimeout=function(){$scope.errorHideTimer&&(clearTimeout($scope.errorHideTimer),delete $scope.errorHideTimer)},$scope.dismissError=function(){$scope.clearTimeout,$scope.errorVisible=!1,delete $scope.errorMessage,delete $scope.alertTitle},$scope.stickError=function(){clearTimeout($scope.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var s=this;s.grid=null,s.scope=null,s.services=null,s.init=function(e,r,o){s.grid=r,s.scope=e,s.services=o},s.createCSV=function(){var e,r,o;e=(s.scope.titleWithSubstitutions||s.scope.reportSchema.title)+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(s.prepareCSV()),(o=document.createElement("a")).download=e,o.href=r,e=new MouseEvent("click"),o.dispatchEvent(e)},s.prepareCSV=function(){function t(e,r){return null==e?"":r?r.filter(e,r.filterParam):"number"==typeof e?""+e:"boolean"==typeof e?e?"TRUE":"FALSE":("string"==typeof e?e:JSON.stringify(e)).replace(/"/g,'""')}function e(e){return e.substr(0,e.length-1)+"\n"}var a="",n={};return angular.forEach(s.grid.columns,function(e){var r;s.scope.extractFilter(e,n),e.visible&&(void 0===e.width||"*"===e.width||0<e.width)&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef&&e.colDef.cellTemplate?"function"==typeof(r=s.scope.showsContent(e.colDef.cellTemplate,e.field))?(a+='"'+t(e.displayName)+'",',e.doCSVExport=r):"HTML"===r?(a+='"'+t(e.displayName)+'",',e.doCSVExport=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):r?(a+='"'+t(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1:(a+='"'+t(e.displayName)+'",',e.doCSVExport=!0))}),a=e(a),angular.forEach(s.scope.gridApi.core.getVisibleRows(),function(o){o.visible&&(angular.forEach(s.grid.columns,function(r){if(r.doCSVExport){let e=o.entity[r.field];"function"==typeof r.doCSVExport&&(e=r.doCSVExport(e,o.entity,r)),a+='"'+t(e,n[r.field])+'",'}}),a=e(a))}),a}}function ngGridPdfExportPlugin(t){var c=this;c.grid=null,c.scope=null,c.services=null,c.options=t,c.init=function(e,r,o){c.grid=r,c.scope=e,c.services=o,t.inhibitButton||(e=r.$root.find(".ngFooterPanel"),null!=(o=r.$root.find(".ngFooterPanel .pdf-data-link-span"))&&o.remove(),e.append('<button class="pdf-data-link-span">PDF Export</button>'),e.on("click",function(){c.createPDF()}))},c.createPDF=function(){var o=[],a=[],e=[],n={},s={},r=(angular.forEach(c.grid.columns,function(e){var r;e.visible&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef&&e.colDef.cellTemplate?"HTML"===(r=c.scope.showsContent(e.colDef.cellTemplate,e.field))?(o.push(e.displayName),a.push(e.field),s[e.field]=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):r&&(o.push(e.displayName),a.push(e.field)):(o.push(e.displayName),a.push(e.field))),e.colDef&&e.colDef.totalsRow&&(e.field,c.grid.getTotalVal(e.field,e.filter).toString()),c.scope.extractFilter(e,n)}),angular.forEach(c.scope.gridApi.core.getVisibleRows(),function(o){var t=[];o.visible&&(a.forEach(function(e){var r=o.entity[e];n[e]&&(r=n[e].filter(r,n[e].filterParam)),"string"==typeof(r=s[e]?s[e](r):r)&&(r=(r=(r=(r=(r=r.replace(/\u2019/g,"'")).replace(/\u2018/g,"'")).replace(/\u201c/g,'"')).replace(/\u201d/g,'"')).replace(/[^\x00-\xFF]/g,"")),t.push(r)}),e.push(t))}),new jspdf.jsPDF("landscape","mm","a4"));r.autoTable({head:[o],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(a,o){return{scope:!1,compile:function(){return{pre:function(e,r){var o=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),o=o?e.col.cellTemplate.replace("COL_FIELD |"+o[1],'getTotalVal("'+e.col.field+'","'+o[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),t=e.col.enableCellEdit?(t=(t=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,o)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):o,o=a(t)(e);e.enableCellSelection&&-1===o[0].className.indexOf("ngSelectionCell")&&(o[0].setAttribute("tabindex",0),o.addClass("ngCellElement")),r.append(o)},post:function(e,r){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,r),e.$on("ngGridEventDigestCell",function(){o.digest(e)})}}}}}]);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
declare namespace fngReports {
|
|
2
|
+
// See http://ui-grid.info/docs/#!/api/ui.grid.class:GridOptions.columnDef for details and full list of options
|
|
3
|
+
export interface IColumnDef {
|
|
4
|
+
name: string;
|
|
5
|
+
field: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
align?: string;
|
|
8
|
+
cellFilter?: string;
|
|
9
|
+
totalsRow?: string;
|
|
10
|
+
width?: number | string;
|
|
11
|
+
maxWidth?: number;
|
|
12
|
+
minWidth?: number;
|
|
13
|
+
enableFiltering?: boolean;
|
|
14
|
+
enableSorting?: boolean;
|
|
15
|
+
cellTemplate?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IMenuOption {
|
|
19
|
+
text: string;
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IReportParam {
|
|
24
|
+
type: any;
|
|
25
|
+
value?: any;
|
|
26
|
+
noInput?: boolean;
|
|
27
|
+
size?: string; // should be fng.FieldSizeString;
|
|
28
|
+
add?: string;
|
|
29
|
+
conversionExpression?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IReportParams {
|
|
33
|
+
[name: string]: IReportParam;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IReportSchema {
|
|
37
|
+
pipeline: any;
|
|
38
|
+
title?: string;
|
|
39
|
+
drilldown?: string;
|
|
40
|
+
params?: IReportParams;
|
|
41
|
+
columnDefs?: IColumnDef[];
|
|
42
|
+
filter?: boolean;
|
|
43
|
+
menu?: IMenuOption[];
|
|
44
|
+
}
|
|
45
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
declare namespace fngReports {
|
|
2
|
+
// See http://ui-grid.info/docs/#!/api/ui.grid.class:GridOptions.columnDef for details and full list of options
|
|
3
|
+
export interface IColumnDef {
|
|
4
|
+
name: string;
|
|
5
|
+
field: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
align?: string;
|
|
8
|
+
cellFilter?: string;
|
|
9
|
+
totalsRow?: string;
|
|
10
|
+
width?: number | string;
|
|
11
|
+
maxWidth?: number;
|
|
12
|
+
minWidth?: number;
|
|
13
|
+
enableFiltering?: boolean;
|
|
14
|
+
enableSorting?: boolean;
|
|
15
|
+
cellTemplate?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IMenuOption {
|
|
19
|
+
text: string;
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IReportParam {
|
|
24
|
+
type: any;
|
|
25
|
+
value?: any;
|
|
26
|
+
noInput?: boolean;
|
|
27
|
+
size?: string; // should be fng.FieldSizeString;
|
|
28
|
+
add?: string;
|
|
29
|
+
conversionExpression?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IReportParams {
|
|
33
|
+
[name: string]: IReportParam;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IReportSchema {
|
|
37
|
+
pipeline: any;
|
|
38
|
+
title?: string;
|
|
39
|
+
drilldown?: string;
|
|
40
|
+
params?: IReportParams;
|
|
41
|
+
columnDefs?: IColumnDef[];
|
|
42
|
+
filter?: boolean;
|
|
43
|
+
menu?: IMenuOption[];
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fng-reports",
|
|
3
|
-
"version": "0.12.0-beta.
|
|
3
|
+
"version": "0.12.0-beta.310",
|
|
4
4
|
"description": "Reporting plugin for forms-angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,42 +12,48 @@
|
|
|
12
12
|
"angular",
|
|
13
13
|
"reporting"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo Error - no tests specified - there is one that needs fixing",
|
|
17
|
+
"brokenTest": "grunt build"
|
|
18
|
+
},
|
|
15
19
|
"author": "Mark Chapman <support@forms-angular.org>",
|
|
16
20
|
"license": "MIT",
|
|
17
21
|
"bugs": {
|
|
18
22
|
"url": "https://github.com/forms-angular/fng-reports/issues"
|
|
19
23
|
},
|
|
20
24
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"jspdf": "
|
|
25
|
+
"angular-ui-grid": "4.12.7",
|
|
26
|
+
"jquery": "^3.7.1",
|
|
27
|
+
"jspdf": "2.5.1",
|
|
28
|
+
"jspdf-autotable": "^3.8.2"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
|
-
"angular": "1.
|
|
27
|
-
"angular-
|
|
28
|
-
"angular-
|
|
29
|
-
"angular-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
31
|
+
"angular": "^1.8.3",
|
|
32
|
+
"angular-animate": "1.8.3",
|
|
33
|
+
"angular-messages": "1.8.3",
|
|
34
|
+
"angular-mocks": "1.8.3",
|
|
35
|
+
"angular-sanitize": "1.8.3",
|
|
36
|
+
"forms-angular": "0.12.0-beta.310",
|
|
37
|
+
"grunt": "^1.6.1",
|
|
32
38
|
"grunt-autoprefixer": "3.0.4",
|
|
33
|
-
"grunt-concurrent": "
|
|
34
|
-
"grunt-contrib-clean": "2.0.
|
|
35
|
-
"grunt-contrib-concat": "1.0
|
|
39
|
+
"grunt-concurrent": "3.0.0",
|
|
40
|
+
"grunt-contrib-clean": "2.0.1",
|
|
41
|
+
"grunt-contrib-concat": "2.1.0",
|
|
36
42
|
"grunt-contrib-copy": "1.0.0",
|
|
37
|
-
"grunt-contrib-jshint": "2.0
|
|
38
|
-
"grunt-contrib-uglify": "
|
|
43
|
+
"grunt-contrib-jshint": "3.2.0",
|
|
44
|
+
"grunt-contrib-uglify": "5.2.2",
|
|
39
45
|
"grunt-contrib-watch": "^1.1.0",
|
|
40
|
-
"grunt-karma": "
|
|
46
|
+
"grunt-karma": "4.0.2",
|
|
41
47
|
"grunt-newer": "1.3.0",
|
|
42
|
-
"grunt-ng-annotate": "
|
|
48
|
+
"grunt-ng-annotate": "4.0.0",
|
|
43
49
|
"grunt-rev": "0.1.0",
|
|
44
|
-
"grunt-usemin": "mchapman/grunt-usemin",
|
|
45
|
-
"jasmine-core": "
|
|
46
|
-
"karma": "^4.
|
|
47
|
-
"karma-chrome-launcher": "
|
|
48
|
-
"karma-jasmine": "
|
|
49
|
-
"karma-junit-reporter": "
|
|
50
|
-
"lodash": "4.17.
|
|
50
|
+
"grunt-usemin": "github:mchapman/grunt-usemin",
|
|
51
|
+
"jasmine-core": "5.1.2",
|
|
52
|
+
"karma": "^6.4.3",
|
|
53
|
+
"karma-chrome-launcher": "3.2.0",
|
|
54
|
+
"karma-jasmine": "5.1.0",
|
|
55
|
+
"karma-junit-reporter": "2.0.1",
|
|
56
|
+
"lodash": "^4.17.21",
|
|
51
57
|
"matchdep": "2.0.0",
|
|
52
58
|
"ng-infinite-scroll": "1.3.0"
|
|
53
59
|
}
|
package/readme.md
CHANGED
|
@@ -19,4 +19,4 @@ Add the following lines to your index.html (or equivalent) file
|
|
|
19
19
|
<script src="jspdf/dist/jspdf.min.js"></script>
|
|
20
20
|
<script src="fng-reports/dist/fng-reports.js"></script>
|
|
21
21
|
|
|
22
|
-
The full documentation, which includes examples, is at www.forms-angular.org/#/plugins
|
|
22
|
+
The full documentation, which includes examples, is at www.forms-angular.org/#/plugins
|