fng-reports 0.12.0-beta.236 → 0.12.0-beta.237
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/dist/fng-reports.js +24 -10
- package/dist/fng-reports.min.js +2 -2
- package/package.json +2 -2
- package/src/fng-reports.js +23 -9
package/dist/fng-reports.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! forms-angular 2023-
|
|
1
|
+
/*! forms-angular 2023-11-13 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService', 'uiGridConstants',
|
|
@@ -38,7 +38,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter
|
|
|
38
38
|
isParamTest = /\((.+)\)/.exec(param);
|
|
39
39
|
if (isParamTest) {
|
|
40
40
|
var instructions = $scope.reportSchema.params[isParamTest[1]];
|
|
41
|
-
if (instructions) {
|
|
41
|
+
if (instructions && $scope.record) {
|
|
42
42
|
$scope.param = $scope.record[isParamTest[1]];
|
|
43
43
|
if (instructions.conversionExpression) {
|
|
44
44
|
return $scope.$eval(instructions.conversionExpression);
|
|
@@ -244,23 +244,36 @@ ${e.message}`);
|
|
|
244
244
|
$scope.refreshQuery = function () {
|
|
245
245
|
|
|
246
246
|
function substituteParams(str) {
|
|
247
|
-
function toTextValue(obj) {
|
|
247
|
+
function toTextValue(obj, conversionExpression) {
|
|
248
|
+
let retVal;
|
|
249
|
+
if (!(obj instanceof Date)) {
|
|
250
|
+
if (typeof obj === 'string' && obj.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} \d{4}/)) {
|
|
251
|
+
obj = new Date(obj.replace(' ', '+'));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
248
254
|
if (obj instanceof Date) {
|
|
249
|
-
|
|
255
|
+
if (conversionExpression) {
|
|
256
|
+
$scope.param = obj;
|
|
257
|
+
retVal = $scope.$eval(conversionExpression);
|
|
258
|
+
} else {
|
|
259
|
+
retVal = obj.toISOString();
|
|
260
|
+
}
|
|
250
261
|
} else {
|
|
251
262
|
return obj;
|
|
252
263
|
}
|
|
264
|
+
return retVal;
|
|
253
265
|
}
|
|
254
266
|
return $q(function (resolve) {
|
|
255
267
|
let promises = [];
|
|
256
268
|
str.replace(/\|.+?\|/g, function (match) {
|
|
257
269
|
var param = match.slice(1, -1);
|
|
258
270
|
// See if we have a function to run (check for brackets)
|
|
259
|
-
var hasBrackets =
|
|
271
|
+
var hasBrackets = /(.+)\((.+)\)/.exec(param);
|
|
260
272
|
if (hasBrackets) {
|
|
261
273
|
try {
|
|
262
|
-
const
|
|
263
|
-
|
|
274
|
+
const paramsObj = $scope.reportSchema.params[hasBrackets[2]];
|
|
275
|
+
const paramValue = paramsObj.value;
|
|
276
|
+
if (hasBrackets.length > 2) {
|
|
264
277
|
// We have a title function to run
|
|
265
278
|
promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
|
|
266
279
|
if (response && response.status === 200 && response.data) {
|
|
@@ -270,14 +283,15 @@ ${e.message}`);
|
|
|
270
283
|
}
|
|
271
284
|
}));
|
|
272
285
|
} else {
|
|
273
|
-
promises.push(Promise.resolve(toTextValue(
|
|
286
|
+
promises.push(Promise.resolve(toTextValue(paramValue, paramsObj.conversionExpression)));
|
|
274
287
|
}
|
|
275
288
|
} catch(e) {
|
|
276
289
|
console.error(e);
|
|
277
290
|
promises.push('Error in fng-reports: ' + e.message);
|
|
278
291
|
}
|
|
279
292
|
} else {
|
|
280
|
-
|
|
293
|
+
const paramsObj = $scope.reportSchema.params[param];
|
|
294
|
+
promises.push(Promise.resolve(toTextValue(paramsObj.value, paramsObj.conversionExpression)));
|
|
281
295
|
}
|
|
282
296
|
return match;
|
|
283
297
|
});
|
|
@@ -365,7 +379,7 @@ ${e.message}`);
|
|
|
365
379
|
}
|
|
366
380
|
}
|
|
367
381
|
|
|
368
|
-
if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !==
|
|
382
|
+
if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== '1') {
|
|
369
383
|
setupParamsForm(data.schema.params);
|
|
370
384
|
}
|
|
371
385
|
|
package/dist/fng-reports.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! forms-angular 2023-
|
|
1
|
+
/*! forms-angular 2023-11-13 */
|
|
2
2
|
"use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$q","$filter","$scope","$http","$location","CssFrameworkService","RoutingService","uiGridConstants",function(e,r,l,a,s,c,p,n,t,u){var d=!0,o=new ngGridPdfExportPlugin({inhibitButton:!0}),i=new ngGridCsvExportPlugin({inhibitButton:!0});function f(r){try{return JSON.parse(r)}catch(e){throw new Error(`Invalid JSON ${r}
|
|
3
|
-
`+e.message)}}if(angular.extend(s,t.parsePathFunc()(p.$$path)),s.reportSchema={},s.gridOptions={enableFiltering:!1,data:"report",columnDefs:s.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,i],onRegisterApi:function(r){s.gridApi=r,s.gridOptions.plugins.forEach(function(e){e.init(s,r.grid,null)}),r.selection.on.rowSelectionChanged(s,function(o){var e=s.reportSchema.drilldown;e&&("string"==typeof e?(e=t.buildUrl(e.replace(/\|.+?\|/g,function(e){var r,e=e.slice(1,-1),t=/\((.+)\)/.exec(e);return t?(r=s.reportSchema.params[t[1]])?(s.param=s.record[t[1]],r.conversionExpression?s.$eval(r.conversionExpression):r.value):s.reportSchema.params[t[1]].value:o.entity[e]})),window.location=e):console.error("Was expecting drilldown to be string but it was "+typeof e+" ("+e+")"))})},appScopeProvider:{http:function(r,e,t){r.currentTarget.getAttributeNames().forEach(e=>{e.startsWith("data-")&&(t=t.replace(":"+e.slice(5),r.currentTarget.getAttribute(e)))});var o=r.currentTarget.getAttribute("data-disable-button"),o=(o&&(r.currentTarget.setAttribute("disabled","disabled"),"true"!==o)&&(r.currentTarget.innerText=o),{method:e,url:t});-1!==["POST","PUT","PATCH"].indexOf(e)&&(o.data={val:r.currentTarget.getAttribute("data-data")||{}}),c(o),r.stopPropagation()}}},s.report=[],!s.reportSchemaName&&p.$$search.r)switch(p.$$search.r.slice(0,1)){case"[":s.reportSchema.pipeline=f(p.$$search.r);break;case"{":angular.extend(s.reportSchema,f(p.$$search.r));break;default:throw new Error("No report instructions specified")}function m(e){for(var r in s.paramSchema=[],s.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=s.paramSchema.push({name:r,id:"fp_"+r,label:t.label||a("titleCase")(r),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===n.frameWork?"large":"medium")}),"select"===t.type&&(s[r+"_Opts"]=t.enum,s.paramSchema[o-1].options=r+"_Opts")),(o=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(t.value))&&(t.value=new Date(o[0])),s.record[r]=t.value)}s.$watch("record",function(e,r){r!==e&&s.refreshQuery()},!0)}s.getTotalVal=function(r,e){var t="",o=_.find(s.reportSchema.columnDefs,function(e){return e.field===r});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var n=0,i=0;i<s.report.length;i++)n+=s.report[i][r];t=n,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},s.$on("exportToPDF",function(){o.createPDF()}),s.$on("exportToCSV",function(){i.createCSV()}),s.extractFilter=function(e,r){var t,o,n;e.cellFilter&&(-1===(n=e.cellFilter.indexOf(":"))?t=e.cellFilter:(t=e.cellFilter.slice(0,n).trim(),"'"!==(o=e.cellFilter.slice(n+1,999).trim())[0]&&'"'!==o[0]||(o=o.slice(1,-1))),n=angular.element(document.body).injector().get("$filter")(t.trim()),r[e.field]={filter:n,filterParam:o})};var g,h,S,v=document.querySelector("div.report-grow"),E=(v&&(g=v.offsetLeft,h=v.offsetTop+g,S=(S=document.querySelector("div.ui-grid-header"))?S.clientHeight:31,r=Math.floor((r.innerHeight-h-S-g)/30),angular.element(v).css("height",30*r+"px")),e.navScope);E.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:i.createCSV,text:"Export as CSV"}],E.contextMenu="Report",E.contextMenuId="reportMenu",s.titleWithSubstitutions=s.reportSchema.title,s.inhibitRefresh||(s.refreshQuery=function(){function n(o){function i(e){return e instanceof Date?e.toISOString():e}return l(function(e){let n=[];o.replace(/\|.+?\|/g,function(e){var r=e.slice(1,-1),t=/\((.+)\)/.exec(r);if(t)try{var o=s.reportSchema.params[t[0].slice(1,-1)].value;0<t.index?n.push(c.get(`/api/${t[1]}/${o}/list`).then(function(e){return e&&200===e.status&&e.data?e.data.list:""})):n.push(Promise.resolve(i(s.reportSchema.params[t[1]].value)))}catch(e){console.error(e),n.push("Error in fng-reports: "+e.message)}else n.push(Promise.resolve(i(s.reportSchema.params[r].value)));return e}),Promise.all(n).then(function(r){let t=0;e(o.replace(/\|.+?\|/g,function(){var e=r[t];return t+=1,e}))})})}var e="/api/report/"+s.modelName,r="?",t=!1,o=p.$$url.match(/\?.*/);if(s.reportSchemaName?e+="/"+s.reportSchemaName:o&&(d&&(s.paramSchema=JSON.parse(p.search().r).params,m(s.paramSchema)),e+=r+o[0].slice(1),r="&",t=!0),s.paramSchema){for(var i in s.record)if(s.record.hasOwnProperty(i)){var a=s.reportSchema.params[i];if(s.record[i]&&""!==s.record[i])s.param=s.record[i],a.conversionExpression&&(s.param=s.$eval(a.conversionExpression)),e+=r+i+"="+s.param,r="&";else if(a.required)return}}else!t&&o&&(e+=r+o[0].slice(1),r="&");return c.get(e).then(function(e){if(e&&e.data&&e.data.success){var r,t=e.data;if(s.report=t.report,s.reportSchema=t.schema,d){if(d=!1,t.schema.columnDefs&&0<t.schema.columnDefs.length)for(const o of t.schema.columnDefs)o.align&&(r="fng-"+o.align,o.cellClass=o.cellClass||"",-1===o.cellClass.indexOf(r))&&(o.cellClass=o.cellClass+" "+r),o.aggregationTypeStr&&(s.gridOptions.showColumnFooter=!0,o.aggregationType=u.aggregationTypes[o.aggregationTypeStr],o.aggregationHideLabel="sum"===o.aggregationTypeStr,o.footerCellFilter=o.cellFilter,o.footerCellClass=o.cellClass),s.gridOptions.columnDefs.push(o),o.width&&"string"==typeof o.width&&-1!==o.width.indexOf("px")&&(o.width=parseInt(o.width.slice(0,-2)));!s.paramSchema&&t.schema.params&&"1"!==p.$$search.noinput&&m(t.schema.params)}s.reportSchema.title=s.reportSchema.title||s.modelName,n(s.reportSchema.title).then(function(e){s.titleWithSubstitutions=e}),s.gridOptions.enableFiltering=!!s.reportSchema.filter,E&&E.items&&(E.items.length=2,s.reportSchema.menu)&&s.reportSchema.menu.forEach(function(e){n(JSON.stringify(e)).then(function(e){E.items.push(JSON.parse(e))})})}else s.showError(JSON.stringify(e.data.error),"Invalid Response Error"),s.reportSchema.title="Error - see console log"},function(e){let r,t;t=403===e.status?(r="You do not have permission to run this report (permission to GET all "+s.modelName+" records is required)","Permission denied"):(r="The server could not process the request","Error"),s.showError(r,t)})},s.refreshQuery()),s.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)},s.$on("$locationChangeStart",function(){delete E.contextMenu,delete E.items}),s.showError=function(r,e){if(s.alertTitle=e||"Error!","string"==typeof r)s.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)s.errorMessage=r.message;else if(r.data&&r.data.message)s.errorMessage=r.data.message;else try{s.errorMessage=JSON.stringify(r)}catch(e){s.errorMessage=r}else s.errorMessage="An error occurred - that's all we got. Sorry.";s.errorHideTimer=window.setTimeout(function(){s.dismissError(),s.$digest()},3500+1e3*(s.alertTitle+s.errorMessage).length/50),s.errorVisible=!0,window.setTimeout(()=>{s.$digest()})},s.clearTimeout=function(){s.errorHideTimer&&(clearTimeout(s.errorHideTimer),delete s.errorHideTimer)},s.dismissError=function(){s.clearTimeout,s.errorVisible=!1,delete s.errorMessage,delete s.alertTitle},s.stickError=function(){clearTimeout(s.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var a=this;a.grid=null,a.scope=null,a.services=null,a.init=function(e,r,t){a.grid=r,a.scope=e,a.services=t},a.createCSV=function(){var e,r,t;e=a.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(a.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},a.prepareCSV=function(){function o(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 n="",i={};return angular.forEach(a.grid.columns,function(e){var r;a.scope.extractFilter(e,i),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.cellTemplate?"HTML"===(r=a.scope.showsContent(e.colDef.cellTemplate,e.field))?(n+='"'+o(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?(n+='"'+o(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1:(n+='"'+o(e.displayName)+'",',e.doCSVExport=!0))}),n=e(n),angular.forEach(a.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(a.grid.columns,function(r){if(r.doCSVExport){let e=t.entity[r.field];"function"==typeof r.doCSVExport&&(e=r.doCSVExport(e)),n+='"'+o(e,i[r.field])+'",'}}),n=e(n))}),n}}function ngGridPdfExportPlugin(o){var l=this;l.grid=null,l.scope=null,l.services=null,l.options=o,l.init=function(e,r,t){l.grid=r,l.scope=e,l.services=t,o.inhibitButton||(e=r.$root.find(".ngFooterPanel"),null!=(t=r.$root.find(".ngFooterPanel .pdf-data-link-span"))&&t.remove(),e.append('<button class="pdf-data-link-span">PDF Export</button>'),e.on("click",function(){l.createPDF()}))},l.createPDF=function(){var o=[],n=[],e=[],i={},a={},r=(angular.forEach(l.grid.columns,function(e,r){var t;e.visible&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(t=l.scope.showsContent(e.colDef.cellTemplate,e.field))?(o.push(e.displayName),n.push(e.field),a[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")}):t&&(o.push(e.displayName),n.push(e.field)):(o.push(e.displayName),n.push(e.field))),e.colDef.totalsRow&&(e.field,l.grid.getTotalVal(e.field,e.filter).toString()),l.scope.extractFilter(e,i)}),angular.forEach(l.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(n.forEach(function(e){var r=t.entity[e];i[e]&&(r=i[e].filter(r,i[e].filterParam)),"string"==typeof(r=a[e]?a[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,"")),o.push(r)}),e.push(o))}),new jspdf.jsPDF("landscape","mm","a4"));r.autoTable({head:[o],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(n,t){return{scope:!1,compile:function(){return{pre:function(e,r){var t=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),t=t?e.col.cellTemplate.replace("COL_FIELD |"+t[1],'getTotalVal("'+e.col.field+'","'+t[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),o=e.col.enableCellEdit?(o=(o=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,t)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):t,t=n(o)(e);e.enableCellSelection&&-1===t[0].className.indexOf("ngSelectionCell")&&(t[0].setAttribute("tabindex",0),t.addClass("ngCellElement")),r.append(t)},post:function(e,r){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,r),e.$on("ngGridEventDigestCell",function(){t.digest(e)})}}}}}]);
|
|
3
|
+
`+e.message)}}if(angular.extend(s,t.parsePathFunc()(p.$$path)),s.reportSchema={},s.gridOptions={enableFiltering:!1,data:"report",columnDefs:s.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,i],onRegisterApi:function(r){s.gridApi=r,s.gridOptions.plugins.forEach(function(e){e.init(s,r.grid,null)}),r.selection.on.rowSelectionChanged(s,function(o){var e=s.reportSchema.drilldown;e&&("string"==typeof e?(e=t.buildUrl(e.replace(/\|.+?\|/g,function(e){var r,e=e.slice(1,-1),t=/\((.+)\)/.exec(e);return t?(r=s.reportSchema.params[t[1]])&&s.record?(s.param=s.record[t[1]],r.conversionExpression?s.$eval(r.conversionExpression):r.value):s.reportSchema.params[t[1]].value:o.entity[e]})),window.location=e):console.error("Was expecting drilldown to be string but it was "+typeof e+" ("+e+")"))})},appScopeProvider:{http:function(r,e,t){r.currentTarget.getAttributeNames().forEach(e=>{e.startsWith("data-")&&(t=t.replace(":"+e.slice(5),r.currentTarget.getAttribute(e)))});var o=r.currentTarget.getAttribute("data-disable-button"),o=(o&&(r.currentTarget.setAttribute("disabled","disabled"),"true"!==o)&&(r.currentTarget.innerText=o),{method:e,url:t});-1!==["POST","PUT","PATCH"].indexOf(e)&&(o.data={val:r.currentTarget.getAttribute("data-data")||{}}),c(o),r.stopPropagation()}}},s.report=[],!s.reportSchemaName&&p.$$search.r)switch(p.$$search.r.slice(0,1)){case"[":s.reportSchema.pipeline=f(p.$$search.r);break;case"{":angular.extend(s.reportSchema,f(p.$$search.r));break;default:throw new Error("No report instructions specified")}function m(e){for(var r in s.paramSchema=[],s.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=s.paramSchema.push({name:r,id:"fp_"+r,label:t.label||a("titleCase")(r),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===n.frameWork?"large":"medium")}),"select"===t.type&&(s[r+"_Opts"]=t.enum,s.paramSchema[o-1].options=r+"_Opts")),(o=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(t.value))&&(t.value=new Date(o[0])),s.record[r]=t.value)}s.$watch("record",function(e,r){r!==e&&s.refreshQuery()},!0)}s.getTotalVal=function(r,e){var t="",o=_.find(s.reportSchema.columnDefs,function(e){return e.field===r});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var n=0,i=0;i<s.report.length;i++)n+=s.report[i][r];t=n,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},s.$on("exportToPDF",function(){o.createPDF()}),s.$on("exportToCSV",function(){i.createCSV()}),s.extractFilter=function(e,r){var t,o,n;e.cellFilter&&(-1===(n=e.cellFilter.indexOf(":"))?t=e.cellFilter:(t=e.cellFilter.slice(0,n).trim(),"'"!==(o=e.cellFilter.slice(n+1,999).trim())[0]&&'"'!==o[0]||(o=o.slice(1,-1))),n=angular.element(document.body).injector().get("$filter")(t.trim()),r[e.field]={filter:n,filterParam:o})};var g,h,S,v=document.querySelector("div.report-grow"),E=(v&&(g=v.offsetLeft,h=v.offsetTop+g,S=(S=document.querySelector("div.ui-grid-header"))?S.clientHeight:31,r=Math.floor((r.innerHeight-h-S-g)/30),angular.element(v).css("height",30*r+"px")),e.navScope);E.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:i.createCSV,text:"Export as CSV"}],E.contextMenu="Report",E.contextMenuId="reportMenu",s.titleWithSubstitutions=s.reportSchema.title,s.inhibitRefresh||(s.refreshQuery=function(){function n(o){function a(e,r){let t;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?t=r?(s.param=e,s.$eval(r)):e.toISOString():e}return l(function(e){let i=[];o.replace(/\|.+?\|/g,function(e){var r=e.slice(1,-1),t=/(.+)\((.+)\)/.exec(r);if(t)try{var o=s.reportSchema.params[t[2]],n=o.value;2<t.length?i.push(c.get(`/api/${t[1]}/${n}/list`).then(function(e){return e&&200===e.status&&e.data?e.data.list:""})):i.push(Promise.resolve(a(n,o.conversionExpression)))}catch(e){console.error(e),i.push("Error in fng-reports: "+e.message)}else{t=s.reportSchema.params[r];i.push(Promise.resolve(a(t.value,t.conversionExpression)))}return e}),Promise.all(i).then(function(r){let t=0;e(o.replace(/\|.+?\|/g,function(){var e=r[t];return t+=1,e}))})})}var e="/api/report/"+s.modelName,r="?",t=!1,o=p.$$url.match(/\?.*/);if(s.reportSchemaName?e+="/"+s.reportSchemaName:o&&(d&&(s.paramSchema=JSON.parse(p.search().r).params,m(s.paramSchema)),e+=r+o[0].slice(1),r="&",t=!0),s.paramSchema){for(var i in s.record)if(s.record.hasOwnProperty(i)){var a=s.reportSchema.params[i];if(s.record[i]&&""!==s.record[i])s.param=s.record[i],a.conversionExpression&&(s.param=s.$eval(a.conversionExpression)),e+=r+i+"="+s.param,r="&";else if(a.required)return}}else!t&&o&&(e+=r+o[0].slice(1),r="&");return c.get(e).then(function(e){if(e&&e.data&&e.data.success){var r,t=e.data;if(s.report=t.report,s.reportSchema=t.schema,d){if(d=!1,t.schema.columnDefs&&0<t.schema.columnDefs.length)for(const o of t.schema.columnDefs)o.align&&(r="fng-"+o.align,o.cellClass=o.cellClass||"",-1===o.cellClass.indexOf(r))&&(o.cellClass=o.cellClass+" "+r),o.aggregationTypeStr&&(s.gridOptions.showColumnFooter=!0,o.aggregationType=u.aggregationTypes[o.aggregationTypeStr],o.aggregationHideLabel="sum"===o.aggregationTypeStr,o.footerCellFilter=o.cellFilter,o.footerCellClass=o.cellClass),s.gridOptions.columnDefs.push(o),o.width&&"string"==typeof o.width&&-1!==o.width.indexOf("px")&&(o.width=parseInt(o.width.slice(0,-2)));!s.paramSchema&&t.schema.params&&"1"!==p.$$search.noinput&&m(t.schema.params)}s.reportSchema.title=s.reportSchema.title||s.modelName,n(s.reportSchema.title).then(function(e){s.titleWithSubstitutions=e}),s.gridOptions.enableFiltering=!!s.reportSchema.filter,E&&E.items&&(E.items.length=2,s.reportSchema.menu)&&s.reportSchema.menu.forEach(function(e){n(JSON.stringify(e)).then(function(e){E.items.push(JSON.parse(e))})})}else s.showError(JSON.stringify(e.data.error),"Invalid Response Error"),s.reportSchema.title="Error - see console log"},function(e){let r,t;t=403===e.status?(r="You do not have permission to run this report (permission to GET all "+s.modelName+" records is required)","Permission denied"):(r="The server could not process the request","Error"),s.showError(r,t)})},s.refreshQuery()),s.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)},s.$on("$locationChangeStart",function(){delete E.contextMenu,delete E.items}),s.showError=function(r,e){if(s.alertTitle=e||"Error!","string"==typeof r)s.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)s.errorMessage=r.message;else if(r.data&&r.data.message)s.errorMessage=r.data.message;else try{s.errorMessage=JSON.stringify(r)}catch(e){s.errorMessage=r}else s.errorMessage="An error occurred - that's all we got. Sorry.";s.errorHideTimer=window.setTimeout(function(){s.dismissError(),s.$digest()},3500+1e3*(s.alertTitle+s.errorMessage).length/50),s.errorVisible=!0,window.setTimeout(()=>{s.$digest()})},s.clearTimeout=function(){s.errorHideTimer&&(clearTimeout(s.errorHideTimer),delete s.errorHideTimer)},s.dismissError=function(){s.clearTimeout,s.errorVisible=!1,delete s.errorMessage,delete s.alertTitle},s.stickError=function(){clearTimeout(s.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var a=this;a.grid=null,a.scope=null,a.services=null,a.init=function(e,r,t){a.grid=r,a.scope=e,a.services=t},a.createCSV=function(){var e,r,t;e=a.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(a.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},a.prepareCSV=function(){function o(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 n="",i={};return angular.forEach(a.grid.columns,function(e){var r;a.scope.extractFilter(e,i),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.cellTemplate?"HTML"===(r=a.scope.showsContent(e.colDef.cellTemplate,e.field))?(n+='"'+o(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?(n+='"'+o(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1:(n+='"'+o(e.displayName)+'",',e.doCSVExport=!0))}),n=e(n),angular.forEach(a.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(a.grid.columns,function(r){if(r.doCSVExport){let e=t.entity[r.field];"function"==typeof r.doCSVExport&&(e=r.doCSVExport(e)),n+='"'+o(e,i[r.field])+'",'}}),n=e(n))}),n}}function ngGridPdfExportPlugin(o){var l=this;l.grid=null,l.scope=null,l.services=null,l.options=o,l.init=function(e,r,t){l.grid=r,l.scope=e,l.services=t,o.inhibitButton||(e=r.$root.find(".ngFooterPanel"),null!=(t=r.$root.find(".ngFooterPanel .pdf-data-link-span"))&&t.remove(),e.append('<button class="pdf-data-link-span">PDF Export</button>'),e.on("click",function(){l.createPDF()}))},l.createPDF=function(){var o=[],n=[],e=[],i={},a={},r=(angular.forEach(l.grid.columns,function(e,r){var t;e.visible&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(t=l.scope.showsContent(e.colDef.cellTemplate,e.field))?(o.push(e.displayName),n.push(e.field),a[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")}):t&&(o.push(e.displayName),n.push(e.field)):(o.push(e.displayName),n.push(e.field))),e.colDef.totalsRow&&(e.field,l.grid.getTotalVal(e.field,e.filter).toString()),l.scope.extractFilter(e,i)}),angular.forEach(l.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(n.forEach(function(e){var r=t.entity[e];i[e]&&(r=i[e].filter(r,i[e].filterParam)),"string"==typeof(r=a[e]?a[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,"")),o.push(r)}),e.push(o))}),new jspdf.jsPDF("landscape","mm","a4"));r.autoTable({head:[o],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(n,t){return{scope:!1,compile:function(){return{pre:function(e,r){var t=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),t=t?e.col.cellTemplate.replace("COL_FIELD |"+t[1],'getTotalVal("'+e.col.field+'","'+t[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),o=e.col.enableCellEdit?(o=(o=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,t)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):t,t=n(o)(e);e.enableCellSelection&&-1===t[0].className.indexOf("ngSelectionCell")&&(t[0].setAttribute("tabindex",0),t.addClass("ngCellElement")),r.append(t)},post:function(e,r){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,r),e.$on("ngGridEventDigestCell",function(){t.digest(e)})}}}}}]);
|
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.237",
|
|
4
4
|
"description": "Reporting plugin for forms-angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"angular-messages": "1.8.3",
|
|
34
34
|
"angular-mocks": "1.8.3",
|
|
35
35
|
"angular-sanitize": "1.8.3",
|
|
36
|
-
"forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.
|
|
36
|
+
"forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.237.tgz",
|
|
37
37
|
"grunt": "^1.5.3",
|
|
38
38
|
"grunt-autoprefixer": "3.0.4",
|
|
39
39
|
"grunt-concurrent": "3.0.0",
|
package/src/fng-reports.js
CHANGED
|
@@ -37,7 +37,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter
|
|
|
37
37
|
isParamTest = /\((.+)\)/.exec(param);
|
|
38
38
|
if (isParamTest) {
|
|
39
39
|
var instructions = $scope.reportSchema.params[isParamTest[1]];
|
|
40
|
-
if (instructions) {
|
|
40
|
+
if (instructions && $scope.record) {
|
|
41
41
|
$scope.param = $scope.record[isParamTest[1]];
|
|
42
42
|
if (instructions.conversionExpression) {
|
|
43
43
|
return $scope.$eval(instructions.conversionExpression);
|
|
@@ -243,23 +243,36 @@ ${e.message}`);
|
|
|
243
243
|
$scope.refreshQuery = function () {
|
|
244
244
|
|
|
245
245
|
function substituteParams(str) {
|
|
246
|
-
function toTextValue(obj) {
|
|
246
|
+
function toTextValue(obj, conversionExpression) {
|
|
247
|
+
let retVal;
|
|
248
|
+
if (!(obj instanceof Date)) {
|
|
249
|
+
if (typeof obj === 'string' && obj.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} \d{4}/)) {
|
|
250
|
+
obj = new Date(obj.replace(' ', '+'));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
247
253
|
if (obj instanceof Date) {
|
|
248
|
-
|
|
254
|
+
if (conversionExpression) {
|
|
255
|
+
$scope.param = obj;
|
|
256
|
+
retVal = $scope.$eval(conversionExpression);
|
|
257
|
+
} else {
|
|
258
|
+
retVal = obj.toISOString();
|
|
259
|
+
}
|
|
249
260
|
} else {
|
|
250
261
|
return obj;
|
|
251
262
|
}
|
|
263
|
+
return retVal;
|
|
252
264
|
}
|
|
253
265
|
return $q(function (resolve) {
|
|
254
266
|
let promises = [];
|
|
255
267
|
str.replace(/\|.+?\|/g, function (match) {
|
|
256
268
|
var param = match.slice(1, -1);
|
|
257
269
|
// See if we have a function to run (check for brackets)
|
|
258
|
-
var hasBrackets =
|
|
270
|
+
var hasBrackets = /(.+)\((.+)\)/.exec(param);
|
|
259
271
|
if (hasBrackets) {
|
|
260
272
|
try {
|
|
261
|
-
const
|
|
262
|
-
|
|
273
|
+
const paramsObj = $scope.reportSchema.params[hasBrackets[2]];
|
|
274
|
+
const paramValue = paramsObj.value;
|
|
275
|
+
if (hasBrackets.length > 2) {
|
|
263
276
|
// We have a title function to run
|
|
264
277
|
promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
|
|
265
278
|
if (response && response.status === 200 && response.data) {
|
|
@@ -269,14 +282,15 @@ ${e.message}`);
|
|
|
269
282
|
}
|
|
270
283
|
}));
|
|
271
284
|
} else {
|
|
272
|
-
promises.push(Promise.resolve(toTextValue(
|
|
285
|
+
promises.push(Promise.resolve(toTextValue(paramValue, paramsObj.conversionExpression)));
|
|
273
286
|
}
|
|
274
287
|
} catch(e) {
|
|
275
288
|
console.error(e);
|
|
276
289
|
promises.push('Error in fng-reports: ' + e.message);
|
|
277
290
|
}
|
|
278
291
|
} else {
|
|
279
|
-
|
|
292
|
+
const paramsObj = $scope.reportSchema.params[param];
|
|
293
|
+
promises.push(Promise.resolve(toTextValue(paramsObj.value, paramsObj.conversionExpression)));
|
|
280
294
|
}
|
|
281
295
|
return match;
|
|
282
296
|
});
|
|
@@ -364,7 +378,7 @@ ${e.message}`);
|
|
|
364
378
|
}
|
|
365
379
|
}
|
|
366
380
|
|
|
367
|
-
if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !==
|
|
381
|
+
if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== '1') {
|
|
368
382
|
setupParamsForm(data.schema.params);
|
|
369
383
|
}
|
|
370
384
|
|