fng-reports 0.12.0-beta.216 → 0.12.0-beta.218
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 +15 -12
- package/dist/fng-reports.min.js +3 -3
- package/package.json +2 -2
- package/src/fng-reports.js +14 -11
- package/test/karma.conf.js +1 -1
- package/test/specs/reportSpec.js +3 -3
package/dist/fng-reports.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/*! forms-angular 2023-06-
|
|
1
|
+
/*! forms-angular 2023-06-27 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', '
|
|
5
|
-
function ($rootScope, $window, $filter, $scope, $http, $location,
|
|
4
|
+
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService',
|
|
5
|
+
function ($rootScope, $window, $filter, $scope, $http, $location, CssFrameworkService, RoutingService) {
|
|
6
6
|
/*jshint newcap: false */
|
|
7
7
|
var firstTime = true,
|
|
8
8
|
pdfPlugIn = new ngGridPdfExportPlugin({inhibitButton: true}),
|
|
9
9
|
csvPlugIn = new ngGridCsvExportPlugin({inhibitButton: true});
|
|
10
10
|
/*jshint newcap: true */
|
|
11
11
|
|
|
12
|
-
angular.extend($scope,
|
|
12
|
+
angular.extend($scope, RoutingService.parsePathFunc()($location.$$path));
|
|
13
13
|
|
|
14
14
|
$scope.reportSchema = {
|
|
15
15
|
columnDefs: []
|
|
@@ -38,7 +38,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$s
|
|
|
38
38
|
var url = $scope.reportSchema.drilldown;
|
|
39
39
|
if (url) {
|
|
40
40
|
if (typeof url === 'string') {
|
|
41
|
-
url =
|
|
41
|
+
url = RoutingService.buildUrl(url.replace(/\|.+?\|/g, function (match) {
|
|
42
42
|
var param = match.slice(1, -1),
|
|
43
43
|
isParamTest = /\((.+)\)/.exec(param);
|
|
44
44
|
if (isParamTest) {
|
|
@@ -68,19 +68,22 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$s
|
|
|
68
68
|
/*
|
|
69
69
|
* This allows us to make an arbitrary http request from a cell template. Example:
|
|
70
70
|
* <div class="ui-grid-cell-contents">
|
|
71
|
-
* <
|
|
72
|
-
*
|
|
73
|
-
* </
|
|
71
|
+
* <button class="btn btn-small" data-ng-click="grid.appScope.http($event, 'GET', '/apix/queue/cancel/:id')" data-id="{{COL_FIELD}}" data-disable-button="true">
|
|
72
|
+
* <span class="glyphicon glyphicon-remove"></span> Cancel
|
|
73
|
+
* </button>
|
|
74
74
|
* </div>
|
|
75
75
|
* The value of any attribute beginning with data will replace the corresponding :attribute in the url,
|
|
76
76
|
* so in this case the :id in the url will be replaced by the value of the data-id attribute.
|
|
77
77
|
*/
|
|
78
78
|
http: function ($event, method, url) {
|
|
79
|
-
$event.
|
|
79
|
+
$event.currentTarget.getAttributeNames().forEach(a => {
|
|
80
80
|
if (a.startsWith('data-')) {
|
|
81
|
-
url = url.replace(`:${a.slice(5)}`, $event.
|
|
81
|
+
url = url.replace(`:${a.slice(5)}`, $event.currentTarget.getAttribute(a));
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
+
if ($event.currentTarget.getAttribute('data-disable-button') === 'true') {
|
|
85
|
+
$event.currentTarget.setAttribute('disabled', 'disabled');
|
|
86
|
+
}
|
|
84
87
|
$http({
|
|
85
88
|
method: method,
|
|
86
89
|
url: url,
|
|
@@ -185,7 +188,7 @@ ${e.message}`);
|
|
|
185
188
|
type: thisPart.type || 'text',
|
|
186
189
|
required: true,
|
|
187
190
|
add: thisPart.add || undefined,
|
|
188
|
-
size: thisPart.size || (
|
|
191
|
+
size: thisPart.size || (CssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
189
192
|
});
|
|
190
193
|
if (thisPart.type === 'select') {
|
|
191
194
|
// TODO: Remove when select and select2 is modified during the restructure
|
|
@@ -379,7 +382,7 @@ ${e.message}`);
|
|
|
379
382
|
delete navScope.items;
|
|
380
383
|
});
|
|
381
384
|
|
|
382
|
-
// Error handling, stolen quickly from forms-
|
|
385
|
+
// Error handling, stolen quickly from forms-angular record-handler
|
|
383
386
|
$scope.showError = function(error, alertTitle) {
|
|
384
387
|
$scope.alertTitle = alertTitle ? alertTitle : 'Error!';
|
|
385
388
|
if (typeof error === 'string') {
|
package/dist/fng-reports.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! forms-angular 2023-06-
|
|
2
|
-
"use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$filter","$scope","$http","$location","
|
|
3
|
-
`+e.message)}}if(angular.extend(l,t.parsePathFunc()(c.$$path)),l.reportSchema={columnDefs:[]},l.gridOptions={data:"report",columnDefs:l.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(r){l.gridApi=r,l.gridOptions.plugins.forEach(function(e){e.init(l,r.grid,null)}),r.selection.on.rowSelectionChanged(l,function(o){var e=l.reportSchema.drilldown;e&&("string"==typeof e?(e=t.buildUrl(e.replace(/\|.+?\|/g,function(e){var r,e=e.slice(1,-1),t=/\((.+)\)/.exec(e);return t?(r=l.reportSchema.params[t[1]])?(l.param=l.record[t[1]],r.conversionExpression?l.$eval(r.conversionExpression):r.value):l.reportSchema.params[t[1]].value:o.entity[e]})),window.location=e):console.error("Was expecting drilldown to be string but it was "+typeof e+" ("+e+")"))})},appScopeProvider:{http:function(r,e,t){r.target.getAttributeNames().forEach(e=>{e.startsWith("data-")&&(t=t.replace(":"+e.slice(5),r.target.getAttribute(e)))}),s({method:e,url:t}),r.stopPropagation()}}},l.report=[],!l.reportSchemaName&&c.$$search.r)switch(c.$$search.r.slice(0,1)){case"[":l.reportSchema.pipeline=d(c.$$search.r);break;case"{":angular.extend(l.reportSchema,d(c.$$search.r));break;default:throw new Error("No report instructions specified")}function u(e){for(var r in l.paramSchema=[],l.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=l.paramSchema.push({name:r,id:"fp_"+r,label:t.label||a("titleCase")(r),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===i.frameWork?"large":"medium")}),"select"===t.type&&(l[r+"_Opts"]=t.enum,l.paramSchema[o-1].options=r+"_Opts")),(o=/^(\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(o[1])),l.record[r]=t.value)}l.$watch("record",function(e,r){r!==e&&l.refreshQuery()},!0)}l.getTotalVal=function(r,e){var t="",o=_.find(l.reportSchema.columnDefs,function(e){return e.field===r});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var i=0,n=0;n<l.report.length;n++)i+=l.report[n][r];t=i,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},l.$on("exportToPDF",function(){o.createPDF()}),l.$on("exportToCSV",function(){n.createCSV()}),l.extractFilter=function(e,r){var t,o,i;e.cellFilter&&(-1===(i=e.cellFilter.indexOf(":"))?t=e.cellFilter:(t=e.cellFilter.slice(0,i).trim(),"'"!==(o=e.cellFilter.slice(i+1,999).trim())[0]&&'"'!==o[0]||(o=o.slice(1,-1))),i=angular.element(document.body).injector().get("$filter")(t.trim()),r[e.field]={filter:i,filterParam:o})};var f,m,h,g=document.querySelector("div.report-grow"),S=(g&&(f=g.offsetLeft,m=g.offsetTop+f,h=(h=document.querySelector("div.ui-grid-header"))?h.clientHeight:31,r=Math.floor((r.innerHeight-m-h-f)/30),angular.element(g).css("height",30*r+"px")),e.navScope);S.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:n.createCSV,text:"Export as CSV"}],S.contextMenu="Report",S.contextMenuId="reportMenu",l.titleWithSubstitutions=l.reportSchema.title,l.inhibitRefresh||(l.refreshQuery=function(){function t(e){return e.replace(/\|.+?\|/g,function(e){e=e.slice(1,-1),e=/\((.+)\)/.exec(e);return e?l.reportSchema.params[e[1]].value:""})}var e="/api/report/"+l.modelName,r="?",o=!1,i=c.$$url.match(/\?.*/);if(l.reportSchemaName?e+="/"+l.reportSchemaName:i&&(p&&(l.paramSchema=JSON.parse(c.search().r).params,u(l.paramSchema)),e+=r+i[0].slice(1),r="&",o=!0),l.paramSchema){for(var n in l.record)if(l.record.hasOwnProperty(n)){var a=l.reportSchema.params[n];if(l.record[n]&&""!==l.record[n])l.param=l.record[n],a.conversionExpression&&(l.param=l.$eval(a.conversionExpression)),e+=r+n+"="+l.param,r="&";else if(a.required)return}}else!o&&i&&(e+=r+i[0].slice(1),r="&");return s.get(e).then(function(e){var r;e&&e.data&&e.data.success?(r=e.data,l.report=r.report,l.reportSchema=r.schema,l.reportSchema.title=l.reportSchema.title||l.modelName,l.titleWithSubstitutions=t(l.reportSchema.title),l.gridOptions.enableFiltering=!!l.reportSchema.filter,S&&S.items&&(S.items.length=2,l.reportSchema.menu)&&l.reportSchema.menu.forEach(function(e){S.items.push(JSON.parse(t(JSON.stringify(e))))}),p&&(p=!1,l.$watch("reportSchema.columnDefs",function(e){var r=!1;if(e){for(var t,o=0;o<e.length;o++)e[o].totalsRow&&(r=!0),e[o].align&&(t="fng-"+e[o].align,e[o].cellClass=e[o].cellClass||"",-1===e[o].cellClass.indexOf(t))&&(e[o].cellClass=e[o].cellClass+" "+t);e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),l.gridOptions.columnDefs=e}l.gridOptions.showTotals=r,l.gridOptions.reallyShowFooter=r,l.gridOptions.footerRowHeight=55+(r?10:0)},!0),!l.paramSchema)&&r.schema.params&&u(r.schema.params)):(l.showError(JSON.stringify(e.data.error),"Invalid Response Error"),l.reportSchema.title="Error - see console log")},function(e){let r,t;t=403===e.status?(r="You do not have permission to run this report (permission to GET all "+l.modelName+" records is required)","Permission denied"):(r="The server could not process the request","Error"),l.showError(r,t)})},l.refreshQuery()),l.showsContent=function(e,r){return!!/{{[\s]*COL_FIELD[\s]*}}/.test(e.replace(/(<([^>]+)>)/gi,""))||(-1!==e.indexOf('ng-bind-html="row.entity.'+r)?"HTML":void 0)},l.$on("$locationChangeStart",function(){delete S.contextMenu,delete S.items}),l.showError=function(r,e){if(l.alertTitle=e||"Error!","string"==typeof r)l.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)l.errorMessage=r.message;else if(r.data&&r.data.message)l.errorMessage=r.data.message;else try{l.errorMessage=JSON.stringify(r)}catch(e){l.errorMessage=r}else l.errorMessage="An error occurred - that's all we got. Sorry.";l.errorHideTimer=window.setTimeout(function(){l.dismissError(),l.$digest()},3500+1e3*(l.alertTitle+l.errorMessage).length/50),l.errorVisible=!0,window.setTimeout(()=>{l.$digest()})},l.clearTimeout=function(){l.errorHideTimer&&(clearTimeout(l.errorHideTimer),delete l.errorHideTimer)},l.dismissError=function(){l.clearTimeout,l.errorVisible=!1,delete l.errorMessage,delete l.alertTitle},l.stickError=function(){clearTimeout(l.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var a=this;a.grid=null,a.scope=null,a.services=null,a.init=function(e,r,t){a.grid=r,a.scope=e,a.services=t},a.createCSV=function(){var e,r,t;e=a.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(a.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},a.prepareCSV=function(){function o(e,r){return null==e?"":r?r.filter(e,r.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 i="",n={};return angular.forEach(a.grid.columns,function(e){var r;a.scope.extractFilter(e,n),e.visible&&(void 0===e.width||"*"===e.width||0<e.width)&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(r=a.scope.showsContent(e.colDef.cellTemplate,e.field))?(i+='"'+o(e.displayName)+'",',e.doCSVExport=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):r?(i+='"'+o(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1:(i+='"'+o(e.displayName)+'",',e.doCSVExport=!0))}),i=e(i),angular.forEach(a.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(a.grid.columns,function(r){if(r.doCSVExport){let e=t.entity[r.field];"function"==typeof r.doCSVExport&&(e=r.doCSVExport(e)),i+='"'+o(e,n[r.field])+'",'}}),i=e(i))}),i}}function ngGridPdfExportPlugin(o){var l=this;l.grid=null,l.scope=null,l.services=null,l.options=o,l.init=function(e,r,t){l.grid=r,l.scope=e,l.services=t,o.inhibitButton||(e=r.$root.find(".ngFooterPanel"),null!=(t=r.$root.find(".ngFooterPanel .pdf-data-link-span"))&&t.remove(),e.append('<button class="pdf-data-link-span">PDF Export</button>'),e.on("click",function(){l.createPDF()}))},l.createPDF=function(){var o=[],i=[],e=[],n={},a={},r=(angular.forEach(l.grid.columns,function(e,r){var t;e.visible&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(t=l.scope.showsContent(e.colDef.cellTemplate,e.field))?(o.push(e.displayName),i.push(e.field),a[e.field]=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):t&&(o.push(e.displayName),i.push(e.field)):(o.push(e.displayName),i.push(e.field))),e.colDef.totalsRow&&(e.field,l.grid.getTotalVal(e.field,e.filter).toString()),l.scope.extractFilter(e,n)}),angular.forEach(l.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(i.forEach(function(e){var r=t.entity[e];n[e]&&(r=n[e].filter(r,n[e].filterParam)),"string"==typeof(r=a[e]?a[e](r):r)&&(r=(r=(r=(r=(r=r.replace(/\u2019/g,"'")).replace(/\u2018/g,"'")).replace(/\u201c/g,'"')).replace(/\u201d/g,'"')).replace(/[^\x00-\xFF]/g,"")),o.push(r)}),e.push(o))}),new jspdf.jsPDF("landscape","mm","a4"));r.autoTable({head:[o],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(i,t){return{scope:!1,compile:function(){return{pre:function(e,r){var t=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),t=t?e.col.cellTemplate.replace("COL_FIELD |"+t[1],'getTotalVal("'+e.col.field+'","'+t[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),o=e.col.enableCellEdit?(o=(o=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,t)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):t,t=i(o)(e);e.enableCellSelection&&-1===t[0].className.indexOf("ngSelectionCell")&&(t[0].setAttribute("tabindex",0),t.addClass("ngCellElement")),r.append(t)},post:function(e,r){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,r),e.$on("ngGridEventDigestCell",function(){t.digest(e)})}}}}}]);
|
|
1
|
+
/*! forms-angular 2023-06-27 */
|
|
2
|
+
"use strict";formsAngular.controller("AnalysisCtrl",["$rootScope","$window","$filter","$scope","$http","$location","CssFrameworkService","RoutingService",function(e,r,a,l,s,c,i,t){var p=!0,o=new ngGridPdfExportPlugin({inhibitButton:!0}),n=new ngGridCsvExportPlugin({inhibitButton:!0});function d(r){try{return JSON.parse(r)}catch(e){throw new Error(`Invalid JSON ${r}
|
|
3
|
+
`+e.message)}}if(angular.extend(l,t.parsePathFunc()(c.$$path)),l.reportSchema={columnDefs:[]},l.gridOptions={data:"report",columnDefs:l.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(r){l.gridApi=r,l.gridOptions.plugins.forEach(function(e){e.init(l,r.grid,null)}),r.selection.on.rowSelectionChanged(l,function(o){var e=l.reportSchema.drilldown;e&&("string"==typeof e?(e=t.buildUrl(e.replace(/\|.+?\|/g,function(e){var r,e=e.slice(1,-1),t=/\((.+)\)/.exec(e);return t?(r=l.reportSchema.params[t[1]])?(l.param=l.record[t[1]],r.conversionExpression?l.$eval(r.conversionExpression):r.value):l.reportSchema.params[t[1]].value:o.entity[e]})),window.location=e):console.error("Was expecting drilldown to be string but it was "+typeof e+" ("+e+")"))})},appScopeProvider:{http:function(r,e,t){r.currentTarget.getAttributeNames().forEach(e=>{e.startsWith("data-")&&(t=t.replace(":"+e.slice(5),r.currentTarget.getAttribute(e)))}),"true"===r.currentTarget.getAttribute("data-disable-button")&&r.currentTarget.setAttribute("disabled","disabled"),s({method:e,url:t}),r.stopPropagation()}}},l.report=[],!l.reportSchemaName&&c.$$search.r)switch(c.$$search.r.slice(0,1)){case"[":l.reportSchema.pipeline=d(c.$$search.r);break;case"{":angular.extend(l.reportSchema,d(c.$$search.r));break;default:throw new Error("No report instructions specified")}function u(e){for(var r in l.paramSchema=[],l.record={},e){var t,o;e.hasOwnProperty(r)&&((t=e[r]).noInput||(o=l.paramSchema.push({name:r,id:"fp_"+r,label:t.label||a("titleCase")(r),type:t.type||"text",required:!0,add:t.add||void 0,size:t.size||("bs3"===i.frameWork?"large":"medium")}),"select"===t.type&&(l[r+"_Opts"]=t.enum,l.paramSchema[o-1].options=r+"_Opts")),(o=/^(\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(o[1])),l.record[r]=t.value)}l.$watch("record",function(e,r){r!==e&&l.refreshQuery()},!0)}l.getTotalVal=function(r,e){var t="",o=_.find(l.reportSchema.columnDefs,function(e){return e.field===r});if(o)switch(o.totalsRow){case void 0:break;case"$SUM":for(var i=0,n=0;n<l.report.length;n++)i+=l.report[n][r];t=i,e&&(t=a(e)(t));break;default:t=o.totalsRow}return t},l.$on("exportToPDF",function(){o.createPDF()}),l.$on("exportToCSV",function(){n.createCSV()}),l.extractFilter=function(e,r){var t,o,i;e.cellFilter&&(-1===(i=e.cellFilter.indexOf(":"))?t=e.cellFilter:(t=e.cellFilter.slice(0,i).trim(),"'"!==(o=e.cellFilter.slice(i+1,999).trim())[0]&&'"'!==o[0]||(o=o.slice(1,-1))),i=angular.element(document.body).injector().get("$filter")(t.trim()),r[e.field]={filter:i,filterParam:o})};var f,m,g,h=document.querySelector("div.report-grow"),S=(h&&(f=h.offsetLeft,m=h.offsetTop+f,g=(g=document.querySelector("div.ui-grid-header"))?g.clientHeight:31,r=Math.floor((r.innerHeight-m-g-f)/30),angular.element(h).css("height",30*r+"px")),e.navScope);S.items=[{fn:o.createPDF,text:"Save as PDF"},{fn:n.createCSV,text:"Export as CSV"}],S.contextMenu="Report",S.contextMenuId="reportMenu",l.titleWithSubstitutions=l.reportSchema.title,l.inhibitRefresh||(l.refreshQuery=function(){function t(e){return e.replace(/\|.+?\|/g,function(e){e=e.slice(1,-1),e=/\((.+)\)/.exec(e);return e?l.reportSchema.params[e[1]].value:""})}var e="/api/report/"+l.modelName,r="?",o=!1,i=c.$$url.match(/\?.*/);if(l.reportSchemaName?e+="/"+l.reportSchemaName:i&&(p&&(l.paramSchema=JSON.parse(c.search().r).params,u(l.paramSchema)),e+=r+i[0].slice(1),r="&",o=!0),l.paramSchema){for(var n in l.record)if(l.record.hasOwnProperty(n)){var a=l.reportSchema.params[n];if(l.record[n]&&""!==l.record[n])l.param=l.record[n],a.conversionExpression&&(l.param=l.$eval(a.conversionExpression)),e+=r+n+"="+l.param,r="&";else if(a.required)return}}else!o&&i&&(e+=r+i[0].slice(1),r="&");return s.get(e).then(function(e){var r;e&&e.data&&e.data.success?(r=e.data,l.report=r.report,l.reportSchema=r.schema,l.reportSchema.title=l.reportSchema.title||l.modelName,l.titleWithSubstitutions=t(l.reportSchema.title),l.gridOptions.enableFiltering=!!l.reportSchema.filter,S&&S.items&&(S.items.length=2,l.reportSchema.menu)&&l.reportSchema.menu.forEach(function(e){S.items.push(JSON.parse(t(JSON.stringify(e))))}),p&&(p=!1,l.$watch("reportSchema.columnDefs",function(e){var r=!1;if(e){for(var t,o=0;o<e.length;o++)e[o].totalsRow&&(r=!0),e[o].align&&(t="fng-"+e[o].align,e[o].cellClass=e[o].cellClass||"",-1===e[o].cellClass.indexOf(t))&&(e[o].cellClass=e[o].cellClass+" "+t);e.forEach(function(e){e.width&&"string"==typeof e.width&&-1!==e.width.indexOf("px")&&(e.width=parseInt(e.width.slice(0,-2)))}),l.gridOptions.columnDefs=e}l.gridOptions.showTotals=r,l.gridOptions.reallyShowFooter=r,l.gridOptions.footerRowHeight=55+(r?10:0)},!0),!l.paramSchema)&&r.schema.params&&u(r.schema.params)):(l.showError(JSON.stringify(e.data.error),"Invalid Response Error"),l.reportSchema.title="Error - see console log")},function(e){let r,t;t=403===e.status?(r="You do not have permission to run this report (permission to GET all "+l.modelName+" records is required)","Permission denied"):(r="The server could not process the request","Error"),l.showError(r,t)})},l.refreshQuery()),l.showsContent=function(e,r){return!!/{{[\s]*COL_FIELD[\s]*}}/.test(e.replace(/(<([^>]+)>)/gi,""))||(-1!==e.indexOf('ng-bind-html="row.entity.'+r)?"HTML":void 0)},l.$on("$locationChangeStart",function(){delete S.contextMenu,delete S.items}),l.showError=function(r,e){if(l.alertTitle=e||"Error!","string"==typeof r)l.errorMessage=r;else if(r)if(r.message&&"string"==typeof r.message)l.errorMessage=r.message;else if(r.data&&r.data.message)l.errorMessage=r.data.message;else try{l.errorMessage=JSON.stringify(r)}catch(e){l.errorMessage=r}else l.errorMessage="An error occurred - that's all we got. Sorry.";l.errorHideTimer=window.setTimeout(function(){l.dismissError(),l.$digest()},3500+1e3*(l.alertTitle+l.errorMessage).length/50),l.errorVisible=!0,window.setTimeout(()=>{l.$digest()})},l.clearTimeout=function(){l.errorHideTimer&&(clearTimeout(l.errorHideTimer),delete l.errorHideTimer)},l.dismissError=function(){l.clearTimeout,l.errorVisible=!1,delete l.errorMessage,delete l.alertTitle},l.stickError=function(){clearTimeout(l.errorHideTimer)}}]);var COL_FIELD=/COL_FIELD/g;function ngGridCsvExportPlugin(e){var a=this;a.grid=null,a.scope=null,a.services=null,a.init=function(e,r,t){a.grid=r,a.scope=e,a.services=t},a.createCSV=function(){var e,r,t;e=a.scope.reportSchema.title+".csv",r="data:text/csv;charset=UTF-8,"+encodeURIComponent(a.prepareCSV()),(t=document.createElement("a")).download=e,t.href=r,e=new MouseEvent("click"),t.dispatchEvent(e)},a.prepareCSV=function(){function o(e,r){return null==e?"":r?r.filter(e,r.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 i="",n={};return angular.forEach(a.grid.columns,function(e){var r;a.scope.extractFilter(e,n),e.visible&&(void 0===e.width||"*"===e.width||0<e.width)&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(r=a.scope.showsContent(e.colDef.cellTemplate,e.field))?(i+='"'+o(e.displayName)+'",',e.doCSVExport=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):r?(i+='"'+o(e.displayName)+'",',e.doCSVExport=!0):e.doCSVExport=!1:(i+='"'+o(e.displayName)+'",',e.doCSVExport=!0))}),i=e(i),angular.forEach(a.scope.gridApi.core.getVisibleRows(),function(t){t.visible&&(angular.forEach(a.grid.columns,function(r){if(r.doCSVExport){let e=t.entity[r.field];"function"==typeof r.doCSVExport&&(e=r.doCSVExport(e)),i+='"'+o(e,n[r.field])+'",'}}),i=e(i))}),i}}function ngGridPdfExportPlugin(o){var l=this;l.grid=null,l.scope=null,l.services=null,l.options=o,l.init=function(e,r,t){l.grid=r,l.scope=e,l.services=t,o.inhibitButton||(e=r.$root.find(".ngFooterPanel"),null!=(t=r.$root.find(".ngFooterPanel .pdf-data-link-span"))&&t.remove(),e.append('<button class="pdf-data-link-span">PDF Export</button>'),e.on("click",function(){l.createPDF()}))},l.createPDF=function(){var o=[],i=[],e=[],n={},a={},r=(angular.forEach(l.grid.columns,function(e,r){var t;e.visible&&(-1!==e.field.indexOf(".")?console.error(`Cannot export nested fields such as ${e.field}. Use $project to simplify.`):e.colDef.cellTemplate?"HTML"===(t=l.scope.showsContent(e.colDef.cellTemplate,e.field))?(o.push(e.displayName),i.push(e.field),a[e.field]=function(e){return e=(e=(e=(e=(e=(e=(e=e.replace(/<p>/g,"\n\n")).replace(/<\/p>/g,"")).replace(/<\s?br\s?\/?>/g,"\n")).replace(/<[^>]+>/g,"")).replaceAll(" "," ").trim()).replaceAll("\n\n \n\n","\n\n")).replaceAll("\n\n\n","\n\n")}):t&&(o.push(e.displayName),i.push(e.field)):(o.push(e.displayName),i.push(e.field))),e.colDef.totalsRow&&(e.field,l.grid.getTotalVal(e.field,e.filter).toString()),l.scope.extractFilter(e,n)}),angular.forEach(l.scope.gridApi.core.getVisibleRows(),function(t){var o=[];t.visible&&(i.forEach(function(e){var r=t.entity[e];n[e]&&(r=n[e].filter(r,n[e].filterParam)),"string"==typeof(r=a[e]?a[e](r):r)&&(r=(r=(r=(r=(r=r.replace(/\u2019/g,"'")).replace(/\u2018/g,"'")).replace(/\u201c/g,'"')).replace(/\u201d/g,'"')).replace(/[^\x00-\xFF]/g,"")),o.push(r)}),e.push(o))}),new jspdf.jsPDF("landscape","mm","a4"));r.autoTable({head:[o],body:e}),window.open(r.output("bloburl"))}}formsAngular.directive("ngTotalCell",["$compile","$domUtilityService",function(i,t){return{scope:!1,compile:function(){return{pre:function(e,r){var t=e.col.cellTemplate.match(/{{COL_FIELD \|(.+)}}/),t=t?e.col.cellTemplate.replace("COL_FIELD |"+t[1],'getTotalVal("'+e.col.field+'","'+t[1]+'")'):e.col.cellTemplate.replace(COL_FIELD,'getTotalVal("'+e.col.field+'")'),o=e.col.enableCellEdit?(o=(o=e.col.cellEditTemplate).replace(DISPLAY_CELL_TEMPLATE,t)).replace(EDITABLE_CELL_TEMPLATE,e.col.editableCellTemplate.replace(COL_FIELD,"row.entity."+e.col.field)):t,t=i(o)(e);e.enableCellSelection&&-1===t[0].className.indexOf("ngSelectionCell")&&(t[0].setAttribute("tabindex",0),t.addClass("ngCellElement")),r.append(t)},post:function(e,r){e.enableCellSelection&&e.domAccessProvider.selectionHandlers(e,r),e.$on("ngGridEventDigestCell",function(){t.digest(e)})}}}}}]);
|
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.218",
|
|
4
4
|
"description": "Reporting plugin for forms-angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"angular-messages": "1.8.3",
|
|
33
33
|
"angular-mocks": "1.8.3",
|
|
34
34
|
"angular-sanitize": "1.8.3",
|
|
35
|
-
"forms-angular": "0.12.0-beta.
|
|
35
|
+
"forms-angular": "file:../forms-angular/forms-angular-0.12.0-beta.218.tgz",
|
|
36
36
|
"grunt": "^1.5.3",
|
|
37
37
|
"grunt-autoprefixer": "3.0.4",
|
|
38
38
|
"grunt-concurrent": "3.0.0",
|
package/src/fng-reports.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', '
|
|
4
|
-
function ($rootScope, $window, $filter, $scope, $http, $location,
|
|
3
|
+
formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$scope', '$http', '$location', 'CssFrameworkService', 'RoutingService',
|
|
4
|
+
function ($rootScope, $window, $filter, $scope, $http, $location, CssFrameworkService, RoutingService) {
|
|
5
5
|
/*jshint newcap: false */
|
|
6
6
|
var firstTime = true,
|
|
7
7
|
pdfPlugIn = new ngGridPdfExportPlugin({inhibitButton: true}),
|
|
8
8
|
csvPlugIn = new ngGridCsvExportPlugin({inhibitButton: true});
|
|
9
9
|
/*jshint newcap: true */
|
|
10
10
|
|
|
11
|
-
angular.extend($scope,
|
|
11
|
+
angular.extend($scope, RoutingService.parsePathFunc()($location.$$path));
|
|
12
12
|
|
|
13
13
|
$scope.reportSchema = {
|
|
14
14
|
columnDefs: []
|
|
@@ -37,7 +37,7 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$s
|
|
|
37
37
|
var url = $scope.reportSchema.drilldown;
|
|
38
38
|
if (url) {
|
|
39
39
|
if (typeof url === 'string') {
|
|
40
|
-
url =
|
|
40
|
+
url = RoutingService.buildUrl(url.replace(/\|.+?\|/g, function (match) {
|
|
41
41
|
var param = match.slice(1, -1),
|
|
42
42
|
isParamTest = /\((.+)\)/.exec(param);
|
|
43
43
|
if (isParamTest) {
|
|
@@ -67,19 +67,22 @@ formsAngular.controller('AnalysisCtrl', ['$rootScope', '$window', '$filter', '$s
|
|
|
67
67
|
/*
|
|
68
68
|
* This allows us to make an arbitrary http request from a cell template. Example:
|
|
69
69
|
* <div class="ui-grid-cell-contents">
|
|
70
|
-
* <
|
|
71
|
-
*
|
|
72
|
-
* </
|
|
70
|
+
* <button class="btn btn-small" data-ng-click="grid.appScope.http($event, 'GET', '/apix/queue/cancel/:id')" data-id="{{COL_FIELD}}" data-disable-button="true">
|
|
71
|
+
* <span class="glyphicon glyphicon-remove"></span> Cancel
|
|
72
|
+
* </button>
|
|
73
73
|
* </div>
|
|
74
74
|
* The value of any attribute beginning with data will replace the corresponding :attribute in the url,
|
|
75
75
|
* so in this case the :id in the url will be replaced by the value of the data-id attribute.
|
|
76
76
|
*/
|
|
77
77
|
http: function ($event, method, url) {
|
|
78
|
-
$event.
|
|
78
|
+
$event.currentTarget.getAttributeNames().forEach(a => {
|
|
79
79
|
if (a.startsWith('data-')) {
|
|
80
|
-
url = url.replace(`:${a.slice(5)}`, $event.
|
|
80
|
+
url = url.replace(`:${a.slice(5)}`, $event.currentTarget.getAttribute(a));
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
+
if ($event.currentTarget.getAttribute('data-disable-button') === 'true') {
|
|
84
|
+
$event.currentTarget.setAttribute('disabled', 'disabled');
|
|
85
|
+
}
|
|
83
86
|
$http({
|
|
84
87
|
method: method,
|
|
85
88
|
url: url,
|
|
@@ -184,7 +187,7 @@ ${e.message}`);
|
|
|
184
187
|
type: thisPart.type || 'text',
|
|
185
188
|
required: true,
|
|
186
189
|
add: thisPart.add || undefined,
|
|
187
|
-
size: thisPart.size || (
|
|
190
|
+
size: thisPart.size || (CssFrameworkService.frameWork === 'bs3' ? 'large' : 'medium')
|
|
188
191
|
});
|
|
189
192
|
if (thisPart.type === 'select') {
|
|
190
193
|
// TODO: Remove when select and select2 is modified during the restructure
|
|
@@ -378,7 +381,7 @@ ${e.message}`);
|
|
|
378
381
|
delete navScope.items;
|
|
379
382
|
});
|
|
380
383
|
|
|
381
|
-
// Error handling, stolen quickly from forms-
|
|
384
|
+
// Error handling, stolen quickly from forms-angular record-handler
|
|
382
385
|
$scope.showError = function(error, alertTitle) {
|
|
383
386
|
$scope.alertTitle = alertTitle ? alertTitle : 'Error!';
|
|
384
387
|
if (typeof error === 'string') {
|
package/test/karma.conf.js
CHANGED
|
@@ -8,7 +8,7 @@ module.exports = function(config) {
|
|
|
8
8
|
'node_modules/angular-animate/angular-animate.js',
|
|
9
9
|
'node_modules/angular-mocks/angular-mocks.js',
|
|
10
10
|
'node_modules/angular-messages/angular-messages.js',
|
|
11
|
-
'node_modules/jspdf/dist/jspdf.
|
|
11
|
+
'node_modules/jspdf/dist/jspdf.umd.js',
|
|
12
12
|
'node_modules/forms-angular/dist/client/forms-angular.js',
|
|
13
13
|
'node_modules/ng-infinite-scroll/build/ng-infinite-scroll.js',
|
|
14
14
|
'node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js',
|
package/test/specs/reportSpec.js
CHANGED
|
@@ -26,14 +26,14 @@ describe('Reports', function () {
|
|
|
26
26
|
]});
|
|
27
27
|
$rootScope.navScope = {};
|
|
28
28
|
var scope = $rootScope.$new();
|
|
29
|
-
var
|
|
29
|
+
var RoutingService = {
|
|
30
30
|
parsePathFunc: function () {
|
|
31
31
|
return function () {
|
|
32
|
-
return {modelName: 'collection', reportSchemaName: 'myReport'}
|
|
32
|
+
return {modelName: 'collection', reportSchemaName: 'myReport'};
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
$controller('AnalysisCtrl', {$scope: scope,
|
|
36
|
+
$controller('AnalysisCtrl', {$scope: scope, RoutingService: RoutingService});
|
|
37
37
|
$httpBackend.flush();
|
|
38
38
|
expect(scope.report.length).toBe(2);
|
|
39
39
|
});
|