diff --git a/generator/fluentReportsGenerator.js b/generator/fluentReportsGenerator.js index eeaeb5e..a39c893 100644 --- a/generator/fluentReportsGenerator.js +++ b/generator/fluentReportsGenerator.js @@ -3165,35 +3165,33 @@ class frElement { // jshint ignore:line } let targetX = null; let targetY = null; + if(src.settings){ + // turns "absoluteX", "x", and "left" into absoluteX + // same with the "Y" equivalents + targetX = (src.settings.x || src.settings.newX || src.settings.addX || src.settings.left || 0); + targetY = (src.settings.y || src.settings.newY || src.settings.addY || src.settings.top || 0); + } + for (let i = 0; i < props.length; i++) { if (typeof src[props[i]] !== 'undefined') { dest[props[i]] = src[props[i]]; } if (src.settings && typeof src.settings[props[i]] !== 'undefined') { - // turns "absoluteX", "x", and "left" into absoluteX - // same with the "Y" equivalents const lcProp = props[i].toLowerCase(); switch (lcProp) { - case "x": - case "addx": case "left": if (targetX === null) { targetX = src.settings[props[i]]; } break; - case "absolutex": targetX = src.settings[props[i]]; break; - - case "y": - case "addy": case "top": if (targetY === null) { targetY = src.settings[props[i]]; } break; - case "absolutey": targetY = src.settings[props[i]]; break; @@ -3951,6 +3949,7 @@ class frStandardFooter extends frTitledLabel { // jshint ignore:line } + class frPageBreak extends frTitledLabel { // jshint ignore:line get active() { return this._active; @@ -4629,6 +4628,48 @@ class frPrint extends frTitledLabel { } +class frPageBreak extends frTitledLabel { // jshint ignore:line + get active() { return this._active; } + set active(val) { + this._active = this.getBooleanOrFunction(val); + if(this.isFunction(val)) { + this.label = "Page Break: {FUNC}"; + } else { + this.label = "Page Break: ("+(this._active ? "active" : "inactive")+")"; + } + } + get absoluteY(){ + return this.top; + } + set absoluteY(val){ + this.top = parseInt(val,10); + } + constructor(report, parent, options={}) { + super(report, parent, options); + this.active = true; + this.elementTitle = "Page Breaking Point"; + this._deleteProperties([ "top","left", "width", "height"]) + this._addProperties([ + {type: 'boolean', field: "active", default: false, functionable: true}, + {type: 'number', field: "absoluteY", title:"Y", default: null, destination: "settings"} + ]); + } + + _saveProperties(props) { + super._saveProperties(props); + props.type = "newPage"; + } + + _parseElement(data) { + //super._parseElement(data); + this._copyProperties(data, this, ["active", "absoluteY"]); + if(data){ +// this.absoluteY = data.absoluteY || 0; + // this.active = data.active; + } + } +} + class frPrintLabel extends frPrint { // jshint ignore:line constructor(report, parent, options = {}) { diff --git a/lib/fluentReportsBuilder.js b/lib/fluentReportsBuilder.js index 12fb4fc..35109ee 100644 --- a/lib/fluentReportsBuilder.js +++ b/lib/fluentReportsBuilder.js @@ -17,7 +17,19 @@ const BlobStream = require("./third-party/blob-stream"); */ class ReportRunnable { + get newPageSubtraction(){ + return this._newPageSubtractionFunc(); + } + set newPageSubtraction(val){ + this._newPageSubtractionFunc(val); + } constructor(options) { + if(typeof options.newPageSubtraction === "function"){ + this._newPageSubtractionFunc = options.newPageSubtraction; + } + else{ + this._newPageSubtractionFunc = ()=>{return 0;} + } if(options.headerFooter) { this._settings = options.headerFooter; } else { @@ -478,7 +490,13 @@ class ReportRunnable } _runSetting(setting, info, callback) { - + if(setting && setting.settings) { + if(setting.settings.top){ + setting.settings.absoluteY = setting.settings.top; + } + else setting.settings.absoluteY = setting.settings.absoluteY || 0; + //setting.settings.absoluteY -= this.newPageSubtraction; + } // Skip anything set to skip: true if (setting.skip === true) { return callback(); } @@ -509,11 +527,13 @@ class ReportRunnable case 'newPage': if(typeof setting.active === "boolean" && setting.active === true) { + this.newPageSubtraction += (setting.settings && setting.settings.absoluteY && setting.settings.absoluteY + 20) || 20; info.report.newPage(!!setting.saveOptions, callback); } else if(setting.active != null && typeof setting.active === "object" && setting.active.type === "function") { this._handleFunction(setting.active, info,(error, output) => { if (output) { + this.newPageSubtraction += (setting.settings && setting.settings.absoluteY && setting.settings.absoluteY + 20) || 20; info.report.newPage(!!setting.saveOptions, callback); } else { @@ -545,6 +565,9 @@ class ReportRunnable } _run(report, data, state, callback) { + if(this.newPageSubtraction !== 0){ + this.newPageSubtraction = 0-this.newPageSubtraction; + } const variables = this._getVariables(state.CurrentGroup || report._primaryReport._detailGroup); let counter=-1; let info = {report, data, state, variables, startY: report.currentY(), startX: report.minX()}; @@ -582,8 +605,15 @@ class ReportBuilder { * @param {Object?} reportData * @returns {Report|ReportBuilder} */ + _updateNewPageSubtraction(val){ + if(typeof val === "number" && !isNaN(val)) { + this._newPageSubtraction +=val; + } + else{ + return this._newPageSubtraction || 0; + } + } constructor(ReportDesignLayout, reportData) { - this._primaryReportGroup = null; if (ReportDesignLayout) { return this.parseReport(ReportDesignLayout, reportData); @@ -608,7 +638,7 @@ class ReportBuilder { }; } } - + this._newPageSubtraction = 0; this._formatterFunctions = {}; if(reportDesignLayout.formatterFunctions){ for (let key in reportDesignLayout.formatterFunctions) { @@ -629,6 +659,7 @@ class ReportBuilder { if (reportDesignLayout.data != null) { this._primaryReportGroup.data(reportDesignLayout.data); } + return this._primaryReportGroup; } @@ -802,6 +833,7 @@ class ReportBuilder { } report[type]( new ReportRunnable({ formatterFunctions: this._formatterFunctions, + newPageSubtraction:this._updateNewPageSubtraction.bind(this), headerFooter: {children: headerFooter} }) ); @@ -825,6 +857,7 @@ class ReportBuilder { } report[type]( new ReportRunnable({ formatterFunctions: this._formatterFunctions, + newPageSubtraction:this._updateNewPageSubtraction.bind(this), headerFooter }) , options); @@ -837,6 +870,7 @@ class ReportBuilder { } else { report[type](new ReportRunnable({ formatterFunctions: this._formatterFunctions, + newPageSubtraction:this._updateNewPageSubtraction.bind(this), headerFooter: {children: [headerFooter]} })); }