node-red-node-ui-table
Advanced tools
Comparing version 0.3.1 to 0.3.2
109
node.js
@@ -19,2 +19,31 @@ /** | ||
var mergeTabulator = function(target,source) { | ||
if (typeof source === 'object') { | ||
Object.keys(source).forEach(element => { | ||
if (typeof source[element] !== "object") { | ||
target[element] = source[element]; | ||
} else { | ||
if (!target.hasOwnProperty(element)) { | ||
target[element] = (Array.isArray(source[element])) ? [] : {}; | ||
} | ||
// handle the columns array to merge columns if the field property matches. Otherwise push a new column | ||
if (element==='columns' && Array.isArray(source[element])){ | ||
source[element].forEach(sourceElement => { | ||
let index = target[element].findIndex(targetElement => targetElement.field===sourceElement.field); | ||
if (index<0) { // add new column | ||
target[element].push({}); | ||
index=target[element].length-1; | ||
} | ||
mergeTabulator(target[element][index],sourceElement); | ||
}) | ||
} else { | ||
mergeTabulator(target[element],source[element]) | ||
} | ||
} | ||
}); | ||
} else { | ||
target=source; | ||
} | ||
} | ||
module.exports = function (RED) { | ||
@@ -68,6 +97,27 @@ function checkConfig(node, conf) { | ||
storeFrontEndInputAsState: false, | ||
// to make msg.ui_control work without msg.payload we have to send msg.payload=null. | ||
// we correct this here into undefined to get the last known payload form currentValues[opt.node.id]. | ||
convert: function (value) { | ||
if (value===null) { value=undefined; } | ||
return value; | ||
}, | ||
// merge new ui_control messages into config.ui_control | ||
beforeEmit: function (msg, value) { | ||
return {msg: { | ||
// cache ui_control messages for new clients | ||
if (msg.hasOwnProperty('ui_control')) { | ||
if (!config.hasOwnProperty('ui_control')){ | ||
config.ui_control={ | ||
"tabulator":{ | ||
"columns":config.columns | ||
}}; | ||
} | ||
// instead of | ||
// config.ui_control=Object.assign(config.ui_control,msg.ui_control); | ||
// use mergeTabulator to correctly merge columns arrays if field property matches | ||
mergeTabulator(config.ui_control,msg.ui_control); | ||
} | ||
return { msg: { | ||
payload: value, | ||
ui_control: (msg.hasOwnProperty("ui_control")) ? msg.ui_control : undefined, | ||
ui_control: config.ui_control | ||
}}; | ||
@@ -82,12 +132,33 @@ }, | ||
var tablediv; | ||
var mergeObject = function(target,source) { | ||
if (typeof source === 'object') { | ||
Object.keys(source).forEach(element => { | ||
if (typeof source[element] !== "object") { | ||
target[element] = source[element]; | ||
} else { | ||
if (!target.hasOwnProperty(element)) { | ||
target[element] = (Array.isArray(source[element])) ? [] : {}; | ||
} | ||
mergeObject(target[element],source[element]) | ||
} | ||
}); | ||
} else { | ||
target = source; | ||
} | ||
}; | ||
var createTable = function(basediv, tabledata, columndata, outputs, ui_control) { | ||
// add id field if not already exists | ||
if (tabledata.length>0 && tabledata[0] && typeof tabledata[0] === 'object' && !tabledata[0].hasOwnProperty('id')) { | ||
tabledata.map((row,index) => row.id = index); | ||
} | ||
var opts = { | ||
data: tabledata, | ||
layout: 'fitColumns', | ||
columns: columndata, | ||
autoColumns: columndata.length == 0, | ||
movableColumns: true, | ||
} | ||
if (!ui_control || !ui_control.tabulator) { | ||
var y = (columndata.length === 0) ? 25 : 32; | ||
var opts = { | ||
data: tabledata, | ||
layout: 'fitColumns', | ||
columns: columndata, | ||
autoColumns: columndata.length == 0, | ||
movableColumns: true, | ||
} | ||
if ($scope.height==2) { // auto height | ||
@@ -98,13 +169,11 @@ opts.height = (tabledata.length > 0 )? tabledata.length * y + 26 : $scope.height*(sizes.sy+sizes.cy); | ||
} | ||
} else { // configuration via ui_control | ||
var y = (ui_control.tabulator.columns.length > 0) ? 32 : 25; | ||
var opts = ui_control.tabulator; | ||
opts.data = tabledata; | ||
if (!ui_control.tabulator.layout) opts.layout = 'fitColumns'; | ||
if (!ui_control.tabulator.movableColumns) opts.movableColumns = true; | ||
if (!ui_control.tabulator.columns) opts.columns = columndata; | ||
if (!ui_control.tabulator.autoColumns) autoColumns = columndata.length == 0; | ||
} | ||
else { // configuration via ui_control | ||
//as Object.assign is not supported by Internet Explorer | ||
//opts = Object.assign(opts, ui_control.tabulator); | ||
mergeObject(opts,ui_control.tabulator); | ||
var y = (opts.columns && (opts.columns.length > 0)) ? 32 : 25; | ||
if (ui_control.customHeight) { | ||
opts.height= ui_control.customHeight * y + 26; | ||
} else { // | ||
} else { | ||
if ($scope.height==2) { // auto height | ||
@@ -118,3 +187,3 @@ opts.height= (tabledata.length > 0 )? tabledata.length * y + 26 : $scope.height*(sizes.sy+sizes.cy); | ||
if (outputs > 0) { | ||
if ((outputs > 0) && !opts.hasOwnProperty('cellClick')) { // default cellClick if not already defined by ui_control | ||
opts.cellClick = function(e, cell) { | ||
@@ -124,3 +193,3 @@ $scope.send({topic:cell.getField(), payload:cell.getData(), row:(cell.getRow()).getPosition()}); | ||
} | ||
// console.log("createTabulator",opts); | ||
$scope.table = new Tabulator(basediv, opts); | ||
@@ -127,0 +196,0 @@ }; |
{ | ||
"name": "node-red-node-ui-table", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Table UI widget node for Node-RED Dashboard", | ||
@@ -5,0 +5,0 @@ "author": "Kazuhito Yokoi", |
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
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
1149150
20
19220