fng-reports 0.12.0-beta.21 → 0.12.0-beta.210

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.
@@ -3,57 +3,46 @@ function ngGridCsvExportPlugin(opts) {
3
3
  var self = this;
4
4
  self.grid = null;
5
5
  self.scope = null;
6
+ self.services = null;
6
7
 
7
8
  self.init = function (scope, grid, services) {
8
-
9
- function doDownloadButton() {
10
- var fp = angular.element('h1').parent();
11
- var csvDataLinkPrevious = angular.element('#csv-data-link');
12
- if (csvDataLinkPrevious != null) {
13
- csvDataLinkPrevious.remove();
14
- }
15
- var csvDataLinkHtml = "<button id=\"csv-data-link\" class=\"btn\"><a href=\"data:text/csv;charset=UTF-8,";
16
- csvDataLinkHtml += encodeURIComponent(self.prepareCSV());
17
- csvDataLinkHtml += "\" download=\"Export.csv\">CSV Export</button>";
18
- fp.append(csvDataLinkHtml);
19
- }
20
-
21
9
  self.grid = grid;
22
10
  self.scope = scope;
23
-
24
- if (!opts.inhibitButton) {
25
- setTimeout(doDownloadButton, 0);
26
- scope.catHashKeys = function () {
27
- var hash = '';
28
- for (var idx in scope.renderedRows) {
29
- hash += scope.renderedRows[idx].$$hashKey;
30
- }
31
- return hash;
32
- };
33
- scope.$watch('catHashKeys()', doDownloadButton);
34
- }
11
+ self.services = services;
35
12
  };
36
13
 
14
+ function downloadFile(fileName, urlData) {
15
+
16
+ var aLink = document.createElement('a');
17
+ aLink.download = fileName;
18
+ aLink.href = urlData;
19
+
20
+ var event = new MouseEvent('click');
21
+ aLink.dispatchEvent(event);
22
+ }
23
+
37
24
  self.createCSV = function () {
38
- window.open('data:text/csv;charset=UTF-8,' + encodeURIComponent(self.prepareCSV()));
25
+ downloadFile(self.scope.reportSchema.title + '.csv','data:text/csv;charset=UTF-8,' + encodeURIComponent(self.prepareCSV()));
39
26
  };
40
27
 
41
28
  self.prepareCSV = function () {
42
29
 
43
- function csvStringify(str) {
30
+ function csvStringify(str, filter) {
44
31
  if (str == null) { // we want to catch anything null-ish, hence just == not ===
45
32
  return '';
46
33
  }
47
- if (typeof(str) === 'number') {
34
+ if (filter) {
35
+ return filter.filter(str, filter.filterParam);
36
+ }
37
+ if (typeof (str) === 'number') {
48
38
  return '' + str;
49
39
  }
50
- if (typeof(str) === 'boolean') {
40
+ if (typeof (str) === 'boolean') {
51
41
  return (str ? 'TRUE' : 'FALSE');
52
42
  }
53
- if (typeof(str) === 'string') {
43
+ if (typeof (str) === 'string') {
54
44
  return str.replace(/"/g, '""');
55
45
  }
56
-
57
46
  return JSON.stringify(str).replace(/"/g, '""');
58
47
  }
59
48
 
@@ -63,21 +52,56 @@ function ngGridCsvExportPlugin(opts) {
63
52
  }
64
53
 
65
54
  var csvData = '';
66
- angular.forEach(self.scope.columns, function (col) {
67
- if (col.visible && (col.width === undefined || col.width > 0)) {
68
- csvData += '"' + csvStringify(col.displayName) + '",';
55
+ var filters = {};
56
+ angular.forEach(self.grid.columns, function (col) {
57
+ self.scope.extractFilter(col, filters);
58
+ if (col.visible && (col.width === undefined || col.width === '*' || col.width > 0)) {
59
+ if (col.field.indexOf('.') !== -1) {
60
+ console.error(`Cannot export nested fields such as ${col.field}. Use $project to simplify.`);
61
+ } else {
62
+ if (!col.colDef.cellTemplate) {
63
+ csvData += '"' + csvStringify(col.displayName) + '",';
64
+ col.doCSVExport = true;
65
+ } else {
66
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
67
+ if (templateResp === 'HTML') {
68
+ csvData += '"' + csvStringify(col.displayName) + '",';
69
+ col.doCSVExport = function (value) {
70
+ value = value.replace(/<p>/g, '\n\n');
71
+ value = value.replace(/<\/p>/g, '');
72
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
73
+ value = value.replace(/<[^>]+>/g, '');
74
+ value = value.replaceAll('&nbsp;', ' ').trim();
75
+ value = value.replaceAll('\n\n \n\n', '\n\n');
76
+ value = value.replaceAll('\n\n\n', '\n\n');
77
+ return value;
78
+ };
79
+ } else if (templateResp) {
80
+ csvData += '"' + csvStringify(col.displayName) + '",';
81
+ col.doCSVExport = true;
82
+ } else {
83
+ col.doCSVExport = false;
84
+ }
85
+ }
86
+ }
69
87
  }
70
88
  });
71
89
 
72
90
  csvData = swapLastCommaForNewline(csvData);
73
91
 
74
- angular.forEach(self.grid.filteredRows, function (row) {
75
- angular.forEach(self.scope.columns, function (col) {
76
- if (col.visible) {
77
- csvData += '"' + csvStringify(row.entity[col.field]) + '",';
78
- }
79
- });
80
- csvData = swapLastCommaForNewline(csvData);
92
+ angular.forEach(self.scope.gridApi.core.getVisibleRows(), function (row) {
93
+ if (row.visible) {
94
+ angular.forEach(self.grid.columns, function (col) {
95
+ if (col.doCSVExport) {
96
+ let value = row.entity[col.field];
97
+ if (typeof col.doCSVExport === 'function') {
98
+ value = col.doCSVExport(value);
99
+ }
100
+ csvData += '"' + csvStringify(value, filters[col.field]) + '",';
101
+ }
102
+ });
103
+ csvData = swapLastCommaForNewline(csvData);
104
+ }
81
105
  });
82
106
 
83
107
  return csvData;
@@ -5,6 +5,10 @@
5
5
  but that would require putting the totals (ngGridTotalCell.js) into a plugin.
6
6
  */
7
7
 
8
+ /**
9
+ * FOOTER NO LONGER SUPPORTED
10
+ */
11
+
8
12
  function ngGridPdfExportPlugin(options) {
9
13
  var self = this;
10
14
  self.grid = null;
@@ -33,33 +37,85 @@ function ngGridPdfExportPlugin(options) {
33
37
 
34
38
  self.createPDF = function () {
35
39
  var headers = [],
36
- data = [],
37
- footers = {},
38
- gridWidth = self.scope.totalRowWidth(),
39
- margin = 15; // mm defined as unit when setting up jsPDF
40
+ headerNames = [],
41
+ footers = [],
42
+ data = [],
43
+ filters = {},
44
+ transformers = {};
40
45
 
41
- angular.forEach(self.scope.columns, function (col) {
42
- if (col.visible && (col.width === undefined || col.width > 0)) {
43
- headers.push({name: col.field, prompt: col.displayName, width: col.width * (185 / gridWidth), align: (col.colDef.align || 'left')});
44
- if (col.colDef.totalsRow) {
45
- footers[col.field] = self.scope.getTotalVal(col.field, col.filter).toString();
46
+
47
+ angular.forEach(self.grid.columns, function (col, index) {
48
+ if (col.visible) {
49
+ if (col.field.indexOf('.') !== -1) {
50
+ console.error(`Cannot export nested fields such as ${col.field}. Use $project to simplify.`);
51
+ } else {
52
+ if (!col.colDef.cellTemplate) {
53
+ headers.push(col.displayName);
54
+ headerNames.push(col.field);
55
+ } else {
56
+ const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
57
+ if (templateResp === 'HTML') {
58
+ headers.push(col.displayName);
59
+ headerNames.push(col.field);
60
+ transformers[col.field] = function (value) {
61
+ value = value.replace(/<p>/g, '\n\n');
62
+ value = value.replace(/<\/p>/g, '');
63
+ value = value.replace(/<\s?br\s?\/?>/g, '\n');
64
+ value = value.replace(/<[^>]+>/g, '');
65
+ value = value.replaceAll('&nbsp;', ' ').trim();
66
+ value = value.replaceAll('\n\n \n\n', '\n\n');
67
+ value = value.replaceAll('\n\n\n', '\n\n');
68
+ return value;
69
+ };
70
+ } else if (templateResp) {
71
+ headers.push(col.displayName);
72
+ headerNames.push(col.field);
73
+ }
74
+ }
46
75
  }
47
76
  }
77
+ if (col.colDef.totalsRow) {
78
+ footers[col.field] = self.grid.getTotalVal(col.field, col.filter).toString();
79
+ }
80
+ self.scope.extractFilter(col, filters);
81
+ });
82
+
83
+ angular.forEach(self.scope.gridApi.core.getVisibleRows(), function (row) {
84
+ var output = [];
85
+ if (row.visible) {
86
+ headerNames.forEach(function(h) {
87
+ var val = row.entity[h];
88
+ if (filters[h]) {
89
+ val = filters[h].filter(val, filters[h].filterParam);
90
+ }
91
+ if (transformers[h]) {
92
+ val = transformers[h](val);
93
+ }
94
+ if (typeof val === 'string') {
95
+ // chars > 255 cause BOM characters - see https://reallycare.freshdesk.com/a/tickets/2370
96
+ // first replace the predictable chars
97
+ val = val.replace(/\u2019/g,'\'');
98
+ val = val.replace(/\u2018/g,'\'');
99
+ val = val.replace(/\u201c/g,'"');
100
+ val = val.replace(/\u201d/g,'"');
101
+
102
+ // Then strip out anything left over 255
103
+ val = val.replace(/[^\x00-\xFF]/g, '');
104
+ }
105
+ output.push(val);
106
+ });
107
+ data.push(output);
108
+ }
48
109
  });
49
110
 
50
- angular.forEach(self.grid.filteredRows, function (row) {
51
- data.push(angular.copy(row.entity));
111
+ // var doc = new jsPDF('landscape', 'mm', 'a4');
112
+ var doc = new jspdf.jsPDF('landscape', 'mm', 'a4');
113
+ doc.autoTable({
114
+ head: [headers],
115
+ body: data
52
116
  });
53
117
 
54
- var doc = new jsPDF('landscape', 'mm', 'a4');
55
- doc.setFontStyle('bold');
56
- doc.setFontSize(24);
57
- doc.text(self.scope.reportSchema.title, margin, margin);
58
- doc.setFontStyle('normal');
59
- doc.setFontSize(12);
60
- doc.cellInitialize();
61
- doc.table(margin, 24, data, {headers: headers, footers: footers, printHeaders: true, autoSize: false, margins: {left: margin, top: margin, bottom: margin, width: doc.internal.pageSize - margin}});
62
- doc.output('dataurlnewwindow');
118
+ window.open(doc.output('bloburl'));
63
119
  };
64
120
  }
65
121
 
@@ -5,6 +5,7 @@ module.exports = function(config) {
5
5
  files: [
6
6
  'node_modules/angular/angular.js',
7
7
  'node_modules/angular-sanitize/angular-sanitize.js',
8
+ 'node_modules/angular-animate/angular-animate.js',
8
9
  'node_modules/angular-mocks/angular-mocks.js',
9
10
  'node_modules/angular-messages/angular-messages.js',
10
11
  'node_modules/jspdf/dist/jspdf.debug.js',
@@ -24,6 +24,7 @@ describe('Reports', function () {
24
24
  {'_id': 'F', 'count': 11},
25
25
  {'_id': 'M', 'count': 6}
26
26
  ]});
27
+ $rootScope.navScope = {};
27
28
  var scope = $rootScope.$new();
28
29
  var routingService = {
29
30
  parsePathFunc: function () {