Skip to content

Commit aae0c8b

Browse files
committed
Bit of a hack to allow overrides in CSV output
1 parent d2169f3 commit aae0c8b

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

dist/fng-reports.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! forms-angular 2024-07-26 */
1+
/*! forms-angular 2024-10-25 */
22
'use strict';
33

44
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$q', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService', 'uiGridConstants',
@@ -410,6 +410,21 @@ ${e.message}`);
410410
colDef.width = parseInt(colDef.width.slice(0, -2));
411411
}
412412
}
413+
} else {
414+
// Need to generate columnDefs from the data, including every field (by default the grid gets upset by records with missing data)
415+
var allFields = new Set();
416+
data.report.forEach(function(row) {
417+
for (var field in row) {
418+
allFields.add(field);
419+
}
420+
});
421+
data.schema.columnDefs = Array.from(allFields).map(function(field) {
422+
{
423+
const colDef = { name: field };
424+
$scope.gridOptions.columnDefs.push(colDef);
425+
return colDef;
426+
}
427+
});
413428
}
414429

415430
if (!$scope.paramSchema && data.schema.params && $location.$$search.noinput !== '1') {
@@ -634,7 +649,11 @@ function ngGridCsvExportPlugin(opts) {
634649
col.doCSVExport = true;
635650
} else {
636651
const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
637-
if (templateResp === 'HTML') {
652+
// Third party apps can override showContent and return a function
653+
if (typeof templateResp === 'function') {
654+
csvData += '"' + csvStringify(col.displayName) + '",';
655+
col.doCSVExport = templateResp;
656+
} else if (templateResp === 'HTML') {
638657
csvData += '"' + csvStringify(col.displayName) + '",';
639658
col.doCSVExport = function (value) {
640659
value = value.replace(/<p>/g, '\n\n');
@@ -665,7 +684,7 @@ function ngGridCsvExportPlugin(opts) {
665684
if (col.doCSVExport) {
666685
let value = row.entity[col.field];
667686
if (typeof col.doCSVExport === 'function') {
668-
value = col.doCSVExport(value);
687+
value = col.doCSVExport(value, row.entity, col);
669688
}
670689
csvData += '"' + csvStringify(value, filters[col.field]) + '",';
671690
}
@@ -734,6 +753,12 @@ function ngGridPdfExportPlugin(options) {
734753
headerNames.push(col.field);
735754
} else {
736755
const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
756+
// Third party apps can override showContent and return a function
757+
if (typeof templateResp === 'function') {
758+
headers.push(col.displayName);
759+
headerNames.push(col.field);
760+
transformers[col.field] = templateResp;
761+
} else
737762
if (templateResp === 'HTML') {
738763
headers.push(col.displayName);
739764
headerNames.push(col.field);
@@ -769,7 +794,7 @@ function ngGridPdfExportPlugin(options) {
769794
val = filters[h].filter(val, filters[h].filterParam);
770795
}
771796
if (transformers[h]) {
772-
val = transformers[h](val);
797+
val = transformers[h](val, row.entity, h);
773798
}
774799
if (typeof val === 'string') {
775800
// chars > 255 cause BOM characters - see https://reallycare.freshdesk.com/a/tickets/2370

0 commit comments

Comments
 (0)