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

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-25 */
1
+ /*! forms-angular 2023-10-31 */
2
2
  'use strict';
3
3
 
4
4
  formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService', 'uiGridConstants',
@@ -11,7 +11,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter
11
11
 
12
12
  angular.extend($scope, RoutingService.parsePathFunc()($location.$$path));
13
13
 
14
- $scope.reportSchema = { columnDefs: [{ name: 'Preparing... ', field: 'Preparing... ' },] };
14
+ $scope.reportSchema = {};
15
15
  $scope.gridOptions = {
16
16
  enableFiltering: false,
17
17
  data: 'report',
@@ -244,6 +244,13 @@ ${e.message}`);
244
244
  $scope.refreshQuery = function () {
245
245
 
246
246
  function substituteParams(str) {
247
+ function toTextValue(obj) {
248
+ if (obj instanceof Date) {
249
+ return obj.toISOString();
250
+ } else {
251
+ return obj;
252
+ }
253
+ }
247
254
  return $q(function (resolve) {
248
255
  let promises = [];
249
256
  str.replace(/\|.+?\|/g, function (match) {
@@ -263,14 +270,14 @@ ${e.message}`);
263
270
  }
264
271
  }));
265
272
  } else {
266
- promises.push('Error 265');
273
+ promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[hasBrackets[1]].value)));
267
274
  }
268
275
  } catch(e) {
269
276
  console.error(e);
270
- promises.push('Error 269');
277
+ promises.push('Error in fng-reports: ' + e.message);
271
278
  }
272
279
  } else {
273
- promises.push($scope.reportSchema.params[param].value);
280
+ promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[param].value)));
274
281
  }
275
282
  return match;
276
283
  });
@@ -332,35 +339,10 @@ ${e.message}`);
332
339
  var data = response.data;
333
340
  $scope.report = data.report;
334
341
  $scope.reportSchema = data.schema;
335
- $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
336
- substituteParams($scope.reportSchema.title)
337
- .then(function (str) {
338
- $scope.titleWithSubstitutions = str;
339
- });
340
- $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
341
- if (navScope && navScope.items) {
342
- navScope.items.length = 2;
343
- if ($scope.reportSchema.menu) {
344
- $scope.reportSchema.menu.forEach(function (m) {
345
- substituteParams(JSON.stringify(m)).then(function (str) {
346
- navScope.items.push(JSON.parse(str));
347
- });
348
- });
349
- }
350
- }
351
-
352
- /*
353
- Generate link data
354
- */
355
-
356
342
  if (firstTime) {
357
343
  firstTime = false;
358
-
359
- $scope.$watch('reportSchema.columnDefs', function (newValue) {
360
- // var columnTotals = false;
361
- if (newValue) {
362
- $scope.gridOptions.columnDefs.length = 0;
363
- for (const colDef of newValue) {
344
+ if (data.schema.columnDefs && data.schema.columnDefs.length > 0) {
345
+ for (const colDef of data.schema.columnDefs) {
364
346
  if (colDef.align) {
365
347
  var alignClass = 'fng-' + colDef.align;
366
348
  colDef.cellClass = colDef.cellClass || '';
@@ -376,20 +358,33 @@ ${e.message}`);
376
358
  colDef.footerCellClass = colDef.cellClass;
377
359
  }
378
360
  $scope.gridOptions.columnDefs.push(colDef);
379
- }
380
- // Auto-upgrade from ng-grid to ui-grid
381
- newValue.forEach(function (def) {
382
361
  // Remove px from column widths
383
- if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
384
- def.width = parseInt(def.width.slice(0, -2));
362
+ if (colDef.width && typeof colDef.width === 'string' && colDef.width.indexOf('px') !== -1) {
363
+ colDef.width = parseInt(colDef.width.slice(0, -2));
385
364
  }
386
- });
387
- }
388
- }, true);
365
+ }
366
+ }
389
367
 
390
- if (!$scope.paramSchema && data.schema.params) {
368
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
391
369
  setupParamsForm(data.schema.params);
392
370
  }
371
+
372
+ }
373
+ $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
374
+ substituteParams($scope.reportSchema.title)
375
+ .then(function (str) {
376
+ $scope.titleWithSubstitutions = str;
377
+ });
378
+ $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
379
+ if (navScope && navScope.items) {
380
+ navScope.items.length = 2;
381
+ if ($scope.reportSchema.menu) {
382
+ $scope.reportSchema.menu.forEach(function (m) {
383
+ substituteParams(JSON.stringify(m)).then(function (str) {
384
+ navScope.items.push(JSON.parse(str));
385
+ });
386
+ });
387
+ }
393
388
  }
394
389
  } else {
395
390
  $scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');
@@ -1,3 +1,3 @@
1
- /*! forms-angular 2023-10-25 */
1
+ /*! forms-angular 2023-10-31 */
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={columnDefs:[{name:"Preparing... ",field:"Preparing... "}]},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 t(o){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("Error 265")}catch(e){console.error(e),n.push("Error 269")}else n.push(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="?",o=!1,n=p.$$url.match(/\?.*/);if(s.reportSchemaName?e+="/"+s.reportSchemaName:n&&(d&&(s.paramSchema=JSON.parse(p.search().r).params,m(s.paramSchema)),e+=r+n[0].slice(1),r="&",o=!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!o&&n&&(e+=r+n[0].slice(1),r="&");return c.get(e).then(function(e){var r;e&&e.data&&e.data.success?(r=e.data,s.report=r.report,s.reportSchema=r.schema,s.reportSchema.title=s.reportSchema.title||s.modelName,t(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){t(JSON.stringify(e)).then(function(e){E.items.push(JSON.parse(e))})}),d&&(d=!1,s.$watch("reportSchema.columnDefs",function(e){if(e){s.gridOptions.columnDefs.length=0;for(const t of e){var r;t.align&&(r="fng-"+t.align,t.cellClass=t.cellClass||"",-1===t.cellClass.indexOf(r))&&(t.cellClass=t.cellClass+" "+r),t.aggregationTypeStr&&(s.gridOptions.showColumnFooter=!0,t.aggregationType=u.aggregationTypes[t.aggregationTypeStr],t.aggregationHideLabel="sum"===t.aggregationTypeStr,t.footerCellFilter=t.cellFilter,t.footerCellClass=t.cellClass),s.gridOptions.columnDefs.push(t)}e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))})}},!0),!s.paramSchema)&&r.schema.params&&m(r.schema.params)):(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)})}}}}}]);
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)})}}}}}]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-reports",
3
- "version": "0.12.0-beta.234",
3
+ "version": "0.12.0-beta.236",
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.234.tgz",
36
+ "forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.236.tgz",
37
37
  "grunt": "^1.5.3",
