fluentreports
Advanced tools
Comparing version 1.2.8 to 1.2.9
@@ -40,2 +40,4 @@ 0.0.1 - [2013/08/15] - Initial Release | ||
1.2.7 - Fix issues with Builder/Generators | ||
1.2.8 - Fix multiple issues with Engine/Builder/Generators. | ||
1.2.9 - Fix multiple issues with Engine/Builder/Generators. | ||
@@ -42,0 +44,0 @@ |
@@ -804,2 +804,3 @@ # fluentReports Commands | ||
* options - | ||
* useCurrentX - boolean; use the current X location; rather than resetting to left margin. | ||
* x - x coordinate to print at | ||
@@ -810,3 +811,4 @@ * y - y coordinate to print at | ||
* align - alignment (left, center, or right) | ||
* textWidth - the gap between characters | ||
* wordSpacing - the gap between words | ||
* characterSpacing - the gap between characters | ||
* width - the maximum size you want the string to be; it will wrap it after this. | ||
@@ -813,0 +815,0 @@ * textColor - the font color of the text |
@@ -972,2 +972,4 @@ "use strict"; | ||
} | ||
this.page.document._pageBuffer.pop(); | ||
this.page.document._pageBufferStart--; | ||
this.page = { end: function() {} }; | ||
@@ -974,0 +976,0 @@ } |
@@ -8,5 +8,20 @@ // Import the Report system. | ||
*/ | ||
class ReportRunnable { | ||
constructor(settings) { | ||
this._settings = settings; | ||
class ReportRunnable | ||
{ | ||
constructor(options) { | ||
let headerFooter = []; | ||
if(Array.isArray(options)){ | ||
headerFooter = options; | ||
} | ||
else if(typeof options === "object"){ | ||
if(options.headerFooter) { | ||
headerFooter = options.headerFooter; | ||
} | ||
} | ||
this._settings = headerFooter; | ||
if(options.formatterFunctions){ | ||
this._formatterFunctions = options.formatterFunctions; | ||
} else { | ||
this._formatterFunctions = {}; | ||
} | ||
return (report, data, scope, callback) => { | ||
@@ -29,3 +44,5 @@ this._run(report, data, scope, callback); | ||
} | ||
setting.func(info.report, info.data, info.state, info.variables, callback); | ||
setting.func(info.report, info.data, info.state, info.variables, (output)=>{ | ||
callback(null, output); | ||
}); | ||
} else { | ||
@@ -49,7 +66,10 @@ if (!setting.func) { | ||
*/ | ||
_calculateOption(info, key, value, callback) { | ||
_calculateOption(info, key, inOptions, callback, formatCallback) { | ||
let value = inOptions[key]; | ||
if (value == null) { | ||
console.log("Missing Value:", key); | ||
callback(key, ''); | ||
return; | ||
} | ||
if (typeof value.type !== 'undefined') { | ||
@@ -66,15 +86,25 @@ this._handleFunction(value, info, (err, result) => { | ||
// Convert this to a "Field" key so the report engine considers it output... | ||
callback('field', source); | ||
formatCallback('field', source); | ||
} else if (key === 'parentData') { | ||
// Convert this to a "Field" key so the report engine considers it output... | ||
callback('field', info.state.parentData[value]); | ||
formatCallback('field', info.state.parentData[value]); | ||
} else if (key === 'field') { | ||
// Check for parentData if key doesn't exist on | ||
// Check for parentData if key doesn't exist on current row | ||
if (typeof info.data[value] === 'undefined' && typeof info.state.parentData[value] !== 'undefined') { | ||
callback(key, info.state.parentData[value]); | ||
formatCallback(key, info.state.parentData[value]); | ||
} else { | ||
callback(key, info.data[value]); | ||
formatCallback(key, info.data[value]); | ||
} | ||
} else if (key === 'total') { | ||
callback(key, info.report.totals[value]); | ||
formatCallback(key, info.report.totals[value]); | ||
} else if (key === 'absoluteX') { | ||
// console.log("AbsX", info.startX, value); | ||
// Used to make things Absolute for Engine | ||
// We override the "x" value | ||
callback("x", info.startX + value); | ||
} else if (key === 'absoluteY') { | ||
// console.log("AbsY", info.startY, value); | ||
// Used to make things | ||
// We override the "y" value | ||
callback("y", info.startY + value); | ||
} else { | ||
@@ -95,4 +125,7 @@ callback(key, value); | ||
let counter=1, tracking=0; | ||
if (inOptions == null) { callback({}); return; } | ||
if (inOptions == null) { | ||
callback({}); return; | ||
} | ||
const doneChecker = (key, value) => { | ||
@@ -108,6 +141,26 @@ if (key) { | ||
const functionFormatter = (key, value) => { | ||
if(inOptions && inOptions.formatFunction ) { | ||
const functionData = this._formatterFunctions[inOptions.formatFunction]; | ||
if(functionData) { | ||
let handled = false; | ||
functionData(value, info.data, (output)=> { | ||
if (handled) { | ||
console.log("You have an extra callback in your", inOptions.formatFunction, "formatter function"); | ||
return; | ||
} | ||
handled = true; | ||
doneChecker(key, output); | ||
}); | ||
return; | ||
} | ||
} | ||
doneChecker(key, value); | ||
}; | ||
for (let key in inOptions) { | ||
if (inOptions.hasOwnProperty(key)) { | ||
counter++; | ||
this._calculateOption(info, key, inOptions[key], doneChecker); | ||
this._calculateOption(info, key, inOptions, doneChecker, functionFormatter); | ||
} | ||
@@ -126,6 +179,28 @@ } | ||
_handlePrint(setting, info, callback) { | ||
// TODO: See if we can wrap this entire routine in _handleOptions first -- would be more optimized, and cleaner data flow | ||
let output; | ||
if (setting.field) { | ||
output = info.data[setting.field] || ''; | ||
} else if (setting.text ) { | ||
if (!info.data || !info.data[setting.field] ) { | ||
output = ''; | ||
} else { | ||
if(setting.settings && setting.settings.formatFunction){ | ||
const functionData = this._formatterFunctions[setting.settings.formatFunction]; | ||
if(functionData) { | ||
let handled = false; | ||
functionData(info.data[setting.field], info.data, (output) => { | ||
if (handled) { | ||
console.log("FRB: You have an extra callback in your ", setting.settings.formatFunction, "formatting function"); | ||
return; | ||
} | ||
handled = true; | ||
this._handleOptions(setting.settings, info,(options) => { | ||
info.report.print(output, options, callback); | ||
}); | ||
}); | ||
return; | ||
} | ||
} | ||
output = info.data[setting.field] || ''; | ||
} | ||
} else if (setting.text) { | ||
output = setting.text; | ||
@@ -149,2 +224,8 @@ } else if (setting.function) { | ||
setting.settings = {align: "center"}; | ||
} else if (setting.total) { | ||
output = info.report.totals[setting.total]; | ||
} else if (setting.variable) { | ||
output = info.variables[setting.variable]; | ||
} else if (setting.calculation) { | ||
output = info.variables[setting.calculation]; | ||
} | ||
@@ -249,2 +330,69 @@ | ||
/** | ||
* Handle an image | ||
* @param data | ||
* @param info | ||
* @param callback | ||
* @private | ||
*/ | ||
_handleImage(data, info, callback) { | ||
const settings = data.settings; | ||
let options = {}; | ||
if (settings.top > 0) { | ||
options.y = info.report.currentY() + settings.top; | ||
} | ||
if (settings.left > 0) { | ||
options.x = info.report.currentX() + settings.left; | ||
} | ||
if (settings.aspect) { | ||
switch (settings.aspect) { | ||
case 'none': | ||
break; | ||
case 'size': | ||
if (settings.width > 0) { | ||
options.width = settings.width; | ||
} | ||
if (settings.height > 0) { | ||
options.height = settings.height; | ||
} | ||
break; | ||
case 'fit': | ||
options.fit = {width: settings.width || 50, height: settings.height || 50}; | ||
break; | ||
case 'cover': | ||
options.fit = {width: settings.width || 50, height: settings.height || 50}; | ||
break; | ||
case 'scale': | ||
if (settings.scale > 0) { | ||
options.scale = settings.scale; | ||
} | ||
break; | ||
} | ||
} | ||
if (settings.align != null) { | ||
options.align = settings.align; | ||
} | ||
if (settings.valign != null) { | ||
options.valign = settings.valign; | ||
} | ||
if (data.image != null && data.image.length > 0) { | ||
info.report.image(data.image, options); | ||
} | ||
callback(); | ||
} | ||
/** | ||
* Handle the type of Shape | ||
* @param settings | ||
* @param info | ||
* @param callback | ||
* @private | ||
*/ | ||
_handleShape(settings, info, callback) { | ||
@@ -256,13 +404,15 @@ let top = (settings.top > 0) ? settings.top : 0; | ||
let radius = (settings.radius > 0) ? settings.radius : 50; | ||
let curX = info.report.currentX(); | ||
let curY = info.startY; | ||
switch (settings.shape) { | ||
case 'box': | ||
info.report.box(info.report.currentX() + left , info.report.currentY() + top, width + left , height + top, settings); | ||
info.report.box(curX + left , curY + top, curX+ width + left , curY + height + top, settings); | ||
break; | ||
case 'circle': | ||
info.report.circle(info.report.currentX() + left , info.report.currentY() + top, radius, settings); | ||
info.report.circle(curX + left , curY + top, radius, settings); | ||
break; | ||
case 'line': | ||
info.report.line(info.report.currentX() + left , info.report.currentY() + top, width + left, height + top, settings); | ||
info.report.line(curX + left , curY + top, curX + width + left, curY + height + top, settings); | ||
break; | ||
@@ -299,2 +449,3 @@ | ||
break; | ||
case 'newLine': | ||
@@ -312,3 +463,8 @@ info.report.newLine(setting.lines || 1, callback); | ||
case 'image': | ||
this._handleImage(setting, info, callback); | ||
return; | ||
case 'raw': | ||
console.log("Raw", setting); | ||
setting.raw = setting.values; | ||
@@ -327,3 +483,3 @@ this._handlePrint(setting, info, callback); | ||
let counter=-1; | ||
let info = {report, data, state, variables}; | ||
let info = {report, data, state, variables, startY: report.currentY(), startX: report.minX()}; | ||
@@ -373,4 +529,23 @@ const finalCallback = () => { | ||
parseReport(reportDesignLayout, reportData) { | ||
this._formatterFunctions = {}; | ||
if(reportDesignLayout.formatterFunctions){ | ||
for (let key in reportDesignLayout.formatterFunctions) { | ||
if (!reportDesignLayout.formatterFunctions.hasOwnProperty(key)) { continue; } | ||
if (typeof reportDesignLayout.formatterFunctions[key] === 'function') { | ||
this._formatterFunctions[key] = reportDesignLayout.formatterFunctions[key]; | ||
} else { | ||
this._formatterFunctions[key] = new Function ('value', 'row', 'callback', reportDesignLayout.formatterFunctions[key]); // jshint ignore:line | ||
} | ||
} | ||
} | ||
this._handleReportObject(reportDesignLayout); | ||
if (reportData != null) { this._primaryReportGroup.data(reportData); } | ||
if (reportData != null) { | ||
this._primaryReportGroup.data(reportData); | ||
} else | ||
if (reportDesignLayout.data != null) { | ||
this._primaryReportGroup.data(reportDesignLayout.data); | ||
} | ||
return this._primaryReportGroup; | ||
@@ -389,7 +564,8 @@ } | ||
if (typeof reportObject.landscape !== 'undefined') { | ||
options.landscape = reportObject.landscape; | ||
if (reportObject.paperOrientation === "landscape") { | ||
options.landscape = true; | ||
} | ||
if (typeof reportObject.paper !== 'undefined') { | ||
options.paper = reportObject.paper; | ||
if (typeof reportObject.paperSize !== 'undefined') { | ||
options.paper = reportObject.paperSize; | ||
} | ||
@@ -437,4 +613,14 @@ if (typeof reportObject.font !== 'undefined') { | ||
} | ||
if (reportObject.fonts) { | ||
this._handleReportFonts(reportObject.fonts, workItem); | ||
} | ||
} | ||
_handleReportFonts(reportObject, workItem) { | ||
if (!Array.isArray(reportObject) || reportObject.length === 0) { return; } | ||
for (let i=0;i<reportObject.length;i++) { | ||
workItem.registerFont(reportObject[i].name, Buffer.from(reportObject[i].data, "base64")); | ||
} | ||
} | ||
_handleReportCalcs(reportObject, workItem) { | ||
@@ -444,5 +630,11 @@ const calcTypes=['sum', 'min', 'max', 'count', 'average']; | ||
if (reportObject[calcTypes[i]]) { | ||
for (let j=0;j<reportObject[calcTypes[i]].length;j++) { | ||
workItem[calcTypes[i]](reportObject[calcTypes[i]][j]); | ||
let currentGroup = {_parent: workItem}; | ||
while (currentGroup._parent && currentGroup._parent._isGroup) { | ||
currentGroup = currentGroup._parent; | ||
for (let j=0;j<reportObject[calcTypes[i]].length;j++) { | ||
currentGroup[calcTypes[i]](reportObject[calcTypes[i]][j]); | ||
} | ||
} | ||
} | ||
@@ -480,4 +672,18 @@ } | ||
if (reportObject.subReports) { | ||
for (let i=0;i<reportObject.subReports.length;i++) { | ||
this._handleReportObject(reportObject.subReports[i], workItem); | ||
} | ||
} | ||
// Obsolete Method | ||
if (reportObject.subReport) { | ||
this._handleReportObject(reportObject.subReport, workItem); | ||
console.warn("[fluentReportsBuilder: subReport depreciated; switch to using subReports."); | ||
if (!Array.isArray(reportObject.subReport)) { | ||
this._handleReportObject(reportObject.subReport, workItem); | ||
} else { | ||
for (let i=0;i<reportObject.subReport.length;i++) { | ||
this._handleReportObject(reportObject.subReport[i], workItem); | ||
} | ||
} | ||
} | ||
@@ -519,5 +725,9 @@ | ||
} | ||
report[type]( new ReportRunnable(headerFooter) ); | ||
report[type]( new ReportRunnable({ | ||
formatterFunctions: this._formatterFunctions, | ||
headerFooter | ||
}) ); | ||
} else if (typeof headerFooter === "string" || typeof headerFooter === "number") { | ||
} | ||
else if (typeof headerFooter === "string" || typeof headerFooter === "number") { | ||
report[type]([headerFooter]); | ||
@@ -529,3 +739,6 @@ } else if (typeof headerFooter.type !== 'undefined') { | ||
} else { | ||
report[type](new ReportRunnable([headerFooter])); | ||
report[type](new ReportRunnable({ | ||
formatterFunctions: this._formatterFunctions, | ||
headerFooter:[headerFooter] | ||
})); | ||
} | ||
@@ -532,0 +745,0 @@ } else { |
@@ -41,3 +41,3 @@ { | ||
"main": "lib/fluentReports", | ||
"version": "1.2.8", | ||
"version": "1.2.9", | ||
"engines": { | ||
@@ -44,0 +44,0 @@ "node": ">= 0.6.0" |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
339232
6896
3