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.
- package/Gruntfile.js +1 -1
- package/dist/fng-reports.js +955 -738
- package/dist/fng-reports.min.js +3 -2
- package/dist/index.d.ts +45 -0
- package/index.d.ts +45 -0
- package/package.json +32 -27
- package/readme.md +1 -1
- package/src/fng-reports.js +377 -240
- package/src/plugins/jsPDF/jspdf-plugin.cell.js +441 -441
- package/src/plugins/ng-grid/ng-grid-csv-export.js +65 -41
- package/src/plugins/ng-grid/ng-grid-pdf-export.js +76 -20
- package/test/karma.conf.js +1 -0
- package/test/specs/reportSpec.js +1 -0
package/dist/fng-reports.js
CHANGED
|
@@ -1,270 +1,407 @@
|
|
|
1
|
-
/*! forms-angular
|
|
1
|
+
/*! forms-angular 2023-03-03 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
formsAngular.controller('AnalysisCtrl', ['$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
|
|
5
|
+
function ($rootScope, $window, $filter, $scope, $http, $location, cssFrameworkService, routingService) {
|
|
6
|
+
/*jshint newcap: false */
|
|
7
|
+
var firstTime = true,
|
|
8
|
+
pdfPlugIn = new ngGridPdfExportPlugin({inhibitButton: true}),
|
|
9
|
+
csvPlugIn = new ngGridCsvExportPlugin({inhibitButton: true});
|
|
10
|
+
/*jshint newcap: true */
|
|
11
|
+
|
|
12
|
+
angular.extend($scope, routingService.parsePathFunc()($location.$$path));
|
|
13
|
+
|
|
14
|
+
$scope.reportSchema = {
|
|
15
|
+
columnDefs: []
|
|
16
|
+
};
|
|
17
|
+
$scope.gridOptions = {
|
|
18
|
+
data: 'report',
|
|
19
|
+
columnDefs: $scope.reportSchema.columnDefs,
|
|
20
|
+
showColumnMenu: true,
|
|
21
|
+
enableRowHeaderSelection: false,
|
|
22
|
+
enableFiltering: false,
|
|
23
|
+
showGridFooter: false,
|
|
24
|
+
reallyShowFooter: false, // this determines whether it is actually displayed or not
|
|
25
|
+
showTotals: true,
|
|
26
|
+
enableColumnResizing: true,
|
|
27
27
|
// enableColumnReordering: true,
|
|
28
28
|
// jqueryUIDraggable: true,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'<button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="{{i18n.ngPagerNextTitle}}">' +
|
|
77
|
-
'<div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button>' +
|
|
78
|
-
'<button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageToLast()" title="{{i18n.ngPagerLastTitle}}">' +
|
|
79
|
-
'<div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button>' +
|
|
80
|
-
'</div>' +
|
|
81
|
-
'</div>' +
|
|
82
|
-
'</div>'
|
|
83
|
-
};
|
|
84
|
-
$scope.report = [];
|
|
85
|
-
|
|
86
|
-
if (!$scope.reportSchemaName && $location.$$search.r) {
|
|
87
|
-
switch ($location.$$search.r.slice(0, 1)) {
|
|
88
|
-
case '[' :
|
|
89
|
-
$scope.reportSchema.pipeline = JSON.parse($location.$$search.r);
|
|
90
|
-
break;
|
|
91
|
-
case '{' :
|
|
92
|
-
angular.extend($scope.reportSchema, JSON.parse($location.$$search.r));
|
|
93
|
-
break;
|
|
94
|
-
default :
|
|
95
|
-
throw new Error('No report instructions specified');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
$scope.getTotalVal = function (field, filter) {
|
|
100
|
-
var result = '',
|
|
101
|
-
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
102
|
-
return col.field === field;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (instructions) {
|
|
106
|
-
switch (instructions.totalsRow) {
|
|
107
|
-
case undefined :
|
|
108
|
-
break;
|
|
109
|
-
case '$SUM' :
|
|
110
|
-
var sum = 0;
|
|
111
|
-
for (var j = 0; j < $scope.report.length; j++) {
|
|
112
|
-
sum += $scope.report[j][field];
|
|
113
|
-
}
|
|
114
|
-
result = sum;
|
|
115
|
-
if (filter) {
|
|
116
|
-
result = $filter(filter)(result);
|
|
29
|
+
footerRowHeight: 65,
|
|
30
|
+
multiSelect: false,
|
|
31
|
+
plugins: [pdfPlugIn, csvPlugIn],
|
|
32
|
+
onRegisterApi: function (gridApi) {
|
|
33
|
+
$scope.gridApi = gridApi;
|
|
34
|
+
$scope.gridOptions.plugins.forEach(function (p) {
|
|
35
|
+
p.init($scope, gridApi.grid, null);
|
|
36
|
+
});
|
|
37
|
+
gridApi.selection.on.rowSelectionChanged($scope, function afterSelectionChange(rowItem) {
|
|
38
|
+
var url = $scope.reportSchema.drilldown;
|
|
39
|
+
if (url) {
|
|
40
|
+
if (typeof url === 'string') {
|
|
41
|
+
url = routingService.buildUrl(url.replace(/\|.+?\|/g, function (match) {
|
|
42
|
+
var param = match.slice(1, -1),
|
|
43
|
+
isParamTest = /\((.+)\)/.exec(param);
|
|
44
|
+
if (isParamTest) {
|
|
45
|
+
var instructions = $scope.reportSchema.params[isParamTest[1]];
|
|
46
|
+
if (instructions) {
|
|
47
|
+
$scope.param = $scope.record[isParamTest[1]];
|
|
48
|
+
if (instructions.conversionExpression) {
|
|
49
|
+
return $scope.$eval(instructions.conversionExpression);
|
|
50
|
+
} else {
|
|
51
|
+
return instructions.value;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
return $scope.reportSchema.params[isParamTest[1]].value;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
return rowItem.entity[param];
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
window.location = url;
|
|
61
|
+
} else {
|
|
62
|
+
console.error('Was expecting drilldown to be string but it was ' + typeof url + ' (' + url + ')'); // trying to track down Sentry 3037641567
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
$scope.report = [];
|
|
69
|
+
|
|
70
|
+
function parseAndHandleError(str) {
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(str);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new Error(`Invalid JSON ${str}
|
|
75
|
+
${e.message}`);
|
|
117
76
|
}
|
|
118
|
-
break;
|
|
119
|
-
default :
|
|
120
|
-
result = instructions.totalsRow;
|
|
121
|
-
break;
|
|
122
77
|
}
|
|
123
|
-
}
|
|
124
78
|
|
|
125
|
-
|
|
126
|
-
|
|
79
|
+
if (!$scope.reportSchemaName && $location.$$search.r) {
|
|
80
|
+
switch ($location.$$search.r.slice(0, 1)) {
|
|
81
|
+
case '[' :
|
|
82
|
+
$scope.reportSchema.pipeline = parseAndHandleError($location.$$search.r);
|
|
83
|
+
break;
|
|
84
|
+
case '{' :
|
|
85
|
+
angular.extend($scope.reportSchema, parseAndHandleError($location.$$search.r));
|
|
86
|
+
break;
|
|
87
|
+
default :
|
|
88
|
+
throw new Error('No report instructions specified');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
127
91
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
92
|
+
$scope.getTotalVal = function (field, filter) {
|
|
93
|
+
var result = '',
|
|
94
|
+
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
95
|
+
return col.field === field;
|
|
96
|
+
});
|
|
131
97
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
98
|
+
if (instructions) {
|
|
99
|
+
switch (instructions.totalsRow) {
|
|
100
|
+
case undefined :
|
|
101
|
+
break;
|
|
102
|
+
case '$SUM' :
|
|
103
|
+
var sum = 0;
|
|
104
|
+
for (var j = 0; j < $scope.report.length; j++) {
|
|
105
|
+
sum += $scope.report[j][field];
|
|
106
|
+
}
|
|
107
|
+
result = sum;
|
|
108
|
+
if (filter) {
|
|
109
|
+
result = $filter(filter)(result);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
default :
|
|
113
|
+
result = instructions.totalsRow;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
135
117
|
|
|
136
|
-
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
137
120
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
apiCall += '/' + $scope.reportSchemaName;
|
|
142
|
-
}
|
|
121
|
+
$scope.$on('exportToPDF', function () {
|
|
122
|
+
pdfPlugIn.createPDF();
|
|
123
|
+
});
|
|
143
124
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if ($scope.record.hasOwnProperty(paramVal)) {
|
|
148
|
-
var instructions = $scope.reportSchema.params[paramVal];
|
|
149
|
-
if ($scope.record[paramVal] && $scope.record[paramVal] !== '') {
|
|
150
|
-
$scope.param = $scope.record[paramVal];
|
|
151
|
-
if (instructions.conversionExpression) {
|
|
152
|
-
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
153
|
-
}
|
|
154
|
-
apiCall += connector + paramVal + '=' + $scope.param;
|
|
155
|
-
connector = '&';
|
|
156
|
-
} else if (instructions.required) {
|
|
157
|
-
// Don't do a round trip if a required field is empty - it will show up red
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
// take params of the URL
|
|
164
|
-
var query = $location.$$url.match(/\?.*/);
|
|
165
|
-
if (query) {
|
|
166
|
-
apiCall += connector + query[0].slice(1);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
$http.get(apiCall).then(function (response) {
|
|
170
|
-
var data = response.data;
|
|
171
|
-
if (data.success) {
|
|
172
|
-
$scope.report = data.report;
|
|
173
|
-
$scope.reportSchema = data.schema;
|
|
174
|
-
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
175
|
-
$scope.reportSchema.title = $scope.reportSchema.title.replace(/\|.+?\|/g, function (match) {
|
|
176
|
-
var param = match.slice(1, -1);
|
|
177
|
-
var isParamTest = /\((.+)\)/.exec(param);
|
|
178
|
-
return isParamTest ? $scope.reportSchema.params[isParamTest[1]].value : '';
|
|
179
|
-
});
|
|
125
|
+
$scope.$on('exportToCSV', function () {
|
|
126
|
+
csvPlugIn.createCSV();
|
|
127
|
+
});
|
|
180
128
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
newValue[i].cellClass = newValue[i].cellClass || '';
|
|
194
|
-
if (newValue[i].cellClass.indexOf(alignClass) === -1) {
|
|
195
|
-
newValue[i].cellClass = newValue[i].cellClass + ' ' + alignClass;
|
|
129
|
+
$scope.extractFilter = function (col, filters) {
|
|
130
|
+
if (col.cellFilter) {
|
|
131
|
+
var filterName;
|
|
132
|
+
var filterParam;
|
|
133
|
+
var paramPos = col.cellFilter.indexOf(':');
|
|
134
|
+
if (paramPos === -1) {
|
|
135
|
+
filterName = col.cellFilter;
|
|
136
|
+
} else {
|
|
137
|
+
filterName = col.cellFilter.slice(0, paramPos).trim();
|
|
138
|
+
filterParam = col.cellFilter.slice(paramPos + 1, 999).trim();
|
|
139
|
+
if (filterParam[0] === '\'' || filterParam[0] === '"') {
|
|
140
|
+
filterParam = filterParam.slice(1, -1);
|
|
196
141
|
}
|
|
197
|
-
}
|
|
198
142
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
143
|
+
var filter = angular.element(document.body).injector().get('$filter')(filterName.trim());
|
|
144
|
+
filters[col.field] = {filter: filter, filterParam: filterParam};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
function setupParamsForm(params) {
|
|
149
|
+
$scope.paramSchema = [];
|
|
150
|
+
// set up parameters
|
|
151
|
+
$scope.record = {};
|
|
152
|
+
for (var param in params) {
|
|
153
|
+
if (params.hasOwnProperty(param)) {
|
|
154
|
+
var thisPart = params[param];
|
|
155
|
+
// if noInput then this value will be inferred from another parameter
|
|
156
|
+
if (!thisPart.noInput) {
|
|
157
|
+
var newLen = $scope.paramSchema.push({
|
|
158
|
+
name: param,
|
|
159
|
+
id: 'fp_' + param,
|
|
160
|
+
label: thisPart.label || $filter('titleCase')(param),
|
|
161
|
+
type: thisPart.type || 'text',
|
|
162
|
+
required: true,
|
|
163
|
+
add: thisPart.add || undefined,
|
|
164
|
+
size: thisPart.size || (cssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
165
|
+
});
|
|
166
|
+
if (thisPart.type === 'select') {
|
|
167
|
+
// TODO: Remove when select and select2 is modified during the restructure
|
|
168
|
+
$scope[param + '_Opts'] = thisPart.enum;
|
|
169
|
+
$scope.paramSchema[newLen - 1].options = param + '_Opts';
|
|
170
|
+
}
|
|
204
171
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
172
|
+
var dateTest = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(thisPart.value);
|
|
173
|
+
if (dateTest) {
|
|
174
|
+
thisPart.value = new Date(dateTest[1]);
|
|
175
|
+
}
|
|
176
|
+
$scope.record[param] = thisPart.value;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
$scope.$watch('record', function (newValue, oldValue) {
|
|
180
|
+
if (oldValue !== newValue) {
|
|
181
|
+
$scope.refreshQuery();
|
|
182
|
+
}
|
|
211
183
|
}, true);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var container = document.querySelector('div.report-grow');
|
|
187
|
+
if (container) {
|
|
188
|
+
var margin = container.offsetLeft; // let's have the same top and bottom margins as we have side margin
|
|
189
|
+
var topOffset = container.offsetTop + margin;
|
|
190
|
+
var header = document.querySelector('div.ui-grid-header');
|
|
191
|
+
var headerHeight = header ? header.clientHeight : 31;
|
|
192
|
+
var availRows = Math.floor(($window.innerHeight - topOffset - headerHeight - margin) / 30);
|
|
193
|
+
angular.element(container).css('height', '' + availRows * 30 + 'px');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var navScope = $rootScope.navScope;
|
|
197
|
+
navScope.items = [
|
|
198
|
+
{
|
|
199
|
+
fn: pdfPlugIn.createPDF,
|
|
200
|
+
text: 'Save as PDF'
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
fn: csvPlugIn.createCSV,
|
|
204
|
+
text: 'Export as CSV'
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
navScope.contextMenu = 'Report';
|
|
208
|
+
navScope.contextMenuId = 'reportMenu';
|
|
209
|
+
$scope.titleWithSubstitutions = $scope.reportSchema.title;
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
name: param,
|
|
224
|
-
id: 'fp_' + param,
|
|
225
|
-
label: thisPart.label || $filter('titleCase')(param),
|
|
226
|
-
type: thisPart.type || 'text',
|
|
227
|
-
required: true,
|
|
228
|
-
add: thisPart.add || undefined,
|
|
229
|
-
size: thisPart.size || (cssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
211
|
+
// inhibitRefresh can be set by a controller, for example if report data is being provided as part of the URL
|
|
212
|
+
if (!$scope.inhibitRefresh) {
|
|
213
|
+
|
|
214
|
+
$scope.refreshQuery = function () {
|
|
215
|
+
|
|
216
|
+
function substituteParams(str) {
|
|
217
|
+
return str.replace(/\|.+?\|/g, function (match) {
|
|
218
|
+
var param = match.slice(1, -1);
|
|
219
|
+
var isParamTest = /\((.+)\)/.exec(param);
|
|
220
|
+
return isParamTest ? $scope.reportSchema.params[isParamTest[1]].value : '';
|
|
230
221
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
var apiCall = '/api/report/' + $scope.modelName;
|
|
225
|
+
var connector = '?';
|
|
226
|
+
var haveUrlParams = false;
|
|
227
|
+
var query = $location.$$url.match(/\?.*/);
|
|
228
|
+
|
|
229
|
+
if ($scope.reportSchemaName) {
|
|
230
|
+
apiCall += '/' + $scope.reportSchemaName;
|
|
231
|
+
} else if (query) {
|
|
232
|
+
if (firstTime) {
|
|
233
|
+
// See if we have params in the URL (rather than going through schemaName)
|
|
234
|
+
$scope.paramSchema = JSON.parse($location.search().r).params;
|
|
235
|
+
setupParamsForm($scope.paramSchema);
|
|
235
236
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
thisPart.value = (moment(dateTest[1]).format('YYYY-MM-DDTHH:mm:ss.SSS')) + 'Z';
|
|
240
|
-
}
|
|
241
|
-
$scope.record[param] = thisPart.value;
|
|
237
|
+
apiCall += connector + query[0].slice(1);
|
|
238
|
+
connector = '&';
|
|
239
|
+
haveUrlParams = true;
|
|
242
240
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
|
|
242
|
+
if ($scope.paramSchema) {
|
|
243
|
+
// we are using the params form
|
|
244
|
+
for (var paramVal in $scope.record) {
|
|
245
|
+
if ($scope.record.hasOwnProperty(paramVal)) {
|
|
246
|
+
var instructions = $scope.reportSchema.params[paramVal];
|
|
247
|
+
if ($scope.record[paramVal] && $scope.record[paramVal] !== '') {
|
|
248
|
+
$scope.param = $scope.record[paramVal];
|
|
249
|
+
if (instructions.conversionExpression) {
|
|
250
|
+
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
251
|
+
}
|
|
252
|
+
apiCall += connector + paramVal + '=' + $scope.param;
|
|
253
|
+
connector = '&';
|
|
254
|
+
} else if (instructions.required) {
|
|
255
|
+
// Don't do a round trip if a required field is empty - it will show up red
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
if (!haveUrlParams && query) {
|
|
262
|
+
apiCall += connector + query[0].slice(1);
|
|
263
|
+
connector = '&';
|
|
264
|
+
}
|
|
247
265
|
}
|
|
248
|
-
|
|
266
|
+
return $http.get(apiCall).then(function (response) {
|
|
267
|
+
if (response && response.data && response.data.success) {
|
|
268
|
+
var data = response.data;
|
|
269
|
+
$scope.report = data.report;
|
|
270
|
+
$scope.reportSchema = data.schema;
|
|
271
|
+
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
272
|
+
$scope.titleWithSubstitutions = substituteParams($scope.reportSchema.title);
|
|
273
|
+
$scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
|
|
274
|
+
if (navScope && navScope.items) {
|
|
275
|
+
navScope.items.length = 2;
|
|
276
|
+
if ($scope.reportSchema.menu) {
|
|
277
|
+
$scope.reportSchema.menu.forEach(function (m) {
|
|
278
|
+
navScope.items.push(JSON.parse(substituteParams(JSON.stringify(m))));
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/*
|
|
284
|
+
Generate link data
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
if (firstTime) {
|
|
288
|
+
firstTime = false;
|
|
289
|
+
|
|
290
|
+
$scope.$watch('reportSchema.columnDefs', function (newValue) {
|
|
291
|
+
var columnTotals = false;
|
|
292
|
+
if (newValue) {
|
|
293
|
+
for (var i = 0; i < newValue.length; i++) {
|
|
294
|
+
if (newValue[i].totalsRow) {
|
|
295
|
+
columnTotals = true;
|
|
296
|
+
}
|
|
297
|
+
if (newValue[i].align) {
|
|
298
|
+
var alignClass = 'fng-' + newValue[i].align;
|
|
299
|
+
newValue[i].cellClass = newValue[i].cellClass || '';
|
|
300
|
+
if (newValue[i].cellClass.indexOf(alignClass) === -1) {
|
|
301
|
+
newValue[i].cellClass = newValue[i].cellClass + ' ' + alignClass;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Auto-upgrade from ng-grid to ui-grid
|
|
306
|
+
newValue.forEach(function (def) {
|
|
307
|
+
// Remove px from column widths
|
|
308
|
+
if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
|
|
309
|
+
def.width = parseInt(def.width.slice(0, -2));
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
$scope.gridOptions.columnDefs = newValue;
|
|
313
|
+
}
|
|
314
|
+
$scope.gridOptions.showTotals = columnTotals;
|
|
315
|
+
$scope.gridOptions.reallyShowFooter = columnTotals;
|
|
316
|
+
$scope.gridOptions.footerRowHeight = 55 + (columnTotals ? 10 : 0);
|
|
317
|
+
}, true);
|
|
318
|
+
|
|
319
|
+
if (!$scope.paramSchema && data.schema.params) {
|
|
320
|
+
setupParamsForm(data.schema.params);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
$scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');
|
|
325
|
+
$scope.reportSchema.title = 'Error - see console log';
|
|
326
|
+
}
|
|
327
|
+
}, function (error) {
|
|
328
|
+
let body, title;
|
|
329
|
+
if (error.status === 403) {
|
|
330
|
+
body = 'You do not have permission to run this report (permission to GET all ' + $scope.modelName + ' records is required)';
|
|
331
|
+
title = 'Permission denied';
|
|
332
|
+
} else {
|
|
333
|
+
body = 'The server could not process the request';
|
|
334
|
+
title = 'Error';
|
|
335
|
+
}
|
|
336
|
+
$scope.showError(body, title);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
249
339
|
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
console.log(JSON.stringify(data));
|
|
254
|
-
$scope.reportSchema.title = 'Error - see console log';
|
|
340
|
+
$scope.refreshQuery();
|
|
255
341
|
}
|
|
256
|
-
}, function (response) {
|
|
257
|
-
console.log(JSON.stringify(response));
|
|
258
|
-
$location.path('/404');
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
342
|
|
|
262
|
-
|
|
343
|
+
// Check whether a cell template shows the content (in which case we want to output it) or does something funky
|
|
344
|
+
// (for example displays an image)
|
|
345
|
+
$scope.showsContent = function (template, col) {
|
|
346
|
+
if (/{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''))) {
|
|
347
|
+
return true;
|
|
348
|
+
} else if (template.indexOf('ng-bind-html="row.entity.' + col) !== -1) {
|
|
349
|
+
return 'HTML';
|
|
350
|
+
}
|
|
351
|
+
};
|
|
263
352
|
|
|
264
|
-
|
|
353
|
+
$scope.$on('$locationChangeStart', function () {
|
|
354
|
+
delete navScope.contextMenu;
|
|
355
|
+
delete navScope.items;
|
|
356
|
+
});
|
|
265
357
|
|
|
358
|
+
// Error handling, stolen quickly from forms-angulat record-handler
|
|
359
|
+
$scope.showError = function(error, alertTitle) {
|
|
360
|
+
$scope.alertTitle = alertTitle ? alertTitle : 'Error!';
|
|
361
|
+
if (typeof error === 'string') {
|
|
362
|
+
$scope.errorMessage = error;
|
|
363
|
+
} else if (!error) {
|
|
364
|
+
$scope.errorMessage = `An error occurred - that's all we got. Sorry.`;
|
|
365
|
+
} else if (error.message && typeof error.message === 'string') {
|
|
366
|
+
$scope.errorMessage = error.message;
|
|
367
|
+
} else if (error.data && error.data.message) {
|
|
368
|
+
$scope.errorMessage = error.data.message;
|
|
369
|
+
} else {
|
|
370
|
+
try {
|
|
371
|
+
$scope.errorMessage = JSON.stringify(error);
|
|
372
|
+
} catch (e) {
|
|
373
|
+
$scope.errorMessage = error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
$scope.errorHideTimer = window.setTimeout(function() {
|
|
377
|
+
$scope.dismissError();
|
|
378
|
+
$scope.$digest();
|
|
379
|
+
}, 3500 + (1000 * ($scope.alertTitle + $scope.errorMessage).length / 50));
|
|
380
|
+
$scope.errorVisible = true;
|
|
381
|
+
window.setTimeout(() => {
|
|
382
|
+
$scope.$digest();
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
$scope.clearTimeout = function() {
|
|
387
|
+
if ($scope.errorHideTimer) {
|
|
388
|
+
clearTimeout($scope.errorHideTimer);
|
|
389
|
+
delete $scope.errorHideTimer;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
266
392
|
|
|
393
|
+
$scope.dismissError = function() {
|
|
394
|
+
$scope.clearTimeout;
|
|
395
|
+
$scope.errorVisible = false;
|
|
396
|
+
delete $scope.errorMessage;
|
|
397
|
+
delete $scope.alertTitle;
|
|
398
|
+
};
|
|
267
399
|
|
|
400
|
+
$scope.stickError = function() {
|
|
401
|
+
clearTimeout($scope.errorHideTimer);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
}]);
|
|
268
405
|
|
|
269
406
|
'use strict';
|
|
270
407
|
var COL_FIELD = /COL_FIELD/g;
|
|
@@ -323,57 +460,46 @@ function ngGridCsvExportPlugin(opts) {
|
|
|
323
460
|
var self = this;
|
|
324
461
|
self.grid = null;
|
|
325
462
|
self.scope = null;
|
|
463
|
+
self.services = null;
|
|
326
464
|
|
|
327
465
|
self.init = function (scope, grid, services) {
|
|
328
|
-
|
|
329
|
-
function doDownloadButton() {
|
|
330
|
-
var fp = angular.element('h1').parent();
|
|
331
|
-
var csvDataLinkPrevious = angular.element('#csv-data-link');
|
|
332
|
-
if (csvDataLinkPrevious != null) {
|
|
333
|
-
csvDataLinkPrevious.remove();
|
|
334
|
-
}
|
|
335
|
-
var csvDataLinkHtml = "<button id=\"csv-data-link\" class=\"btn\"><a href=\"data:text/csv;charset=UTF-8,";
|
|
336
|
-
csvDataLinkHtml += encodeURIComponent(self.prepareCSV());
|
|
337
|
-
csvDataLinkHtml += "\" download=\"Export.csv\">CSV Export</button>";
|
|
338
|
-
fp.append(csvDataLinkHtml);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
466
|
self.grid = grid;
|
|
342
467
|
self.scope = scope;
|
|
343
|
-
|
|
344
|
-
if (!opts.inhibitButton) {
|
|
345
|
-
setTimeout(doDownloadButton, 0);
|
|
346
|
-
scope.catHashKeys = function () {
|
|
347
|
-
var hash = '';
|
|
348
|
-
for (var idx in scope.renderedRows) {
|
|
349
|
-
hash += scope.renderedRows[idx].$$hashKey;
|
|
350
|
-
}
|
|
351
|
-
return hash;
|
|
352
|
-
};
|
|
353
|
-
scope.$watch('catHashKeys()', doDownloadButton);
|
|
354
|
-
}
|
|
468
|
+
self.services = services;
|
|
355
469
|
};
|
|
356
470
|
|
|
471
|
+
function downloadFile(fileName, urlData) {
|
|
472
|
+
|
|
473
|
+
var aLink = document.createElement('a');
|
|
474
|
+
aLink.download = fileName;
|
|
475
|
+
aLink.href = urlData;
|
|
476
|
+
|
|
477
|
+
var event = new MouseEvent('click');
|
|
478
|
+
aLink.dispatchEvent(event);
|
|
479
|
+
}
|
|
480
|
+
|
|
357
481
|
self.createCSV = function () {
|
|
358
|
-
|
|
482
|
+
downloadFile(self.scope.reportSchema.title + '.csv','data:text/csv;charset=UTF-8,' + encodeURIComponent(self.prepareCSV()));
|
|
359
483
|
};
|
|
360
484
|
|
|
361
485
|
self.prepareCSV = function () {
|
|
362
486
|
|
|
363
|
-
function csvStringify(str) {
|
|
487
|
+
function csvStringify(str, filter) {
|
|
364
488
|
if (str == null) { // we want to catch anything null-ish, hence just == not ===
|
|
365
489
|
return '';
|
|
366
490
|
}
|
|
367
|
-
if (
|
|
491
|
+
if (filter) {
|
|
492
|
+
return filter.filter(str, filter.filterParam);
|
|
493
|
+
}
|
|
494
|
+
if (typeof (str) === 'number') {
|
|
368
495
|
return '' + str;
|
|
369
496
|
}
|
|
370
|
-
if (typeof(str) === 'boolean') {
|
|
497
|
+
if (typeof (str) === 'boolean') {
|
|
371
498
|
return (str ? 'TRUE' : 'FALSE');
|
|
372
499
|
}
|
|
373
|
-
if (typeof(str) === 'string') {
|
|
500
|
+
if (typeof (str) === 'string') {
|
|
374
501
|
return str.replace(/"/g, '""');
|
|
375
502
|
}
|
|
376
|
-
|
|
377
503
|
return JSON.stringify(str).replace(/"/g, '""');
|
|
378
504
|
}
|
|
379
505
|
|
|
@@ -383,21 +509,56 @@ function ngGridCsvExportPlugin(opts) {
|
|
|
383
509
|
}
|
|
384
510
|
|
|
385
511
|
var csvData = '';
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
512
|
+
var filters = {};
|
|
513
|
+
angular.forEach(self.grid.columns, function (col) {
|
|
514
|
+
self.scope.extractFilter(col, filters);
|
|
515
|
+
if (col.visible && (col.width === undefined || col.width === '*' || col.width > 0)) {
|
|
516
|
+
if (col.field.indexOf('.') !== -1) {
|
|
517
|
+
console.error(`Cannot export nested fields such as ${col.field}. Use $project to simplify.`);
|
|
518
|
+
} else {
|
|
519
|
+
if (!col.colDef.cellTemplate) {
|
|
520
|
+
csvData += '"' + csvStringify(col.displayName) + '",';
|
|
521
|
+
col.doCSVExport = true;
|
|
522
|
+
} else {
|
|
523
|
+
const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
|
|
524
|
+
if (templateResp === 'HTML') {
|
|
525
|
+
csvData += '"' + csvStringify(col.displayName) + '",';
|
|
526
|
+
col.doCSVExport = function (value) {
|
|
527
|
+
value = value.replace(/<p>/g, '\n\n');
|
|
528
|
+
value = value.replace(/<\/p>/g, '');
|
|
529
|
+
value = value.replace(/<\s?br\s?\/?>/g, '\n');
|
|
530
|
+
value = value.replace(/<[^>]+>/g, '');
|
|
531
|
+
value = value.replaceAll(' ', ' ').trim();
|
|
532
|
+
value = value.replaceAll('\n\n \n\n', '\n\n');
|
|
533
|
+
value = value.replaceAll('\n\n\n', '\n\n');
|
|
534
|
+
return value;
|
|
535
|
+
};
|
|
536
|
+
} else if (templateResp) {
|
|
537
|
+
csvData += '"' + csvStringify(col.displayName) + '",';
|
|
538
|
+
col.doCSVExport = true;
|
|
539
|
+
} else {
|
|
540
|
+
col.doCSVExport = false;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
389
544
|
}
|
|
390
545
|
});
|
|
391
546
|
|
|
392
547
|
csvData = swapLastCommaForNewline(csvData);
|
|
393
548
|
|
|
394
|
-
angular.forEach(self.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
549
|
+
angular.forEach(self.scope.gridApi.core.getVisibleRows(), function (row) {
|
|
550
|
+
if (row.visible) {
|
|
551
|
+
angular.forEach(self.grid.columns, function (col) {
|
|
552
|
+
if (col.doCSVExport) {
|
|
553
|
+
let value = row.entity[col.field];
|
|
554
|
+
if (typeof col.doCSVExport === 'function') {
|
|
555
|
+
value = col.doCSVExport(value);
|
|
556
|
+
}
|
|
557
|
+
csvData += '"' + csvStringify(value, filters[col.field]) + '",';
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
csvData = swapLastCommaForNewline(csvData);
|
|
561
|
+
}
|
|
401
562
|
});
|
|
402
563
|
|
|
403
564
|
return csvData;
|
|
@@ -411,6 +572,10 @@ function ngGridCsvExportPlugin(opts) {
|
|
|
411
572
|
but that would require putting the totals (ngGridTotalCell.js) into a plugin.
|
|
412
573
|
*/
|
|
413
574
|
|
|
575
|
+
/**
|
|
576
|
+
* FOOTER NO LONGER SUPPORTED
|
|
577
|
+
*/
|
|
578
|
+
|
|
414
579
|
function ngGridPdfExportPlugin(options) {
|
|
415
580
|
var self = this;
|
|
416
581
|
self.grid = null;
|
|
@@ -439,475 +604,527 @@ function ngGridPdfExportPlugin(options) {
|
|
|
439
604
|
|
|
440
605
|
self.createPDF = function () {
|
|
441
606
|
var headers = [],
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
angular.forEach(self.scope.columns, function (col) {
|
|
448
|
-
if (col.visible && (col.width === undefined || col.width > 0)) {
|
|
449
|
-
headers.push({name: col.field, prompt: col.displayName, width: col.width * (185 / gridWidth), align: (col.colDef.align || 'left')});
|
|
450
|
-
if (col.colDef.totalsRow) {
|
|
451
|
-
footers[col.field] = self.scope.getTotalVal(col.field, col.filter).toString();
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
angular.forEach(self.grid.filteredRows, function (row) {
|
|
457
|
-
data.push(angular.copy(row.entity));
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
var doc = new jsPDF('landscape', 'mm', 'a4');
|
|
461
|
-
doc.setFontStyle('bold');
|
|
462
|
-
doc.setFontSize(24);
|
|
463
|
-
doc.text(self.scope.reportSchema.title, margin, margin);
|
|
464
|
-
doc.setFontStyle('normal');
|
|
465
|
-
doc.setFontSize(12);
|
|
466
|
-
doc.cellInitialize();
|
|
467
|
-
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}});
|
|
468
|
-
doc.output('dataurlnewwindow');
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
|
|
607
|
+
headerNames = [],
|
|
608
|
+
footers = [],
|
|
609
|
+
data = [],
|
|
610
|
+
filters = {},
|
|
611
|
+
transformers = {};
|
|
472
612
|
|
|
473
|
-
/** ====================================================================
|
|
474
|
-
* jsPDF Cell plugin
|
|
475
|
-
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
|
|
476
|
-
* 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
|
|
477
|
-
* 2013 Lee Driscoll, https://github.com/lsdriscoll
|
|
478
|
-
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
|
|
479
|
-
* 2014 James Hall, james@parall.ax
|
|
480
|
-
*
|
|
481
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
482
|
-
* a copy of this software and associated documentation files (the
|
|
483
|
-
* "Software"), to deal in the Software without restriction, including
|
|
484
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
|
485
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
486
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
|
487
|
-
* the following conditions:
|
|
488
|
-
*
|
|
489
|
-
* The above copyright notice and this permission notice shall be
|
|
490
|
-
* included in all copies or substantial portions of the Software.
|
|
491
|
-
*
|
|
492
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
493
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
494
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
495
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
496
|
-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
497
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
498
|
-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
499
|
-
* ====================================================================
|
|
500
|
-
*/
|
|
501
|
-
|
|
502
|
-
(function (jsPDFAPI) {
|
|
503
|
-
'use strict';
|
|
504
|
-
/*jslint browser:true */
|
|
505
|
-
/*global document: false, jsPDF */
|
|
506
|
-
|
|
507
|
-
var fontName,
|
|
508
|
-
fontSize,
|
|
509
|
-
fontStyle,
|
|
510
|
-
padding = 3,
|
|
511
|
-
margin = 13,
|
|
512
|
-
headerFunction,
|
|
513
|
-
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
|
|
514
|
-
pages = 1,
|
|
515
|
-
setLastCellPosition = function (x, y, w, h, ln) {
|
|
516
|
-
lastCellPos = { 'x': x, 'y': y, 'w': w, 'h': h, 'ln': ln };
|
|
517
|
-
},
|
|
518
|
-
getLastCellPosition = function () {
|
|
519
|
-
return lastCellPos;
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
jsPDFAPI.setHeaderFunction = function (func) {
|
|
523
|
-
headerFunction = func;
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
jsPDFAPI.getTextDimensions = function (txt) {
|
|
527
|
-
fontName = this.internal.getFont().fontName;
|
|
528
|
-
fontSize = this.table_font_size || this.internal.getFontSize();
|
|
529
|
-
fontStyle = this.internal.getFont().fontStyle;
|
|
530
|
-
// 1 pixel = 0.264583 mm and 1 mm = 72/25.4 point
|
|
531
|
-
var px2pt = 0.264583 * 72 / 25.4,
|
|
532
|
-
dimensions,
|
|
533
|
-
text;
|
|
534
|
-
|
|
535
|
-
text = document.createElement('font');
|
|
536
|
-
text.id = "jsPDFCell";
|
|
537
|
-
text.style.fontStyle = fontStyle;
|
|
538
|
-
text.style.fontName = fontName;
|
|
539
|
-
text.style.fontSize = fontSize + 'pt';
|
|
540
|
-
text.innerText = txt;
|
|
541
|
-
|
|
542
|
-
document.body.appendChild(text);
|
|
543
|
-
|
|
544
|
-
dimensions = { w: (text.offsetWidth + 1) * px2pt, h: (text.offsetHeight + 1) * px2pt};
|
|
545
|
-
|
|
546
|
-
document.body.removeChild(text);
|
|
547
|
-
|
|
548
|
-
return dimensions;
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
jsPDFAPI.cellAddPage = function () {
|
|
552
|
-
this.addPage();
|
|
553
|
-
|
|
554
|
-
setLastCellPosition(this.margins.left, this.margins.top, undefined, undefined);
|
|
555
|
-
//setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
|
|
556
|
-
pages += 1;
|
|
557
|
-
};
|
|
558
613
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
jsPDFAPI.cell = function (x, y, w, h, txt, ln, align) {
|
|
565
|
-
var curCell = getLastCellPosition();
|
|
566
|
-
|
|
567
|
-
// If this is not the first cell, we must change its position
|
|
568
|
-
if (curCell.ln !== undefined) {
|
|
569
|
-
if (curCell.ln === ln) {
|
|
570
|
-
//Same line
|
|
571
|
-
x = curCell.x + curCell.w;
|
|
572
|
-
y = curCell.y;
|
|
573
|
-
} else {
|
|
574
|
-
//New line
|
|
575
|
-
if ((curCell.y + curCell.h + h + margin) >= this.internal.pageSize.height - this.margins.bottom) {
|
|
576
|
-
this.cellAddPage();
|
|
577
|
-
if (this.printHeaders && this.tableHeaderRow) {
|
|
578
|
-
this.printHeaderRow(ln, true);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
//We ignore the passed y: the lines may have diferent heights
|
|
582
|
-
y = (getLastCellPosition().y + getLastCellPosition().h);
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
if (txt[0] !== undefined) {
|
|
588
|
-
if (this.printingHeaderRow) {
|
|
589
|
-
this.rect(x, y, w, h, 'FD');
|
|
590
|
-
} else {
|
|
591
|
-
this.rect(x, y, w, h);
|
|
592
|
-
}
|
|
593
|
-
if (align === 'right') {
|
|
594
|
-
var textSize;
|
|
595
|
-
if (txt instanceof Array) {
|
|
596
|
-
for (var i = 0; i < txt.length; i++) {
|
|
597
|
-
var currentLine = txt[i];
|
|
598
|
-
textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize() / (72 / 25.6);
|
|
599
|
-
this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight() * (i + 1));
|
|
600
|
-
}
|
|
614
|
+
angular.forEach(self.grid.columns, function (col, index) {
|
|
615
|
+
if (col.visible) {
|
|
616
|
+
if (col.field.indexOf('.') !== -1) {
|
|
617
|
+
console.error(`Cannot export nested fields such as ${col.field}. Use $project to simplify.`);
|
|
601
618
|
} else {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
: function (object) {
|
|
626
|
-
var keys = [],
|
|
627
|
-
property;
|
|
628
|
-
|
|
629
|
-
for (property in object) {
|
|
630
|
-
if (object.hasOwnProperty(property)) {
|
|
631
|
-
keys.push(property);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
return keys;
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Return the maximum value from an array
|
|
640
|
-
* @param array
|
|
641
|
-
* @param comparisonFn
|
|
642
|
-
* @returns {*}
|
|
643
|
-
*/
|
|
644
|
-
jsPDFAPI.arrayMax = function (array, comparisonFn) {
|
|
645
|
-
var max = array[0],
|
|
646
|
-
i,
|
|
647
|
-
ln,
|
|
648
|
-
item;
|
|
649
|
-
|
|
650
|
-
for (i = 0, ln = array.length; i < ln; i += 1) {
|
|
651
|
-
item = array[i];
|
|
652
|
-
|
|
653
|
-
if (comparisonFn) {
|
|
654
|
-
if (comparisonFn(max, item) === -1) {
|
|
655
|
-
max = item;
|
|
656
|
-
}
|
|
657
|
-
} else {
|
|
658
|
-
if (item > max) {
|
|
659
|
-
max = item;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
return max;
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* Create a table from a set of data.
|
|
669
|
-
* @param {Integer} [x] : left-position for top-left corner of table
|
|
670
|
-
* @param {Integer} [y] top-position for top-left corner of table
|
|
671
|
-
* @param {Object[]} [data] As array of objects containing key-value pairs corresponding to a row of data.
|
|
672
|
-
* @param {Object} [config.headers] String[] Omit or null to auto-generate headers at a performance cost
|
|
673
|
-
* @param {Object} [config.footers] Object containing key-value pairs. Omit or null if not required
|
|
674
|
-
* @param {Object} [config.printHeaders] True to print column headers at the top of every page
|
|
675
|
-
* @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
|
|
676
|
-
* @param {Object} [config.margins] margin values for left, top, bottom, and width
|
|
677
|
-
* @param {Object} [config.fontSize] Integer fontSize to use (optional)
|
|
678
|
-
*/
|
|
679
|
-
|
|
680
|
-
jsPDFAPI.table = function (x, y, data, config) {
|
|
681
|
-
if (!data) {
|
|
682
|
-
throw 'No data for PDF table';
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
var headerNames = [],
|
|
686
|
-
headerPrompts = [],
|
|
687
|
-
header,
|
|
688
|
-
i,
|
|
689
|
-
ln,
|
|
690
|
-
cln,
|
|
691
|
-
columnMatrix = {},
|
|
692
|
-
columnWidths = {},
|
|
693
|
-
columnData,
|
|
694
|
-
column,
|
|
695
|
-
columnMinWidths = [],
|
|
696
|
-
columnAligns = [],
|
|
697
|
-
j,
|
|
698
|
-
tableHeaderConfigs = [],
|
|
699
|
-
model,
|
|
700
|
-
jln,
|
|
701
|
-
func,
|
|
702
|
-
|
|
703
|
-
//set up defaults. If a value is provided in config, defaults will be overwritten:
|
|
704
|
-
autoSize = false,
|
|
705
|
-
printHeaders = true,
|
|
706
|
-
fontSize = 12,
|
|
707
|
-
headers = null,
|
|
708
|
-
footers = null,
|
|
709
|
-
margins = {left: 0, top: 0, bottom: 0, width: this.internal.pageSize.width};
|
|
710
|
-
|
|
711
|
-
if (config) {
|
|
712
|
-
//override config defaults if the user has specified non-default behavior:
|
|
713
|
-
if (config.autoSize === true) {
|
|
714
|
-
autoSize = true;
|
|
715
|
-
}
|
|
716
|
-
if (config.printHeaders === false) {
|
|
717
|
-
printHeaders = false;
|
|
718
|
-
}
|
|
719
|
-
if (config.fontSize) {
|
|
720
|
-
fontSize = config.fontSize;
|
|
721
|
-
}
|
|
722
|
-
if (config.margins) {
|
|
723
|
-
margins = config.margins;
|
|
724
|
-
}
|
|
725
|
-
if (config.headers) {
|
|
726
|
-
headers = config.headers;
|
|
727
|
-
}
|
|
728
|
-
if (config.footers) {
|
|
729
|
-
footers = config.footers;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* @property {Number} lnMod
|
|
735
|
-
* Keep track of the current line number modifier used when creating cells
|
|
736
|
-
*/
|
|
737
|
-
this.lnMod = 0;
|
|
738
|
-
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
|
|
739
|
-
pages = 1;
|
|
740
|
-
|
|
741
|
-
this.printHeaders = printHeaders;
|
|
742
|
-
this.margins = margins;
|
|
743
|
-
this.setFontSize(fontSize);
|
|
744
|
-
this.table_font_size = fontSize;
|
|
745
|
-
|
|
746
|
-
// Set header values
|
|
747
|
-
if (headers === undefined || (headers === null)) {
|
|
748
|
-
// No headers defined so we derive from data
|
|
749
|
-
headerNames = this.getKeys(data[0]);
|
|
750
|
-
|
|
751
|
-
} else if (headers[0] && (typeof headers[0] !== 'string')) {
|
|
752
|
-
// var px2pt = 0.264583 * 72 / 25.4;
|
|
753
|
-
var constant = 1.5; // arrived at by trial and error
|
|
754
|
-
|
|
755
|
-
// Split header configs into names and prompts
|
|
756
|
-
for (i = 0, ln = headers.length; i < ln; i += 1) {
|
|
757
|
-
header = headers[i];
|
|
758
|
-
headerNames.push(header.name);
|
|
759
|
-
headerPrompts.push(header.prompt);
|
|
760
|
-
columnWidths[header.name] = header.width * constant;
|
|
761
|
-
columnAligns[header.name] = header.align;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
} else {
|
|
765
|
-
headerNames = headers;
|
|
766
|
-
}
|
|
767
|
-
if (autoSize) {
|
|
768
|
-
// Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]}
|
|
769
|
-
func = function (rec) {
|
|
770
|
-
return rec[header];
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
for (i = 0, ln = headerNames.length; i < ln; i += 1) {
|
|
774
|
-
header = headerNames[i];
|
|
775
|
-
|
|
776
|
-
columnMatrix[header] = data.map(
|
|
777
|
-
func
|
|
778
|
-
);
|
|
779
|
-
|
|
780
|
-
// get header width
|
|
781
|
-
columnMinWidths.push(this.getTextDimensions(headerPrompts[i] || header).w);
|
|
782
|
-
column = columnMatrix[header];
|
|
783
|
-
|
|
784
|
-
// get cell widths
|
|
785
|
-
for (j = 0, cln = column.length; j < cln; j += 1) {
|
|
786
|
-
columnData = column[j];
|
|
787
|
-
columnMinWidths.push(this.getTextDimensions(columnData).w);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
// get footer width
|
|
791
|
-
if (footers) {
|
|
792
|
-
columnMinWidths.push(this.getTextDimensions(footers[i]).w);
|
|
619
|
+
if (!col.colDef.cellTemplate) {
|
|
620
|
+
headers.push(col.displayName);
|
|
621
|
+
headerNames.push(col.field);
|
|
622
|
+
} else {
|
|
623
|
+
const templateResp = self.scope.showsContent(col.colDef.cellTemplate, col.field);
|
|
624
|
+
if (templateResp === 'HTML') {
|
|
625
|
+
headers.push(col.displayName);
|
|
626
|
+
headerNames.push(col.field);
|
|
627
|
+
transformers[col.field] = function (value) {
|
|
628
|
+
value = value.replace(/<p>/g, '\n\n');
|
|
629
|
+
value = value.replace(/<\/p>/g, '');
|
|
630
|
+
value = value.replace(/<\s?br\s?\/?>/g, '\n');
|
|
631
|
+
value = value.replace(/<[^>]+>/g, '');
|
|
632
|
+
value = value.replaceAll(' ', ' ').trim();
|
|
633
|
+
value = value.replaceAll('\n\n \n\n', '\n\n');
|
|
634
|
+
value = value.replaceAll('\n\n\n', '\n\n');
|
|
635
|
+
return value;
|
|
636
|
+
};
|
|
637
|
+
} else if (templateResp) {
|
|
638
|
+
headers.push(col.displayName);
|
|
639
|
+
headerNames.push(col.field);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
793
642
|
}
|
|
794
|
-
|
|
795
|
-
// get final column width
|
|
796
|
-
columnWidths[header] = jsPDFAPI.arrayMax(columnMinWidths);
|
|
797
643
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
// -- Construct the table
|
|
801
|
-
|
|
802
|
-
if (printHeaders) {
|
|
803
|
-
var lineHeight = this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length ? headerPrompts : headerNames);
|
|
804
|
-
|
|
805
|
-
// Construct the header row
|
|
806
|
-
for (i = 0, ln = headerNames.length; i < ln; i += 1) {
|
|
807
|
-
header = headerNames[i];
|
|
808
|
-
tableHeaderConfigs.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header), 0, columnAligns[header]]);
|
|
644
|
+
if (col.colDef.totalsRow) {
|
|
645
|
+
footers[col.field] = self.grid.getTotalVal(col.field, col.filter).toString();
|
|
809
646
|
}
|
|
647
|
+
self.scope.extractFilter(col, filters);
|
|
648
|
+
});
|
|
810
649
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
650
|
+
angular.forEach(self.scope.gridApi.core.getVisibleRows(), function (row) {
|
|
651
|
+
var output = [];
|
|
652
|
+
if (row.visible) {
|
|
653
|
+
headerNames.forEach(function(h) {
|
|
654
|
+
var val = row.entity[h];
|
|
655
|
+
if (filters[h]) {
|
|
656
|
+
val = filters[h].filter(val, filters[h].filterParam);
|
|
657
|
+
}
|
|
658
|
+
if (transformers[h]) {
|
|
659
|
+
val = transformers[h](val);
|
|
660
|
+
}
|
|
661
|
+
if (typeof val === 'string') {
|
|
662
|
+
// chars > 255 cause BOM characters - see https://reallycare.freshdesk.com/a/tickets/2370
|
|
663
|
+
// first replace the predictable chars
|
|
664
|
+
val = val.replace(/\u2019/g,'\'');
|
|
665
|
+
val = val.replace(/\u2018/g,'\'');
|
|
666
|
+
val = val.replace(/\u201c/g,'"');
|
|
667
|
+
val = val.replace(/\u201d/g,'"');
|
|
668
|
+
|
|
669
|
+
// Then strip out anything left over 255
|
|
670
|
+
val = val.replace(/[^\x00-\xFF]/g, '');
|
|
671
|
+
}
|
|
672
|
+
output.push(val);
|
|
673
|
+
});
|
|
674
|
+
data.push(output);
|
|
835
675
|
}
|
|
676
|
+
});
|
|
836
677
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
};
|
|
844
|
-
/**
|
|
845
|
-
* Calculate the height for containing the highest column
|
|
846
|
-
* @param {String[]} headerNames is the header, used as keys to the data
|
|
847
|
-
* @param {Integer[]} columnWidths is size of each column
|
|
848
|
-
* @param {Object[]} model is the line of data we want to calculate the height of
|
|
849
|
-
*/
|
|
850
|
-
jsPDFAPI.calculateLineHeight = function (headerNames, columnWidths, model) {
|
|
851
|
-
var header, lineHeight = 0;
|
|
852
|
-
for (var j = 0; j < headerNames.length; j++) {
|
|
853
|
-
header = headerNames[j];
|
|
854
|
-
model[header] = this.splitTextToSize(String(model[header]), columnWidths[header] - padding);
|
|
855
|
-
var h = this.internal.getLineHeight() * model[header].length + padding;
|
|
856
|
-
if (h > lineHeight)
|
|
857
|
-
lineHeight = h;
|
|
858
|
-
}
|
|
859
|
-
return lineHeight;
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* Store the config for outputting a table header
|
|
864
|
-
* @param {Object[]} config
|
|
865
|
-
* An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
|
|
866
|
-
* except the ln parameter is excluded
|
|
867
|
-
*/
|
|
868
|
-
jsPDFAPI.setTableHeaderRow = function (config) {
|
|
869
|
-
this.tableHeaderRow = config;
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Output the store header row
|
|
874
|
-
* @param lineNumber The line number to output the header at
|
|
875
|
-
*/
|
|
876
|
-
jsPDFAPI.printHeaderRow = function (lineNumber, new_page) {
|
|
877
|
-
if (!this.tableHeaderRow) {
|
|
878
|
-
throw 'Property tableHeaderRow does not exist.';
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
var tableHeaderCell,
|
|
882
|
-
tmpArray,
|
|
883
|
-
i,
|
|
884
|
-
ln;
|
|
678
|
+
// var doc = new jsPDF('landscape', 'mm', 'a4');
|
|
679
|
+
var doc = new jspdf.jsPDF('landscape', 'mm', 'a4');
|
|
680
|
+
doc.autoTable({
|
|
681
|
+
head: [headers],
|
|
682
|
+
body: data
|
|
683
|
+
});
|
|
885
684
|
|
|
886
|
-
|
|
887
|
-
if (headerFunction !== undefined) {
|
|
888
|
-
var position = headerFunction(this, pages);
|
|
889
|
-
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
|
|
890
|
-
}
|
|
891
|
-
this.setFontStyle('bold');
|
|
892
|
-
var tempHeaderConf = [];
|
|
893
|
-
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
|
|
894
|
-
this.setFillColor(200, 200, 200);
|
|
895
|
-
|
|
896
|
-
tableHeaderCell = this.tableHeaderRow[i];
|
|
897
|
-
if (new_page) {
|
|
898
|
-
tableHeaderCell[1] = this.margins.top;
|
|
899
|
-
tempHeaderConf.push(tableHeaderCell);
|
|
900
|
-
}
|
|
901
|
-
tmpArray = [].concat(tableHeaderCell);
|
|
902
|
-
tmpArray[5] = lineNumber;
|
|
903
|
-
this.cell.apply(this, tmpArray);
|
|
904
|
-
}
|
|
905
|
-
if (tempHeaderConf.length > 0) {
|
|
906
|
-
this.setTableHeaderRow(tempHeaderConf);
|
|
907
|
-
}
|
|
908
|
-
this.setFontStyle('normal');
|
|
909
|
-
this.printingHeaderRow = false;
|
|
685
|
+
window.open(doc.output('bloburl'));
|
|
910
686
|
};
|
|
687
|
+
}
|
|
911
688
|
|
|
912
|
-
})(jsPDF.API);
|
|
913
689
|
|
|
690
|
+
// /** ====================================================================
|
|
691
|
+
// * jsPDF Cell plugin
|
|
692
|
+
// * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
|
|
693
|
+
// * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
|
|
694
|
+
// * 2013 Lee Driscoll, https://github.com/lsdriscoll
|
|
695
|
+
// * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
|
|
696
|
+
// * 2014 James Hall, james@parall.ax
|
|
697
|
+
// *
|
|
698
|
+
// * Permission is hereby granted, free of charge, to any person obtaining
|
|
699
|
+
// * a copy of this software and associated documentation files (the
|
|
700
|
+
// * "Software"), to deal in the Software without restriction, including
|
|
701
|
+
// * without limitation the rights to use, copy, modify, merge, publish,
|
|
702
|
+
// * distribute, sublicense, and/or sell copies of the Software, and to
|
|
703
|
+
// * permit persons to whom the Software is furnished to do so, subject to
|
|
704
|
+
// * the following conditions:
|
|
705
|
+
// *
|
|
706
|
+
// * The above copyright notice and this permission notice shall be
|
|
707
|
+
// * included in all copies or substantial portions of the Software.
|
|
708
|
+
// *
|
|
709
|
+
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
710
|
+
// * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
711
|
+
// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
712
|
+
// * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
713
|
+
// * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
714
|
+
// * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
715
|
+
// * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
716
|
+
// * ====================================================================
|
|
717
|
+
// */
|
|
718
|
+
//
|
|
719
|
+
// (function (jsPDFAPI) {
|
|
720
|
+
// 'use strict';
|
|
721
|
+
// /*jslint browser:true */
|
|
722
|
+
// /*global document: false, jsPDF */
|
|
723
|
+
//
|
|
724
|
+
// var fontName,
|
|
725
|
+
// fontSize,
|
|
726
|
+
// fontStyle,
|
|
727
|
+
// padding = 3,
|
|
728
|
+
// margin = 13,
|
|
729
|
+
// headerFunction,
|
|
730
|
+
// lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
|
|
731
|
+
// pages = 1,
|
|
732
|
+
// setLastCellPosition = function (x, y, w, h, ln) {
|
|
733
|
+
// lastCellPos = { 'x': x, 'y': y, 'w': w, 'h': h, 'ln': ln };
|
|
734
|
+
// },
|
|
735
|
+
// getLastCellPosition = function () {
|
|
736
|
+
// return lastCellPos;
|
|
737
|
+
// };
|
|
738
|
+
//
|
|
739
|
+
// jsPDFAPI.setHeaderFunction = function (func) {
|
|
740
|
+
// headerFunction = func;
|
|
741
|
+
// };
|
|
742
|
+
//
|
|
743
|
+
// jsPDFAPI.getTextDimensions = function (txt) {
|
|
744
|
+
// fontName = this.internal.getFont().fontName;
|
|
745
|
+
// fontSize = this.table_font_size || this.internal.getFontSize();
|
|
746
|
+
// fontStyle = this.internal.getFont().fontStyle;
|
|
747
|
+
// // 1 pixel = 0.264583 mm and 1 mm = 72/25.4 point
|
|
748
|
+
// var px2pt = 0.264583 * 72 / 25.4,
|
|
749
|
+
// dimensions,
|
|
750
|
+
// text;
|
|
751
|
+
//
|
|
752
|
+
// text = document.createElement('font');
|
|
753
|
+
// text.id = "jsPDFCell";
|
|
754
|
+
// text.style.fontStyle = fontStyle;
|
|
755
|
+
// text.style.fontName = fontName;
|
|
756
|
+
// text.style.fontSize = fontSize + 'pt';
|
|
757
|
+
// text.innerText = txt;
|
|
758
|
+
//
|
|
759
|
+
// document.body.appendChild(text);
|
|
760
|
+
//
|
|
761
|
+
// dimensions = { w: (text.offsetWidth + 1) * px2pt, h: (text.offsetHeight + 1) * px2pt};
|
|
762
|
+
//
|
|
763
|
+
// document.body.removeChild(text);
|
|
764
|
+
//
|
|
765
|
+
// return dimensions;
|
|
766
|
+
// };
|
|
767
|
+
//
|
|
768
|
+
// jsPDFAPI.cellAddPage = function () {
|
|
769
|
+
// this.addPage();
|
|
770
|
+
//
|
|
771
|
+
// setLastCellPosition(this.margins.left, this.margins.top, undefined, undefined);
|
|
772
|
+
// //setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
|
|
773
|
+
// pages += 1;
|
|
774
|
+
// };
|
|
775
|
+
//
|
|
776
|
+
// jsPDFAPI.cellInitialize = function () {
|
|
777
|
+
// lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined };
|
|
778
|
+
// pages = 1;
|
|
779
|
+
// };
|
|
780
|
+
//
|
|
781
|
+
// jsPDFAPI.cell = function (x, y, w, h, txt, ln, align) {
|
|
782
|
+
// var curCell = getLastCellPosition();
|
|
783
|
+
//
|
|
784
|
+
// // If this is not the first cell, we must change its position
|
|
785
|
+
// if (curCell.ln !== undefined) {
|
|
786
|
+
// if (curCell.ln === ln) {
|
|
787
|
+
// //Same line
|
|
788
|
+
// x = curCell.x + curCell.w;
|
|
789
|
+
// y = curCell.y;
|
|
790
|
+
// } else {
|
|
791
|
+
// //New line
|
|
792
|
+
// if ((curCell.y + curCell.h + h + margin) >= this.internal.pageSize.height - this.margins.bottom) {
|
|
793
|
+
// this.cellAddPage();
|
|
794
|
+
// if (this.printHeaders && this.tableHeaderRow) {
|
|
795
|
+
// this.printHeaderRow(ln, true);
|
|
796
|
+
// }
|
|
797
|
+
// }
|
|
798
|
+
// //We ignore the passed y: the lines may have diferent heights
|
|
799
|
+
// y = (getLastCellPosition().y + getLastCellPosition().h);
|
|
800
|
+
//
|
|
801
|
+
// }
|
|
802
|
+
// }
|
|
803
|
+
//
|
|
804
|
+
// if (txt[0] !== undefined) {
|
|
805
|
+
// if (this.printingHeaderRow) {
|
|
806
|
+
// this.rect(x, y, w, h, 'FD');
|
|
807
|
+
// } else {
|
|
808
|
+
// this.rect(x, y, w, h);
|
|
809
|
+
// }
|
|
810
|
+
// if (align === 'right') {
|
|
811
|
+
// var textSize;
|
|
812
|
+
// if (txt instanceof Array) {
|
|
813
|
+
// for (var i = 0; i < txt.length; i++) {
|
|
814
|
+
// var currentLine = txt[i];
|
|
815
|
+
// textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize() / (72 / 25.6);
|
|
816
|
+
// this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight() * (i + 1));
|
|
817
|
+
// }
|
|
818
|
+
// } else {
|
|
819
|
+
// textSize = this.getStringUnitWidth(txt) * this.internal.getFontSize() / (72 / 25.6);
|
|
820
|
+
// this.text(txt, x + w - textSize - padding, y + this.internal.getLineHeight());
|
|
821
|
+
// }
|
|
822
|
+
// } else {
|
|
823
|
+
// this.text(txt, x + padding, y + this.internal.getLineHeight());
|
|
824
|
+
// }
|
|
825
|
+
// }
|
|
826
|
+
// setLastCellPosition(x, y, w, h, ln);
|
|
827
|
+
// return this;
|
|
828
|
+
// };
|
|
829
|
+
//
|
|
830
|
+
// /**
|
|
831
|
+
// * Return an array containing all of the owned keys of an Object
|
|
832
|
+
// * @type {Function}
|
|
833
|
+
// * @return {String[]} of Object keys
|
|
834
|
+
// */
|
|
835
|
+
// jsPDFAPI.getKeys = (typeof Object.keys === 'function')
|
|
836
|
+
// ? function (object) {
|
|
837
|
+
// if (!object) {
|
|
838
|
+
// return [];
|
|
839
|
+
// }
|
|
840
|
+
// return Object.keys(object);
|
|
841
|
+
// }
|
|
842
|
+
// : function (object) {
|
|
843
|
+
// var keys = [],
|
|
844
|
+
// property;
|
|
845
|
+
//
|
|
846
|
+
// for (property in object) {
|
|
847
|
+
// if (object.hasOwnProperty(property)) {
|
|
848
|
+
// keys.push(property);
|
|
849
|
+
// }
|
|
850
|
+
// }
|
|
851
|
+
//
|
|
852
|
+
// return keys;
|
|
853
|
+
// };
|
|
854
|
+
//
|
|
855
|
+
// /**
|
|
856
|
+
// * Return the maximum value from an array
|
|
857
|
+
// * @param array
|
|
858
|
+
// * @param comparisonFn
|
|
859
|
+
// * @returns {*}
|
|
860
|
+
// */
|
|
861
|
+
// jsPDFAPI.arrayMax = function (array, comparisonFn) {
|
|
862
|
+
// var max = array[0],
|
|
863
|
+
// i,
|
|
864
|
+
// ln,
|
|
865
|
+
// item;
|
|
866
|
+
//
|
|
867
|
+
// for (i = 0, ln = array.length; i < ln; i += 1) {
|
|
868
|
+
// item = array[i];
|
|
869
|
+
//
|
|
870
|
+
// if (comparisonFn) {
|
|
871
|
+
// if (comparisonFn(max, item) === -1) {
|
|
872
|
+
// max = item;
|
|
873
|
+
// }
|
|
874
|
+
// } else {
|
|
875
|
+
// if (item > max) {
|
|
876
|
+
// max = item;
|
|
877
|
+
// }
|
|
878
|
+
// }
|
|
879
|
+
// }
|
|
880
|
+
//
|
|
881
|
+
// return max;
|
|
882
|
+
// };
|
|
883
|
+
//
|
|
884
|
+
// /**
|
|
885
|
+
// * Create a table from a set of data.
|
|
886
|
+
// * @param {Integer} [x] : left-position for top-left corner of table
|
|
887
|
+
// * @param {Integer} [y] top-position for top-left corner of table
|
|
888
|
+
// * @param {Object[]} [data] As array of objects containing key-value pairs corresponding to a row of data.
|
|
889
|
+
// * @param {Object} [config.headers] String[] Omit or null to auto-generate headers at a performance cost
|
|
890
|
+
// * @param {Object} [config.footers] Object containing key-value pairs. Omit or null if not required
|
|
891
|
+
// * @param {Object} [config.printHeaders] True to print column headers at the top of every page
|
|
892
|
+
// * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
|
|
893
|
+
// * @param {Object} [config.margins] margin values for left, top, bottom, and width
|
|
894
|
+
// * @param {Object} [config.fontSize] Integer fontSize to use (optional)
|
|
895
|
+
// */
|
|
896
|
+
//
|
|
897
|
+
// jsPDFAPI.table = function (x, y, data, config) {
|
|
898
|
+
// if (!data) {
|
|
899
|
+
// throw 'No data for PDF table';
|
|
900
|
+
// }
|
|
901
|
+
//
|
|
902
|
+
// var headerNames = [],
|
|
903
|
+
// headerPrompts = [],
|
|
904
|
+
// header,
|
|
905
|
+
// i,
|
|
906
|
+
// ln,
|
|
907
|
+
// cln,
|
|
908
|
+
// columnMatrix = {},
|
|
909
|
+
// columnWidths = {},
|
|
910
|
+
// columnData,
|
|
911
|
+
// column,
|
|
912
|
+
// columnMinWidths = [],
|
|
913
|
+
// columnAligns = [],
|
|
914
|
+
// j,
|
|
915
|
+
// tableHeaderConfigs = [],
|
|
916
|
+
// model,
|
|
917
|
+
// jln,
|
|
918
|
+
// func,
|
|
919
|
+
//
|
|
920
|
+
// //set up defaults. If a value is provided in config, defaults will be overwritten:
|
|
921
|
+
// autoSize = false,
|
|
922
|
+
// printHeaders = true,
|
|
923
|
+
// fontSize = 12,
|
|
924
|
+
// headers = null,
|
|
925
|
+
// footers = null,
|
|
926
|
+
// margins = {left: 0, top: 0, bottom: 0, width: this.internal.pageSize.width};
|
|
927
|
+
//
|
|
928
|
+
// if (config) {
|
|
929
|
+
// //override config defaults if the user has specified non-default behavior:
|
|
930
|
+
// if (config.autoSize === true) {
|
|
931
|
+
// autoSize = true;
|
|
932
|
+
// }
|
|
933
|
+
// if (config.printHeaders === false) {
|
|
934
|
+
// printHeaders = false;
|
|
935
|
+
// }
|
|
936
|
+
// if (config.fontSize) {
|
|
937
|
+
// fontSize = config.fontSize;
|
|
938
|
+
// }
|
|
939
|
+
// if (config.margins) {
|
|
940
|
+
// margins = config.margins;
|
|
941
|
+
// }
|
|
942
|
+
// if (config.headers) {
|
|
943
|
+
// headers = config.headers;
|
|
944
|
+
// }
|
|
945
|
+
// if (config.footers) {
|
|
946
|
+
// footers = config.footers;
|
|
947
|
+
// }
|
|
948
|
+
// }
|
|
949
|
+
//
|
|
950
|
+
// /**
|
|
951
|
+
// * @property {Number} lnMod
|
|
952
|
+
// * Keep track of the current line number modifier used when creating cells
|
|
953
|
+
// */
|
|
954
|
+
// this.lnMod = 0;
|
|
955
|
+
// lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
|
|
956
|
+
// pages = 1;
|
|
957
|
+
//
|
|
958
|
+
// this.printHeaders = printHeaders;
|
|
959
|
+
// this.margins = margins;
|
|
960
|
+
// this.setFontSize(fontSize);
|
|
961
|
+
// this.table_font_size = fontSize;
|
|
962
|
+
//
|
|
963
|
+
// // Set header values
|
|
964
|
+
// if (headers === undefined || (headers === null)) {
|
|
965
|
+
// // No headers defined so we derive from data
|
|
966
|
+
// headerNames = this.getKeys(data[0]);
|
|
967
|
+
//
|
|
968
|
+
// } else if (headers[0] && (typeof headers[0] !== 'string')) {
|
|
969
|
+
// // var px2pt = 0.264583 * 72 / 25.4;
|
|
970
|
+
// var constant = 1.5; // arrived at by trial and error
|
|
971
|
+
//
|
|
972
|
+
// // Split header configs into names and prompts
|
|
973
|
+
// for (i = 0, ln = headers.length; i < ln; i += 1) {
|
|
974
|
+
// header = headers[i];
|
|
975
|
+
// headerNames.push(header.name);
|
|
976
|
+
// headerPrompts.push(header.prompt);
|
|
977
|
+
// columnWidths[header.name] = header.width * constant;
|
|
978
|
+
// columnAligns[header.name] = header.align;
|
|
979
|
+
// }
|
|
980
|
+
//
|
|
981
|
+
// } else {
|
|
982
|
+
// headerNames = headers;
|
|
983
|
+
// }
|
|
984
|
+
// if (autoSize) {
|
|
985
|
+
// // Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]}
|
|
986
|
+
// func = function (rec) {
|
|
987
|
+
// return rec[header];
|
|
988
|
+
// };
|
|
989
|
+
//
|
|
990
|
+
// for (i = 0, ln = headerNames.length; i < ln; i += 1) {
|
|
991
|
+
// header = headerNames[i];
|
|
992
|
+
//
|
|
993
|
+
// columnMatrix[header] = data.map(
|
|
994
|
+
// func
|
|
995
|
+
// );
|
|
996
|
+
//
|
|
997
|
+
// // get header width
|
|
998
|
+
// columnMinWidths.push(this.getTextDimensions(headerPrompts[i] || header).w);
|
|
999
|
+
// column = columnMatrix[header];
|
|
1000
|
+
//
|
|
1001
|
+
// // get cell widths
|
|
1002
|
+
// for (j = 0, cln = column.length; j < cln; j += 1) {
|
|
1003
|
+
// columnData = column[j];
|
|
1004
|
+
// columnMinWidths.push(this.getTextDimensions(columnData).w);
|
|
1005
|
+
// }
|
|
1006
|
+
//
|
|
1007
|
+
// // get footer width
|
|
1008
|
+
// if (footers) {
|
|
1009
|
+
// columnMinWidths.push(this.getTextDimensions(footers[i]).w);
|
|
1010
|
+
// }
|
|
1011
|
+
//
|
|
1012
|
+
// // get final column width
|
|
1013
|
+
// columnWidths[header] = jsPDFAPI.arrayMax(columnMinWidths);
|
|
1014
|
+
// }
|
|
1015
|
+
// }
|
|
1016
|
+
//
|
|
1017
|
+
// // -- Construct the table
|
|
1018
|
+
//
|
|
1019
|
+
// if (printHeaders) {
|
|
1020
|
+
// var lineHeight = this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length ? headerPrompts : headerNames);
|
|
1021
|
+
//
|
|
1022
|
+
// // Construct the header row
|
|
1023
|
+
// for (i = 0, ln = headerNames.length; i < ln; i += 1) {
|
|
1024
|
+
// header = headerNames[i];
|
|
1025
|
+
// tableHeaderConfigs.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header), 0, columnAligns[header]]);
|
|
1026
|
+
// }
|
|
1027
|
+
//
|
|
1028
|
+
// // Store the table header config
|
|
1029
|
+
// this.setTableHeaderRow(tableHeaderConfigs);
|
|
1030
|
+
//
|
|
1031
|
+
// // Print the header for the start of the table
|
|
1032
|
+
// this.printHeaderRow(1, false);
|
|
1033
|
+
// }
|
|
1034
|
+
//
|
|
1035
|
+
// // Construct the data rows
|
|
1036
|
+
// for (i = 0, ln = data.length; i < ln; i += 1) {
|
|
1037
|
+
// var lineHeight;
|
|
1038
|
+
// model = data[i];
|
|
1039
|
+
// lineHeight = this.calculateLineHeight(headerNames, columnWidths, model);
|
|
1040
|
+
//
|
|
1041
|
+
// for (j = 0, jln = headerNames.length; j < jln; j += 1) {
|
|
1042
|
+
// header = headerNames[j];
|
|
1043
|
+
// this.cell(x, y, columnWidths[header], lineHeight, model[header], i + 2, columnAligns[header]);
|
|
1044
|
+
// }
|
|
1045
|
+
// }
|
|
1046
|
+
//
|
|
1047
|
+
// if (footers) {
|
|
1048
|
+
// // Construct the header row
|
|
1049
|
+
// for (var fi = 0; fi < headerNames.length; fi++) {
|
|
1050
|
+
// header = headerNames[fi];
|
|
1051
|
+
// tableHeaderConfigs[fi][4] = footers[header] || ' ';
|
|
1052
|
+
// }
|
|
1053
|
+
//
|
|
1054
|
+
// // Print the header for the start of the table
|
|
1055
|
+
// this.printHeaderRow(i + 2, false);
|
|
1056
|
+
// }
|
|
1057
|
+
// this.table_x = x;
|
|
1058
|
+
// this.table_y = y;
|
|
1059
|
+
// return this;
|
|
1060
|
+
// };
|
|
1061
|
+
// /**
|
|
1062
|
+
// * Calculate the height for containing the highest column
|
|
1063
|
+
// * @param {String[]} headerNames is the header, used as keys to the data
|
|
1064
|
+
// * @param {Integer[]} columnWidths is size of each column
|
|
1065
|
+
// * @param {Object[]} model is the line of data we want to calculate the height of
|
|
1066
|
+
// */
|
|
1067
|
+
// jsPDFAPI.calculateLineHeight = function (headerNames, columnWidths, model) {
|
|
1068
|
+
// var header, lineHeight = 0;
|
|
1069
|
+
// for (var j = 0; j < headerNames.length; j++) {
|
|
1070
|
+
// header = headerNames[j];
|
|
1071
|
+
// model[header] = this.splitTextToSize(String(model[header]), columnWidths[header] - padding);
|
|
1072
|
+
// var h = this.internal.getLineHeight() * model[header].length + padding;
|
|
1073
|
+
// if (h > lineHeight)
|
|
1074
|
+
// lineHeight = h;
|
|
1075
|
+
// }
|
|
1076
|
+
// return lineHeight;
|
|
1077
|
+
// };
|
|
1078
|
+
//
|
|
1079
|
+
// /**
|
|
1080
|
+
// * Store the config for outputting a table header
|
|
1081
|
+
// * @param {Object[]} config
|
|
1082
|
+
// * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
|
|
1083
|
+
// * except the ln parameter is excluded
|
|
1084
|
+
// */
|
|
1085
|
+
// jsPDFAPI.setTableHeaderRow = function (config) {
|
|
1086
|
+
// this.tableHeaderRow = config;
|
|
1087
|
+
// };
|
|
1088
|
+
//
|
|
1089
|
+
// /**
|
|
1090
|
+
// * Output the store header row
|
|
1091
|
+
// * @param lineNumber The line number to output the header at
|
|
1092
|
+
// */
|
|
1093
|
+
// jsPDFAPI.printHeaderRow = function (lineNumber, new_page) {
|
|
1094
|
+
// if (!this.tableHeaderRow) {
|
|
1095
|
+
// throw 'Property tableHeaderRow does not exist.';
|
|
1096
|
+
// }
|
|
1097
|
+
//
|
|
1098
|
+
// var tableHeaderCell,
|
|
1099
|
+
// tmpArray,
|
|
1100
|
+
// i,
|
|
1101
|
+
// ln;
|
|
1102
|
+
//
|
|
1103
|
+
// this.printingHeaderRow = true;
|
|
1104
|
+
// if (headerFunction !== undefined) {
|
|
1105
|
+
// var position = headerFunction(this, pages);
|
|
1106
|
+
// setLastCellPosition(position[0], position[1], position[2], position[3], -1);
|
|
1107
|
+
// }
|
|
1108
|
+
// this.setFontStyle('bold');
|
|
1109
|
+
// var tempHeaderConf = [];
|
|
1110
|
+
// for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
|
|
1111
|
+
// this.setFillColor(200, 200, 200);
|
|
1112
|
+
//
|
|
1113
|
+
// tableHeaderCell = this.tableHeaderRow[i];
|
|
1114
|
+
// if (new_page) {
|
|
1115
|
+
// tableHeaderCell[1] = this.margins.top;
|
|
1116
|
+
// tempHeaderConf.push(tableHeaderCell);
|
|
1117
|
+
// }
|
|
1118
|
+
// tmpArray = [].concat(tableHeaderCell);
|
|
1119
|
+
// tmpArray[5] = lineNumber;
|
|
1120
|
+
// this.cell.apply(this, tmpArray);
|
|
1121
|
+
// }
|
|
1122
|
+
// if (tempHeaderConf.length > 0) {
|
|
1123
|
+
// this.setTableHeaderRow(tempHeaderConf);
|
|
1124
|
+
// }
|
|
1125
|
+
// this.setFontStyle('normal');
|
|
1126
|
+
// this.printingHeaderRow = false;
|
|
1127
|
+
// };
|
|
1128
|
+
//
|
|
1129
|
+
// })(jsPDF.API);
|
|
1130
|
+
//
|