fng-reports 0.12.0-beta.190 → 0.12.0-beta.192

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 2022-06-03 */
1
+ /*! forms-angular 2022-08-05 */
2
2
  'use strict';
3
3
 
4
4
  formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
@@ -178,7 +178,6 @@ ${e.message}`);
178
178
  }
179
179
  $scope.$watch('record', function (newValue, oldValue) {
180
180
  if (oldValue !== newValue) {
181
- console.log('In the record watch ', JSON.stringify(newValue, null, 2));
182
181
  $scope.refreshQuery();
183
182
  }
184
183
  }, true);
@@ -334,8 +333,12 @@ ${e.message}`);
334
333
 
335
334
  // Check whether a cell template shows the content (in which case we want to output it) or does something funky
336
335
  // (for example displays an image)
337
- $scope.showsContent = function (template) {
338
- return /{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''));
336
+ $scope.showsContent = function (template, col) {
337
+ if (/{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''))) {
338
+ return true;
339
+ } else if (template.indexOf('ng-bind-html="row.entity.' + col) !== -1) {
340
+ return 'HTML';
341
+ }
339
342
  };
340
343
 
341
344
  $scope.$on('$locationChangeStart', function () {
@@ -500,13 +503,31 @@ function ngGridCsvExportPlugin(opts) {
500
503
  var filters = {};
501
504
  angular.forEach(self.grid.columns, function (col) {
502
505
  self.scope.extractFilter(col, filters);
503
- if (col.visible &&
504
- (!col.colDef.cellTemplate || self.scope.showsContent(col.colDef.cellTemplate)) &&
505
- (col.width === undefined || col.width === '*' || col.width > 0)) {
506
- csvData += '"' + csvStringify(col.displayName) + '",';
507
- col.doCSVExport = true;
508
- } else {
509
- col.doCSVExport = false;
506
+ if (col.visible && (col.width === undefined || col.width === '*' || col.width > 0)) {
507
+ if (!col.colDef.cellTemplate) {
508
+ csvData += '"' + csvStringify(col.displayName) + '",';
509
+ col.doCSVExport = true;
510
+ } else {
511
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
512
+ if (templateResp === 'HTML') {
513
+ csvData += '"' + csvStringify(col.displayName) + '",';
514
+ col.doCSVExport = function (value) {
515
+ value = value.replace(/<p>/g, '\n\n');
516
+ value = value.replace(/<\/p>/g, '');
517
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
518
+ value = value.replace(/<[^>]+>/g, '');
519
+ value = value.replaceAll('&nbsp;', ' ').trim();
520
+ value = value.replaceAll('\n\n \n\n', '\n\n');
521
+ value = value.replaceAll('\n\n\n', '\n\n');
522
+ return value;
523
+ };
524
+ } else if (templateResp) {
525
+ csvData += '"' + csvStringify(col.displayName) + '",';
526
+ col.doCSVExport = true;
527
+ } else {
528
+ col.doCSVExport = false;
529
+ }
530
+ }
510
531
  }
511
532
  });
512
533
 
@@ -516,7 +537,11 @@ function ngGridCsvExportPlugin(opts) {
516
537
  if (row.visible) {
517
538
  angular.forEach(self.grid.columns, function (col) {
518
539
  if (col.doCSVExport) {
519
- csvData += '"' + csvStringify(row.entity[col.field], filters[col.field]) + '",';
540
+ let value = row.entity[col.field];
541
+ if (typeof col.doCSVExport === 'function') {
542
+ value = col.doCSVExport(value);
543
+ }
544
+ csvData += '"' + csvStringify(value, filters[col.field]) + '",';
520
545
  }
521
546
  });
522
547
  csvData = swapLastCommaForNewline(csvData);
@@ -569,12 +594,35 @@ function ngGridPdfExportPlugin(options) {
569
594
  headerNames = [],
570
595
  footers = [],
571
596
  data = [],
572
- filters = {};
597
+ filters = {},
598
+ transformers = {};
599
+
573
600
 
574
601
  angular.forEach(self.grid.columns, function (col, index) {
575
- if (col.visible && (!col.colDef.cellTemplate || self.scope.showsContent(col.colDef.cellTemplate))) {
576
- headers.push(col.displayName);
577
- headerNames.push(col.field);
602
+ if (col.visible) {
603
+ if (!col.colDef.cellTemplate) {
604
+ headers.push(col.displayName);
605
+ headerNames.push(col.field);
606
+ } else {
607
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
608
+ if (templateResp === 'HTML') {
609
+ headers.push(col.displayName);
610
+ headerNames.push(col.field);
611
+ transformers[col.field] = function (value) {
612
+ value = value.replace(/<p>/g, '\n\n');
613
+ value = value.replace(/<\/p>/g, '');
614
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
615
+ value = value.replace(/<[^>]+>/g, '');
616
+ value = value.replaceAll('&nbsp;', ' ').trim();
617
+ value = value.replaceAll('\n\n \n\n', '\n\n');
618
+ value = value.replaceAll('\n\n\n', '\n\n');
619
+ return value;
620
+ };
621
+ } else if (templateResp) {
622
+ headers.push(col.displayName);
623
+ headerNames.push(col.field);
624
+ }
625
+ }
578
626
  }
579
627
  if (col.colDef.totalsRow) {
580
628
  footers[col.field] = self.grid.getTotalVal(col.field, col.filter).toString();
@@ -590,6 +638,9 @@ function ngGridPdfExportPlugin(options) {
590
638
  if (filters[h]) {
591
639
  val = filters[h].filter(val, filters[h].filterParam);
592
640
  }
641
+ if (transformers[h]) {
642
+ val = transformers[h](val);
643
+ }
593
644
  if (typeof val === 'string') {
594
645
  // chars > 255 cause BOM characters - see https://reallycare.freshdesk.com/a/tickets/2370
595
646
  // first replace the predictable chars
@@ -1,3 +1,3 @@
1
- /*! forms-angular 2022-06-03 */
2
- "use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$filter","$scope","$http","$location","cssFrameworkService","routingService",function(e,r,a,l,c,s,i,t){var p=!0,o=new ngGridPdfExportPlugin({inhibitButton:!0}),n=new ngGridCsvExportPlugin({inhibitButton:!0});function u(r){try{return JSON.parse(r)}catch(e){throw new Error(`Invalid JSON ${r}
3
- `+e.message)}}if(angular.extend(l,t.parsePathFunc()(s.$$path)),l.reportSchema={columnDefs:[]},l.gridOptions={data:"report",columnDefs:l.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,enableFiltering:!1,showGridFooter:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,n],onRegisterApi:function(r){l.gridApi=r,l.gridOptions.plugins.forEach(function(e){e.init(l,r.grid,null)}),r.selection.on.rowSelectionChanged(l,function(o){var e=l.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=l.reportSchema.params[t[1]])?(l.param=l.record[t[1]],r.conversionExpression?l.$eval(r.conversionExpression):r.value):l.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+")"))})}},l.report=[],!l.reportSchemaName&&s.$$search.r)switch(s.$$search.r.slice(0,1)){case"[":l.reportSchema.pipeline=u(s.$$search.r);break;case"{":angular.extend(l.reportSchema,u(s.$$search.r));break;default:throw new Error("No report instructions specified")}function d(e){for(var r in l.paramSchema=[],l.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=l.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"===i.frameWork?"large":"medium")}),"select"===t.type&&(l[r+"_Opts"]=t.enum,l.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[1])),l.record[r]=t.value)}l.$watch("record",function(e,r){r!==e&&(console.log("In the record watch ",JSON.stringify(e,null,2)),l.refreshQuery())},!0)}l.getTotalVal=function(r,e){var t="",o=_.find(l.reportSchema.columnDefs,function(e){return e.field===r});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var i=0,n=0;n<l.report.length;n++)i+=l.report[n][r];t=i,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},l.$on("exportToPDF",function(){o.createPDF()}),l.$on("exportToCSV",function(){n.createCSV()}),l.extractFilter=function(e,r){var t,o,i;e.cellFilter&&(-1===(i=e.cellFilter.indexOf(":"))?t=e.cellFilter:(t=e.cellFilter.slice(0,i).trim(),"'"!==(o=e.cellFilter.slice(i+1,999).trim())[0]&&'"'!==o[0]||(o=o.slice(1,-1))),i=angular.element(document.body).injector().get("$filter")(t.trim()),r[e.field]={filter:i,filterParam:o})};var f,m,h,g=document.querySelector("div.report-grow"),S=(g&&(f=g.offsetLeft,m=g.offsetTop+f,h=(h=document.querySelector("div.ui-grid-header"))?h.clientHeight:31,r=Math.floor((r.innerHeight-m-h-f)/30),angular.element(g).css("height",30*r+"px")),e.navScope);S.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:n.createCSV,text:"Export as CSV"}],S.contextMenu="Report",l.titleWithSubstitutions=l.reportSchema.title,l.inhibitRefresh||(l.refreshQuery=function(){function t(e){return e.replace(/\|.+?\|/g,function(e){e=e.slice(1,-1),e=/\((.+)\)/.exec(e);return e?l.reportSchema.params[e[1]].value:""})}var e="/api/report/"+l.modelName,r="?",o=!1,i=s.$$url.match(/\?.*/);if(l.reportSchemaName?e+="/"+l.reportSchemaName:i&&(p&&(l.paramSchema=JSON.parse(s.search().r).params,d(l.paramSchema)),e+=r+i[0].slice(1),r="&",o=!0),l.paramSchema){for(var n in l.record)if(l.record.hasOwnProperty(n)){var a=l.reportSchema.params[n];if(l.record[n]&&""!==l.record[n])l.param=l.record[n],a.conversionExpression&&(l.param=l.$eval(a.conversionExpression)),e+=r+n+"="+l.param,r="&";else if(a.required)return}}else!o&&i&&(e+=r+i[0].slice(1),r="&");return c.get(e).then(function(e){var r;e&&e.data&&e.data.success?(r=e.data,l.report=r.report,l.reportSchema=r.schema,l.reportSchema.title=l.reportSchema.title||l.modelName,l.titleWithSubstitutions=t(l.reportSchema.title),l.gridOptions.enableFiltering=!!l.reportSchema.filter,S&&S.items&&(S.items.length=2,l.reportSchema.menu&&l.reportSchema.menu.forEach(function(e){S.items.push(JSON.parse(t(JSON.stringify(e))))})),p&&(p=!1,l.$watch("reportSchema.columnDefs",function(e){var r=!1;if(e){for(var t,o=0;o<e.length;o++)e[o].totalsRow&&(r=!0),e[o].align&&(t="fng-"+e[o].align,e[o].cellClass=e[o].cellClass||"",-1===e[o].cellClass.indexOf(t)&&(e[o].cellClass=e[o].cellClass+" "+t));e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),l.gridOptions.columnDefs=e}l.gridOptions.showTotals=r,l.gridOptions.reallyShowFooter=r,l.gridOptions.footerRowHeight=55+(r?10:0)},!0),!l.paramSchema&&r.schema.params&&d(r.schema.params))):(l.showError(JSON.stringify(e.data.error),"Invalid Response Error"),l.reportSchema.title="Error - see console log")},function(){l.showError("The server could not process the request","Error")})},l.refreshQuery()),l.showsContent=function(e){return/{{[\s]*COL_FIELD[\s]*}}/.test(e.replace(/(<([^>]+)>)/gi,""))},l.$on("$locationChangeStart",function(){delete S.contextMenu,delete S.items}),l.showError=function(r,e){if(l.alertTitle=e||"Error!","string"==typeof r)l.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)l.errorMessage=r.message;else if(r.data&&r.data.message)l.errorMessage=r.data.message;else try{l.errorMessage=JSON.stringify(r)}catch(e){l.errorMessage=r}else l.errorMessage="An error occurred - that's all we got. Sorry.";l.errorHideTimer=window.setTimeout(function(){l.dismissError(),l.$digest()},3500+1e3*(l.alertTitle+l.errorMessage).length/50),l.errorVisible=!0,window.setTimeout(()=>{l.$digest()})},l.clearTimeout=function(){l.errorHideTimer&&(clearTimeout(l.errorHideTimer),delete l.errorHideTimer)},l.dismissError=function(){l.clearTimeout,l.errorVisible=!1,delete l.errorMessage,delete l.alertTitle},l.stickError=function(){clearTimeout(l.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var n=this;n.grid=null,n.scope=null,n.services=null,n.init=function(e,r,t){n.grid=r,n.scope=e,n.services=t},n.createCSV=function(){var e,r,t;e=n.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(n.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},n.prepareCSV=function(){function t(e,r){return null==e?"":r?r.filter(e,r.filterParam):"number"==typeof e?""+e:"boolean"==typeof e?e?"TRUE":"FALSE":("string"==typeof e?e:JSON.stringify(e)).replace(/"/g,'""')}function e(e){return e.substr(0,e.length-1)+"\n"}var o="",i={};return angular.forEach(n.grid.columns,function(e){n.scope.extractFilter(e,i),e.visible&&(!e.colDef.cellTemplate||n.scope.showsContent(e.colDef.cellTemplate))&&(void 0===e.width||"*"===e.width||0<e.width)?(o+='"'+t(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1}),o=e(o),angular.forEach(n.scope.gridApi.core.getVisibleRows(),function(r){r.visible&&(angular.forEach(n.grid.columns,function(e){e.doCSVExport&&(o+='"'+t(r.entity[e.field],i[e.field])+'",')}),o=e(o))}),o}}function ngGridPdfExportPlugin(o){var a=this;a.grid=null,a.scope=null,a.services=null,a.options=o,a.init=function(e,r,t){a.grid=r,a.scope=e,a.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(){a.createPDF()}))},a.createPDF=function(){var t=[],i=[],o=[],e=[],n={},r=(angular.forEach(a.grid.columns,function(e,r){!e.visible||e.colDef.cellTemplate&&!a.scope.showsContent(e.colDef.cellTemplate)||(t.push(e.displayName),i.push(e.field)),e.colDef.totalsRow&&(o[e.field]=a.grid.getTotalVal(e.field,e.filter).toString()),a.scope.extractFilter(e,n)}),angular.forEach(a.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(i.forEach(function(e){var r=t.entity[e];"string"==typeof(r=n[e]?n[e].filter(r,n[e].filterParam):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:[t],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(i,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=i(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 2022-08-05 */
2
+ "use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$filter","$scope","$http","$location","cssFrameworkService","routingService",function(e,r,l,a,c,s,n,t){var p=!0,o=new ngGridPdfExportPlugin({inhibitButton:!0}),i=new ngGridCsvExportPlugin({inhibitButton:!0});function d(r){try{return JSON.parse(r)}catch(e){throw new Error(`Invalid JSON ${r}
3
+ `+e.message)}}if(angular.extend(a,t.parsePathFunc()(s.$$path)),a.reportSchema={columnDefs:[]},a.gridOptions={data:"report",columnDefs:a.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,enableFiltering:!1,showGridFooter:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,i],onRegisterApi:function(r){a.gridApi=r,a.gridOptions.plugins.forEach(function(e){e.init(a,r.grid,null)}),r.selection.on.rowSelectionChanged(a,function(o){var e=a.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=a.reportSchema.params[t[1]])?(a.param=a.record[t[1]],r.conversionExpression?a.$eval(r.conversionExpression):r.value):a.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+")"))})}},a.report=[],!a.reportSchemaName&&s.$$search.r)switch(s.$$search.r.slice(0,1)){case"[":a.reportSchema.pipeline=d(s.$$search.r);break;case"{":angular.extend(a.reportSchema,d(s.$$search.r));break;default:throw new Error("No report instructions specified")}function u(e){for(var r in a.paramSchema=[],a.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=a.paramSchema.push({name:r,id:"fp_"+r,label:t.label||l("titleCase")(r),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===n.frameWork?"large":"medium")}),"select"===t.type&&(a[r+"_Opts"]=t.enum,a.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[1])),a.record[r]=t.value)}a.$watch("record",function(e,r){r!==e&&a.refreshQuery()},!0)}a.getTotalVal=function(r,e){var t="",o=_.find(a.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<a.report.length;i++)n+=a.report[i][r];t=n,e&&(t=l(e)(t));break;default:t=o.totalsRow}return t},a.$on("exportToPDF",function(){o.createPDF()}),a.$on("exportToCSV",function(){i.createCSV()}),a.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 f,m,g,h=document.querySelector("div.report-grow"),S=(h&&(f=h.offsetLeft,m=h.offsetTop+f,g=(g=document.querySelector("div.ui-grid-header"))?g.clientHeight:31,r=Math.floor((r.innerHeight-m-g-f)/30),angular.element(h).css("height",30*r+"px")),e.navScope);S.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:i.createCSV,text:"Export as CSV"}],S.contextMenu="Report",a.titleWithSubstitutions=a.reportSchema.title,a.inhibitRefresh||(a.refreshQuery=function(){function t(e){return e.replace(/\|.+?\|/g,function(e){e=e.slice(1,-1),e=/\((.+)\)/.exec(e);return e?a.reportSchema.params[e[1]].value:""})}var e="/api/report/"+a.modelName,r="?",o=!1,n=s.$$url.match(/\?.*/);if(a.reportSchemaName?e+="/"+a.reportSchemaName:n&&(p&&(a.paramSchema=JSON.parse(s.search().r).params,u(a.paramSchema)),e+=r+n[0].slice(1),r="&",o=!0),a.paramSchema){for(var i in a.record)if(a.record.hasOwnProperty(i)){var l=a.reportSchema.params[i];if(a.record[i]&&""!==a.record[i])a.param=a.record[i],l.conversionExpression&&(a.param=a.$eval(l.conversionExpression)),e+=r+i+"="+a.param,r="&";else if(l.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,a.report=r.report,a.reportSchema=r.schema,a.reportSchema.title=a.reportSchema.title||a.modelName,a.titleWithSubstitutions=t(a.reportSchema.title),a.gridOptions.enableFiltering=!!a.reportSchema.filter,S&&S.items&&(S.items.length=2,a.reportSchema.menu&&a.reportSchema.menu.forEach(function(e){S.items.push(JSON.parse(t(JSON.stringify(e))))})),p&&(p=!1,a.$watch("reportSchema.columnDefs",function(e){var r=!1;if(e){for(var t,o=0;o<e.length;o++)e[o].totalsRow&&(r=!0),e[o].align&&(t="fng-"+e[o].align,e[o].cellClass=e[o].cellClass||"",-1===e[o].cellClass.indexOf(t)&&(e[o].cellClass=e[o].cellClass+" "+t));e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),a.gridOptions.columnDefs=e}a.gridOptions.showTotals=r,a.gridOptions.reallyShowFooter=r,a.gridOptions.footerRowHeight=55+(r?10:0)},!0),!a.paramSchema&&r.schema.params&&u(r.schema.params))):(a.showError(JSON.stringify(e.data.error),"Invalid Response Error"),a.reportSchema.title="Error - see console log")},function(){a.showError("The server could not process the request","Error")})},a.refreshQuery()),a.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)},a.$on("$locationChangeStart",function(){delete S.contextMenu,delete S.items}),a.showError=function(r,e){if(a.alertTitle=e||"Error!","string"==typeof r)a.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)a.errorMessage=r.message;else if(r.data&&r.data.message)a.errorMessage=r.data.message;else try{a.errorMessage=JSON.stringify(r)}catch(e){a.errorMessage=r}else a.errorMessage="An error occurred - that's all we got. Sorry.";a.errorHideTimer=window.setTimeout(function(){a.dismissError(),a.$digest()},3500+1e3*(a.alertTitle+a.errorMessage).length/50),a.errorVisible=!0,window.setTimeout(()=>{a.$digest()})},a.clearTimeout=function(){a.errorHideTimer&&(clearTimeout(a.errorHideTimer),delete a.errorHideTimer)},a.dismissError=function(){a.clearTimeout,a.errorVisible=!1,delete a.errorMessage,delete a.alertTitle},a.stickError=function(){clearTimeout(a.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var l=this;l.grid=null,l.scope=null,l.services=null,l.init=function(e,r,t){l.grid=r,l.scope=e,l.services=t},l.createCSV=function(){var e,r,t;e=l.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(l.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},l.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(l.grid.columns,function(e){var r;l.scope.extractFilter(e,i),e.visible&&(void 0===e.width||"*"===e.width||0<e.width)&&(e.colDef.cellTemplate?"HTML"===(r=l.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(l.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(l.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 c=this;c.grid=null,c.scope=null,c.services=null,c.options=o,c.init=function(e,r,t){c.grid=r,c.scope=e,c.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(){c.createPDF()}))},c.createPDF=function(){var o=[],n=[],i=[],e=[],l={},a={},r=(angular.forEach(c.grid.columns,function(e,r){var t;e.visible&&(e.colDef.cellTemplate?"HTML"===(t=c.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&&(i[e.field]=c.grid.getTotalVal(e.field,e.filter).toString()),c.scope.extractFilter(e,l)}),angular.forEach(c.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(n.forEach(function(e){var r=t.entity[e];l[e]&&(r=l[e].filter(r,l[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.190",
3
+ "version": "0.12.0-beta.192",
4
4
  "description": "Reporting plugin for forms-angular",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  "angular-messages": "1.8.3",
33
33
  "angular-mocks": "1.8.3",
34
34
  "angular-sanitize": "1.8.3",
35
- "forms-angular": "0.12.0-beta.190",
35
+ "forms-angular": "0.12.0-beta.192",
36
36
  "grunt": "^1.5.2",
37
37
  "grunt-autoprefixer": "3.0.4",
38
38
  "grunt-concurrent": "3.0.0",
@@ -170,14 +170,13 @@ ${e.message}`);
170
170
  }
171
171
  var dateTest = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(thisPart.value);
172
172
  if (dateTest) {
173
- thisPart.value = new Date(dateTest[1]);
173
+ thisPart.value = new Date(thisPart.value);
174
174
  }
175
175
  $scope.record[param] = thisPart.value;
176
176
  }
177
177
  }
178
178
  $scope.$watch('record', function (newValue, oldValue) {
179
179
  if (oldValue !== newValue) {
180
- console.log('In the record watch ', JSON.stringify(newValue, null, 2));
181
180
  $scope.refreshQuery();
182
181
  }
183
182
  }, true);
@@ -333,8 +332,12 @@ ${e.message}`);
333
332
 
334
333
  // Check whether a cell template shows the content (in which case we want to output it) or does something funky
335
334
  // (for example displays an image)
336
- $scope.showsContent = function (template) {
337
- return /{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''));
335
+ $scope.showsContent = function (template, col) {
336
+ if (/{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''))) {
337
+ return true;
338
+ } else if (template.indexOf('ng-bind-html="row.entity.' + col) !== -1) {
339
+ return 'HTML';
340
+ }
338
341
  };
339
342
 
340
343
  $scope.$on('$locationChangeStart', function () {
@@ -55,13 +55,31 @@ function ngGridCsvExportPlugin(opts) {
55
55
  var filters = {};
56
56
  angular.forEach(self.grid.columns, function (col) {
57
57
  self.scope.extractFilter(col, filters);
58
- if (col.visible &&
59
- (!col.colDef.cellTemplate || self.scope.showsContent(col.colDef.cellTemplate)) &&
60
- (col.width === undefined || col.width === '*' || col.width > 0)) {
61
- csvData += '"' + csvStringify(col.displayName) + '",';
62
- col.doCSVExport = true;
63
- } else {
64
- col.doCSVExport = false;
58
+ if (col.visible && (col.width === undefined || col.width === '*' || col.width > 0)) {
59
+ if (!col.colDef.cellTemplate) {
60
+ csvData += '"' + csvStringify(col.displayName) + '",';
61
+ col.doCSVExport = true;
62
+ } else {
63
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
64
+ if (templateResp === 'HTML') {
65
+ csvData += '"' + csvStringify(col.displayName) + '",';
66
+ col.doCSVExport = function (value) {
67
+ value = value.replace(/<p>/g, '\n\n');
68
+ value = value.replace(/<\/p>/g, '');
69
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
70
+ value = value.replace(/<[^>]+>/g, '');
71
+ value = value.replaceAll('&nbsp;', ' ').trim();
72
+ value = value.replaceAll('\n\n \n\n', '\n\n');
73
+ value = value.replaceAll('\n\n\n', '\n\n');
74
+ return value;
75
+ };
76
+ } else if (templateResp) {
77
+ csvData += '"' + csvStringify(col.displayName) + '",';
78
+ col.doCSVExport = true;
79
+ } else {
80
+ col.doCSVExport = false;
81
+ }
82
+ }
65
83
  }
66
84
  });
67
85
 
@@ -71,7 +89,11 @@ function ngGridCsvExportPlugin(opts) {
71
89
  if (row.visible) {
72
90
  angular.forEach(self.grid.columns, function (col) {
73
91
  if (col.doCSVExport) {
74
- csvData += '"' + csvStringify(row.entity[col.field], filters[col.field]) + '",';
92
+ let value = row.entity[col.field];
93
+ if (typeof col.doCSVExport === 'function') {
94
+ value = col.doCSVExport(value);
95
+ }
96
+ csvData += '"' + csvStringify(value, filters[col.field]) + '",';
75
97
  }
76
98
  });
77
99
  csvData = swapLastCommaForNewline(csvData);
@@ -40,12 +40,35 @@ function ngGridPdfExportPlugin(options) {
40
40
  headerNames = [],
41
41
  footers = [],
42
42
  data = [],
43
- filters = {};
43
+ filters = {},
44
+ transformers = {};
45
+
44
46
 
45
47
  angular.forEach(self.grid.columns, function (col, index) {
46
- if (col.visible && (!col.colDef.cellTemplate || self.scope.showsContent(col.colDef.cellTemplate))) {
47
- headers.push(col.displayName);
48
- headerNames.push(col.field);
48
+ if (col.visible) {
49
+ if (!col.colDef.cellTemplate) {
50
+ headers.push(col.displayName);
51
+ headerNames.push(col.field);
52
+ } else {
53
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
54
+ if (templateResp === 'HTML') {
55
+ headers.push(col.displayName);
56
+ headerNames.push(col.field);
57
+ transformers[col.field] = function (value) {
58
+ value = value.replace(/<p>/g, '\n\n');
59
+ value = value.replace(/<\/p>/g, '');
60
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
61
+ value = value.replace(/<[^>]+>/g, '');
62
+ value = value.replaceAll('&nbsp;', ' ').trim();
63
+ value = value.replaceAll('\n\n \n\n', '\n\n');
64
+ value = value.replaceAll('\n\n\n', '\n\n');
65
+ return value;
66
+ };
67
+ } else if (templateResp) {
68
+ headers.push(col.displayName);
69
+ headerNames.push(col.field);
70
+ }
71
+ }
49
72
  }
50
73
  if (col.colDef.totalsRow) {
51
74
  footers[col.field] = self.grid.getTotalVal(col.field, col.filter).toString();
@@ -61,6 +84,9 @@ function ngGridPdfExportPlugin(options) {
61
84
  if (filters[h]) {
62
85
  val = filters[h].filter(val, filters[h].filterParam);
63
86
  }
87
+ if (transformers[h]) {
88
+ val = transformers[h](val);
89
+ }
64
90
  if (typeof val === 'string') {
65
91
  // chars > 255 cause BOM characters - see https://reallycare.freshdesk.com/a/tickets/2370
66
92
  // first replace the predictable chars