fng-reports 0.12.0-beta.21 → 0.12.0-beta.211
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/src/fng-reports.js
CHANGED
|
@@ -1,266 +1,403 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
formsAngular.controller('AnalysisCtrl', ['$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
|
|
4
|
+
function ($rootScope, $window, $filter, $scope, $http, $location, cssFrameworkService, routingService) {
|
|
5
|
+
/*jshint newcap: false */
|
|
6
|
+
var firstTime = true,
|
|
7
|
+
pdfPlugIn = new ngGridPdfExportPlugin({inhibitButton: true}),
|
|
8
|
+
csvPlugIn = new ngGridCsvExportPlugin({inhibitButton: true});
|
|
9
|
+
/*jshint newcap: true */
|
|
10
|
+
|
|
11
|
+
angular.extend($scope, routingService.parsePathFunc()($location.$$path));
|
|
12
|
+
|
|
13
|
+
$scope.reportSchema = {
|
|
14
|
+
columnDefs: []
|
|
15
|
+
};
|
|
16
|
+
$scope.gridOptions = {
|
|
17
|
+
data: 'report',
|
|
18
|
+
columnDefs: $scope.reportSchema.columnDefs,
|
|
19
|
+
showColumnMenu: true,
|
|
20
|
+
enableRowHeaderSelection: false,
|
|
21
|
+
enableFiltering: false,
|
|
22
|
+
showGridFooter: false,
|
|
23
|
+
reallyShowFooter: false, // this determines whether it is actually displayed or not
|
|
24
|
+
showTotals: true,
|
|
25
|
+
enableColumnResizing: true,
|
|
26
26
|
// enableColumnReordering: true,
|
|
27
27
|
// jqueryUIDraggable: true,
|
|
28
|
-
|
|
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
|
-
'</div>' +
|
|
69
|
-
'<div style="float:left; margin-right: 10px; line-height:25px;" class="ngPagerControl" style="float: left; min-width: 135px;">' +
|
|
70
|
-
'<button class="ngPagerButton" ng-click="pageToFirst()" ng-disabled="cantPageBackward()" title="{{i18n.ngPagerFirstTitle}}">' +
|
|
71
|
-
'<div class="ngPagerFirstTriangle"><div class="ngPagerFirstBar"></div></div></button>' +
|
|
72
|
-
'<button class="ngPagerButton" ng-click="pageBackward()" ng-disabled="cantPageBackward()" title="{{i18n.ngPagerPrevTitle}}">' +
|
|
73
|
-
'<div class="ngPagerFirstTriangle ngPagerPrevTriangle"></div></button>' +
|
|
74
|
-
'<input class="ngPagerCurrent" min="1" max="{{maxPages()}}" type="number" style="width:50px; height: 24px; margin-top: 1px; padding: 0 4px;" ng-model="pagingOptions.currentPage"/>' +
|
|
75
|
-
'<button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="{{i18n.ngPagerNextTitle}}">' +
|
|
76
|
-
'<div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button>' +
|
|
77
|
-
'<button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageToLast()" title="{{i18n.ngPagerLastTitle}}">' +
|
|
78
|
-
'<div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button>' +
|
|
79
|
-
'</div>' +
|
|
80
|
-
'</div>' +
|
|
81
|
-
'</div>'
|
|
82
|
-
};
|
|
83
|
-
$scope.report = [];
|
|
84
|
-
|
|
85
|
-
if (!$scope.reportSchemaName && $location.$$search.r) {
|
|
86
|
-
switch ($location.$$search.r.slice(0, 1)) {
|
|
87
|
-
case '[' :
|
|
88
|
-
$scope.reportSchema.pipeline = JSON.parse($location.$$search.r);
|
|
89
|
-
break;
|
|
90
|
-
case '{' :
|
|
91
|
-
angular.extend($scope.reportSchema, JSON.parse($location.$$search.r));
|
|
92
|
-
break;
|
|
93
|
-
default :
|
|
94
|
-
throw new Error('No report instructions specified');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
$scope.getTotalVal = function (field, filter) {
|
|
99
|
-
var result = '',
|
|
100
|
-
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
101
|
-
return col.field === field;
|
|
102
|
-
});
|
|
28
|
+
footerRowHeight: 65,
|
|
29
|
+
multiSelect: false,
|
|
30
|
+
plugins: [pdfPlugIn, csvPlugIn],
|
|
31
|
+
onRegisterApi: function (gridApi) {
|
|
32
|
+
$scope.gridApi = gridApi;
|
|
33
|
+
$scope.gridOptions.plugins.forEach(function (p) {
|
|
34
|
+
p.init($scope, gridApi.grid, null);
|
|
35
|
+
});
|
|
36
|
+
gridApi.selection.on.rowSelectionChanged($scope, function afterSelectionChange(rowItem) {
|
|
37
|
+
var url = $scope.reportSchema.drilldown;
|
|
38
|
+
if (url) {
|
|
39
|
+
if (typeof url === 'string') {
|
|
40
|
+
url = routingService.buildUrl(url.replace(/\|.+?\|/g, function (match) {
|
|
41
|
+
var param = match.slice(1, -1),
|
|
42
|
+
isParamTest = /\((.+)\)/.exec(param);
|
|
43
|
+
if (isParamTest) {
|
|
44
|
+
var instructions = $scope.reportSchema.params[isParamTest[1]];
|
|
45
|
+
if (instructions) {
|
|
46
|
+
$scope.param = $scope.record[isParamTest[1]];
|
|
47
|
+
if (instructions.conversionExpression) {
|
|
48
|
+
return $scope.$eval(instructions.conversionExpression);
|
|
49
|
+
} else {
|
|
50
|
+
return instructions.value;
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
return $scope.reportSchema.params[isParamTest[1]].value;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
return rowItem.entity[param];
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
window.location = url;
|
|
60
|
+
} else {
|
|
61
|
+
console.error('Was expecting drilldown to be string but it was ' + typeof url + ' (' + url + ')'); // trying to track down Sentry 3037641567
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
$scope.report = [];
|
|
103
68
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (var j = 0; j < $scope.report.length; j++) {
|
|
111
|
-
sum += $scope.report[j][field];
|
|
69
|
+
function parseAndHandleError(str) {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(str);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new Error(`Invalid JSON ${str}
|
|
74
|
+
${e.message}`);
|
|
112
75
|
}
|
|
113
|
-
result = sum;
|
|
114
|
-
if (filter) {
|
|
115
|
-
result = $filter(filter)(result);
|
|
116
|
-
}
|
|
117
|
-
break;
|
|
118
|
-
default :
|
|
119
|
-
result = instructions.totalsRow;
|
|
120
|
-
break;
|
|
121
76
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
$scope.refreshQuery = function () {
|
|
136
|
-
|
|
137
|
-
var apiCall = '/api/report/' + $scope.modelName,
|
|
138
|
-
connector = '?';
|
|
139
|
-
if ($scope.reportSchemaName) {
|
|
140
|
-
apiCall += '/' + $scope.reportSchemaName;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if ($scope.paramSchema) {
|
|
144
|
-
// we are using the params form
|
|
145
|
-
for (var paramVal in $scope.record) {
|
|
146
|
-
if ($scope.record.hasOwnProperty(paramVal)) {
|
|
147
|
-
var instructions = $scope.reportSchema.params[paramVal];
|
|
148
|
-
if ($scope.record[paramVal] && $scope.record[paramVal] !== '') {
|
|
149
|
-
$scope.param = $scope.record[paramVal];
|
|
150
|
-
if (instructions.conversionExpression) {
|
|
151
|
-
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
152
|
-
}
|
|
153
|
-
apiCall += connector + paramVal + '=' + $scope.param;
|
|
154
|
-
connector = '&';
|
|
155
|
-
} else if (instructions.required) {
|
|
156
|
-
// Don't do a round trip if a required field is empty - it will show up red
|
|
157
|
-
return;
|
|
77
|
+
|
|
78
|
+
if (!$scope.reportSchemaName && $location.$$search.r) {
|
|
79
|
+
switch ($location.$$search.r.slice(0, 1)) {
|
|
80
|
+
case '[' :
|
|
81
|
+
$scope.reportSchema.pipeline = parseAndHandleError($location.$$search.r);
|
|
82
|
+
break;
|
|
83
|
+
case '{' :
|
|
84
|
+
angular.extend($scope.reportSchema, parseAndHandleError($location.$$search.r));
|
|
85
|
+
break;
|
|
86
|
+
default :
|
|
87
|
+
throw new Error('No report instructions specified');
|
|
158
88
|
}
|
|
159
|
-
}
|
|
160
89
|
}
|
|
161
|
-
} else {
|
|
162
|
-
// take params of the URL
|
|
163
|
-
var query = $location.$$url.match(/\?.*/);
|
|
164
|
-
if (query) {
|
|
165
|
-
apiCall += connector + query[0].slice(1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
$http.get(apiCall).then(function (response) {
|
|
169
|
-
var data = response.data;
|
|
170
|
-
if (data.success) {
|
|
171
|
-
$scope.report = data.report;
|
|
172
|
-
$scope.reportSchema = data.schema;
|
|
173
|
-
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
174
|
-
$scope.reportSchema.title = $scope.reportSchema.title.replace(/\|.+?\|/g, function (match) {
|
|
175
|
-
var param = match.slice(1, -1);
|
|
176
|
-
var isParamTest = /\((.+)\)/.exec(param);
|
|
177
|
-
return isParamTest ? $scope.reportSchema.params[isParamTest[1]].value : '';
|
|
178
|
-
});
|
|
179
90
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
91
|
+
$scope.getTotalVal = function (field, filter) {
|
|
92
|
+
var result = '',
|
|
93
|
+
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
94
|
+
return col.field === field;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (instructions) {
|
|
98
|
+
switch (instructions.totalsRow) {
|
|
99
|
+
case undefined :
|
|
100
|
+
break;
|
|
101
|
+
case '$SUM' :
|
|
102
|
+
var sum = 0;
|
|
103
|
+
for (var j = 0; j < $scope.report.length; j++) {
|
|
104
|
+
sum += $scope.report[j][field];
|
|
105
|
+
}
|
|
106
|
+
result = sum;
|
|
107
|
+
if (filter) {
|
|
108
|
+
result = $filter(filter)(result);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
default :
|
|
112
|
+
result = instructions.totalsRow;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
$scope.$on('exportToPDF', function () {
|
|
121
|
+
pdfPlugIn.createPDF();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
$scope.$on('exportToCSV', function () {
|
|
125
|
+
csvPlugIn.createCSV();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
$scope.extractFilter = function (col, filters) {
|
|
129
|
+
if (col.cellFilter) {
|
|
130
|
+
var filterName;
|
|
131
|
+
var filterParam;
|
|
132
|
+
var paramPos = col.cellFilter.indexOf(':');
|
|
133
|
+
if (paramPos === -1) {
|
|
134
|
+
filterName = col.cellFilter;
|
|
135
|
+
} else {
|
|
136
|
+
filterName = col.cellFilter.slice(0, paramPos).trim();
|
|
137
|
+
filterParam = col.cellFilter.slice(paramPos + 1, 999).trim();
|
|
138
|
+
if (filterParam[0] === '\'' || filterParam[0] === '"') {
|
|
139
|
+
filterParam = filterParam.slice(1, -1);
|
|
195
140
|
}
|
|
196
|
-
}
|
|
197
141
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
142
|
+
var filter = angular.element(document.body).injector().get('$filter')(filterName.trim());
|
|
143
|
+
filters[col.field] = {filter: filter, filterParam: filterParam};
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function setupParamsForm(params) {
|
|
148
|
+
$scope.paramSchema = [];
|
|
149
|
+
// set up parameters
|
|
150
|
+
$scope.record = {};
|
|
151
|
+
for (var param in params) {
|
|
152
|
+
if (params.hasOwnProperty(param)) {
|
|
153
|
+
var thisPart = params[param];
|
|
154
|
+
// if noInput then this value will be inferred from another parameter
|
|
155
|
+
if (!thisPart.noInput) {
|
|
156
|
+
var newLen = $scope.paramSchema.push({
|
|
157
|
+
name: param,
|
|
158
|
+
id: 'fp_' + param,
|
|
159
|
+
label: thisPart.label || $filter('titleCase')(param),
|
|
160
|
+
type: thisPart.type || 'text',
|
|
161
|
+
required: true,
|
|
162
|
+
add: thisPart.add || undefined,
|
|
163
|
+
size: thisPart.size || (cssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
164
|
+
});
|
|
165
|
+
if (thisPart.type === 'select') {
|
|
166
|
+
// TODO: Remove when select and select2 is modified during the restructure
|
|
167
|
+
$scope[param + '_Opts'] = thisPart.enum;
|
|
168
|
+
$scope.paramSchema[newLen - 1].options = param + '_Opts';
|
|
169
|
+
}
|
|
203
170
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
if (dateTest) {
|
|
173
|
+
thisPart.value = new Date(dateTest[1]);
|
|
174
|
+
}
|
|
175
|
+
$scope.record[param] = thisPart.value;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
$scope.$watch('record', function (newValue, oldValue) {
|
|
179
|
+
if (oldValue !== newValue) {
|
|
180
|
+
$scope.refreshQuery();
|
|
181
|
+
}
|
|
210
182
|
}, true);
|
|
183
|
+
}
|
|
211
184
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
185
|
+
var container = document.querySelector('div.report-grow');
|
|
186
|
+
if (container) {
|
|
187
|
+
var margin = container.offsetLeft; // let's have the same top and bottom margins as we have side margin
|
|
188
|
+
var topOffset = container.offsetTop + margin;
|
|
189
|
+
var header = document.querySelector('div.ui-grid-header');
|
|
190
|
+
var headerHeight = header ? header.clientHeight : 31;
|
|
191
|
+
var availRows = Math.floor(($window.innerHeight - topOffset - headerHeight - margin) / 30);
|
|
192
|
+
angular.element(container).css('height', '' + availRows * 30 + 'px');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
var navScope = $rootScope.navScope;
|
|
196
|
+
navScope.items = [
|
|
197
|
+
{
|
|
198
|
+
fn: pdfPlugIn.createPDF,
|
|
199
|
+
text: 'Save as PDF'
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
fn: csvPlugIn.createCSV,
|
|
203
|
+
text: 'Export as CSV'
|
|
204
|
+
}
|
|
205
|
+
];
|
|
206
|
+
navScope.contextMenu = 'Report';
|
|
207
|
+
navScope.contextMenuId = 'reportMenu';
|
|
208
|
+
$scope.titleWithSubstitutions = $scope.reportSchema.title;
|
|
209
|
+
|
|
210
|
+
// inhibitRefresh can be set by a controller, for example if report data is being provided as part of the URL
|
|
211
|
+
if (!$scope.inhibitRefresh) {
|
|
212
|
+
|
|
213
|
+
$scope.refreshQuery = function () {
|
|
214
|
+
|
|
215
|
+
function substituteParams(str) {
|
|
216
|
+
return str.replace(/\|.+?\|/g, function (match) {
|
|
217
|
+
var param = match.slice(1, -1);
|
|
218
|
+
var isParamTest = /\((.+)\)/.exec(param);
|
|
219
|
+
return isParamTest ? $scope.reportSchema.params[isParamTest[1]].value : '';
|
|
229
220
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var apiCall = '/api/report/' + $scope.modelName;
|
|
224
|
+
var connector = '?';
|
|
225
|
+
var haveUrlParams = false;
|
|
226
|
+
var query = $location.$$url.match(/\?.*/);
|
|
227
|
+
|
|
228
|
+
if ($scope.reportSchemaName) {
|
|
229
|
+
apiCall += '/' + $scope.reportSchemaName;
|
|
230
|
+
} else if (query) {
|
|
231
|
+
if (firstTime) {
|
|
232
|
+
// See if we have params in the URL (rather than going through schemaName)
|
|
233
|
+
$scope.paramSchema = JSON.parse($location.search().r).params;
|
|
234
|
+
setupParamsForm($scope.paramSchema);
|
|
234
235
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
thisPart.value = (moment(dateTest[1]).format('YYYY-MM-DDTHH:mm:ss.SSS')) + 'Z';
|
|
239
|
-
}
|
|
240
|
-
$scope.record[param] = thisPart.value;
|
|
236
|
+
apiCall += connector + query[0].slice(1);
|
|
237
|
+
connector = '&';
|
|
238
|
+
haveUrlParams = true;
|
|
241
239
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
|
|
241
|
+
if ($scope.paramSchema) {
|
|
242
|
+
// we are using the params form
|
|
243
|
+
for (var paramVal in $scope.record) {
|
|
244
|
+
if ($scope.record.hasOwnProperty(paramVal)) {
|
|
245
|
+
var instructions = $scope.reportSchema.params[paramVal];
|
|
246
|
+
if ($scope.record[paramVal] && $scope.record[paramVal] !== '') {
|
|
247
|
+
$scope.param = $scope.record[paramVal];
|
|
248
|
+
if (instructions.conversionExpression) {
|
|
249
|
+
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
250
|
+
}
|
|
251
|
+
apiCall += connector + paramVal + '=' + $scope.param;
|
|
252
|
+
connector = '&';
|
|
253
|
+
} else if (instructions.required) {
|
|
254
|
+
// Don't do a round trip if a required field is empty - it will show up red
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
if (!haveUrlParams && query) {
|
|
261
|
+
apiCall += connector + query[0].slice(1);
|
|
262
|
+
connector = '&';
|
|
263
|
+
}
|
|
246
264
|
}
|
|
247
|
-
|
|
265
|
+
return $http.get(apiCall).then(function (response) {
|
|
266
|
+
if (response && response.data && response.data.success) {
|
|
267
|
+
var data = response.data;
|
|
268
|
+
$scope.report = data.report;
|
|
269
|
+
$scope.reportSchema = data.schema;
|
|
270
|
+
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
271
|
+
$scope.titleWithSubstitutions = substituteParams($scope.reportSchema.title);
|
|
272
|
+
$scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
|
|
273
|
+
if (navScope && navScope.items) {
|
|
274
|
+
navScope.items.length = 2;
|
|
275
|
+
if ($scope.reportSchema.menu) {
|
|
276
|
+
$scope.reportSchema.menu.forEach(function (m) {
|
|
277
|
+
navScope.items.push(JSON.parse(substituteParams(JSON.stringify(m))));
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
248
281
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
282
|
+
/*
|
|
283
|
+
Generate link data
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
if (firstTime) {
|
|
287
|
+
firstTime = false;
|
|
288
|
+
|
|
289
|
+
$scope.$watch('reportSchema.columnDefs', function (newValue) {
|
|
290
|
+
var columnTotals = false;
|
|
291
|
+
if (newValue) {
|
|
292
|
+
for (var i = 0; i < newValue.length; i++) {
|
|
293
|
+
if (newValue[i].totalsRow) {
|
|
294
|
+
columnTotals = true;
|
|
295
|
+
}
|
|
296
|
+
if (newValue[i].align) {
|
|
297
|
+
var alignClass = 'fng-' + newValue[i].align;
|
|
298
|
+
newValue[i].cellClass = newValue[i].cellClass || '';
|
|
299
|
+
if (newValue[i].cellClass.indexOf(alignClass) === -1) {
|
|
300
|
+
newValue[i].cellClass = newValue[i].cellClass + ' ' + alignClass;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Auto-upgrade from ng-grid to ui-grid
|
|
305
|
+
newValue.forEach(function (def) {
|
|
306
|
+
// Remove px from column widths
|
|
307
|
+
if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
|
|
308
|
+
def.width = parseInt(def.width.slice(0, -2));
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
$scope.gridOptions.columnDefs = newValue;
|
|
312
|
+
}
|
|
313
|
+
$scope.gridOptions.showTotals = columnTotals;
|
|
314
|
+
$scope.gridOptions.reallyShowFooter = columnTotals;
|
|
315
|
+
$scope.gridOptions.footerRowHeight = 55 + (columnTotals ? 10 : 0);
|
|
316
|
+
}, true);
|
|
317
|
+
|
|
318
|
+
if (!$scope.paramSchema && data.schema.params) {
|
|
319
|
+
setupParamsForm(data.schema.params);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
$scope.showError(JSON.stringify(response.data.error), 'Invalid Response Error');
|
|
324
|
+
$scope.reportSchema.title = 'Error - see console log';
|
|
325
|
+
}
|
|
326
|
+
}, function (error) {
|
|
327
|
+
let body, title;
|
|
328
|
+
if (error.status === 403) {
|
|
329
|
+
body = 'You do not have permission to run this report (permission to GET all ' + $scope.modelName + ' records is required)';
|
|
330
|
+
title = 'Permission denied';
|
|
331
|
+
} else {
|
|
332
|
+
body = 'The server could not process the request';
|
|
333
|
+
title = 'Error';
|
|
334
|
+
}
|
|
335
|
+
$scope.showError(body, title);
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
$scope.refreshQuery();
|
|
254
340
|
}
|
|
255
|
-
}, function (response) {
|
|
256
|
-
console.log(JSON.stringify(response));
|
|
257
|
-
$location.path('/404');
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
341
|
|
|
261
|
-
|
|
342
|
+
// Check whether a cell template shows the content (in which case we want to output it) or does something funky
|
|
343
|
+
// (for example displays an image)
|
|
344
|
+
$scope.showsContent = function (template, col) {
|
|
345
|
+
if (/{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''))) {
|
|
346
|
+
return true;
|
|
347
|
+
} else if (template.indexOf('ng-bind-html="row.entity.' + col) !== -1) {
|
|
348
|
+
return 'HTML';
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
$scope.$on('$locationChangeStart', function () {
|
|
353
|
+
delete navScope.contextMenu;
|
|
354
|
+
delete navScope.items;
|
|
355
|
+
});
|
|
262
356
|
|
|
263
|
-
|
|
357
|
+
// Error handling, stolen quickly from forms-angulat record-handler
|
|
358
|
+
$scope.showError = function(error, alertTitle) {
|
|
359
|
+
$scope.alertTitle = alertTitle ? alertTitle : 'Error!';
|
|
360
|
+
if (typeof error === 'string') {
|
|
361
|
+
$scope.errorMessage = error;
|
|
362
|
+
} else if (!error) {
|
|
363
|
+
$scope.errorMessage = `An error occurred - that's all we got. Sorry.`;
|
|
364
|
+
} else if (error.message && typeof error.message === 'string') {
|
|
365
|
+
$scope.errorMessage = error.message;
|
|
366
|
+
} else if (error.data && error.data.message) {
|
|
367
|
+
$scope.errorMessage = error.data.message;
|
|
368
|
+
} else {
|
|
369
|
+
try {
|
|
370
|
+
$scope.errorMessage = JSON.stringify(error);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
$scope.errorMessage = error;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
$scope.errorHideTimer = window.setTimeout(function() {
|
|
376
|
+
$scope.dismissError();
|
|
377
|
+
$scope.$digest();
|
|
378
|
+
}, 3500 + (1000 * ($scope.alertTitle + $scope.errorMessage).length / 50));
|
|
379
|
+
$scope.errorVisible = true;
|
|
380
|
+
window.setTimeout(() => {
|
|
381
|
+
$scope.$digest();
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
$scope.clearTimeout = function() {
|
|
386
|
+
if ($scope.errorHideTimer) {
|
|
387
|
+
clearTimeout($scope.errorHideTimer);
|
|
388
|
+
delete $scope.errorHideTimer;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
264
391
|
|
|
392
|
+
$scope.dismissError = function() {
|
|
393
|
+
$scope.clearTimeout;
|
|
394
|
+
$scope.errorVisible = false;
|
|
395
|
+
delete $scope.errorMessage;
|
|
396
|
+
delete $scope.alertTitle;
|
|
397
|
+
};
|
|
265
398
|
|
|
399
|
+
$scope.stickError = function() {
|
|
400
|
+
clearTimeout($scope.errorHideTimer);
|
|
401
|
+
};
|
|
266
402
|
|
|
403
|
+
}]);
|