RED.diff = (function() { var currentDiff = {}; function init() { // RED.actions.add("core:show-current-diff",showLocalDiff); RED.actions.add("core:show-remote-diff",showRemoteDiff); // RED.keyboard.add("*","ctrl-shift-l","core:show-current-diff"); RED.keyboard.add("*","ctrl-shift-r","core:show-remote-diff"); var dialog = $('
",{class:"node-diff-property-cell-label"}).html("id").appendTo(row); localCell = $(" | ",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row); if (localNode) { localCell.addClass("node-diff-node-unchanged"); $('').appendTo(localCell); RED.utils.createObjectElement(localNode.id).appendTo(localCell); } else { localCell.addClass("node-diff-empty"); } if (remoteNode !== undefined) { remoteCell = $(" | ",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row); remoteCell.addClass("node-diff-node-unchanged"); if (remoteNode) { $('').appendTo(remoteCell); RED.utils.createObjectElement(remoteNode.id).appendTo(remoteCell); } else { remoteCell.addClass("node-diff-empty"); } } if (node.hasOwnProperty('x')) { if (localNode) { if (localNode.x !== node.x || localNode.y !== node.y) { localChanged = true; localChanges++; } } if (remoteNode) { if (remoteNode.x !== node.x || remoteNode.y !== node.y) { remoteChanged = true; remoteChanges++; } } if ( (remoteChanged && localChanged && (localNode.x !== remoteNode.x || localNode.y !== remoteNode.y)) || (!localChanged && remoteChanged && localNodeObj.diff.deleted[node.id]) || (localChanged && !remoteChanged && remoteNodeObj.diff.deleted[node.id]) ) { conflict = true; } row = $(" |
",{class:"node-diff-property-cell-label"}).html("position").appendTo(row); localCell = $(" | ",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row); if (localNode) { localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged")); $(''+(localChanged?'':'')+'').appendTo(localCell); RED.utils.createObjectElement({x:localNode.x,y:localNode.y}).appendTo(localCell); } else { localCell.addClass("node-diff-empty"); } if (remoteNode !== undefined) { remoteCell = $(" | ",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row); remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged")); if (remoteNode) { $(''+(remoteChanged?'':'')+'').appendTo(remoteCell); RED.utils.createObjectElement({x:remoteNode.x,y:remoteNode.y}).appendTo(remoteCell); } else { remoteCell.addClass("node-diff-empty"); } } } // localChanged = remoteChanged = conflict = false; if (node.hasOwnProperty('wires')) { currentValue = JSON.stringify(node.wires); if (localNode) { localValue = JSON.stringify(localNode.wires); if (currentValue !== localValue) { localChanged = true; localChanges++; } } if (remoteNode) { remoteValue = JSON.stringify(remoteNode.wires); if (currentValue !== remoteValue) { remoteChanged = true; remoteChanges++; } } if ( (remoteChanged && localChanged && (localValue !== remoteValue)) || (!localChanged && remoteChanged && localNodeObj.diff.deleted[node.id]) || (localChanged && !remoteChanged && remoteNodeObj.diff.deleted[node.id]) ){ conflict = true; } row = $(" |
",{class:"node-diff-property-cell-label"}).html("wires").appendTo(row); localCell = $(" | ",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row); if (localNode) { if (!conflict) { localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged")); $(''+(localChanged?'':'')+'').appendTo(localCell); } else { localCell.addClass("node-diff-node-conflict"); $('').appendTo(localCell); } formatWireProperty(localNode.wires,localNodeObj.all).appendTo(localCell); } else { localCell.addClass("node-diff-empty"); } if (remoteNode !== undefined) { remoteCell = $(" | ",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row); if (remoteNode) { if (!conflict) { remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged")); $(''+(remoteChanged?'':'')+'').appendTo(remoteCell); } else { remoteCell.addClass("node-diff-node-conflict"); $('').appendTo(remoteCell); } formatWireProperty(remoteNode.wires,remoteNodeObj.all).appendTo(remoteCell); } else { remoteCell.addClass("node-diff-empty"); } } } var properties = Object.keys(node).filter(function(p) { return p!='z'&&p!='wires'&&p!=='x'&&p!=='y'&&p!=='id'&&p!=='type'&&(!def.defaults||!def.defaults.hasOwnProperty(p))}); if (def.defaults) { properties = properties.concat(Object.keys(def.defaults)); } properties.forEach(function(d) { localChanged = false; remoteChanged = false; conflict = false; currentValue = JSON.stringify(node[d]); if (localNode) { localValue = JSON.stringify(localNode[d]); if (currentValue !== localValue) { localChanged = true; localChanges++; } } if (remoteNode) { remoteValue = JSON.stringify(remoteNode[d]); if (currentValue !== remoteValue) { remoteChanged = true; remoteChanges++; } } if ( (remoteChanged && localChanged && (localValue !== remoteValue)) || (!localChanged && remoteChanged && localNodeObj.diff.deleted[node.id]) || (localChanged && !remoteChanged && remoteNodeObj.diff.deleted[node.id]) ){ conflict = true; } row = $(" |
",{class:"node-diff-property-cell-label"}).html(d).appendTo(row); localCell = $(" | ",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row); if (localNode) { if (!conflict) { localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged")); $(''+(localChanged?'':'')+'').appendTo(localCell); } else { localCell.addClass("node-diff-node-conflict"); $('').appendTo(localCell); } RED.utils.createObjectElement(localNode[d]).appendTo(localCell); } else { localCell.addClass("node-diff-empty"); } if (remoteNode !== undefined) { remoteCell = $(" | ",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row); if (remoteNode) { if (!conflict) { remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged")); $(''+(remoteChanged?'':'')+'').appendTo(remoteCell); } else { remoteCell.addClass("node-diff-node-conflict"); $('').appendTo(remoteCell); } RED.utils.createObjectElement(remoteNode[d]).appendTo(remoteCell); } else { remoteCell.addClass("node-diff-empty"); } } }); return nodePropertiesDiv; } function createNodeConflictRadioBoxes(node,row,localDiv,remoteDiv,propertiesTable,hide,state) { var safeNodeId = "node-diff-selectbox-"+node.id.replace(/\./g,'-')+(propertiesTable?"-props":""); var className = ""; if (node.z||propertiesTable) { className = "node-diff-selectbox-tab-"+(propertiesTable?node.id:node.z).replace(/\./g,'-'); } var titleRow = !propertiesTable && (node.type === 'tab' || node.type === 'subflow'); var changeHandler = function(evt) { var className; if (node.type === undefined) { // TODO: handle globals } else if (titleRow) { className = "node-diff-selectbox-tab-"+node.id.replace(/\./g,'-'); $("."+className+"-"+this.value).prop('checked',true); if (this.value === 'local') { $("."+className+"-"+this.value).closest(".node-diff-node-entry").addClass("node-diff-select-local"); $("."+className+"-"+this.value).closest(".node-diff-node-entry").removeClass("node-diff-select-remote"); } else { $("."+className+"-"+this.value).closest(".node-diff-node-entry").removeClass("node-diff-select-local"); $("."+className+"-"+this.value).closest(".node-diff-node-entry").addClass("node-diff-select-remote"); } } else { // Individual node or properties table var parentId = "node-diff-selectbox-"+(propertiesTable?node.id:node.z).replace(/\./g,'-'); $('#'+parentId+"-local").prop('checked',false); $('#'+parentId+"-remote").prop('checked',false); var titleRowDiv = $('#'+parentId+"-local").closest(".node-diff-tab").find(".node-diff-tab-title"); titleRowDiv.removeClass("node-diff-select-local"); titleRowDiv.removeClass("node-diff-select-remote"); } if (this.value === 'local') { row.removeClass("node-diff-select-remote"); row.addClass("node-diff-select-local"); } else if (this.value === 'remote') { row.addClass("node-diff-select-remote"); row.removeClass("node-diff-select-local"); } refreshConflictHeader(); } var localSelectDiv = $(' |