fng-reports 0.12.0-beta.236 → 0.12.0-beta.238

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.
@@ -1,4 +1,4 @@
1
- /*! forms-angular 2023-10-31 */
1
+ /*! forms-angular 2023-11-14 */
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,40 +244,60 @@ ${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
- return obj.toISOString();
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 = /\((.+)\)/.exec(param);
271
+ var hasBrackets = /(.*)\((.+)\)/.exec(param);
272
+ let promise;
260
273
  if (hasBrackets) {
261
274
  try {
262
- const paramValue = $scope.reportSchema.params[hasBrackets[0].slice(1,-1)].value;
263
- if (hasBrackets.index > 0) {
264
- // We have a title function to run
265
- promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
266
- if (response && response.status === 200 && response.data) {
267
- return response.data.list;
268
- } else {
269
- return '';
270
- }
271
- }));
275
+ const paramsObj = $scope.reportSchema.params[hasBrackets[2]];
276
+ const paramValue = paramsObj.value;
277
+ if (hasBrackets.length > 2) {
278
+ // We may have a title function to run
279
+ if (hasBrackets[1] !== '') {
280
+ promise = $http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
281
+ if (response && response.status === 200 && response.data) {
282
+ return response.data.list;
283
+ } else {
284
+ return '';
285
+ }
286
+ });
287
+ }
288
+ }
289
+ if (promise) {
290
+ promises.push(promise);
272
291
  } else {
273
- promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[hasBrackets[1]].value)));
292
+ promises.push(Promise.resolve(toTextValue(paramValue, paramsObj.conversionExpression)));
274
293
  }
275
294
  } catch(e) {
276
295
  console.error(e);
277
296
  promises.push('Error in fng-reports: ' + e.message);
278
297
  }
279
298
  } else {
280
- promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[param].value)));
299
+ const paramsObj = $scope.reportSchema.params[param];
300
+ promises.push(Promise.resolve(toTextValue(paramsObj.value, paramsObj.conversionExpression)));
281
301
  }
282
302
  return match;
283
303
  });
