Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New page subtraction #211

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 50 additions & 9 deletions generator/fluentReportsGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3951,6 +3949,7 @@ class frStandardFooter extends frTitledLabel { // jshint ignore:line

}


class frPageBreak extends frTitledLabel { // jshint ignore:line
get active() {
return this._active;
Expand Down Expand Up @@ -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 = {}) {

Expand Down
40 changes: 37 additions & 3 deletions lib/fluentReportsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(); }

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()};
Expand Down Expand Up @@ -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);
Expand All @@ -608,7 +638,7 @@ class ReportBuilder {
};
}
}

this._newPageSubtraction = 0;
this._formatterFunctions = {};
if(reportDesignLayout.formatterFunctions){
for (let key in reportDesignLayout.formatterFunctions) {
Expand All @@ -629,6 +659,7 @@ class ReportBuilder {
if (reportDesignLayout.data != null) {
this._primaryReportGroup.data(reportDesignLayout.data);
}

return this._primaryReportGroup;
}

Expand Down Expand Up @@ -802,6 +833,7 @@ class ReportBuilder {
}
report[type]( new ReportRunnable({
formatterFunctions: this._formatterFunctions,
newPageSubtraction:this._updateNewPageSubtraction.bind(this),
headerFooter: {children: headerFooter}
}) );

Expand All @@ -825,6 +857,7 @@ class ReportBuilder {
}
report[type]( new ReportRunnable({
formatterFunctions: this._formatterFunctions,
newPageSubtraction:this._updateNewPageSubtraction.bind(this),
headerFooter
}) , options);

Expand All @@ -837,6 +870,7 @@ class ReportBuilder {
} else {
report[type](new ReportRunnable({
formatterFunctions: this._formatterFunctions,
newPageSubtraction:this._updateNewPageSubtraction.bind(this),
headerFooter: {children: [headerFooter]}
}));
}
Expand Down