fng-reports 0.12.0-beta.233 → 0.12.0-beta.235

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-24 */
1
+ /*! forms-angular 2023-10-28 */
2
2
  'use strict';
3
3
 
4
4
  formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService', 'uiGridConstants',
@@ -11,11 +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 = {
15
- columnDefs: [
16
- // { name: 'dummy', field: 'dummy' },
17
- ]
18
- };
14
+ $scope.reportSchema = {};
19
15
  $scope.gridOptions = {
20
16
  enableFiltering: false,
21
17
  data: 'report',
@@ -252,23 +248,29 @@ ${e.message}`);
252
248
  let promises = [];
253
249
  str.replace(/\|.+?\|/g, function (match) {
254
250
  var param = match.slice(1, -1);
255
- var isParamTest = /\((.+)\)/.exec(param);
256
- if (isParamTest[1]) {
257
- const paramValue = $scope.reportSchema.params[isParamTest[1]].value;
258
- if (isParamTest.index > 0) {
259
- // We have a title function to run
260
- promises.push($http.get(`/api/${'organisation'}/${paramValue}/list`).then(function (response) {
261
- if (response && response.status === 200 && response.data) {
262
- return response.data.list;
263
- } else {
264
- return '';
265
- }
266
- }));
267
- } else {
268
- promises.push(paramValue);
251
+ // See if we have a function to run (check for brackets)
252
+ var hasBrackets = /\((.+)\)/.exec(param);
253
+ if (hasBrackets) {
254
+ try {
255
+ const paramValue = $scope.reportSchema.params[hasBrackets[0].slice(1,-1)].value;
256
+ if (hasBrackets.index > 0) {
257
+ // We have a title function to run
258
+ promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
259
+ if (response && response.status === 200 && response.data) {
260
+ return response.data.list;
261
+ } else {
262
+ return '';
263
+ }
264
+ }));
265
+ } else {
266
+ promises.push('Error 265');
267
+ }
268
+ } catch(e) {
269
+ console.error(e);
270
+ promises.push('Error 269');
269
271
  }
270
272
  } else {
271
- promises.push('');
273
+ promises.push($scope.reportSchema.params[param].value);
272
274
  }
273
275
  return match;
274
276
  });
@@ -330,35 +332,10 @@ ${e.message}`);
330
332
  var data = response.data;
331
333
  $scope.report = data.report;
332
334
  $scope.reportSchema = data.schema;