38
38
  "grunt-autoprefixer": "3.0.4",
39
39
  "grunt-concurrent": "3.0.0",
@@ -10,7 +10,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter
10
10
 
11
11
  angular.extend($scope, RoutingService.parsePathFunc()($location.$$path));
12
12
 
13
- $scope.reportSchema = { columnDefs: [{ name: 'Preparing... ', field: 'Preparing... ' },] };
13
+ $scope.reportSchema = {};
14
14
  $scope.gridOptions = {
15
15
  enableFiltering: false,
16
16
  data: 'report',
@@ -243,6 +243,13 @@ ${e.message}`);
243
243
  $scope.refreshQuery = function () {
244
244
 
245
245
  function substituteParams(str) {
246
+ function toTextValue(obj) {
247
+ if (obj instanceof Date) {
248
+ return obj.toISOString();
249
+ } else {
250
+ return obj;
251
+ }
252
+ }
246
253
  return $q(function (resolve) {
247
254
  let promises = [];
248
255
  str.replace(/\|.+?\|/g, function (match) {
@@ -262,14 +269,14 @@ ${e.message}`);
262
269
  }
263
270
  }));
264
271
  } else {
265
- promises.push('Error 265');
272
+ promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[hasBrackets[1]].value)));
266
273
  }
267
274
  } catch(e) {
268
275
  console.error(e);
269
- promises.push('Error 269');
276
+ promises.push('Error in fng-reports: ' + e.message);
270
277
  }
271
278
  } else {
272
- promises.push($scope.reportSchema.params[param].value);
279
+ promises.push(Promise.resolve(toTextValue($scope.reportSchema.params[param].value)));
273
280
  }
274
281
  return match;
275
282
  });
@@ -331,35 +338,10 @@ ${e.message}`);
331
338
  var data = response.data;
332
339
  $scope.report = data.report;
333
340
  $scope.reportSchema = data.schema;
334
- $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
335
- substituteParams($scope.reportSchema.title)
336
- .then(function (str) {
337
- $scope.titleWithSubstitutions = str;
338
- });
339
- $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
340
- if (navScope && navScope.items) {
341
- navScope.items.length = 2;
342
- if ($scope.reportSchema.menu) {
343
- $scope.reportSchema.menu.forEach(function (m) {
344
- substituteParams(JSON.stringify(m)).then(function (str) {
345
- navScope.items.push(JSON.parse(str));
346
- });
347
- });
348
- }
349
- }
350
-
351
- /*
352
- Generate link data
353
- */
354
-
355
341
  if (firstTime) {
356
342
  firstTime = false;
357
-
358
- $scope.$watch('reportSchema.columnDefs', function (newValue) {
359
- // var columnTotals = false;
360
- if (newValue) {
361
- $scope.gridOptions.columnDefs.length = 0;
362
- for (const colDef of newValue) {
343
+ if (data.schema.columnDefs && data.schema.columnDefs.length > 0) {
344
+ for (const colDef of data.schema.columnDefs) {
363
345
  if (colDef.align) {
364
346
  var alignClass = 'fng-' + colDef.align;
365
347
  colDef.cellClass = colDef.cellClass || '';
@@ -375,20 +357,33 @@ ${e.message}`);
375
357
  colDef.footerCellClass = colDef.cellClass;
376
358
  }
377
359
  $scope.gridOptions.columnDefs.push(colDef);
378
- }
379
- // Auto-upgrade from ng-grid to ui-grid
380
- newValue.forEach(function (def) {
381
360
  // Remove px from column widths
382
- if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
383
- def.width = parseInt(def.width.slice(0, -2));
361
+ if (colDef.width && typeof colDef.width === 'string' && colDef.width.indexOf('px') !== -1) {
362
+ colDef.width = parseInt(colDef.width.slice(0, -2));
384
363
  }
385
- });
386
- }
387
- }, true);
364
+ }
365
+ }
388
366
 
389
- if (!$scope.paramSchema && data.schema.params) {
367
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
390
368
  setupParamsForm(data.schema.params);
391
369
  }
370
+
371
+ }
372
+ $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
373
+ substituteParams($scope.reportSchema.title)
374
+ .then(function (str) {
375
+ $scope.titleWithSubstitutions = str;
376
+ });
377
+ $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
378
+ if (navScope && navScope.items) {
379
+ navScope.items.length = 2;
380
+ if ($scope.reportSchema.menu) {
381
+ $scope.reportSchema.menu.forEach(function (m) {
382
+ substituteParams(JSON.stringify(m)).then(function (str) {
383
+ navScope.items.push(JSON.parse(str));
384
+ });
385
+ });
386
+ }
392
387
  }
393
388
  } else {
394
389
  $scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');