fng-reports 0.12.0-beta.160 → 0.12.0-beta.166
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/dist/fng-reports.js +1 -1
- package/dist/fng-reports.min.js +1 -1
- package/dist/index.d.ts +1 -1
- package/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/fng-reports.js +285 -308
package/dist/fng-reports.js
CHANGED
package/dist/fng-reports.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! forms-angular 2021-
|
|
1
|
+
/*! forms-angular 2021-08-21 */
|
|
2
2
|
|
|
3
3
|
"use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$filter","$scope","$http","$location","cssFrameworkService","routingService",function(e,t,a,c,s,p,u,r){var d=!0,o=new ngGridPdfExportPlugin({inhibitButton:!0}),n=new ngGridCsvExportPlugin({inhibitButton:!0});if(angular.extend(c,r.parsePathFunc()(p.$$path)),c.reportSchema={columnDefs:[]},c.gridOptions={data:"report",columnDefs:c.reportSchema.columnDefs,showColumnMenu:!0,enableRowHeaderSelection:!1,enableFiltering:!1,showGridFooter:!1,reallyShowFooter:!1,showTotals:!0,enableColumnResizing:!0,footerRowHeight:65,multiSelect:!1,plugins:[o,n],onRegisterApi:function(t){c.gridApi=t,c.gridOptions.plugins.forEach(function(e){e.init(c,t.grid,null)}),t.selection.on.rowSelectionChanged(c,function(o){var e=c.reportSchema.drilldown;e&&(e=r.buildUrl(e.replace(/\|.+?\|/g,function(e){var t=e.slice(1,-1),r=/\((.+)\)/.exec(t);if(r){e=c.reportSchema.params[r[1]];return e?(c.param=c.record[r[1]],e.conversionExpression?c.$eval(e.conversionExpression):e.value):c.reportSchema.params[r[1]].value}return o.entity[t]})),window.location=e)})}},c.report=[],!c.reportSchemaName&&p.$$search.r)switch(p.$$search.r.slice(0,1)){case"[":c.reportSchema.pipeline=JSON.parse(p.$$search.r);break;case"{":angular.extend(c.reportSchema,JSON.parse(p.$$search.r));break;default:throw new Error("No report instructions specified")}c.getTotalVal=function(t,e){var r="",o=_.find(c.reportSchema.columnDefs,function(e){return e.field===t});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var n=0,i=0;i<c.report.length;i++)n+=c.report[i][t];r=n,e&&(r=a(e)(r));break;default:r=o.totalsRow}return r},c.$on("exportToPDF",function(){o.createPDF()}),c.$on("exportToCSV",function(){n.createCSV()}),c.extractFilter=function(e,t){var r,o,n;e.cellFilter&&(-1===(o=e.cellFilter.indexOf(":"))?n=e.cellFilter:(n=e.cellFilter.slice(0,o).trim(),"'"!==(r=e.cellFilter.slice(o+1,999).trim())[0]&&'"'!==r[0]||(r=r.slice(1,-1))),n=angular.element(document.body).injector().get("$filter")(n.trim()),t[e.field]={filter:n,filterParam:r})};var i,l,f,m=document.querySelector("div.report-grow");m&&(f=m.offsetLeft,i=m.offsetTop+f,l=(l=document.querySelector("div.ui-grid-header"))?l.clientHeight:31,f=Math.floor((t.innerHeight-i-l-f)/30),angular.element(m).css("height",30*f+"px"));var h=e.navScope;h.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:n.createCSV,text:"Export as CSV"}],h.contextMenu="Report",c.titleWithSubstitutions=c.reportSchema.title,c.inhibitRefresh||(c.refreshQuery=function(){function i(e){return e.replace(/\|.+?\|/g,function(e){e=e.slice(1,-1),e=/\((.+)\)/.exec(e);return e?c.reportSchema.params[e[1]].value:""})}var e="/api/report/"+c.modelName,t="?",r=!1,o=p.$$url.match(/\?.*/);if(c.reportSchemaName?e+="/"+c.reportSchemaName:o&&(e+=t+o[0].slice(1),t="&",r=!0),c.paramSchema){for(var n in c.record)if(c.record.hasOwnProperty(n)){var l=c.reportSchema.params[n];if(c.record[n]&&""!==c.record[n])c.param=c.record[n],l.conversionExpression&&(c.param=c.$eval(l.conversionExpression)),e+=t+n+"="+c.param,t="&";else if(l.required)return}}else!r&&o&&(e+=t+o[0].slice(1),t="&");return s.get(e).then(function(e){var t,r,o=e.data;if(o.success){if(c.report=o.report,c.reportSchema=o.schema,c.reportSchema.title=c.reportSchema.title||c.modelName,c.titleWithSubstitutions=i(c.reportSchema.title),c.gridOptions.enableFiltering=!!c.reportSchema.filter,h&&h.items&&(h.items.length=2,c.reportSchema.menu&&c.reportSchema.menu.forEach(function(e){h.items.push(JSON.parse(i(JSON.stringify(e))))})),d&&(d=!1,c.$watch("reportSchema.columnDefs",function(e){var t=!1;if(e){for(var r,o=0;o<e.length;o++)e[o].totalsRow&&(t=!0),e[o].align&&(r="fng-"+e[o].align,e[o].cellClass=e[o].cellClass||"",-1===e[o].cellClass.indexOf(r)&&(e[o].cellClass=e[o].cellClass+" "+r));e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),c.gridOptions.columnDefs=e}c.gridOptions.showTotals=t,c.gridOptions.reallyShowFooter=t,c.gridOptions.footerRowHeight=55+(t?10:0)},!0),!c.paramSchema&&o.schema.params)){for(var n in c.paramSchema=[],c.record={},o.schema.params)o.schema.params.hasOwnProperty(n)&&((t=o.schema.params[n]).noInput||(r=c.paramSchema.push({name:n,id:"fp_"+n,label:t.label||a("titleCase")(n),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===u.frameWork?"large":"medium")}),"select"===t.type&&(c[n+"_Opts"]=t.enum,c.paramSchema[r-1].options=n+"_Opts")),(r=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(t.value))&&(t.value=new Date(r[1])),c.record[n]=t.value);c.$watch("record",function(e,t){t!==e&&c.refreshQuery()},!0)}}else console.log(JSON.stringify(o)),c.reportSchema.title="Error - see console log"},function(e){console.log(JSON.stringify(e)),p.url("/404")})},c.refreshQuery()),c.showsContent=function(e){return/{{[\s]*COL_FIELD[\s]*}}/.test(e.replace(/(<([^>]+)>)/gi,""))},c.$on("$locationChangeStart",function(){delete h.contextMenu,delete h.items})}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var i=this;i.grid=null,i.scope=null,i.services=null,i.init=function(e,t,r){i.grid=t,i.scope=e,i.services=r},i.createCSV=function(){var e,t,r;e=i.scope.reportSchema.title+".csv",t="data:text/csv;charset=UTF-8,"+encodeURIComponent(i.prepareCSV()),(r=document.createElement("a")).download=e,r.href=t,t=new MouseEvent("click"),r.dispatchEvent(t)},i.prepareCSV=function(){function r(e,t){return null==e?"":t?t.filter(e,t.filterParam):"number"==typeof e?""+e:"boolean"==typeof e?e?"TRUE":"FALSE":("string"==typeof e?e:JSON.stringify(e)).replace(/"/g,'""')}function e(e){return e.substr(0,e.length-1)+"\n"}var o="",n={};return angular.forEach(i.grid.columns,function(e){i.scope.extractFilter(e,n),e.visible&&(!e.colDef.cellTemplate||i.scope.showsContent(e.colDef.cellTemplate))&&(void 0===e.width||"*"===e.width||0<e.width)?(o+='"'+r(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1}),o=e(o),angular.forEach(i.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(i.grid.columns,function(e){e.doCSVExport&&(o+='"'+r(t.entity[e.field],n[e.field])+'",')}),o=e(o))}),o}}function ngGridPdfExportPlugin(o){var l=this;l.grid=null,l.scope=null,l.services=null,l.options=o,l.init=function(e,t,r){l.grid=t,l.scope=e,l.services=r,o.inhibitButton||(r=t.$root.find(".ngFooterPanel"),null!=(t=t.$root.find(".ngFooterPanel .pdf-data-link-span"))&&t.remove(),r.append('<button class="pdf-data-link-span">PDF Export</button>'),r.on("click",function(){l.createPDF()}))},l.createPDF=function(){var r=[],n=[],o=[],e=[],i={};angular.forEach(l.grid.columns,function(e,t){!e.visible||e.colDef.cellTemplate&&!l.scope.showsContent(e.colDef.cellTemplate)||(r.push(e.displayName),n.push(e.field)),e.colDef.totalsRow&&(o[e.field]=l.grid.getTotalVal(e.field,e.filter).toString()),l.scope.extractFilter(e,i)}),angular.forEach(l.scope.gridApi.core.getVisibleRows(),function(r){var o=[];r.visible&&(n.forEach(function(e){var t=r.entity[e];"string"==typeof(t=i[e]?i[e].filter(t,i[e].filterParam):t)&&(t=(t=(t=(t=(t=t.replace(/\u2019/g,"'")).replace(/\u2018/g,"'")).replace(/\u201c/g,'"')).replace(/\u201d/g,'"')).replace(/[^\x00-\xFF]/g,"")),o.push(t)}),e.push(o))});var t=new jspdf.jsPDF("landscape","mm","a4");t.autoTable({head:[r],body:e}),window.open(t.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(n,r){return{scope:!1,compile:function(){return{pre:function(e,t){var r=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),r=r?e.col.cellTemplate.replace("COL_FIELD |"+r[1],'getTotalVal("'+e.col.field+'","'+r[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),o=e.col.enableCellEdit?(o=(o=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,r)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):r,o=n(o)(e);e.enableCellSelection&&-1===o[0].className.indexOf("ngSelectionCell")&&(o[0].setAttribute("tabindex",0),o.addClass("ngCellElement")),t.append(o)},post:function(e,t){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,t),e.$on("ngGridEventDigestCell",function(){r.digest(e)})}}}}}]);
|
package/dist/index.d.ts
CHANGED
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fng-reports",
|
|
3
|
-
"version": "0.12.0-beta.
|
|
3
|
+
"version": "0.12.0-beta.166",
|
|
4
4
|
"description": "Reporting plugin for forms-angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"angular-messages": "1.8.2",
|
|
30
30
|
"angular-mocks": "1.8.2",
|
|
31
31
|
"angular-sanitize": "1.8.2",
|
|
32
|
-
"forms-angular": "0.12.0-beta.
|
|
32
|
+
"forms-angular": "0.12.0-beta.159",
|
|
33
33
|
"grunt": "^1.4.1",
|
|
34
34
|
"grunt-autoprefixer": "3.0.4",
|
|
35
35
|
"grunt-concurrent": "3.0.0",
|
package/src/fng-reports.js
CHANGED
|
@@ -1,345 +1,322 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'cssFrameworkService', 'routingService',
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
10
|
|
|
11
|
-
|
|
11
|
+
angular.extend($scope, routingService.parsePathFunc()($location.$$path));
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
$scope.report = [];
|
|
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) {p.init($scope, gridApi.grid, null); });
|
|
34
|
+
gridApi.selection.on.rowSelectionChanged($scope, function afterSelectionChange(rowItem) {
|
|
35
|
+
var url = $scope.reportSchema.drilldown;
|
|
36
|
+
if (url) {
|
|
37
|
+
url = routingService.buildUrl(url.replace(/\|.+?\|/g, function (match) {
|
|
38
|
+
var param = match.slice(1, -1),
|
|
39
|
+
isParamTest = /\((.+)\)/.exec(param);
|
|
40
|
+
if (isParamTest) {
|
|
41
|
+
var instructions = $scope.reportSchema.params[isParamTest[1]];
|
|
42
|
+
if (instructions) {
|
|
43
|
+
$scope.param = $scope.record[isParamTest[1]];
|
|
44
|
+
if (instructions.conversionExpression) {
|
|
45
|
+
return $scope.$eval(instructions.conversionExpression);
|
|
46
|
+
} else {
|
|
47
|
+
return instructions.value;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return $scope.reportSchema.params[isParamTest[1]].value;
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
return rowItem.entity[param];
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
window.location = url;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
$scope.report = [];
|
|
64
62
|
|
|
65
|
-
function parseAndHandleError(str) {
|
|
66
|
-
try {
|
|
67
|
-
return JSON.parse(str);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
throw new Error(`Invalid JSON ${str}
|
|
70
|
-
${e.message}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
if (!$scope.reportSchemaName && $location.$$search.r) {
|
|
65
|
+
switch ($location.$$search.r.slice(0, 1)) {
|
|
66
|
+
case '[' :
|
|
67
|
+
$scope.reportSchema.pipeline = JSON.parse($location.$$search.r);
|
|
68
|
+
break;
|
|
69
|
+
case '{' :
|
|
70
|
+
angular.extend($scope.reportSchema, JSON.parse($location.$$search.r));
|
|
71
|
+
break;
|
|
72
|
+
default :
|
|
73
|
+
throw new Error('No report instructions specified');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
$scope.getTotalVal = function (field, filter) {
|
|
78
|
+
var result = '',
|
|
79
|
+
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
80
|
+
return col.field === field;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (instructions) {
|
|
84
|
+
switch (instructions.totalsRow) {
|
|
85
|
+
case undefined :
|
|
86
|
+
break;
|
|
87
|
+
case '$SUM' :
|
|
88
|
+
var sum = 0;
|
|
89
|
+
for (var j = 0; j < $scope.report.length; j++) {
|
|
90
|
+
sum += $scope.report[j][field];
|
|
84
91
|
}
|
|
92
|
+
result = sum;
|
|
93
|
+
if (filter) {
|
|
94
|
+
result = $filter(filter)(result);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
default :
|
|
98
|
+
result = instructions.totalsRow;
|
|
99
|
+
break;
|
|
85
100
|
}
|
|
101
|
+
}
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
instructions = _.find($scope.reportSchema.columnDefs, function (col) {
|
|
90
|
-
return col.field === field;
|
|
91
|
-
});
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
92
105
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
break;
|
|
97
|
-
case '$SUM' :
|
|
98
|
-
var sum = 0;
|
|
99
|
-
for (var j = 0; j < $scope.report.length; j++) {
|
|
100
|
-
sum += $scope.report[j][field];
|
|
101
|
-
}
|
|
102
|
-
result = sum;
|
|
103
|
-
if (filter) {
|
|
104
|
-
result = $filter(filter)(result);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
default :
|
|
108
|
-
result = instructions.totalsRow;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
106
|
+
$scope.$on('exportToPDF', function () {
|
|
107
|
+
pdfPlugIn.createPDF();
|
|
108
|
+
});
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
$scope.$on('exportToCSV', function () {
|
|
111
|
+
csvPlugIn.createCSV();
|
|
112
|
+
});
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
$scope.extractFilter = function(col, filters) {
|
|
115
|
+
if (col.cellFilter) {
|
|
116
|
+
var filterName;
|
|
117
|
+
var filterParam;
|
|
118
|
+
var paramPos = col.cellFilter.indexOf(':');
|
|
119
|
+
if (paramPos === -1) {
|
|
120
|
+
filterName = col.cellFilter;
|
|
121
|
+
} else {
|
|
122
|
+
filterName = col.cellFilter.slice(0, paramPos).trim();
|
|
123
|
+
filterParam = col.cellFilter.slice(paramPos + 1, 999).trim();
|
|
124
|
+
if (filterParam[0] === '\'' || filterParam[0] === '"') {
|
|
125
|
+
filterParam = filterParam.slice(1,-1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
var filter = angular.element(document.body).injector().get('$filter')(filterName.trim());
|
|
129
|
+
filters[col.field] = {filter: filter, filterParam: filterParam };
|
|
130
|
+
}
|
|
131
|
+
};
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
var container = document.querySelector('div.report-grow');
|
|
134
|
+
if (container) {
|
|
135
|
+
var margin = container.offsetLeft; // let's have the same top and bottom margins as we have side margin
|
|
136
|
+
var topOffset = container.offsetTop + margin;
|
|
137
|
+
var header = document.querySelector('div.ui-grid-header');
|
|
138
|
+
var headerHeight = header ? header.clientHeight : 31;
|
|
139
|
+
var availRows = Math.floor(($window.innerHeight - topOffset - headerHeight - margin) / 30);
|
|
140
|
+
angular.element(container).css('height', '' + availRows * 30 + 'px');
|
|
141
|
+
}
|
|
123
142
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
var filter = angular.element(document.body).injector().get('$filter')(filterName.trim());
|
|
139
|
-
filters[col.field] = {filter: filter, filterParam: filterParam};
|
|
140
|
-
}
|
|
141
|
-
};
|
|
143
|
+
var navScope = $rootScope.navScope;
|
|
144
|
+
navScope.items = [
|
|
145
|
+
{
|
|
146
|
+
fn: pdfPlugIn.createPDF,
|
|
147
|
+
text: 'Save as PDF'
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
fn: csvPlugIn.createCSV,
|
|
151
|
+
text: 'Export as CSV'
|
|
152
|
+
}
|
|
153
|
+
];
|
|
154
|
+
navScope.contextMenu = 'Report';
|
|
155
|
+
$scope.titleWithSubstitutions = $scope.reportSchema.title;
|
|
142
156
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
$scope.record = {};
|
|
147
|
-
for (var param in params) {
|
|
148
|
-
if (params.hasOwnProperty(param)) {
|
|
149
|
-
var thisPart = params[param];
|
|
150
|
-
// if noInput then this value will be inferred from another parameter
|
|
151
|
-
if (!thisPart.noInput) {
|
|
152
|
-
var newLen = $scope.paramSchema.push({
|
|
153
|
-
name: param,
|
|
154
|
-
id: 'fp_' + param,
|
|
155
|
-
label: thisPart.label || $filter('titleCase')(param),
|
|
156
|
-
type: thisPart.type || 'text',
|
|
157
|
-
required: true,
|
|
158
|
-
add: thisPart.add || undefined,
|
|
159
|
-
size: thisPart.size || (cssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
160
|
-
});
|
|
161
|
-
if (thisPart.type === 'select') {
|
|
162
|
-
// TODO: Remove when select and select2 is modified during the restructure
|
|
163
|
-
$scope[param + '_Opts'] = thisPart.enum;
|
|
164
|
-
$scope.paramSchema[newLen - 1].options = param + '_Opts';
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
var dateTest = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(thisPart.value);
|
|
168
|
-
if (dateTest) {
|
|
169
|
-
thisPart.value = new Date(dateTest[1]);
|
|
170
|
-
}
|
|
171
|
-
$scope.record[param] = thisPart.value;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
$scope.$watch('record', function (newValue, oldValue) {
|
|
175
|
-
if (oldValue !== newValue) {
|
|
176
|
-
console.log('In the record watch ', JSON.stringify(newValue, null, 2));
|
|
177
|
-
$scope.refreshQuery();
|
|
178
|
-
}
|
|
179
|
-
}, true);
|
|
180
|
-
}
|
|
157
|
+
// inhibitRefresh can be set by a controller, for example if report data is being provided as part of the URL
|
|
158
|
+
if (!$scope.inhibitRefresh) {
|
|
159
|
+
$scope.refreshQuery = function () {
|
|
181
160
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
var
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var availRows = Math.floor(($window.innerHeight - topOffset - headerHeight - margin) / 30);
|
|
189
|
-
angular.element(container).css('height', '' + availRows * 30 + 'px');
|
|
161
|
+
function substituteParams(str) {
|
|
162
|
+
return str.replace(/\|.+?\|/g, function (match) {
|
|
163
|
+
var param = match.slice(1, -1);
|
|
164
|
+
var isParamTest = /\((.+)\)/.exec(param);
|
|
165
|
+
return isParamTest ? $scope.reportSchema.params[isParamTest[1]].value : '';
|
|
166
|
+
});
|
|
190
167
|
}
|
|
191
168
|
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
text: 'Save as PDF'
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
fn: csvPlugIn.createCSV,
|
|
200
|
-
text: 'Export as CSV'
|
|
201
|
-
}
|
|
202
|
-
];
|
|
203
|
-
navScope.contextMenu = 'Report';
|
|
204
|
-
$scope.titleWithSubstitutions = $scope.reportSchema.title;
|
|
205
|
-
|
|
206
|
-
// inhibitRefresh can be set by a controller, for example if report data is being provided as part of the URL
|
|
207
|
-
if (!$scope.inhibitRefresh) {
|
|
169
|
+
var apiCall = '/api/report/' + $scope.modelName;
|
|
170
|
+
var connector = '?';
|
|
171
|
+
var haveUrlParams = false;
|
|
172
|
+
var query = $location.$$url.match(/\?.*/);
|
|
208
173
|
|
|
209
|
-
|
|
174
|
+
if ($scope.reportSchemaName) {
|
|
175
|
+
apiCall += '/' + $scope.reportSchemaName;
|
|
176
|
+
} else if (query) {
|
|
177
|
+
apiCall += connector + query[0].slice(1);
|
|
178
|
+
connector = '&';
|
|
179
|
+
haveUrlParams = true;
|
|
180
|
+
}
|
|
210
181
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
182
|
+
if ($scope.paramSchema) {
|
|
183
|
+
// we are using the params form
|
|
184
|
+
for (var paramVal in $scope.record) {
|
|
185
|
+
if ($scope.record.hasOwnProperty(paramVal)) {
|
|
186
|
+
var instructions = $scope.reportSchema.params[paramVal];
|
|
187
|
+
if ($scope.record[paramVal] && $scope.record[paramVal] !== '') {
|
|
188
|
+
$scope.param = $scope.record[paramVal];
|
|
189
|
+
if (instructions.conversionExpression) {
|
|
190
|
+
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
217
191
|
}
|
|
192
|
+
apiCall += connector + paramVal + '=' + $scope.param;
|
|
193
|
+
connector = '&';
|
|
194
|
+
} else if (instructions.required) {
|
|
195
|
+
// Don't do a round trip if a required field is empty - it will show up red
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
if (!haveUrlParams && query) {
|
|
202
|
+
apiCall += connector + query[0].slice(1);
|
|
203
|
+
connector = '&';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return $http.get(apiCall).then(function (response) {
|
|
207
|
+
var data = response.data;
|
|
208
|
+
if (data.success) {
|
|
209
|
+
$scope.report = data.report;
|
|
210
|
+
$scope.reportSchema = data.schema;
|
|
211
|
+
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
212
|
+
$scope.titleWithSubstitutions = substituteParams($scope.reportSchema.title);
|
|
213
|
+
$scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
|
|
214
|
+
if (navScope && navScope.items) {
|
|
215
|
+
navScope.items.length = 2;
|
|
216
|
+
if ($scope.reportSchema.menu) {
|
|
217
|
+
$scope.reportSchema.menu.forEach(function(m){
|
|
218
|
+
navScope.items.push(JSON.parse(substituteParams(JSON.stringify(m))));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
218
222
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
var query = $location.$$url.match(/\?.*/);
|
|
223
|
+
/*
|
|
224
|
+
Generate link data
|
|
225
|
+
*/
|
|
223
226
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
} else if (query) {
|
|
227
|
-
if (firstTime) {
|
|
228
|
-
// See if we have params in the URL (rather than going through schemaName)
|
|
229
|
-
$scope.paramSchema = JSON.parse($location.search().r).params;
|
|
230
|
-
setupParamsForm($scope.paramSchema);
|
|
231
|
-
}
|
|
232
|
-
apiCall += connector + query[0].slice(1);
|
|
233
|
-
connector = '&';
|
|
234
|
-
haveUrlParams = true;
|
|
235
|
-
}
|
|
227
|
+
if (firstTime) {
|
|
228
|
+
firstTime = false;
|
|
236
229
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
$scope.param = $scope.record[paramVal];
|
|
244
|
-
if (instructions.conversionExpression) {
|
|
245
|
-
$scope.param = $scope.$eval(instructions.conversionExpression);
|
|
246
|
-
}
|
|
247
|
-
apiCall += connector + paramVal + '=' + $scope.param;
|
|
248
|
-
connector = '&';
|
|
249
|
-
} else if (instructions.required) {
|
|
250
|
-
// Don't do a round trip if a required field is empty - it will show up red
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
230
|
+
$scope.$watch('reportSchema.columnDefs', function (newValue) {
|
|
231
|
+
var columnTotals = false;
|
|
232
|
+
if (newValue) {
|
|
233
|
+
for (var i = 0; i < newValue.length; i++) {
|
|
234
|
+
if (newValue[i].totalsRow) {
|
|
235
|
+
columnTotals = true;
|
|
254
236
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
237
|
+
if (newValue[i].align) {
|
|
238
|
+
var alignClass = 'fng-' + newValue[i].align;
|
|
239
|
+
newValue[i].cellClass = newValue[i].cellClass || '';
|
|
240
|
+
if (newValue[i].cellClass.indexOf(alignClass) === -1) {
|
|
241
|
+
newValue[i].cellClass = newValue[i].cellClass + ' ' + alignClass;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Auto-upgrade from ng-grid to ui-grid
|
|
246
|
+
newValue.forEach(function (def) {
|
|
247
|
+
// Remove px from column widths
|
|
248
|
+
if (def.width && typeof def.width === 'string' && def.width.indexOf('px') !== -1) {
|
|
249
|
+
def.width = parseInt(def.width.slice(0, -2));
|
|
259
250
|
}
|
|
251
|
+
});
|
|
252
|
+
$scope.gridOptions.columnDefs = newValue;
|
|
260
253
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
$scope.report = data.report;
|
|
266
|
-
$scope.reportSchema = data.schema;
|
|
267
|
-
$scope.reportSchema.title = $scope.reportSchema.title || $scope.modelName;
|
|
268
|
-
$scope.titleWithSubstitutions = substituteParams($scope.reportSchema.title);
|
|
269
|
-
$scope.gridOptions.enableFiltering = !!$scope.reportSchema.filter;
|
|
270
|
-
if (navScope && navScope.items) {
|
|
271
|
-
navScope.items.length = 2;
|
|
272
|
-
if ($scope.reportSchema.menu) {
|
|
273
|
-
$scope.reportSchema.menu.forEach(function (m) {
|
|
274
|
-
navScope.items.push(JSON.parse(substituteParams(JSON.stringify(m))));
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/*
|
|
280
|
-
Generate link data
|
|
281
|
-
*/
|
|
254
|
+
$scope.gridOptions.showTotals = columnTotals;
|
|
255
|
+
$scope.gridOptions.reallyShowFooter = columnTotals;
|
|
256
|
+
$scope.gridOptions.footerRowHeight = 55 + (columnTotals ? 10 : 0);
|
|
257
|
+
}, true);
|
|
282
258
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
$scope.gridOptions.columnDefs = newValue;
|
|
309
|
-
}
|
|
310
|
-
$scope.gridOptions.showTotals = columnTotals;
|
|
311
|
-
$scope.gridOptions.reallyShowFooter = columnTotals;
|
|
312
|
-
$scope.gridOptions.footerRowHeight = 55 + (columnTotals ? 10 : 0);
|
|
313
|
-
}, true);
|
|
314
|
-
|
|
315
|
-
if (!$scope.paramSchema && data.schema.params) {
|
|
316
|
-
setupParamsForm(data.schema.params);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
console.log(JSON.stringify(data));
|
|
321
|
-
$scope.reportSchema.title = 'Error - see console log';
|
|
259
|
+
if (!$scope.paramSchema && data.schema.params) {
|
|
260
|
+
$scope.paramSchema = [];
|
|
261
|
+
// set up parameters
|
|
262
|
+
$scope.record = {};
|
|
263
|
+
for (var param in data.schema.params) {
|
|
264
|
+
if (data.schema.params.hasOwnProperty(param)) {
|
|
265
|
+
var thisPart = data.schema.params[param];
|
|
266
|
+
// if noInput then this value will be inferred from another parameter
|
|
267
|
+
if (!thisPart.noInput) {
|
|
268
|
+
var newLen = $scope.paramSchema.push({
|
|
269
|
+
name: param,
|
|
270
|
+
id: 'fp_' + param,
|
|
271
|
+
label: thisPart.label || $filter('titleCase')(param),
|
|
272
|
+
type: thisPart.type || 'text',
|
|
273
|
+
required: true,
|
|
274
|
+
add: thisPart.add || undefined,
|
|
275
|
+
size: thisPart.size || (cssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
276
|
+
});
|
|
277
|
+
if (thisPart.type === 'select') {
|
|
278
|
+
// TODO: Remove when select and select2 is modified during the restructure
|
|
279
|
+
$scope[param + '_Opts'] = thisPart.enum;
|
|
280
|
+
$scope.paramSchema[newLen - 1].options = param + '_Opts';
|
|
281
|
+
}
|
|
322
282
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
283
|
+
var dateTest = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})(Z|[+ -]\d{4})$/.exec(thisPart.value);
|
|
284
|
+
if (dateTest) {
|
|
285
|
+
thisPart.value = new Date(dateTest[1]);
|
|
286
|
+
}
|
|
287
|
+
$scope.record[param] = thisPart.value;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
$scope.$watch('record', function (newValue, oldValue) {
|
|
291
|
+
if (oldValue !== newValue) {
|
|
292
|
+
$scope.refreshQuery();
|
|
293
|
+
}
|
|
294
|
+
}, true);
|
|
328
295
|
|
|
329
|
-
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
console.log(JSON.stringify(data));
|
|
300
|
+
$scope.reportSchema.title = 'Error - see console log';
|
|
301
|
+
}
|
|
302
|
+
}, function (response) {
|
|
303
|
+
console.log(JSON.stringify(response));
|
|
304
|
+
$location.url('/404');
|
|
305
|
+
});
|
|
306
|
+
};
|
|
330
307
|
|
|
331
|
-
|
|
332
|
-
|
|
308
|
+
$scope.refreshQuery();
|
|
309
|
+
}
|
|
333
310
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
311
|
+
// Check whether a cell template shows the content (in which case we want to output it) or does something funky
|
|
312
|
+
// (for example displays an image)
|
|
313
|
+
$scope.showsContent = function(template) {
|
|
314
|
+
return /{{[\s]*COL_FIELD[\s]*}}/.test(template.replace(/(<([^>]+)>)/gi, ''));
|
|
315
|
+
};
|
|
339
316
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
317
|
+
$scope.$on('$locationChangeStart', function() {
|
|
318
|
+
delete navScope.contextMenu;
|
|
319
|
+
delete navScope.items;
|
|
320
|
+
});
|
|
344
321
|
|
|
345
|
-
|
|
322
|
+
}]);
|