333
- $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
334
- substituteParams($scope.reportSchema.title)
335
- .then(function (str) {
336
- $scope.titleWithSubstitutions = str;
337
- });
338
- $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
339
- if (navScope && navScope.items) {
340
- navScope.items.length = 2;
341
- if ($scope.reportSchema.menu) {
342
- $scope.reportSchema.menu.forEach(function (m) {
343
- substituteParams(JSON.stringify(m)).then(function (str) {
344
- navScope.items.push(JSON.parse(str));
345
- });
346
- });
347
- }
348
- }
349
-
350
- /*
351
- Generate link data
352
- */
353
-
354
335
  if (firstTime) {
355
336
  firstTime = false;
356
-
357
- $scope.$watch('reportSchema.columnDefs', function (newValue) {
358
- // var columnTotals = false;
359
- if (newValue) {
360
- $scope.gridOptions.columnDefs.length = 0;
361
- for (const colDef of newValue) {
337
+ if (data.schema.columnDefs && data.schema.columnDefs.length > 0) {
338
+ for (const colDef of data.schema.columnDefs) {
362
339
  if (colDef.align) {
363
340
  var alignClass = 'fng-' + colDef.align;
364
341
  colDef.cellClass = colDef.cellClass || '';
@@ -374,20 +351,33 @@ ${e.message}`);
374
351
  colDef.footerCellClass = colDef.cellClass;
375
352
  }
376
353
  $scope.gridOptions.columnDefs.push(colDef);
377
- }
378
- // Auto-upgrade from ng-grid to ui-grid
379
- newValue.forEach(function (def) {
380
354
  // Remove px from column widths
381
- if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
382
- def.width = parseInt(def.width.slice(0, -2));
355
+ if (colDef.width && typeof colDef.width === 'string' && colDef.width.indexOf('px') !== -1) {
356
+ colDef.width = parseInt(colDef.width.slice(0, -2));
383
357
  }
384
- });
385
- }
386
- }, true);
358
+ }
359
+ }
387
360
 
388
- if (!$scope.paramSchema && data.schema.params) {
361
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
389
362
  setupParamsForm(data.schema.params);
390
363
  }
364
+
365
+ }
366
+ $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
367
+ substituteParams($scope.reportSchema.title)
368
+ .then(function (str) {
369
+ $scope.titleWithSubstitutions = str;
370
+ });
371
+ $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
372
+ if (navScope && navScope.items) {
373
+ navScope.items.length = 2;
374
+ if ($scope.reportSchema.menu) {
375
+ $scope.reportSchema.menu.forEach(function (m) {
376
+ substituteParams(JSON.stringify(m)).then(function (str) {
377
+ navScope.items.push(JSON.parse(str));
378
+ });
379
+ });
380
+ }
391
381
  }
392
382
  } else {
393
383
  $scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');
@@ -1,3 +1,3 @@
1
- /*! forms-angular 2023-10-24 */
1
+ /*! forms-angular 2023-10-28 */
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:[]},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(n){return l(function(e){let o=[];n.replace(/\|.+?\|/g,function(e){var r,t=e.slice(1,-1),t=/\((.+)\)/.exec(t);return t[1]?(r=s.reportSchema.params[t[1]].value,0<t.index?o.push(c.get(`/api/organisation/${r}/list`).then(function(e){return e&&200===e.status&&e.data?e.data.list:""})):o.push(r)):o.push(""),e}),Promise.all(o).then(function(r){let t=0;e(n.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){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="?",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.233",
3
+ "version": "0.12.0-beta.235",
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.233.tgz",
36
+ "forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.235.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: [] };
13
+ $scope.reportSchema = {};
14
14
  $scope.gridOptions = {
15
15
  enableFiltering: false,
16
16
  data: 'report',
@@ -247,23 +247,29 @@ ${e.message}`);
247
247
  let promises = [];
248
248
  str.replace(/\|.+?\|/g, function (match) {
249
249
  var param = match.slice(1, -1);
250
- var isParamTest = /\((.+)\)/.exec(param);
251
- if (isParamTest[1]) {
252
- const paramValue = $scope.reportSchema.params[isParamTest[1]].value;
253
- if (isParamTest.index > 0) {
254
- // We have a title function to run
255
- promises.push($http.get(`/api/${'organisation'}/${paramValue}/list`).then(function (response) {
256
- if (response && response.status === 200 && response.data) {
257
- return response.data.list;
258
- } else {
259
- return '';
260
- }
261
- }));
262
- } else {
263
- promises.push(paramValue);
250
+ // See if we have a function to run (check for brackets)
251
+ var hasBrackets = /\((.+)\)/.exec(param);
252
+ if (hasBrackets) {
253
+ try {
254
+ const paramValue = $scope.reportSchema.params[hasBrackets[0].slice(1,-1)].value;
255
+ if (hasBrackets.index > 0) {
256
+ // We have a title function to run
257
+ promises.push($http.get(`/api/${hasBrackets[1]}/${paramValue}/list`).then(function (response) {
258
+ if (response && response.status === 200 && response.data) {
259
+ return response.data.list;
260
+ } else {
261
+ return '';
262
+ }
263
+ }));
264
+ } else {
265
+ promises.push('Error 265');
266
+ }
267
+ } catch(e) {
268
+ console.error(e);
269
+ promises.push('Error 269');
264
270
  }
265
271
  } else {
266
- promises.push('');
272
+ promises.push($scope.reportSchema.params[param].value);
267
273
  }
268
274
  return match;
269
275
  });
@@ -325,35 +331,10 @@ ${e.message}`);
325
331
  var data = response.data;
326
332
  $scope.report = data.report;
327
333
  $scope.reportSchema = data.schema;
328
- $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
329
- substituteParams($scope.reportSchema.title)
330
- .then(function (str) {
331
- $scope.titleWithSubstitutions = str;
332
- });
333
- $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
334
- if (navScope && navScope.items) {
335
- navScope.items.length = 2;
336
- if ($scope.reportSchema.menu) {
337
- $scope.reportSchema.menu.forEach(function (m) {
338
- substituteParams(JSON.stringify(m)).then(function (str) {
339
- navScope.items.push(JSON.parse(str));
340
- });
341
- });
342
- }
343
- }
344
-
345
- /*
346
- Generate link data
347
- */
348
-
349
334
  if (firstTime) {
350
335
  firstTime = false;
351
-
352
- $scope.$watch('reportSchema.columnDefs', function (newValue) {
353
- // var columnTotals = false;
354
- if (newValue) {
355
- $scope.gridOptions.columnDefs.length = 0;
356
- for (const colDef of newValue) {
336
+ if (data.schema.columnDefs && data.schema.columnDefs.length > 0) {
337
+ for (const colDef of data.schema.columnDefs) {
357
338
  if (colDef.align) {
358
339
  var alignClass = 'fng-' + colDef.align;
359
340
  colDef.cellClass = colDef.cellClass || '';
@@ -369,20 +350,33 @@ ${e.message}`);
369
350
  colDef.footerCellClass = colDef.cellClass;
370
351
  }
371
352
  $scope.gridOptions.columnDefs.push(colDef);
372
- }
373
- // Auto-upgrade from ng-grid to ui-grid
374
- newValue.forEach(function (def) {
375
353
  // Remove px from column widths
376
- if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
377
- def.width = parseInt(def.width.slice(0, -2));
354
+ if (colDef.width && typeof colDef.width === 'string' && colDef.width.indexOf('px') !== -1) {
355
+ colDef.width = parseInt(colDef.width.slice(0, -2));
378
356
  }
379
- });
380
- }
381
- }, true);
357
+ }
358
+ }
382
359
 
383
- if (!$scope.paramSchema && data.schema.params) {
360
+ if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== "1") {
384
361
  setupParamsForm(data.schema.params);
385
362
  }
363
+
364
+ }
365
+ $scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
366
+ substituteParams($scope.reportSchema.title)
367
+ .then(function (str) {
368
+ $scope.titleWithSubstitutions = str;
369
+ });
370
+ $scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
371
+ if (navScope && navScope.items) {
372
+ navScope.items.length = 2;
373
+ if ($scope.reportSchema.menu) {
374
+ $scope.reportSchema.menu.forEach(function (m) {
375
+ substituteParams(JSON.stringify(m)).then(function (str) {
376
+ navScope.items.push(JSON.parse(str));
377
+ });
378
+ });
379
+ }
386
380
  }
387
381
  } else {
388
382
  $scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');