@@ -365,7 +385,7 @@ ${e.message}`);
365
385
  }
366
386
  }
367
387
 
368
- if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
388
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== '1') {
369
389
  setupParamsForm(data.schema.params);
370
390
  }
371
391
 
@@ -1,3 +1,3 @@
1
- /*! forms-angular 2023-10-31 */
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("&nbsp;"," ").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("&nbsp;"," ").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)})}}}}}]);
1
+ /*! forms-angular 2023-11-14 */
2
+ "use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$q","$filter","$scope","$http","$location","CssFrameworkService","RoutingService","uiGridConstants",function(e,r,s,a,c,p,l,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(c,t.parsePathFunc()(l.$$path)),c.reportSchema={},c.gridOptions={enableFiltering:!1,data:"report",columnDefs:c.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,i],onRegisterApi:function(r){c.gridApi=r,c.gridOptions.plugins.forEach(function(e){e.init(c,r.grid,null)}),r.selection.on.rowSelectionChanged(c,function(o){var e=c.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=c.reportSchema.params[t[1]])&&c.record?(c.param=c.record[t[1]],r.conversionExpression?c.$eval(r.conversionExpression):r.value):c.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")||{}}),p(o),r.stopPropagation()}}},c.report=[],!c.reportSchemaName&&l.$$search.r)switch(l.$$search.r.slice(0,1)){case"[":c.reportSchema.pipeline=f(l.$$search.r);break;case"{":angular.extend(c.reportSchema,f(l.$$search.r));break;default:throw new Error("No report instructions specified")}function m(e){for(var r in c.paramSchema=[],c.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=c.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&&(c[r+"_Opts"]=t.enum,c.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])),c.record[r]=t.value)}c.$watch("record",function(e,r){r!==e&&c.refreshQuery()},!0)}c.getTotalVal=function(r,e){var t="",o=_.find(c.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<c.report.length;i++)n+=c.report[i][r];t=n,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},c.$on("exportToPDF",function(){o.createPDF()}),c.$on("exportToCSV",function(){i.createCSV()}),c.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",c.titleWithSubstitutions=c.reportSchema.title,c.inhibitRefresh||(c.refreshQuery=function(){function n(o){function l(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?(c.param=e,c.$eval(r)):e.toISOString():e}return s(function(e){let a=[];o.replace(/\|.+?\|/g,function(e){var r=e.slice(1,-1),t=/(.*)\((.+)\)/.exec(r);let o;if(t)try{var n=c.reportSchema.params[t[2]],i=n.value;(o=2<t.length&&""!==t[1]?p.get(`/api/${t[1]}/${i}/list`).then(function(e){return e&&200===e.status&&e.data?e.data.list:""}):o)?a.push(o):a.push(Promise.resolve(l(i,n.conversionExpression)))}catch(e){console.error(e),a.push("Error in fng-reports: "+e.message)}else{t=c.reportSchema.params[r];a.push(Promise.resolve(l(t.value,t.conversionExpression)))}return e}),Promise.all(a).then(function(r){let t=0;e(o.replace(/\|.+?\|/g,function(){var e=r[t];return t+=1,e}))})})}var e="/api/report/"+c.modelName,r="?",t=!1,o=l.$$url.match(/\?.*/);if(c.reportSchemaName?e+="/"+c.reportSchemaName:o&&(d&&(c.paramSchema=JSON.parse(l.search().r).params,m(c.paramSchema)),e+=r+o[0].slice(1),r="&",t=!0),c.paramSchema){for(var i in c.record)if(c.record.hasOwnProperty(i)){var a=c.reportSchema.params[i];if(c.record[i]&&""!==c.record[i])c.param=c.record[i],a.conversionExpression&&(c.param=c.$eval(a.conversionExpression)),e+=r+i+"="+c.param,r="&";else if(a.required)return}}else!t&&o&&(e+=r+o[0].slice(1),r="&");return p.get(e).then(function(e){if(e&&e.data&&e.data.success){var r,t=e.data;if(c.report=t.report,c.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&&(c.gridOptions.showColumnFooter=!0,o.aggregationType=u.aggregationTypes[o.aggregationTypeStr],o.aggregationHideLabel="sum"===o.aggregationTypeStr,o.footerCellFilter=o.cellFilter,o.footerCellClass=o.cellClass),c.gridOptions.columnDefs.push(o),o.width&&"string"==typeof o.width&&-1!==o.width.indexOf("px")&&(o.width=parseInt(o.width.slice(0,-2)));!c.paramSchema&&t.schema.params&&"1"!==l.$$search.noinput&&m(t.schema.params)}c.reportSchema.title=c.reportSchema.title||c.modelName,n(c.reportSchema.title).then(function(e){c.titleWithSubstitutions=e}),c.gridOptions.enableFiltering=!!c.reportSchema.filter,E&&E.items&&(E.items.length=2,c.reportSchema.menu)&&c.reportSchema.menu.forEach(function(e){n(JSON.stringify(e)).then(function(e){E.items.push(JSON.parse(e))})})}else c.showError(JSON.stringify(e.data.error),"Invalid Response Error"),c.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 "+c.modelName+" records is required)","Permission denied"):(r="The server could not process the request","Error"),c.showError(r,t)})},c.refreshQuery()),c.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)},c.$on("$locationChangeStart",function(){delete E.contextMenu,delete E.items}),c.showError=function(r,e){if(c.alertTitle=e||"Error!","string"==typeof r)c.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)c.errorMessage=r.message;else if(r.data&&r.data.message)c.errorMessage=r.data.message;else try{c.errorMessage=JSON.stringify(r)}catch(e){c.errorMessage=r}else c.errorMessage="An error occurred - that's all we got. Sorry.";c.errorHideTimer=window.setTimeout(function(){c.dismissError(),c.$digest()},3500+1e3*(c.alertTitle+c.errorMessage).length/50),c.errorVisible=!0,window.setTimeout(()=>{c.$digest()})},c.clearTimeout=function(){c.errorHideTimer&&(clearTimeout(c.errorHideTimer),delete c.errorHideTimer)},c.dismissError=function(){c.clearTimeout,c.errorVisible=!1,delete c.errorMessage,delete c.alertTitle},c.stickError=function(){clearTimeout(c.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("&nbsp;"," ").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("&nbsp;"," ").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.236",
3
+ "version": "0.12.0-beta.238",
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.236.tgz",
36
+ "forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.238.tgz",
37
37
  "grunt": "^1.5.3",
38
38
  "grunt-autoprefixer": "3.0.4",
39
39
  "grunt-concurrent": "3.0.0",
@@ -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,40 +243,60 @@ ${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
- return obj.toISOString();
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 = /\((.+)\)/.exec(param);
270
+ var hasBrackets = /(.*)\((.+)\)/.exec(param);
271
+ let promise;
259
272
  if (hasBrackets) {
260
273
  try {
261
- const paramValue = $scope.reportSchema.params[hasBrackets[0].slice(1,-1)].value;
262
- if (hasBrackets.index > 0) {
263
- // We have a title function to run
264
- promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
265
- if (response && response.status === 200 && response.data) {
266
- return response.data.list;
267
- } else {
268
- return '';
269
- }
270
- }));
274
+ const paramsObj = $scope.reportSchema.params[hasBrackets[2]];
275
+ const paramValue = paramsObj.value;
276
+ if (hasBrackets.length > 2) {
277
+ // We may have a title function to run
278
+ if (hasBrackets[1] !== '') {
279
+ promise = $http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
280
+ if (response && response.status === 200 && response.data) {
281
+ return response.data.list;
282
+ } else {
283
+ return '';
284
+ }
285
+ });
286
+ }
287
+ }
288
+ if (promise) {
289
+ promises.push(promise);
271
290
  } else {
272
- promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[hasBrackets[1]].value)));
291
+ promises.push(Promise.resolve(toTextValue(paramValue, paramsObj.conversionExpression)));
273
292
  }
274
293
  } catch(e) {
275
294
  console.error(e);
276
295
  promises.push('Error in fng-reports: ' + e.message);
277
296
  }
278
297
  } else {
279
- promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[param].value)));
298
+ const paramsObj = $scope.reportSchema.params[param];
299
+ promises.push(Promise.resolve(toTextValue(paramsObj.value, paramsObj.conversionExpression)));
280
300
  }
281
301
  return match;
282
302
  });
@@ -364,7 +384,7 @@ ${e.message}`);
364
384
  }
365
385
  }
366
386
 
367
- if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
387
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== '1') {
368
388
  setupParamsForm(data.schema.params);
369
389
  }
370
390