2016-12-07 14:51:20 +01:00
|
|
|
RED.diff = (function() {
|
|
|
|
|
2016-12-20 20:42:38 +01:00
|
|
|
var currentDiff = {};
|
2017-08-03 10:58:25 +02:00
|
|
|
var diffVisible = false;
|
|
|
|
var diffList;
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
function init() {
|
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
// RED.actions.add("core:show-current-diff",showLocalDiff);
|
2016-12-15 21:41:53 +01:00
|
|
|
RED.actions.add("core:show-remote-diff",showRemoteDiff);
|
2017-01-01 01:18:39 +01:00
|
|
|
// RED.keyboard.add("*","ctrl-shift-l","core:show-current-diff");
|
2018-02-14 10:54:07 +01:00
|
|
|
// RED.keyboard.add("*","ctrl-shift-r","core:show-remote-diff");
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-08-20 23:59:51 +02:00
|
|
|
|
2018-02-14 10:54:07 +01:00
|
|
|
// RED.actions.add("core:show-test-flow-diff-1",function(){showTestFlowDiff(1)});
|
|
|
|
// RED.keyboard.add("*","ctrl-shift-f 1","core:show-test-flow-diff-1");
|
|
|
|
//
|
|
|
|
// RED.actions.add("core:show-test-flow-diff-2",function(){showTestFlowDiff(2)});
|
|
|
|
// RED.keyboard.add("*","ctrl-shift-f 2","core:show-test-flow-diff-2");
|
|
|
|
// RED.actions.add("core:show-test-flow-diff-3",function(){showTestFlowDiff(3)});
|
|
|
|
// RED.keyboard.add("*","ctrl-shift-f 3","core:show-test-flow-diff-3");
|
2017-08-20 23:59:51 +02:00
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
function createDiffTable(container,CurrentDiff) {
|
2017-10-25 16:26:24 +02:00
|
|
|
var diffList = $('<ol class="node-dialog-view-diff-diff"></ol>').appendTo(container);
|
|
|
|
diffList.editableList({
|
2016-12-07 14:51:20 +01:00
|
|
|
addButton: false,
|
2018-02-14 00:09:51 +01:00
|
|
|
height: "auto",
|
2016-12-07 14:51:20 +01:00
|
|
|
scrollOnAdd: false,
|
|
|
|
addItem: function(container,i,object) {
|
|
|
|
var localDiff = object.diff;
|
2016-12-15 21:41:53 +01:00
|
|
|
var remoteDiff = object.remoteDiff;
|
2016-12-07 14:51:20 +01:00
|
|
|
var tab = object.tab.n;
|
|
|
|
var def = object.def;
|
2018-02-14 00:09:51 +01:00
|
|
|
var conflicts = CurrentDiff.conflicts;
|
2017-01-01 01:18:39 +01:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
var tabDiv = $('<div>',{class:"node-diff-tab"}).appendTo(container);
|
2016-12-20 20:42:38 +01:00
|
|
|
tabDiv.addClass('collapsed');
|
2016-12-07 14:51:20 +01:00
|
|
|
var titleRow = $('<div>',{class:"node-diff-tab-title"}).appendTo(tabDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
var nodesDiv = $('<div>').appendTo(tabDiv);
|
|
|
|
var originalCell = $('<div>',{class:"node-diff-node-entry-cell"}).appendTo(titleRow);
|
2016-12-20 20:42:38 +01:00
|
|
|
var localCell = $('<div>',{class:"node-diff-node-entry-cell node-diff-node-local"}).appendTo(titleRow);
|
2016-12-15 21:41:53 +01:00
|
|
|
var remoteCell;
|
2016-12-20 20:42:38 +01:00
|
|
|
var selectState;
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteDiff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteCell = $('<div>',{class:"node-diff-node-entry-cell node-diff-node-remote"}).appendTo(titleRow);
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
$('<span class="node-diff-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(originalCell);
|
|
|
|
createNodeIcon(tab,def).appendTo(originalCell);
|
2016-12-07 14:51:20 +01:00
|
|
|
var tabForLabel = (object.newTab || object.tab).n;
|
2016-12-15 21:41:53 +01:00
|
|
|
var titleSpan = $('<span>',{class:"node-diff-tab-title-meta"}).appendTo(originalCell);
|
2016-12-07 14:51:20 +01:00
|
|
|
if (tabForLabel.type === 'tab') {
|
2016-12-15 21:41:53 +01:00
|
|
|
titleSpan.html(tabForLabel.label||tabForLabel.id);
|
2016-12-07 14:51:20 +01:00
|
|
|
} else if (tab.type === 'subflow') {
|
2016-12-15 21:41:53 +01:00
|
|
|
titleSpan.html((tabForLabel.name||tabForLabel.id));
|
2016-12-07 14:51:20 +01:00
|
|
|
} else {
|
2017-08-07 11:00:28 +02:00
|
|
|
titleSpan.html(RED._("diff.globalNodes"));
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
var flowStats = {
|
|
|
|
local: {
|
|
|
|
addedCount:0,
|
|
|
|
deletedCount:0,
|
|
|
|
changedCount:0,
|
|
|
|
unchangedCount: 0
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
addedCount:0,
|
|
|
|
deletedCount:0,
|
|
|
|
changedCount:0,
|
|
|
|
unchangedCount: 0
|
|
|
|
},
|
|
|
|
conflicts: 0
|
|
|
|
}
|
|
|
|
if (object.newTab || object.remoteTab) {
|
|
|
|
var localTabNode = {
|
|
|
|
node: localDiff.newConfig.all[tab.id],
|
|
|
|
all: localDiff.newConfig.all,
|
|
|
|
diff: localDiff
|
|
|
|
}
|
|
|
|
var remoteTabNode;
|
|
|
|
if (remoteDiff) {
|
|
|
|
remoteTabNode = {
|
|
|
|
node:remoteDiff.newConfig.all[tab.id]||null,
|
|
|
|
all: remoteDiff.newConfig.all,
|
|
|
|
diff: remoteDiff
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tab.type !== undefined) {
|
|
|
|
var div = $("<div>",{class:"node-diff-node-entry node-diff-node-props collapsed"}).appendTo(nodesDiv);
|
|
|
|
var row = $("<div>",{class:"node-diff-node-entry-header"}).appendTo(div);
|
|
|
|
var originalNodeDiv = $("<div>",{class:"node-diff-node-entry-cell"}).appendTo(row);
|
2016-12-20 20:42:38 +01:00
|
|
|
var localNodeDiv = $("<div>",{class:"node-diff-node-entry-cell node-diff-node-local"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
var localChanged = false;
|
2017-01-01 01:18:39 +01:00
|
|
|
var remoteChanged = false;
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (!localDiff.newConfig.all[tab.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else if (localDiff.added[tab.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-node-added");
|
2016-12-20 20:42:38 +01:00
|
|
|
localChanged = true;
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(localNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (localDiff.changed[tab.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-node-changed");
|
2016-12-20 20:42:38 +01:00
|
|
|
localChanged = true;
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(localNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(localNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var remoteNodeDiv;
|
|
|
|
if (remoteDiff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteNodeDiv = $("<div>",{class:"node-diff-node-entry-cell node-diff-node-remote"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (!remoteDiff.newConfig.all[tab.id]) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
2017-01-01 01:18:39 +01:00
|
|
|
if (remoteDiff.deleted[tab.id]) {
|
|
|
|
remoteChanged = true;
|
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (remoteDiff.added[tab.id]) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-added");
|
2017-01-01 01:18:39 +01:00
|
|
|
remoteChanged = true;
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (remoteDiff.changed[tab.id]) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-changed");
|
2017-01-01 01:18:39 +01:00
|
|
|
remoteChanged = true;
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$('<span class="node-diff-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(originalNodeDiv);
|
2017-08-07 11:00:28 +02:00
|
|
|
$('<span>').html(RED._("diff.flowProperties")).appendTo(originalNodeDiv);
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
row.click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$(this).parent().toggleClass('collapsed');
|
|
|
|
});
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
createNodePropertiesTable(def,tab,localTabNode,remoteTabNode,conflicts).appendTo(div);
|
2016-12-20 20:42:38 +01:00
|
|
|
selectState = "";
|
2017-01-01 01:18:39 +01:00
|
|
|
if (conflicts[tab.id]) {
|
2016-12-20 20:42:38 +01:00
|
|
|
flowStats.conflicts++;
|
2016-12-15 21:41:53 +01:00
|
|
|
|
2016-12-20 20:42:38 +01:00
|
|
|
if (!localNodeDiv.hasClass("node-diff-empty")) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(localNodeDiv);
|
|
|
|
}
|
|
|
|
if (!remoteNodeDiv.hasClass("node-diff-empty")) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(remoteNodeDiv);
|
|
|
|
}
|
|
|
|
div.addClass("node-diff-node-entry-conflict");
|
|
|
|
} else {
|
2018-02-14 00:09:51 +01:00
|
|
|
selectState = CurrentDiff.resolutions[tab.id];
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
// Tab properties row
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeConflictRadioBoxes(tab,div,localNodeDiv,remoteNodeDiv,true,!conflicts[tab.id],selectState,CurrentDiff);
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// var stats = $('<span>',{class:"node-diff-tab-stats"}).appendTo(titleRow);
|
|
|
|
var localNodeCount = 0;
|
|
|
|
var remoteNodeCount = 0;
|
2016-12-07 14:51:20 +01:00
|
|
|
var seen = {};
|
|
|
|
object.tab.nodes.forEach(function(node) {
|
|
|
|
seen[node.id] = true;
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeDiffRow(node,flowStats,CurrentDiff).appendTo(nodesDiv)
|
2016-12-07 14:51:20 +01:00
|
|
|
});
|
|
|
|
if (object.newTab) {
|
2016-12-20 20:42:38 +01:00
|
|
|
localNodeCount = object.newTab.nodes.length;
|
2016-12-07 14:51:20 +01:00
|
|
|
object.newTab.nodes.forEach(function(node) {
|
|
|
|
if (!seen[node.id]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
seen[node.id] = true;
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeDiffRow(node,flowStats,CurrentDiff).appendTo(nodesDiv)
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (object.remoteTab) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteNodeCount = object.remoteTab.nodes.length;
|
2016-12-15 21:41:53 +01:00
|
|
|
object.remoteTab.nodes.forEach(function(node) {
|
|
|
|
if (!seen[node.id]) {
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeDiffRow(node,flowStats,CurrentDiff).appendTo(nodesDiv)
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
titleRow.click(function(evt) {
|
2016-12-15 21:41:53 +01:00
|
|
|
// if (titleRow.parent().find(".node-diff-node-entry:not(.hide)").length > 0) {
|
|
|
|
titleRow.parent().toggleClass('collapsed');
|
|
|
|
if ($(this).parent().hasClass('collapsed')) {
|
|
|
|
$(this).parent().find('.node-diff-node-entry').addClass('collapsed');
|
|
|
|
$(this).parent().find('.debug-message-element').addClass('collapsed');
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
// }
|
2016-12-07 14:51:20 +01:00
|
|
|
})
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (localDiff.deleted[tab.id]) {
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-node-deleted"><span class="node-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.flowDeleted"></span></span></span>').appendTo(localCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (object.newTab) {
|
|
|
|
if (localDiff.added[tab.id]) {
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-node-added"><span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.flowAdded"></span></span></span>').appendTo(localCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
if (tab.id) {
|
|
|
|
if (localDiff.changed[tab.id]) {
|
|
|
|
flowStats.local.changedCount++;
|
|
|
|
} else {
|
|
|
|
flowStats.local.unchangedCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var localStats = $('<span>',{class:"node-diff-tab-stats"}).appendTo(localCell);
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"></span>').html(RED._('diff.nodeCount',{count:localNodeCount})).appendTo(localStats);
|
2016-12-20 20:42:38 +01:00
|
|
|
|
|
|
|
if (flowStats.conflicts + flowStats.local.addedCount + flowStats.local.changedCount + flowStats.local.deletedCount > 0) {
|
|
|
|
$('<span class="node-diff-status"> [ </span>').appendTo(localStats);
|
|
|
|
if (flowStats.conflicts > 0) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i> '+flowStats.conflicts+'</span></span>').appendTo(localStats);
|
|
|
|
}
|
|
|
|
if (flowStats.local.addedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-added"><span class="node-diff-status"><i class="fa fa-plus-square"></i> '+flowStats.local.addedCount+'</span></span>').appendTo(localStats);
|
|
|
|
}
|
|
|
|
if (flowStats.local.changedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-changed"><span class="node-diff-status"><i class="fa fa-square"></i> '+flowStats.local.changedCount+'</span></span>').appendTo(localStats);
|
|
|
|
}
|
|
|
|
if (flowStats.local.deletedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-deleted"><span class="node-diff-status"><i class="fa fa-minus-square"></i> '+flowStats.local.deletedCount+'</span></span>').appendTo(localStats);
|
|
|
|
}
|
|
|
|
$('<span class="node-diff-status"> ] </span>').appendTo(localStats);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-empty");
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
|
|
|
|
if (remoteDiff) {
|
|
|
|
if (remoteDiff.deleted[tab.id]) {
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-node-deleted"><span class="node-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.flowDeleted"></span></span></span>').appendTo(remoteCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (object.remoteTab) {
|
|
|
|
if (remoteDiff.added[tab.id]) {
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-node-added"><span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.flowAdded"></span></span></span>').appendTo(remoteCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
if (tab.id) {
|
|
|
|
if (remoteDiff.changed[tab.id]) {
|
|
|
|
flowStats.remote.changedCount++;
|
|
|
|
} else {
|
|
|
|
flowStats.remote.unchangedCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var remoteStats = $('<span>',{class:"node-diff-tab-stats"}).appendTo(remoteCell);
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"></span>').html(RED._('diff.nodeCount',{count:remoteNodeCount})).appendTo(remoteStats);
|
2016-12-20 20:42:38 +01:00
|
|
|
if (flowStats.conflicts + flowStats.remote.addedCount + flowStats.remote.changedCount + flowStats.remote.deletedCount > 0) {
|
|
|
|
$('<span class="node-diff-status"> [ </span>').appendTo(remoteStats);
|
|
|
|
if (flowStats.conflicts > 0) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i> '+flowStats.conflicts+'</span></span>').appendTo(remoteStats);
|
|
|
|
}
|
|
|
|
if (flowStats.remote.addedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-added"><span class="node-diff-status"><i class="fa fa-plus-square"></i> '+flowStats.remote.addedCount+'</span></span>').appendTo(remoteStats);
|
|
|
|
}
|
|
|
|
if (flowStats.remote.changedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-changed"><span class="node-diff-status"><i class="fa fa-square"></i> '+flowStats.remote.changedCount+'</span></span>').appendTo(remoteStats);
|
|
|
|
}
|
|
|
|
if (flowStats.remote.deletedCount > 0) {
|
|
|
|
$('<span class="node-diff-node-deleted"><span class="node-diff-status"><i class="fa fa-minus-square"></i> '+flowStats.remote.deletedCount+'</span></span>').appendTo(remoteStats);
|
|
|
|
}
|
|
|
|
$('<span class="node-diff-status"> ] </span>').appendTo(remoteStats);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-empty");
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
selectState = "";
|
2016-12-20 20:42:38 +01:00
|
|
|
if (flowStats.conflicts > 0) {
|
|
|
|
titleRow.addClass("node-diff-node-entry-conflict");
|
2017-01-01 01:18:39 +01:00
|
|
|
} else {
|
2018-02-14 00:09:51 +01:00
|
|
|
selectState = CurrentDiff.resolutions[tab.id];
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
if (tab.id) {
|
2017-01-01 01:18:39 +01:00
|
|
|
var hide = !(flowStats.conflicts > 0 &&(localDiff.deleted[tab.id] || remoteDiff.deleted[tab.id]));
|
|
|
|
// Tab parent row
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeConflictRadioBoxes(tab,titleRow,localCell,remoteCell, false, hide, selectState, CurrentDiff);
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
if (tabDiv.find(".node-diff-node-entry").length === 0) {
|
|
|
|
tabDiv.addClass("node-diff-tab-empty");
|
|
|
|
}
|
2017-01-04 23:02:35 +01:00
|
|
|
container.i18n();
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
});
|
2017-10-25 16:26:24 +02:00
|
|
|
return diffList;
|
|
|
|
}
|
|
|
|
function buildDiffPanel(container,diff,options) {
|
|
|
|
var diffPanel = $('<div class="node-dialog-view-diff-panel"></div>').appendTo(container);
|
|
|
|
var diffHeaders = $('<div class="node-dialog-view-diff-headers"></div>').appendTo(diffPanel);
|
|
|
|
if (options.mode === "merge") {
|
|
|
|
diffPanel.addClass("node-dialog-view-diff-panel-merge");
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
var diffList = createDiffTable(diffPanel, diff);
|
2017-10-25 16:26:24 +02:00
|
|
|
|
|
|
|
var localDiff = diff.localDiff;
|
|
|
|
var remoteDiff = diff.remoteDiff;
|
|
|
|
var conflicts = diff.conflicts;
|
|
|
|
|
|
|
|
var currentConfig = localDiff.currentConfig;
|
|
|
|
var newConfig = localDiff.newConfig;
|
|
|
|
|
|
|
|
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
diffPanel.addClass('node-diff-three-way');
|
|
|
|
var localTitle = options.oldRevTitle || RED._('diff.local');
|
|
|
|
var remoteTitle = options.newRevTitle || RED._('diff.remote');
|
|
|
|
$('<div></div>').text(localTitle).appendTo(diffHeaders);
|
|
|
|
$('<div></div>').text(remoteTitle).appendTo(diffHeaders);
|
|
|
|
} else {
|
|
|
|
diffPanel.removeClass('node-diff-three-way');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
list: diffList,
|
|
|
|
finish: function() {
|
|
|
|
var el = {
|
|
|
|
diff: localDiff,
|
|
|
|
def: {
|
|
|
|
category: 'config',
|
|
|
|
color: '#f0f0f0'
|
|
|
|
},
|
|
|
|
tab: {
|
|
|
|
n: {},
|
|
|
|
nodes: currentConfig.globals
|
|
|
|
},
|
|
|
|
newTab: {
|
|
|
|
n: {},
|
|
|
|
nodes: newConfig.globals
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
el.remoteTab = {
|
|
|
|
n:{},
|
|
|
|
nodes:remoteDiff.newConfig.globals
|
|
|
|
};
|
|
|
|
el.remoteDiff = remoteDiff;
|
|
|
|
}
|
|
|
|
diffList.editableList('addItem',el);
|
|
|
|
|
|
|
|
var seenTabs = {};
|
|
|
|
|
|
|
|
currentConfig.tabOrder.forEach(function(tabId) {
|
|
|
|
var tab = currentConfig.tabs[tabId];
|
|
|
|
var el = {
|
|
|
|
diff: localDiff,
|
|
|
|
def: RED.nodes.getType('tab'),
|
|
|
|
tab:tab
|
|
|
|
};
|
|
|
|
if (newConfig.tabs.hasOwnProperty(tabId)) {
|
|
|
|
el.newTab = newConfig.tabs[tabId];
|
|
|
|
}
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
el.remoteTab = remoteDiff.newConfig.tabs[tabId];
|
|
|
|
el.remoteDiff = remoteDiff;
|
|
|
|
}
|
|
|
|
seenTabs[tabId] = true;
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
});
|
|
|
|
newConfig.tabOrder.forEach(function(tabId) {
|
|
|
|
if (!seenTabs[tabId]) {
|
|
|
|
seenTabs[tabId] = true;
|
|
|
|
var tab = newConfig.tabs[tabId];
|
|
|
|
var el = {
|
|
|
|
diff: localDiff,
|
|
|
|
def: RED.nodes.getType('tab'),
|
|
|
|
tab:tab,
|
|
|
|
newTab: tab
|
|
|
|
};
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
el.remoteDiff = remoteDiff;
|
|
|
|
}
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
remoteDiff.newConfig.tabOrder.forEach(function(tabId) {
|
|
|
|
if (!seenTabs[tabId]) {
|
|
|
|
var tab = remoteDiff.newConfig.tabs[tabId];
|
|
|
|
// TODO how to recognise this is a remotely added flow
|
|
|
|
var el = {
|
|
|
|
diff: localDiff,
|
|
|
|
remoteDiff: remoteDiff,
|
|
|
|
def: RED.nodes.getType('tab'),
|
|
|
|
tab:tab,
|
|
|
|
remoteTab:tab
|
|
|
|
};
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var subflowId;
|
|
|
|
for (subflowId in currentConfig.subflows) {
|
|
|
|
if (currentConfig.subflows.hasOwnProperty(subflowId)) {
|
|
|
|
seenTabs[subflowId] = true;
|
|
|
|
el = {
|
|
|
|
diff: localDiff,
|
|
|
|
def: {
|
|
|
|
defaults:{},
|
|
|
|
icon:"subflow.png",
|
|
|
|
category: "subflows",
|
|
|
|
color: "#da9"
|
|
|
|
},
|
|
|
|
tab:currentConfig.subflows[subflowId]
|
|
|
|
}
|
|
|
|
if (newConfig.subflows.hasOwnProperty(subflowId)) {
|
|
|
|
el.newTab = newConfig.subflows[subflowId];
|
|
|
|
}
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
el.remoteTab = remoteDiff.newConfig.subflows[subflowId];
|
|
|
|
el.remoteDiff = remoteDiff;
|
|
|
|
}
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (subflowId in newConfig.subflows) {
|
|
|
|
if (newConfig.subflows.hasOwnProperty(subflowId) && !seenTabs[subflowId]) {
|
|
|
|
seenTabs[subflowId] = true;
|
|
|
|
el = {
|
|
|
|
diff: localDiff,
|
|
|
|
def: {
|
|
|
|
defaults:{},
|
|
|
|
icon:"subflow.png",
|
|
|
|
category: "subflows",
|
|
|
|
color: "#da9"
|
|
|
|
},
|
|
|
|
tab:newConfig.subflows[subflowId],
|
|
|
|
newTab:newConfig.subflows[subflowId]
|
|
|
|
}
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
el.remoteDiff = remoteDiff;
|
|
|
|
}
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (remoteDiff !== undefined) {
|
|
|
|
for (subflowId in remoteDiff.newConfig.subflows) {
|
|
|
|
if (remoteDiff.newConfig.subflows.hasOwnProperty(subflowId) && !seenTabs[subflowId]) {
|
|
|
|
el = {
|
|
|
|
diff: localDiff,
|
|
|
|
remoteDiff: remoteDiff,
|
|
|
|
def: {
|
|
|
|
defaults:{},
|
|
|
|
icon:"subflow.png",
|
|
|
|
category: "subflows",
|
|
|
|
color: "#da9"
|
|
|
|
},
|
|
|
|
tab:remoteDiff.newConfig.subflows[subflowId],
|
|
|
|
remoteTab: remoteDiff.newConfig.subflows[subflowId]
|
|
|
|
}
|
|
|
|
diffList.editableList('addItem',el)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
function formatWireProperty(wires,allNodes) {
|
|
|
|
var result = $("<div>",{class:"node-diff-property-wires"})
|
|
|
|
var list = $("<ol></ol>");
|
|
|
|
var c = 0;
|
2016-12-07 14:51:20 +01:00
|
|
|
wires.forEach(function(p,i) {
|
2016-12-15 21:41:53 +01:00
|
|
|
var port = $("<li>").appendTo(list);
|
2016-12-07 14:51:20 +01:00
|
|
|
if (p && p.length > 0) {
|
2016-12-15 21:41:53 +01:00
|
|
|
$("<span>").html(i+1).appendTo(port);
|
2016-12-07 14:51:20 +01:00
|
|
|
var links = $("<ul>").appendTo(port);
|
|
|
|
p.forEach(function(d) {
|
2016-12-15 21:41:53 +01:00
|
|
|
c++;
|
|
|
|
var entry = $("<li>").appendTo(links);
|
|
|
|
var node = allNodes[d];
|
|
|
|
if (node) {
|
|
|
|
var def = RED.nodes.getType(node.type)||{};
|
|
|
|
createNode(node,def).appendTo(entry);
|
|
|
|
} else {
|
|
|
|
entry.html(d);
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
port.html('none');
|
|
|
|
}
|
|
|
|
})
|
2016-12-15 21:41:53 +01:00
|
|
|
if (c === 0) {
|
|
|
|
result.html("none");
|
|
|
|
} else {
|
|
|
|
list.appendTo(result);
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
function createNodeIcon(node,def) {
|
|
|
|
var nodeDiv = $("<div>",{class:"node-diff-node-entry-node"});
|
|
|
|
var colour = def.color;
|
2017-01-18 14:06:22 +01:00
|
|
|
var icon_url = RED.utils.getNodeIcon(def,node);
|
2016-12-07 14:51:20 +01:00
|
|
|
if (node.type === 'tab') {
|
|
|
|
colour = "#C0DEED";
|
|
|
|
}
|
|
|
|
nodeDiv.css('backgroundColor',colour);
|
|
|
|
|
|
|
|
var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
|
2017-01-18 14:06:22 +01:00
|
|
|
$('<div/>',{class:"palette_icon",style:"background-image: url("+icon_url+")"}).appendTo(iconContainer);
|
2016-12-07 14:51:20 +01:00
|
|
|
|
|
|
|
return nodeDiv;
|
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
function createNode(node,def) {
|
|
|
|
var nodeTitleDiv = $("<div>",{class:"node-diff-node-entry-title"})
|
|
|
|
createNodeIcon(node,def).appendTo(nodeTitleDiv);
|
|
|
|
var contentDiv = $('<div>',{class:"node-diff-node-description"}).appendTo(nodeTitleDiv);
|
|
|
|
var nodeLabel = node.label || node.name || node.id;
|
|
|
|
$('<span>',{class:"node-diff-node-label"}).html(nodeLabel).appendTo(contentDiv);
|
|
|
|
return nodeTitleDiv;
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
function createNodeDiffRow(node,stats,CurrentDiff) {
|
|
|
|
var localDiff = CurrentDiff.localDiff;
|
|
|
|
var remoteDiff = CurrentDiff.remoteDiff;
|
|
|
|
var conflicted = CurrentDiff.conflicts[node.id];
|
2017-01-01 01:18:39 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
var hasChanges = false; // exists in original and local/remote but with changes
|
|
|
|
var unChanged = true; // existing in original,local,remote unchanged
|
2016-12-20 20:42:38 +01:00
|
|
|
var localChanged = false;
|
2016-12-15 21:41:53 +01:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
if (localDiff.added[node.id]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
stats.local.addedCount++;
|
|
|
|
unChanged = false;
|
|
|
|
}
|
|
|
|
if (remoteDiff && remoteDiff.added[node.id]) {
|
|
|
|
stats.remote.addedCount++;
|
|
|
|
unChanged = false;
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
if (localDiff.deleted[node.id]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
stats.local.deletedCount++;
|
|
|
|
unChanged = false;
|
|
|
|
}
|
|
|
|
if (remoteDiff && remoteDiff.deleted[node.id]) {
|
|
|
|
stats.remote.deletedCount++;
|
|
|
|
unChanged = false;
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
if (localDiff.changed[node.id]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
stats.local.changedCount++;
|
2016-12-07 14:51:20 +01:00
|
|
|
hasChanges = true;
|
2016-12-15 21:41:53 +01:00
|
|
|
unChanged = false;
|
|
|
|
}
|
|
|
|
if (remoteDiff && remoteDiff.changed[node.id]) {
|
|
|
|
stats.remote.changedCount++;
|
|
|
|
hasChanges = true;
|
|
|
|
unChanged = false;
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
// console.log(node.id,localDiff.added[node.id],remoteDiff.added[node.id],localDiff.deleted[node.id],remoteDiff.deleted[node.id],localDiff.changed[node.id],remoteDiff.changed[node.id])
|
2016-12-15 21:41:53 +01:00
|
|
|
var def = RED.nodes.getType(node.type);
|
|
|
|
if (def === undefined) {
|
|
|
|
if (/^subflow:/.test(node.type)) {
|
|
|
|
def = {
|
|
|
|
icon:"subflow.png",
|
|
|
|
category: "subflows",
|
|
|
|
color: "#da9",
|
|
|
|
defaults:{name:{value:""}}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
def = {};
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
var div = $("<div>",{class:"node-diff-node-entry collapsed"});
|
2016-12-20 20:42:38 +01:00
|
|
|
var row = $("<div>",{class:"node-diff-node-entry-header"}).appendTo(div);
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
var originalNodeDiv = $("<div>",{class:"node-diff-node-entry-cell"}).appendTo(row);
|
2016-12-20 20:42:38 +01:00
|
|
|
var localNodeDiv = $("<div>",{class:"node-diff-node-entry-cell node-diff-node-local"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
var remoteNodeDiv;
|
|
|
|
var chevron;
|
|
|
|
if (remoteDiff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteNodeDiv = $("<div>",{class:"node-diff-node-entry-cell node-diff-node-remote"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
$('<span class="node-diff-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(originalNodeDiv);
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (unChanged) {
|
|
|
|
stats.local.unchangedCount++;
|
|
|
|
createNode(node,def).appendTo(originalNodeDiv);
|
|
|
|
localNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(localNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteDiff) {
|
|
|
|
stats.remote.unchangedCount++;
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
div.addClass("node-diff-node-unchanged");
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (localDiff.added[node.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-node-added");
|
|
|
|
if (remoteNodeDiv) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
|
|
|
}
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(localNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
createNode(node,def).appendTo(originalNodeDiv);
|
|
|
|
} else if (remoteDiff && remoteDiff.added[node.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-added");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
createNode(node,def).appendTo(originalNodeDiv);
|
|
|
|
} else {
|
|
|
|
createNode(node,def).appendTo(originalNodeDiv);
|
2016-12-23 13:53:59 +01:00
|
|
|
if (localDiff.moved[node.id]) {
|
|
|
|
var localN = localDiff.newConfig.all[node.id];
|
|
|
|
if (!localDiff.deleted[node.z] && node.z !== localN.z && node.z !== "" && !localDiff.newConfig.all[node.z]) {
|
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
localNodeDiv.addClass("node-diff-node-moved");
|
|
|
|
var localMovedMessage = "";
|
|
|
|
if (node.z === localN.z) {
|
2017-01-04 23:02:35 +01:00
|
|
|
localMovedMessage = RED._("diff.type.movedFrom",{id:(localDiff.currentConfig.all[node.id].z||'global')});
|
2016-12-23 13:53:59 +01:00
|
|
|
} else {
|
2017-01-04 23:02:35 +01:00
|
|
|
localMovedMessage = RED._("diff.type.movedTo",{id:(localN.z||'global')});
|
2016-12-23 13:53:59 +01:00
|
|
|
}
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-caret-square-o-right"></i> '+localMovedMessage+'</span>').appendTo(localNodeDiv);
|
|
|
|
}
|
|
|
|
localChanged = true;
|
|
|
|
} else if (localDiff.deleted[node.z]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
2016-12-20 20:42:38 +01:00
|
|
|
localChanged = true;
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (localDiff.deleted[node.id]) {
|
|
|
|
localNodeDiv.addClass("node-diff-node-deleted");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.deleted"></span></span>').appendTo(localNodeDiv);
|
2016-12-20 20:42:38 +01:00
|
|
|
localChanged = true;
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (localDiff.changed[node.id]) {
|
2016-12-23 13:53:59 +01:00
|
|
|
if (localDiff.newConfig.all[node.id].z !== node.z) {
|
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
localNodeDiv.addClass("node-diff-node-changed");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(localNodeDiv);
|
2016-12-23 13:53:59 +01:00
|
|
|
localChanged = true;
|
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
2016-12-23 13:53:59 +01:00
|
|
|
if (localDiff.newConfig.all[node.id].z !== node.z) {
|
|
|
|
localNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
stats.local.unchangedCount++;
|
|
|
|
localNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(localNodeDiv);
|
2016-12-23 13:53:59 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteDiff) {
|
2016-12-23 13:53:59 +01:00
|
|
|
if (remoteDiff.moved[node.id]) {
|
|
|
|
var remoteN = remoteDiff.newConfig.all[node.id];
|
|
|
|
if (!remoteDiff.deleted[node.z] && node.z !== remoteN.z && node.z !== "" && !remoteDiff.newConfig.all[node.z]) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-moved");
|
|
|
|
var remoteMovedMessage = "";
|
|
|
|
if (node.z === remoteN.z) {
|
2017-01-04 23:02:35 +01:00
|
|
|
remoteMovedMessage = RED._("diff.type.movedFrom",{id:(remoteDiff.currentConfig.all[node.id].z||'global')});
|
2016-12-23 13:53:59 +01:00
|
|
|
} else {
|
2017-01-04 23:02:35 +01:00
|
|
|
remoteMovedMessage = RED._("diff.type.movedTo",{id:(remoteN.z||'global')});
|
2016-12-23 13:53:59 +01:00
|
|
|
}
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-caret-square-o-right"></i> '+remoteMovedMessage+'</span>').appendTo(remoteNodeDiv);
|
|
|
|
}
|
|
|
|
} else if (remoteDiff.deleted[node.z]) {
|
2016-12-15 21:41:53 +01:00
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else if (remoteDiff.deleted[node.id]) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-deleted");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.deleted"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else if (remoteDiff.changed[node.id]) {
|
2016-12-23 13:53:59 +01:00
|
|
|
if (remoteDiff.newConfig.all[node.id].z !== node.z) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-changed");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-23 13:53:59 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
2016-12-23 13:53:59 +01:00
|
|
|
if (remoteDiff.newConfig.all[node.id].z !== node.z) {
|
|
|
|
remoteNodeDiv.addClass("node-diff-empty");
|
|
|
|
} else {
|
|
|
|
stats.remote.unchangedCount++;
|
|
|
|
remoteNodeDiv.addClass("node-diff-node-unchanged");
|
2017-01-04 23:02:35 +01:00
|
|
|
$('<span class="node-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(remoteNodeDiv);
|
2016-12-23 13:53:59 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var localNode = {
|
|
|
|
node: localDiff.newConfig.all[node.id],
|
|
|
|
all: localDiff.newConfig.all,
|
|
|
|
diff: localDiff
|
|
|
|
};
|
|
|
|
var remoteNode;
|
|
|
|
if (remoteDiff) {
|
|
|
|
remoteNode = {
|
|
|
|
node:remoteDiff.newConfig.all[node.id]||null,
|
|
|
|
all: remoteDiff.newConfig.all,
|
|
|
|
diff: remoteDiff
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
createNodePropertiesTable(def,node,localNode,remoteNode).appendTo(div);
|
|
|
|
|
|
|
|
var selectState = "";
|
|
|
|
|
|
|
|
if (conflicted) {
|
|
|
|
stats.conflicts++;
|
|
|
|
if (!localNodeDiv.hasClass("node-diff-empty")) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(localNodeDiv);
|
|
|
|
}
|
|
|
|
if (!remoteNodeDiv.hasClass("node-diff-empty")) {
|
|
|
|
$('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(remoteNodeDiv);
|
|
|
|
}
|
|
|
|
div.addClass("node-diff-node-entry-conflict");
|
|
|
|
} else {
|
2018-02-14 00:09:51 +01:00
|
|
|
selectState = CurrentDiff.resolutions[node.id];
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
// Node row
|
2018-02-14 00:09:51 +01:00
|
|
|
createNodeConflictRadioBoxes(node,div,localNodeDiv,remoteNodeDiv,false,!conflicted,selectState,CurrentDiff);
|
2016-12-15 21:41:53 +01:00
|
|
|
row.click(function(evt) {
|
|
|
|
$(this).parent().toggleClass('collapsed');
|
|
|
|
});
|
2016-12-07 14:51:20 +01:00
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
function createNodePropertiesTable(def,node,localNodeObj,remoteNodeObj) {
|
2017-08-01 00:29:36 +02:00
|
|
|
var propertyElements = {};
|
2016-12-15 21:41:53 +01:00
|
|
|
var localNode = localNodeObj.node;
|
|
|
|
var remoteNode;
|
|
|
|
if (remoteNodeObj) {
|
|
|
|
remoteNode = remoteNodeObj.node;
|
|
|
|
}
|
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
var nodePropertiesDiv = $("<div>",{class:"node-diff-node-entry-properties"});
|
|
|
|
var nodePropertiesTable = $("<table>").appendTo(nodePropertiesDiv);
|
2017-08-03 10:58:25 +02:00
|
|
|
var nodePropertiesTableCols = $('<colgroup><col/><col/></colgroup>').appendTo(nodePropertiesTable);
|
|
|
|
if (remoteNode !== undefined) {
|
|
|
|
$("<col/>").appendTo(nodePropertiesTableCols);
|
|
|
|
}
|
|
|
|
var nodePropertiesTableBody = $("<tbody>").appendTo(nodePropertiesTable);
|
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
var row;
|
2016-12-15 21:41:53 +01:00
|
|
|
var localCell, remoteCell;
|
2017-07-26 16:55:53 +02:00
|
|
|
var element;
|
2016-12-15 21:41:53 +01:00
|
|
|
var currentValue, localValue, remoteValue;
|
|
|
|
var localChanged = false;
|
|
|
|
var remoteChanged = false;
|
|
|
|
var localChanges = 0;
|
|
|
|
var remoteChanges = 0;
|
|
|
|
var conflict = false;
|
|
|
|
var status;
|
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
row = $("<tr>").appendTo(nodePropertiesTableBody);
|
2016-12-23 13:53:59 +01:00
|
|
|
$("<td>",{class:"node-diff-property-cell-label"}).html("id").appendTo(row);
|
|
|
|
localCell = $("<td>",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row);
|
|
|
|
if (localNode) {
|
|
|
|
localCell.addClass("node-diff-node-unchanged");
|
|
|
|
$('<span class="node-diff-status"></span>').appendTo(localCell);
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(localCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['local.id'] = RED.utils.createObjectElement(localNode.id).appendTo(element);
|
2016-12-23 13:53:59 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-empty");
|
|
|
|
}
|
|
|
|
if (remoteNode !== undefined) {
|
|
|
|
remoteCell = $("<td>",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row);
|
|
|
|
remoteCell.addClass("node-diff-node-unchanged");
|
|
|
|
if (remoteNode) {
|
|
|
|
$('<span class="node-diff-status"></span>').appendTo(remoteCell);
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(remoteCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['remote.id'] = RED.utils.createObjectElement(remoteNode.id).appendTo(element);
|
2016-12-23 13:53:59 +01:00
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-empty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
if (node.hasOwnProperty('x')) {
|
2016-12-15 21:41:53 +01:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
if ( (remoteChanged && localChanged && (localNode.x !== remoteNode.x || localNode.y !== remoteNode.y)) ||
|
2016-12-15 21:41:53 +01:00
|
|
|
(!localChanged && remoteChanged && localNodeObj.diff.deleted[node.id]) ||
|
|
|
|
(localChanged && !remoteChanged && remoteNodeObj.diff.deleted[node.id])
|
|
|
|
) {
|
|
|
|
conflict = true;
|
|
|
|
}
|
2017-08-03 10:58:25 +02:00
|
|
|
row = $("<tr>").appendTo(nodePropertiesTableBody);
|
2016-12-15 21:41:53 +01:00
|
|
|
$("<td>",{class:"node-diff-property-cell-label"}).html("position").appendTo(row);
|
2016-12-20 20:42:38 +01:00
|
|
|
localCell = $("<td>",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (localNode) {
|
|
|
|
localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged"));
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(localChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(localCell);
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(localCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['local.position'] = RED.utils.createObjectElement({x:localNode.x,y:localNode.y},
|
|
|
|
{
|
|
|
|
path: "position",
|
|
|
|
exposeApi: true,
|
|
|
|
ontoggle: function(path,state) {
|
|
|
|
if (propertyElements['remote.'+path]) {
|
|
|
|
propertyElements['remote.'+path].prop('expand')(path,state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).appendTo(element);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-empty");
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteNode !== undefined) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteCell = $("<td>",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged"));
|
|
|
|
if (remoteNode) {
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(remoteChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(remoteCell);
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(remoteCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['remote.position'] = RED.utils.createObjectElement({x:remoteNode.x,y:remoteNode.y},
|
|
|
|
{
|
|
|
|
path: "position",
|
|
|
|
exposeApi: true,
|
|
|
|
ontoggle: function(path,state) {
|
|
|
|
if (propertyElements['local.'+path]) {
|
|
|
|
propertyElements['local.'+path].prop('expand')(path,state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).appendTo(element);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-empty");
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
//
|
|
|
|
localChanged = remoteChanged = conflict = false;
|
2016-12-07 14:51:20 +01:00
|
|
|
if (node.hasOwnProperty('wires')) {
|
2016-12-15 21:41:53 +01:00
|
|
|
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;
|
|
|
|
}
|
2017-08-03 10:58:25 +02:00
|
|
|
row = $("<tr>").appendTo(nodePropertiesTableBody);
|
2016-12-15 21:41:53 +01:00
|
|
|
$("<td>",{class:"node-diff-property-cell-label"}).html("wires").appendTo(row);
|
2016-12-20 20:42:38 +01:00
|
|
|
localCell = $("<td>",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (localNode) {
|
|
|
|
if (!conflict) {
|
|
|
|
localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged"));
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(localChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(localCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-node-conflict");
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(localCell);
|
|
|
|
}
|
|
|
|
formatWireProperty(localNode.wires,localNodeObj.all).appendTo(localCell);
|
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-empty");
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteNode !== undefined) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteCell = $("<td>",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteNode) {
|
|
|
|
if (!conflict) {
|
|
|
|
remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged"));
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(remoteChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(remoteCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-node-conflict");
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(remoteCell);
|
|
|
|
}
|
|
|
|
formatWireProperty(remoteNode.wires,remoteNodeObj.all).appendTo(remoteCell);
|
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-empty");
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2017-08-02 22:57:23 +02:00
|
|
|
|
|
|
|
var properties = Object.keys(node).filter(function(p) { return p!='inputLabels'&&p!='outputLabels'&&p!='z'&&p!='wires'&&p!=='x'&&p!=='y'&&p!=='id'&&p!=='type'&&(!def.defaults||!def.defaults.hasOwnProperty(p))});
|
2016-12-07 14:51:20 +01:00
|
|
|
if (def.defaults) {
|
|
|
|
properties = properties.concat(Object.keys(def.defaults));
|
|
|
|
}
|
2017-08-04 15:26:05 +02:00
|
|
|
if (node.type !== 'tab') {
|
2017-08-02 22:57:23 +02:00
|
|
|
properties = properties.concat(['inputLabels','outputLabels']);
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
properties.forEach(function(d) {
|
2016-12-15 21:41:53 +01:00
|
|
|
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++;
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
if ( (remoteChanged && localChanged && (localValue !== remoteValue)) ||
|
|
|
|
(!localChanged && remoteChanged && localNodeObj.diff.deleted[node.id]) ||
|
|
|
|
(localChanged && !remoteChanged && remoteNodeObj.diff.deleted[node.id])
|
|
|
|
){
|
|
|
|
conflict = true;
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
row = $("<tr>").appendTo(nodePropertiesTableBody);
|
|
|
|
var propertyNameCell = $("<td>",{class:"node-diff-property-cell-label"}).html(d).appendTo(row);
|
2016-12-20 20:42:38 +01:00
|
|
|
localCell = $("<td>",{class:"node-diff-property-cell node-diff-node-local"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (localNode) {
|
|
|
|
if (!conflict) {
|
|
|
|
localCell.addClass("node-diff-node-"+(localChanged?"changed":"unchanged"));
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(localChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(localCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-node-conflict");
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(localCell);
|
|
|
|
}
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(localCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['local.'+d] = RED.utils.createObjectElement(localNode[d],
|
|
|
|
{
|
|
|
|
path: d,
|
|
|
|
exposeApi: true,
|
|
|
|
ontoggle: function(path,state) {
|
|
|
|
if (propertyElements['remote.'+d]) {
|
|
|
|
propertyElements['remote.'+d].prop('expand')(path,state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).appendTo(element);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
localCell.addClass("node-diff-empty");
|
|
|
|
}
|
|
|
|
if (remoteNode !== undefined) {
|
2016-12-20 20:42:38 +01:00
|
|
|
remoteCell = $("<td>",{class:"node-diff-property-cell node-diff-node-remote"}).appendTo(row);
|
2016-12-15 21:41:53 +01:00
|
|
|
if (remoteNode) {
|
|
|
|
if (!conflict) {
|
|
|
|
remoteCell.addClass("node-diff-node-"+(remoteChanged?"changed":"unchanged"));
|
2016-12-20 20:42:38 +01:00
|
|
|
$('<span class="node-diff-status">'+(remoteChanged?'<i class="fa fa-square"></i>':'')+'</span>').appendTo(remoteCell);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-node-conflict");
|
|
|
|
$('<span class="node-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(remoteCell);
|
|
|
|
}
|
2017-07-26 16:47:19 +02:00
|
|
|
element = $('<span class="node-diff-element"></span>').appendTo(remoteCell);
|
2017-08-01 00:29:36 +02:00
|
|
|
propertyElements['remote.'+d] = RED.utils.createObjectElement(remoteNode[d],
|
|
|
|
{
|
|
|
|
path: d,
|
|
|
|
exposeApi: true,
|
|
|
|
ontoggle: function(path,state) {
|
|
|
|
if (propertyElements['local.'+d]) {
|
|
|
|
propertyElements['local.'+d].prop('expand')(path,state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).appendTo(element);
|
2016-12-15 21:41:53 +01:00
|
|
|
} else {
|
|
|
|
remoteCell.addClass("node-diff-empty");
|
|
|
|
}
|
|
|
|
}
|
2017-08-20 23:59:51 +02:00
|
|
|
if (localNode && remoteNode && typeof localNode[d] === "string") {
|
|
|
|
if (/\n/.test(localNode[d]) || /\n/.test(remoteNode[d])) {
|
|
|
|
$('<button class="editor-button editor-button-small node-diff-text-diff-button"><i class="fa fa-file-o"> <i class="fa fa-caret-left"></i> <i class="fa fa-caret-right"></i> <i class="fa fa-file-o"></i></button>').click(function() {
|
|
|
|
showTextDiff(localNode[d],remoteNode[d]);
|
|
|
|
}).appendTo(propertyNameCell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
});
|
2016-12-20 20:42:38 +01:00
|
|
|
return nodePropertiesDiv;
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
function createNodeConflictRadioBoxes(node,row,localDiv,remoteDiv,propertiesTable,hide,state,diff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
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");
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
refreshConflictHeader(diff);
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2016-12-20 20:42:38 +01:00
|
|
|
var localSelectDiv = $('<label>',{class:"node-diff-selectbox",for:safeNodeId+"-local"}).click(function(e) { e.stopPropagation();}).appendTo(localDiv);
|
|
|
|
var localRadio = $('<input>',{id:safeNodeId+"-local",type:'radio',value:"local",name:safeNodeId,class:className+"-local"+(titleRow?"":" node-diff-select-node")}).data('node-id',node.id).change(changeHandler).appendTo(localSelectDiv);
|
|
|
|
var remoteSelectDiv = $('<label>',{class:"node-diff-selectbox",for:safeNodeId+"-remote"}).click(function(e) { e.stopPropagation();}).appendTo(remoteDiv);
|
|
|
|
var remoteRadio = $('<input>',{id:safeNodeId+"-remote",type:'radio',value:"remote",name:safeNodeId,class:className+"-remote"+(titleRow?"":" node-diff-select-node")}).data('node-id',node.id).change(changeHandler).appendTo(remoteSelectDiv);
|
|
|
|
if (state === 'local') {
|
|
|
|
localRadio.prop('checked',true);
|
|
|
|
} else if (state === 'remote') {
|
|
|
|
remoteRadio.prop('checked',true);
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
if (hide||localDiv.hasClass("node-diff-empty") || remoteDiv.hasClass("node-diff-empty")) {
|
|
|
|
localSelectDiv.hide();
|
|
|
|
remoteSelectDiv.hide();
|
|
|
|
}
|
|
|
|
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
function refreshConflictHeader(currentDiff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
var resolutionCount = 0;
|
|
|
|
$(".node-diff-selectbox>input:checked").each(function() {
|
|
|
|
if (currentDiff.conflicts[$(this).data('node-id')]) {
|
|
|
|
resolutionCount++;
|
|
|
|
}
|
|
|
|
currentDiff.resolutions[$(this).data('node-id')] = $(this).val();
|
|
|
|
})
|
|
|
|
var conflictCount = Object.keys(currentDiff.conflicts).length;
|
|
|
|
if (conflictCount - resolutionCount === 0) {
|
|
|
|
$("#node-diff-toolbar-resolved-conflicts").html('<span class="node-diff-node-added"><span class="node-diff-status"><i class="fa fa-check"></i></span></span> '+RED._("diff.unresolvedCount",{count:conflictCount - resolutionCount}));
|
|
|
|
} else {
|
|
|
|
$("#node-diff-toolbar-resolved-conflicts").html('<span class="node-diff-node-conflict"><span class="node-diff-status"><i class="fa fa-exclamation"></i></span></span> '+RED._("diff.unresolvedCount",{count:conflictCount - resolutionCount}));
|
|
|
|
}
|
|
|
|
if (conflictCount === resolutionCount) {
|
|
|
|
$("#node-diff-view-diff-merge").removeClass('disabled');
|
2018-02-14 00:09:51 +01:00
|
|
|
$("#node-diff-view-resolve-diff").removeClass('disabled');
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
function getRemoteDiff(callback) {
|
2016-12-15 21:41:53 +01:00
|
|
|
$.ajax({
|
|
|
|
headers: {
|
|
|
|
"Accept":"application/json",
|
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
url: 'flows',
|
|
|
|
success: function(nodes) {
|
|
|
|
var localFlow = RED.nodes.createCompleteNodeSet();
|
|
|
|
var originalFlow = RED.nodes.originalFlow();
|
|
|
|
var remoteFlow = nodes.flows;
|
|
|
|
var localDiff = generateDiff(originalFlow,localFlow);
|
|
|
|
var remoteDiff = generateDiff(originalFlow,remoteFlow);
|
2017-01-01 01:18:39 +01:00
|
|
|
remoteDiff.rev = nodes.rev;
|
|
|
|
callback(resolveDiffs(localDiff,remoteDiff))
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
|
|
|
});
|
2016-12-20 20:42:38 +01:00
|
|
|
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
// function showLocalDiff() {
|
|
|
|
// var nns = RED.nodes.createCompleteNodeSet();
|
|
|
|
// var originalFlow = RED.nodes.originalFlow();
|
|
|
|
// var diff = generateDiff(originalFlow,nns);
|
|
|
|
// showDiff(diff);
|
|
|
|
// }
|
2016-12-20 20:42:38 +01:00
|
|
|
function showRemoteDiff(diff) {
|
|
|
|
if (diff === undefined) {
|
|
|
|
getRemoteDiff(showRemoteDiff);
|
|
|
|
} else {
|
2017-10-25 16:26:24 +02:00
|
|
|
showDiff(diff,{mode:'merge'});
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2016-12-15 21:41:53 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
function parseNodes(nodeList) {
|
|
|
|
var tabOrder = [];
|
|
|
|
var tabs = {};
|
|
|
|
var subflows = {};
|
|
|
|
var globals = [];
|
|
|
|
var all = {};
|
|
|
|
|
|
|
|
nodeList.forEach(function(node) {
|
|
|
|
all[node.id] = node;
|
|
|
|
if (node.type === 'tab') {
|
|
|
|
tabOrder.push(node.id);
|
|
|
|
tabs[node.id] = {n:node,nodes:[]};
|
|
|
|
} else if (node.type === 'subflow') {
|
|
|
|
subflows[node.id] = {n:node,nodes:[]};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
nodeList.forEach(function(node) {
|
|
|
|
if (node.type !== 'tab' && node.type !== 'subflow') {
|
|
|
|
if (tabs[node.z]) {
|
|
|
|
tabs[node.z].nodes.push(node);
|
|
|
|
} else if (subflows[node.z]) {
|
|
|
|
subflows[node.z].nodes.push(node);
|
|
|
|
} else {
|
|
|
|
globals.push(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
all: all,
|
|
|
|
tabOrder: tabOrder,
|
|
|
|
tabs: tabs,
|
|
|
|
subflows: subflows,
|
|
|
|
globals: globals
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function generateDiff(currentNodes,newNodes) {
|
|
|
|
var currentConfig = parseNodes(currentNodes);
|
|
|
|
var newConfig = parseNodes(newNodes);
|
|
|
|
var added = {};
|
|
|
|
var deleted = {};
|
|
|
|
var changed = {};
|
2016-12-23 13:53:59 +01:00
|
|
|
var moved = {};
|
2016-12-07 14:51:20 +01:00
|
|
|
|
|
|
|
Object.keys(currentConfig.all).forEach(function(id) {
|
|
|
|
var node = RED.nodes.workspace(id)||RED.nodes.subflow(id)||RED.nodes.node(id);
|
|
|
|
if (!newConfig.all.hasOwnProperty(id)) {
|
2016-12-20 20:42:38 +01:00
|
|
|
deleted[id] = true;
|
2016-12-07 14:51:20 +01:00
|
|
|
} else if (JSON.stringify(currentConfig.all[id]) !== JSON.stringify(newConfig.all[id])) {
|
|
|
|
changed[id] = true;
|
2016-12-23 13:53:59 +01:00
|
|
|
|
|
|
|
if (currentConfig.all[id].z !== newConfig.all[id].z) {
|
|
|
|
moved[id] = true;
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.keys(newConfig.all).forEach(function(id) {
|
2016-12-20 20:42:38 +01:00
|
|
|
if (!currentConfig.all.hasOwnProperty(id)) {
|
2016-12-07 14:51:20 +01:00
|
|
|
added[id] = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
currentConfig: currentConfig,
|
|
|
|
newConfig: newConfig,
|
|
|
|
added: added,
|
|
|
|
deleted: deleted,
|
|
|
|
changed: changed,
|
2016-12-23 13:53:59 +01:00
|
|
|
moved: moved
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
function resolveDiffs(localDiff,remoteDiff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
var conflicted = {};
|
2017-01-01 01:18:39 +01:00
|
|
|
var resolutions = {};
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
var diff = {
|
|
|
|
localDiff: localDiff,
|
|
|
|
remoteDiff: remoteDiff,
|
|
|
|
conflicts: conflicted,
|
|
|
|
resolutions: resolutions
|
|
|
|
}
|
|
|
|
var seen = {};
|
|
|
|
var id,node;
|
2016-12-20 20:42:38 +01:00
|
|
|
for (id in localDiff.currentConfig.all) {
|
|
|
|
if (localDiff.currentConfig.all.hasOwnProperty(id)) {
|
|
|
|
seen[id] = true;
|
|
|
|
var localNode = localDiff.newConfig.all[id];
|
|
|
|
if (localDiff.changed[id] && remoteDiff.deleted[id]) {
|
|
|
|
conflicted[id] = true;
|
|
|
|
} else if (localDiff.deleted[id] && remoteDiff.changed[id]) {
|
|
|
|
conflicted[id] = true;
|
|
|
|
} else if (localDiff.changed[id] && remoteDiff.changed[id]) {
|
|
|
|
var remoteNode = remoteDiff.newConfig.all[id];
|
|
|
|
if (JSON.stringify(localNode) !== JSON.stringify(remoteNode)) {
|
|
|
|
conflicted[id] = true;
|
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
if (!conflicted[id]) {
|
|
|
|
if (remoteDiff.added[id]||remoteDiff.changed[id]||remoteDiff.deleted[id]) {
|
|
|
|
resolutions[id] = 'remote';
|
|
|
|
} else {
|
|
|
|
resolutions[id] = 'local';
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
for (id in localDiff.added) {
|
|
|
|
if (localDiff.added.hasOwnProperty(id)) {
|
|
|
|
node = localDiff.newConfig.all[id];
|
|
|
|
if (remoteDiff.deleted[node.z]) {
|
|
|
|
conflicted[id] = true;
|
|
|
|
// conflicted[node.z] = true;
|
2017-01-01 01:18:39 +01:00
|
|
|
} else {
|
|
|
|
resolutions[id] = 'local';
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (id in remoteDiff.added) {
|
|
|
|
if (remoteDiff.added.hasOwnProperty(id)) {
|
|
|
|
node = remoteDiff.newConfig.all[id];
|
|
|
|
if (localDiff.deleted[node.z]) {
|
|
|
|
conflicted[id] = true;
|
|
|
|
// conflicted[node.z] = true;
|
2017-01-01 01:18:39 +01:00
|
|
|
} else {
|
|
|
|
resolutions[id] = 'remote';
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
// console.log(diff.resolutions);
|
2016-12-20 20:42:38 +01:00
|
|
|
// console.log(conflicted);
|
2017-01-01 01:18:39 +01:00
|
|
|
return diff;
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
function showDiff(diff,options) {
|
2017-08-03 10:58:25 +02:00
|
|
|
if (diffVisible) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-25 16:26:24 +02:00
|
|
|
options = options || {};
|
|
|
|
var mode = options.mode || 'merge';
|
2017-08-03 10:58:25 +02:00
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
var localDiff = diff.localDiff;
|
|
|
|
var remoteDiff = diff.remoteDiff;
|
|
|
|
var conflicts = diff.conflicts;
|
2018-02-14 00:09:51 +01:00
|
|
|
// currentDiff = diff;
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
var trayOptions = {
|
2017-10-25 16:26:24 +02:00
|
|
|
title: options.title||"Review Changes", //TODO: nls
|
2017-08-03 10:58:25 +02:00
|
|
|
width: Infinity,
|
2017-10-25 16:26:24 +02:00
|
|
|
overlay: true,
|
2017-08-03 10:58:25 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2017-10-25 16:26:24 +02:00
|
|
|
text: RED._((options.mode === 'merge')?"common.label.cancel":"common.label.close"),
|
2017-08-03 10:58:25 +02:00
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(dimensions) {
|
|
|
|
// trayWidth = dimensions.width;
|
2016-12-07 14:51:20 +01:00
|
|
|
},
|
2017-08-03 10:58:25 +02:00
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
2018-02-14 00:09:51 +01:00
|
|
|
var toolbar = $('<div class="node-diff-toolbar">'+
|
|
|
|
'<span><span id="node-diff-toolbar-resolved-conflicts"></span></span> '+
|
|
|
|
'</div>').prependTo(trayBody);
|
|
|
|
var diffContainer = $('<div class="node-diff-container"></div>').appendTo(trayBody);
|
|
|
|
var diffTable = buildDiffPanel(diffContainer,diff,options);
|
2017-10-25 16:26:24 +02:00
|
|
|
diffTable.list.hide();
|
2017-08-03 10:58:25 +02:00
|
|
|
if (remoteDiff) {
|
|
|
|
$("#node-diff-view-diff-merge").show();
|
|
|
|
if (Object.keys(conflicts).length === 0) {
|
|
|
|
$("#node-diff-view-diff-merge").removeClass('disabled');
|
|
|
|
} else {
|
|
|
|
$("#node-diff-view-diff-merge").addClass('disabled');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$("#node-diff-view-diff-merge").hide();
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
refreshConflictHeader(diff);
|
2017-08-03 10:58:25 +02:00
|
|
|
// console.log("--------------");
|
|
|
|
// console.log(localDiff);
|
|
|
|
// console.log(remoteDiff);
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
diffTable.finish();
|
|
|
|
diffTable.list.show();
|
|
|
|
},300);
|
2017-08-03 10:58:25 +02:00
|
|
|
$("#sidebar-shade").show();
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
diffVisible = false;
|
|
|
|
$("#sidebar-shade").hide();
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
},
|
|
|
|
show: function() {
|
2016-12-07 14:51:20 +01:00
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-25 16:26:24 +02:00
|
|
|
if (options.mode === 'merge') {
|
|
|
|
trayOptions.buttons.push(
|
|
|
|
{
|
|
|
|
id: "node-diff-view-diff-merge",
|
|
|
|
text: RED._("deploy.confirm.button.merge"),
|
|
|
|
class: "primary disabled",
|
|
|
|
click: function() {
|
|
|
|
if (!$("#node-diff-view-diff-merge").hasClass('disabled')) {
|
2018-02-14 00:09:51 +01:00
|
|
|
refreshConflictHeader(diff);
|
|
|
|
mergeDiff(diff);
|
2017-10-25 16:26:24 +02:00
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
RED.tray.show(trayOptions);
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
2017-08-03 10:58:25 +02:00
|
|
|
|
2018-02-14 00:09:51 +01:00
|
|
|
function applyDiff(diff) {
|
2016-12-20 20:42:38 +01:00
|
|
|
var currentConfig = diff.localDiff.currentConfig;
|
|
|
|
var localDiff = diff.localDiff;
|
|
|
|
var remoteDiff = diff.remoteDiff;
|
|
|
|
var conflicts = diff.conflicts;
|
|
|
|
var resolutions = diff.resolutions;
|
|
|
|
var id;
|
2017-01-01 01:18:39 +01:00
|
|
|
|
|
|
|
for (id in conflicts) {
|
|
|
|
if (conflicts.hasOwnProperty(id)) {
|
|
|
|
if (!resolutions.hasOwnProperty(id)) {
|
|
|
|
console.log(diff);
|
|
|
|
throw new Error("No resolution for conflict on node",id);
|
|
|
|
}
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
|
|
|
|
var newConfig = [];
|
|
|
|
var node;
|
|
|
|
var nodeChangedStates = {};
|
|
|
|
var localChangedStates = {};
|
|
|
|
for (id in localDiff.newConfig.all) {
|
|
|
|
if (localDiff.newConfig.all.hasOwnProperty(id)) {
|
|
|
|
node = RED.nodes.node(id);
|
2016-12-20 20:42:38 +01:00
|
|
|
if (resolutions[id] === 'local') {
|
2017-01-01 01:18:39 +01:00
|
|
|
if (node) {
|
|
|
|
nodeChangedStates[id] = node.changed;
|
|
|
|
}
|
|
|
|
newConfig.push(localDiff.newConfig.all[id]);
|
|
|
|
} else if (resolutions[id] === 'remote') {
|
|
|
|
if (!remoteDiff.deleted[id] && remoteDiff.newConfig.all.hasOwnProperty(id)) {
|
|
|
|
if (node) {
|
|
|
|
nodeChangedStates[id] = node.changed;
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
localChangedStates[id] = true;
|
|
|
|
newConfig.push(remoteDiff.newConfig.all[id]);
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
} else {
|
|
|
|
console.log("Unresolved",id)
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
for (id in remoteDiff.added) {
|
|
|
|
if (remoteDiff.added.hasOwnProperty(id)) {
|
|
|
|
node = RED.nodes.node(id);
|
|
|
|
if (node) {
|
|
|
|
nodeChangedStates[id] = node.changed;
|
|
|
|
}
|
|
|
|
if (!localDiff.added.hasOwnProperty(id)) {
|
|
|
|
localChangedStates[id] = true;
|
|
|
|
newConfig.push(remoteDiff.newConfig.all[id]);
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
return {
|
|
|
|
config: newConfig,
|
|
|
|
nodeChangedStates: nodeChangedStates,
|
|
|
|
localChangedStates: localChangedStates
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeDiff(diff) {
|
|
|
|
var appliedDiff = applyDiff(diff);
|
|
|
|
|
|
|
|
var newConfig = appliedDiff.config;
|
|
|
|
var nodeChangedStates = appliedDiff.nodeChangedStates;
|
|
|
|
var localChangedStates = appliedDiff.localChangedStates;
|
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
var historyEvent = {
|
|
|
|
t:"replace",
|
|
|
|
config: RED.nodes.createCompleteNodeSet(),
|
|
|
|
changed: nodeChangedStates,
|
|
|
|
dirty: RED.nodes.dirty(),
|
|
|
|
rev: RED.nodes.version()
|
|
|
|
}
|
2016-12-23 13:53:59 +01:00
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
RED.history.push(historyEvent);
|
|
|
|
|
|
|
|
RED.nodes.clear();
|
|
|
|
var imported = RED.nodes.import(newConfig);
|
|
|
|
imported[0].forEach(function(n) {
|
|
|
|
if (nodeChangedStates[n.id] || localChangedStates[n.id]) {
|
|
|
|
n.changed = true;
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
})
|
2016-12-20 20:42:38 +01:00
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
RED.nodes.version(remoteDiff.rev);
|
2016-12-20 20:42:38 +01:00
|
|
|
|
|
|
|
RED.view.redraw(true);
|
2016-12-20 22:13:39 +01:00
|
|
|
RED.palette.refresh();
|
|
|
|
RED.workspaces.refresh();
|
|
|
|
RED.sidebar.config.refresh();
|
2016-12-20 20:42:38 +01:00
|
|
|
}
|
2017-08-20 23:59:51 +02:00
|
|
|
function showTestFlowDiff(index) {
|
|
|
|
if (index === 1) {
|
|
|
|
var localFlow = RED.nodes.createCompleteNodeSet();
|
|
|
|
var originalFlow = RED.nodes.originalFlow();
|
|
|
|
showTextDiff(JSON.stringify(localFlow,null,4),JSON.stringify(originalFlow,null,4))
|
|
|
|
} else if (index === 2) {
|
|
|
|
var local = "1\n2\n3\n4\n5\nA\n6\n7\n8\n9\n";
|
|
|
|
var remote = "1\nA\n2\n3\nD\nE\n6\n7\n8\n9\n";
|
|
|
|
showTextDiff(local,remote);
|
|
|
|
} else if (index === 3) {
|
|
|
|
var local = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22";
|
|
|
|
var remote = "1\nTWO\nTHREE\nEXTRA\n4\n5\n6\n7\n8\n9\n10\n11\n12\nTHIRTEEN\n14\n15\n16\n17\n18\n19\n20\n21\n22";
|
|
|
|
showTextDiff(local,remote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showTextDiff(textA,textB) {
|
|
|
|
var trayOptions = {
|
|
|
|
title: "Compare Changes", //TODO: nls
|
|
|
|
width: Infinity,
|
|
|
|
overlay: true,
|
|
|
|
buttons: [
|
|
|
|
{
|
2017-10-25 16:26:24 +02:00
|
|
|
text: RED._("common.label.close"),
|
2017-08-20 23:59:51 +02:00
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(dimensions) {
|
|
|
|
// trayWidth = dimensions.width;
|
|
|
|
},
|
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
|
|
|
var diffPanel = $('<div class="node-text-diff"></div>').appendTo(trayBody);
|
|
|
|
|
2018-02-14 00:09:51 +01:00
|
|
|
var codeTable = $("<table>",{class:"node-text-diff-content"}).appendTo(diffPanel);
|
2017-08-20 23:59:51 +02:00
|
|
|
$('<colgroup><col width="50"><col width="50%"><col width="50"><col width="50%"></colgroup>').appendTo(codeTable);
|
|
|
|
var codeBody = $('<tbody>').appendTo(codeTable);
|
|
|
|
var diffSummary = diffText(textA||"",textB||"");
|
|
|
|
var aIndex = 0;
|
|
|
|
var bIndex = 0;
|
|
|
|
var diffLength = Math.max(diffSummary.a.length, diffSummary.b.length);
|
|
|
|
|
|
|
|
var diffLines = [];
|
|
|
|
var diffBlocks = [];
|
|
|
|
var currentBlock;
|
|
|
|
var blockLength = 0;
|
|
|
|
var blockType = 0;
|
|
|
|
|
|
|
|
for (var i=0;i<diffLength;i++) {
|
|
|
|
var diffLine = diffSummary[i];
|
|
|
|
var Adiff = (aIndex < diffSummary.a.length)?diffSummary.a[aIndex]:{type:2,line:""};
|
|
|
|
var Bdiff = (bIndex < diffSummary.b.length)?diffSummary.b[bIndex]:{type:2,line:""};
|
|
|
|
if (Adiff.type === 0 && Bdiff.type !== 0) {
|
|
|
|
Adiff = {type:2,line:""};
|
|
|
|
bIndex++;
|
|
|
|
} else if (Bdiff.type === 0 && Adiff.type !== 0) {
|
|
|
|
Bdiff = {type:2,line:""};
|
|
|
|
aIndex++;
|
|
|
|
} else {
|
|
|
|
aIndex++;
|
|
|
|
bIndex++;
|
|
|
|
}
|
|
|
|
diffLines.push({
|
|
|
|
a: Adiff,
|
|
|
|
b: Bdiff
|
|
|
|
});
|
|
|
|
if (currentBlock === undefined) {
|
|
|
|
currentBlock = {start:i,end:i};
|
|
|
|
blockLength = 0;
|
|
|
|
blockType = (Adiff.type === 0 && Bdiff.type === 0)?0:1;
|
|
|
|
} else {
|
|
|
|
if (Adiff.type === 0 && Bdiff.type === 0) {
|
|
|
|
// Unchanged line
|
|
|
|
if (blockType === 0) {
|
|
|
|
// still unchanged - extend the block
|
|
|
|
currentBlock.end = i;
|
|
|
|
blockLength++;
|
|
|
|
} else if (blockType === 1) {
|
|
|
|
// end of a change
|
|
|
|
currentBlock.end = i;
|
|
|
|
blockType = 2;
|
|
|
|
blockLength = 0;
|
|
|
|
} else if (blockType === 2) {
|
|
|
|
// post-change unchanged
|
|
|
|
currentBlock.end = i;
|
|
|
|
blockLength++;
|
|
|
|
if (blockLength === 8) {
|
|
|
|
currentBlock.end -= 5; // rollback the end
|
|
|
|
diffBlocks.push(currentBlock);
|
|
|
|
currentBlock = {start:i-5,end:i-5};
|
|
|
|
blockType = 0;
|
|
|
|
blockLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// in a change
|
|
|
|
currentBlock.end = i;
|
|
|
|
blockLength++;
|
|
|
|
if (blockType === 0) {
|
|
|
|
if (currentBlock.end > 3) {
|
|
|
|
currentBlock.end -= 3;
|
|
|
|
currentBlock.empty = true;
|
|
|
|
diffBlocks.push(currentBlock);
|
|
|
|
currentBlock = {start:i-3,end:i-3};
|
|
|
|
}
|
|
|
|
blockType = 1;
|
|
|
|
} else if (blockType === 2) {
|
|
|
|
// we were in unchanged, but hit a change again
|
|
|
|
blockType = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (blockType === 0) {
|
|
|
|
currentBlock.empty = true;
|
|
|
|
}
|
|
|
|
currentBlock.end = diffLength;
|
|
|
|
diffBlocks.push(currentBlock);
|
2017-10-09 01:11:07 +02:00
|
|
|
// console.table(diffBlocks);
|
2017-08-20 23:59:51 +02:00
|
|
|
var diffRow;
|
|
|
|
for (var b = 0; b<diffBlocks.length; b++) {
|
|
|
|
currentBlock = diffBlocks[b];
|
|
|
|
if (currentBlock.empty) {
|
|
|
|
diffRow = createExpandLine(currentBlock.start,currentBlock.end,diffLines).appendTo(codeBody);
|
|
|
|
} else {
|
|
|
|
for (var i=currentBlock.start;i<currentBlock.end;i++) {
|
|
|
|
var row = createDiffLine(diffLines[i]).appendTo(codeBody);
|
|
|
|
if (i === currentBlock.start) {
|
|
|
|
row.addClass("start-block");
|
|
|
|
} else if (i === currentBlock.end-1) {
|
|
|
|
row.addClass("end-block");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
diffVisible = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RED.tray.show(trayOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createExpandLine(start,end,diffLines) {
|
2017-10-09 01:11:07 +02:00
|
|
|
diffRow = $('<tr class="node-text-diff-header node-text-diff-expand">');
|
2017-08-20 23:59:51 +02:00
|
|
|
var content = $('<td colspan="4"> <i class="fa fa-arrows-v"></i> </td>').appendTo(diffRow);
|
|
|
|
var label = $('<span></span>').appendTo(content);
|
|
|
|
if (end < diffLines.length-1) {
|
|
|
|
label.text("@@ -"+(diffLines[end-1].a.i+1)+" +"+(diffLines[end-1].b.i+1));
|
|
|
|
}
|
|
|
|
diffRow.click(function(evt) {
|
2017-10-10 00:37:19 +02:00
|
|
|
// console.log(start,end,diffLines.length);
|
2017-08-20 23:59:51 +02:00
|
|
|
if (end - start > 20) {
|
|
|
|
var startPos = $(this).offset();
|
2017-10-10 00:37:19 +02:00
|
|
|
// console.log(startPos);
|
2017-08-20 23:59:51 +02:00
|
|
|
if (start > 0) {
|
|
|
|
for (var i=start;i<start+10;i++) {
|
|
|
|
createDiffLine(diffLines[i]).addClass("unchanged").insertBefore($(this));
|
|
|
|
}
|
|
|
|
start += 10;
|
|
|
|
}
|
|
|
|
if (end < diffLines.length-1) {
|
|
|
|
for (var i=end-1;i>end-11;i--) {
|
|
|
|
createDiffLine(diffLines[i]).addClass("unchanged").insertAfter($(this));
|
|
|
|
}
|
|
|
|
end -= 10;
|
|
|
|
}
|
|
|
|
if (end < diffLines.length-1) {
|
|
|
|
label.text("@@ -"+(diffLines[end-1].a.i+1)+" +"+(diffLines[end-1].b.i+1));
|
|
|
|
}
|
|
|
|
var endPos = $(this).offset();
|
|
|
|
var delta = endPos.top - startPos.top;
|
|
|
|
$(".node-text-diff").scrollTop($(".node-text-diff").scrollTop() + delta);
|
|
|
|
} else {
|
|
|
|
for (var i=start;i<end;i++) {
|
|
|
|
createDiffLine(diffLines[i]).addClass("unchanged").insertBefore($(this));
|
|
|
|
}
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return diffRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createDiffLine(diffLine) {
|
|
|
|
var diffRow = $('<tr>');
|
|
|
|
var Adiff = diffLine.a;
|
|
|
|
var Bdiff = diffLine.b;
|
|
|
|
//console.log(diffLine);
|
2017-10-09 01:11:07 +02:00
|
|
|
var cellNo = $('<td class="lineno">').text(Adiff.type === 2?"":Adiff.i).appendTo(diffRow);
|
|
|
|
var cellLine = $('<td class="linetext">').text(Adiff.line).appendTo(diffRow);
|
2017-08-20 23:59:51 +02:00
|
|
|
if (Adiff.type === 2) {
|
|
|
|
cellNo.addClass('blank');
|
|
|
|
cellLine.addClass('blank');
|
2017-11-22 00:31:41 +01:00
|
|
|
} else if (Adiff.type === 4) {
|
2017-08-20 23:59:51 +02:00
|
|
|
cellNo.addClass('added');
|
|
|
|
cellLine.addClass('added');
|
2017-11-22 00:31:41 +01:00
|
|
|
} else if (Adiff.type === 1) {
|
2017-08-20 23:59:51 +02:00
|
|
|
cellNo.addClass('removed');
|
|
|
|
cellLine.addClass('removed');
|
|
|
|
}
|
2017-10-09 01:11:07 +02:00
|
|
|
cellNo = $('<td class="lineno">').text(Bdiff.type === 2?"":Bdiff.i).appendTo(diffRow);
|
|
|
|
cellLine = $('<td class="linetext">').text(Bdiff.line).appendTo(diffRow);
|
2017-08-20 23:59:51 +02:00
|
|
|
if (Bdiff.type === 2) {
|
|
|
|
cellNo.addClass('blank');
|
|
|
|
cellLine.addClass('blank');
|
2017-11-22 00:31:41 +01:00
|
|
|
} else if (Bdiff.type === 4) {
|
2017-08-20 23:59:51 +02:00
|
|
|
cellNo.addClass('added');
|
|
|
|
cellLine.addClass('added');
|
2017-11-22 00:31:41 +01:00
|
|
|
} else if (Bdiff.type === 1) {
|
2017-08-20 23:59:51 +02:00
|
|
|
cellNo.addClass('removed');
|
|
|
|
cellLine.addClass('removed');
|
|
|
|
}
|
|
|
|
return diffRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
function diffText(string1, string2,ignoreWhitespace) {
|
|
|
|
var lines1 = string1.split(/\r?\n/);
|
|
|
|
var lines2 = string2.split(/\r?\n/);
|
|
|
|
var i = lines1.length;
|
|
|
|
var j = lines2.length;
|
|
|
|
var k;
|
|
|
|
var m;
|
|
|
|
var diffSummary = {a:[],b:[]};
|
|
|
|
var diffMap = [];
|
|
|
|
for (k = 0; k < i + 1; k++) {
|
|
|
|
diffMap[k] = [];
|
|
|
|
for (m = 0; m < j + 1; m++) {
|
|
|
|
diffMap[k][m] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var c = 0;
|
|
|
|
for (k = i - 1; k >= 0; k--) {
|
|
|
|
for (m = j - 1; m >=0; m--) {
|
|
|
|
c++;
|
|
|
|
if (compareLines(lines1[k],lines2[m],ignoreWhitespace) !== 1) {
|
|
|
|
diffMap[k][m] = diffMap[k+1][m+1]+1;
|
|
|
|
} else {
|
|
|
|
diffMap[k][m] = Math.max(diffMap[(k + 1)][m], diffMap[k][(m + 1)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//console.log(c);
|
|
|
|
k = 0;
|
|
|
|
m = 0;
|
|
|
|
|
|
|
|
while ((k < i) && (m < j)) {
|
|
|
|
var n = compareLines(lines1[k],lines2[m],ignoreWhitespace);
|
|
|
|
if (n !== 1) {
|
|
|
|
var d = 0;
|
|
|
|
if (n===0) {
|
|
|
|
d = 0;
|
|
|
|
} else if (n==2) {
|
|
|
|
d = 3;
|
|
|
|
}
|
|
|
|
diffSummary.a.push({i:k+1,j:m+1,line:lines1[k],type:d});
|
|
|
|
diffSummary.b.push({i:m+1,j:k+1,line:lines2[m],type:d});
|
|
|
|
k++;
|
|
|
|
m++;
|
|
|
|
} else if (diffMap[(k + 1)][m] >= diffMap[k][(m + 1)]) {
|
|
|
|
diffSummary.a.push({i:k+1,line:lines1[k],type:1});
|
|
|
|
k++;
|
|
|
|
} else {
|
|
|
|
diffSummary.b.push({i:m+1,line:lines2[m],type:4});
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((k < i) || (m < j)) {
|
|
|
|
if (k == i) {
|
|
|
|
diffSummary.b.push({i:m+1,line:lines2[m],type:4});
|
|
|
|
m++;
|
|
|
|
} else if (m == j) {
|
|
|
|
diffSummary.a.push({i:k+1,line:lines1[k],type:1});
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return diffSummary;
|
|
|
|
}
|
|
|
|
|
|
|
|
function compareLines(string1, string2, ignoreWhitespace) {
|
|
|
|
if (ignoreWhitespace) {
|
|
|
|
if (string1 === string2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return string1.trim() === string2.trime() ? 2 : 1;
|
|
|
|
}
|
|
|
|
return string1 === string2 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
function createUnifiedDiffTable(files,commitOptions) {
|
2017-10-10 00:37:19 +02:00
|
|
|
var diffPanel = $('<div></div>');
|
|
|
|
files.forEach(function(file) {
|
|
|
|
var hunks = file.hunks;
|
2017-12-11 18:05:27 +01:00
|
|
|
var isBinary = file.binary;
|
2018-02-14 00:09:51 +01:00
|
|
|
var codeTable = $("<table>",{class:"node-text-diff-content"}).appendTo(diffPanel);
|
2017-10-10 00:37:19 +02:00
|
|
|
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
|
|
|
|
var codeBody = $('<tbody>').appendTo(codeTable);
|
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
var diffFileRow = $('<tr class="node-text-diff-file-header">').appendTo(codeBody);
|
|
|
|
var content = $('<td colspan="3"></td>').appendTo(diffFileRow);
|
|
|
|
|
|
|
|
var chevron = $('<i class="node-diff-chevron fa fa-angle-down"></i>').appendTo(content);
|
|
|
|
diffFileRow.click(function(e) {
|
|
|
|
diffFileRow.toggleClass("collapsed");
|
|
|
|
var isCollapsed = diffFileRow.hasClass("collapsed");
|
|
|
|
diffFileRow.nextUntil(".node-text-diff-file-header").toggle(!isCollapsed);
|
|
|
|
})
|
2017-11-22 00:31:41 +01:00
|
|
|
var label = $('<span class="filename"></span>').text(file.file).appendTo(content);
|
|
|
|
|
|
|
|
var conflictHeader;
|
|
|
|
var unresolvedConflicts = 0;
|
|
|
|
var resolvedConflicts = 0;
|
|
|
|
var conflictResolutions = {};
|
2018-02-14 00:09:51 +01:00
|
|
|
if (commitOptions.project.files && commitOptions.project.files.flow === file.file) {
|
|
|
|
if (commitOptions.unmerged) {
|
|
|
|
$('<span style="float: right;"><span id="node-diff-toolbar-resolved-conflicts"></span></span>').appendTo(content);
|
|
|
|
}
|
|
|
|
// var tools = $('<span style="float: right;" class="button-group"></span>').appendTo(content);
|
|
|
|
// $('<button class="editor-button editor-button-small">show flow diff</button>').appendTo(tools).click(function(e) {
|
|
|
|
// e.preventDefault();
|
|
|
|
// e.stopPropagation();
|
|
|
|
// var projectName = commitOptions.project.name;
|
|
|
|
// var filename = commitOptions.project.files.flow;
|
|
|
|
// var commonVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.commonRev+"/"+filename;
|
|
|
|
// var oldVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.oldRev+"/"+filename;
|
|
|
|
// var newVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.newRev+"/"+filename;
|
|
|
|
// var promises = [];
|
|
|
|
// if (commitOptions.commonRev) {
|
|
|
|
// var commonVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.commonRev+"/"+filename;
|
|
|
|
// promises.push($.getJSON(commonVersionUrl));
|
|
|
|
// } else {
|
|
|
|
// promises.push($.when(null));
|
|
|
|
// }
|
|
|
|
// promises.push($.getJSON(oldVersionUrl));
|
|
|
|
// promises.push($.getJSON(newVersionUrl));
|
|
|
|
// $.when.apply($,promises).done(function(commonVersion, oldVersion,newVersion) {
|
|
|
|
// var commonFlow;
|
|
|
|
// var oldFlow;
|
|
|
|
// var newFlow;
|
|
|
|
// if (commonVersion) {
|
|
|
|
// try {
|
|
|
|
// commonFlow = JSON.parse(commonVersion[0].content||"[]");
|
|
|
|
// } catch(err) {
|
|
|
|
// console.log("Common Version doesn't contain valid JSON:",commonVersionUrl);
|
|
|
|
// console.log(err);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// try {
|
|
|
|
// oldFlow = JSON.parse(oldVersion[0].content||"[]");
|
|
|
|
// } catch(err) {
|
|
|
|
// console.log("Old Version doesn't contain valid JSON:",oldVersionUrl);
|
|
|
|
// console.log(err);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// if (!commonFlow) {
|
|
|
|
// commonFlow = oldFlow;
|
|
|
|
// }
|
|
|
|
// try {
|
|
|
|
// newFlow = JSON.parse(newVersion[0].content||"[]");
|
|
|
|
// } catch(err) {
|
|
|
|
// console.log("New Version doesn't contain valid JSON:",newFlow);
|
|
|
|
// console.log(err);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// var localDiff = generateDiff(commonFlow,oldFlow);
|
|
|
|
// var remoteDiff = generateDiff(commonFlow,newFlow);
|
|
|
|
// var diff = resolveDiffs(localDiff,remoteDiff);
|
|
|
|
// showDiff(diff,{
|
|
|
|
// title: filename,
|
|
|
|
// mode: commitOptions.commonRev?'merge':'view',
|
|
|
|
// oldRevTitle: commitOptions.oldRevTitle,
|
|
|
|
// newRevTitle: commitOptions.newRevTitle
|
|
|
|
// });
|
|
|
|
// // var flowDiffRow = $("<tr>").insertAfter(diffRow);
|
|
|
|
// // var content = $('<td colspan="3"></td>').appendTo(flowDiffRow);
|
|
|
|
// // currentDiff = diff;
|
|
|
|
// // var diffTable = buildDiffPanel(content,diff,{mode:"view"}).finish();
|
|
|
|
// });
|
|
|
|
// })
|
|
|
|
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
|
|
|
var flowDiffContent = $('<td class="flow-diff" colspan="3"></td>').appendTo(diffRow);
|
|
|
|
|
|
|
|
var projectName = commitOptions.project.name;
|
|
|
|
var filename = commitOptions.project.files.flow;
|
|
|
|
var commonVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.commonRev+"/"+filename;
|
|
|
|
var oldVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.oldRev+"/"+filename;
|
|
|
|
var newVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.newRev+"/"+filename;
|
|
|
|
var promises = [$.Deferred(),$.Deferred(),$.Deferred()];
|
|
|
|
if (commitOptions.commonRev) {
|
|
|
|
var commonVersionUrl = "/projects/"+projectName+"/files/"+commitOptions.commonRev+"/"+filename;
|
|
|
|
$.ajax({dataType: "json",url: commonVersionUrl}).then(function(data) { promises[0].resolve(data); }).fail(function() { promises[0].resolve(null);})
|
|
|
|
} else {
|
|
|
|
promises[0].resolve(null);
|
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
|
2018-02-14 00:09:51 +01:00
|
|
|
$.ajax({dataType: "json",url: oldVersionUrl}).then(function(data) { promises[1].resolve(data); }).fail(function() { promises[1].resolve({content:"[]"});})
|
|
|
|
$.ajax({dataType: "json",url: newVersionUrl}).then(function(data) { promises[2].resolve(data); }).fail(function() { promises[2].resolve({content:"[]"});})
|
|
|
|
$.when.apply($,promises).always(function(commonVersion, oldVersion,newVersion) {
|
|
|
|
var commonFlow;
|
|
|
|
var oldFlow;
|
|
|
|
var newFlow;
|
|
|
|
if (commonVersion) {
|
2017-10-25 16:26:24 +02:00
|
|
|
try {
|
2018-02-14 00:09:51 +01:00
|
|
|
commonFlow = JSON.parse(commonVersion.content||"[]");
|
2017-10-25 16:26:24 +02:00
|
|
|
} catch(err) {
|
2018-02-14 00:09:51 +01:00
|
|
|
console.log("Common Version doesn't contain valid JSON:",commonVersionUrl);
|
2017-10-25 16:26:24 +02:00
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
2018-02-14 00:09:51 +01:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
oldFlow = JSON.parse(oldVersion.content||"[]");
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Old Version doesn't contain valid JSON:",oldVersionUrl);
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!commonFlow) {
|
|
|
|
commonFlow = oldFlow;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
newFlow = JSON.parse(newVersion.content||"[]");
|
|
|
|
} catch(err) {
|
|
|
|
console.log("New Version doesn't contain valid JSON:",newFlow);
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var localDiff = generateDiff(commonFlow,oldFlow);
|
|
|
|
var remoteDiff = generateDiff(commonFlow,newFlow);
|
|
|
|
commitOptions.currentDiff = resolveDiffs(localDiff,remoteDiff);
|
|
|
|
var diffTable = buildDiffPanel(flowDiffContent,commitOptions.currentDiff,{
|
|
|
|
title: filename,
|
|
|
|
mode: commitOptions.commonRev?'merge':'view',
|
|
|
|
oldRevTitle: commitOptions.oldRevTitle,
|
|
|
|
newRevTitle: commitOptions.newRevTitle
|
2017-10-25 16:26:24 +02:00
|
|
|
});
|
2018-02-14 00:09:51 +01:00
|
|
|
diffTable.list.hide();
|
|
|
|
refreshConflictHeader(commitOptions.currentDiff);
|
|
|
|
setTimeout(function() {
|
|
|
|
diffTable.finish();
|
|
|
|
diffTable.list.show();
|
|
|
|
},300);
|
|
|
|
// var flowDiffRow = $("<tr>").insertAfter(diffRow);
|
|
|
|
// var content = $('<td colspan="3"></td>').appendTo(flowDiffRow);
|
|
|
|
// currentDiff = diff;
|
|
|
|
// var diffTable = buildDiffPanel(content,diff,{mode:"view"}).finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
2017-10-25 16:26:24 +02:00
|
|
|
|
2017-12-11 18:05:27 +01:00
|
|
|
if (isBinary) {
|
|
|
|
var diffBinaryRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
|
|
|
var binaryContent = $('<td colspan="3"></td>').appendTo(diffBinaryRow);
|
|
|
|
$('<span></span>').text("Cannot show binary file contents").appendTo(binaryContent);
|
2017-10-25 16:26:24 +02:00
|
|
|
|
2017-12-11 18:05:27 +01:00
|
|
|
} else {
|
2018-02-14 00:09:51 +01:00
|
|
|
if (commitOptions.unmerged) {
|
|
|
|
conflictHeader = $('<span style="float: right;"><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(content);
|
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
hunks.forEach(function(hunk) {
|
|
|
|
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
|
|
|
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
|
|
|
var label = $('<span></span>').text(hunk.header).appendTo(content);
|
|
|
|
var isConflict = hunk.conflict;
|
|
|
|
var localLine = hunk.localStartLine;
|
|
|
|
var remoteLine = hunk.remoteStartLine;
|
2017-11-22 00:31:41 +01:00
|
|
|
if (isConflict) {
|
2017-12-11 18:05:27 +01:00
|
|
|
unresolvedConflicts++;
|
2017-11-22 00:31:41 +01:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
|
|
|
|
hunk.lines.forEach(function(lineText,lineNumber) {
|
|
|
|
// if (lineText[0] === '\\' || lineText === "") {
|
|
|
|
// // Comment line - bail out of this hunk
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
|
|
|
var actualLineNumber = hunk.diffStart + lineNumber;
|
2018-02-08 23:22:58 +01:00
|
|
|
var isMergeHeader = isConflict && /^\+\+(<<<<<<<|=======$|>>>>>>>)/.test(lineText);
|
2017-12-11 18:05:27 +01:00
|
|
|
var diffRow = $('<tr>').appendTo(codeBody);
|
|
|
|
var localLineNo = $('<td class="lineno">').appendTo(diffRow);
|
|
|
|
var remoteLineNo;
|
|
|
|
if (!isMergeHeader) {
|
|
|
|
remoteLineNo = $('<td class="lineno">').appendTo(diffRow);
|
2017-11-22 00:31:41 +01:00
|
|
|
} else {
|
2017-12-11 18:05:27 +01:00
|
|
|
localLineNo.attr('colspan',2);
|
2017-11-22 00:31:41 +01:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
var line = $('<td class="linetext">').appendTo(diffRow);
|
|
|
|
var prefixStart = 0;
|
|
|
|
var prefixEnd = 1;
|
|
|
|
if (isConflict) {
|
|
|
|
prefixEnd = 2;
|
2017-11-22 00:31:41 +01:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
if (!isMergeHeader) {
|
|
|
|
var changeMarker = lineText[0];
|
|
|
|
if (isConflict && !commitOptions.unmerged && changeMarker === ' ') {
|
|
|
|
changeMarker = lineText[1];
|
|
|
|
}
|
|
|
|
$('<span class="prefix">').text(changeMarker).appendTo(line);
|
|
|
|
var handledlLine = false;
|
|
|
|
if (isConflict && commitOptions.unmerged) {
|
|
|
|
$('<span class="prefix">').text(lineText[1]).appendTo(line);
|
|
|
|
if (lineText[0] === '+') {
|
|
|
|
localLineNo.text(localLine++);
|
|
|
|
handledlLine = true;
|
|
|
|
}
|
|
|
|
if (lineText[1] === '+') {
|
|
|
|
remoteLineNo.text(remoteLine++);
|
|
|
|
handledlLine = true;
|
|
|
|
}
|
2017-11-22 00:31:41 +01:00
|
|
|
} else {
|
2017-12-11 18:05:27 +01:00
|
|
|
if (lineText[0] === '+' || (isConflict && lineText[1] === '+')) {
|
|
|
|
localLineNo.addClass("added");
|
|
|
|
remoteLineNo.addClass("added");
|
|
|
|
line.addClass("added");
|
|
|
|
remoteLineNo.text(remoteLine++);
|
|
|
|
handledlLine = true;
|
|
|
|
} else if (lineText[0] === '-' || (isConflict && lineText[1] === '-')) {
|
|
|
|
localLineNo.addClass("removed");
|
|
|
|
remoteLineNo.addClass("removed");
|
|
|
|
line.addClass("removed");
|
|
|
|
localLineNo.text(localLine++);
|
|
|
|
handledlLine = true;
|
|
|
|
}
|
2017-11-22 00:31:41 +01:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
if (!handledlLine) {
|
|
|
|
line.addClass("unchanged");
|
|
|
|
if (localLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
|
|
|
localLineNo.text(localLine++);
|
|
|
|
}
|
|
|
|
if (remoteLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
|
|
|
remoteLineNo.text(remoteLine++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
|
2017-11-22 00:31:41 +01:00
|
|
|
} else {
|
2017-12-11 18:05:27 +01:00
|
|
|
diffRow.addClass("mergeHeader");
|
2018-02-08 23:22:58 +01:00
|
|
|
var isSeparator = /^\+\+=======$/.test(lineText);
|
2017-12-11 18:05:27 +01:00
|
|
|
if (!isSeparator) {
|
|
|
|
var isOurs = /^..<<<<<<</.test(lineText);
|
|
|
|
if (isOurs) {
|
|
|
|
$('<span>').text("<<<<<<< Local Changes").appendTo(line);
|
|
|
|
hunk.localChangeStart = actualLineNumber;
|
|
|
|
} else {
|
|
|
|
hunk.remoteChangeEnd = actualLineNumber;
|
|
|
|
$('<span>').text(">>>>>>> Remote Changes").appendTo(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
diffRow.addClass("mergeHeader-"+(isOurs?"ours":"theirs"));
|
|
|
|
$('<button class="editor-button editor-button-small" style="float: right; margin-right: 20px;"><i class="fa fa-angle-double-'+(isOurs?"down":"up")+'"></i> use '+(isOurs?"local":"remote")+' changes</button>')
|
|
|
|
.appendTo(line)
|
|
|
|
.click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
resolvedConflicts++;
|
|
|
|
var addedRows;
|
|
|
|
var midRow;
|
|
|
|
if (isOurs) {
|
|
|
|
addedRows = diffRow.nextUntil(".mergeHeader-separator");
|
|
|
|
midRow = addedRows.last().next();
|
|
|
|
midRow.nextUntil(".mergeHeader").remove();
|
|
|
|
midRow.next().remove();
|
|
|
|
} else {
|
|
|
|
addedRows = diffRow.prevUntil(".mergeHeader-separator");
|
|
|
|
midRow = addedRows.last().prev();
|
|
|
|
midRow.prevUntil(".mergeHeader").remove();
|
|
|
|
midRow.prev().remove();
|
|
|
|
}
|
|
|
|
midRow.remove();
|
|
|
|
diffRow.remove();
|
|
|
|
addedRows.find(".linetext").addClass('added');
|
|
|
|
conflictHeader.empty();
|
|
|
|
$('<span><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(conflictHeader);
|
|
|
|
|
|
|
|
conflictResolutions[file.file] = conflictResolutions[file.file] || {};
|
|
|
|
conflictResolutions[file.file][hunk.localChangeStart] = {
|
|
|
|
changeStart: hunk.localChangeStart,
|
|
|
|
separator: hunk.changeSeparator,
|
|
|
|
changeEnd: hunk.remoteChangeEnd,
|
|
|
|
selection: isOurs?"A":"B"
|
|
|
|
}
|
|
|
|
if (commitOptions.resolveConflict) {
|
|
|
|
commitOptions.resolveConflict({
|
|
|
|
conflicts: unresolvedConflicts,
|
|
|
|
resolved: resolvedConflicts,
|
|
|
|
resolutions: conflictResolutions
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
hunk.changeSeparator = actualLineNumber;
|
|
|
|
diffRow.addClass("mergeHeader-separator");
|
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
});
|
2017-11-22 00:31:41 +01:00
|
|
|
});
|
2017-12-11 18:05:27 +01:00
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
});
|
|
|
|
return diffPanel;
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
function showCommitDiff(options) {
|
|
|
|
var commit = parseCommitDiff(options.commit);
|
2017-10-09 01:11:07 +02:00
|
|
|
var trayOptions = {
|
2017-10-25 16:26:24 +02:00
|
|
|
title: "View Commit Changes", //TODO: nls
|
2017-10-09 01:11:07 +02:00
|
|
|
width: Infinity,
|
|
|
|
overlay: true,
|
|
|
|
buttons: [
|
|
|
|
{
|
2017-10-25 16:26:24 +02:00
|
|
|
text: RED._("common.label.close"),
|
2017-10-09 01:11:07 +02:00
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(dimensions) {
|
|
|
|
// trayWidth = dimensions.width;
|
|
|
|
},
|
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
|
|
|
var diffPanel = $('<div class="node-text-diff"></div>').appendTo(trayBody);
|
|
|
|
|
2018-02-14 00:09:51 +01:00
|
|
|
var codeTable = $("<table>",{class:"node-text-diff-content"}).appendTo(diffPanel);
|
2017-10-09 01:11:07 +02:00
|
|
|
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
|
|
|
|
var codeBody = $('<tbody>').appendTo(codeTable);
|
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
var diffRow = $('<tr class="node-text-diff-commit-header">').appendTo(codeBody);
|
2017-10-10 00:37:19 +02:00
|
|
|
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
2017-10-09 01:11:07 +02:00
|
|
|
|
2017-10-25 16:26:24 +02:00
|
|
|
$("<h3>").text(commit.title).appendTo(content);
|
|
|
|
$('<div class="commit-body"></div>').text(commit.comment).appendTo(content);
|
|
|
|
var summary = $('<div class="commit-summary"></div>').appendTo(content);
|
|
|
|
$('<div style="float: right">').text("Commit "+commit.sha).appendTo(summary);
|
|
|
|
$('<div>').text((commit.authorName||commit.author)+" - "+options.date).appendTo(summary);
|
2017-10-09 01:11:07 +02:00
|
|
|
|
2017-11-22 00:31:41 +01:00
|
|
|
if (commit.files) {
|
|
|
|
createUnifiedDiffTable(commit.files,options).appendTo(diffPanel);
|
|
|
|
}
|
2017-10-09 01:11:07 +02:00
|
|
|
|
|
|
|
|
2017-10-10 00:37:19 +02:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
diffVisible = false;
|
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RED.tray.show(trayOptions);
|
|
|
|
}
|
2017-10-25 16:26:24 +02:00
|
|
|
function showUnifiedDiff(options) {
|
|
|
|
var diff = options.diff;
|
|
|
|
var title = options.title;
|
2017-10-10 00:37:19 +02:00
|
|
|
var files = parseUnifiedDiff(diff);
|
2017-11-22 00:31:41 +01:00
|
|
|
|
|
|
|
var currentResolution;
|
|
|
|
if (options.unmerged) {
|
|
|
|
options.resolveConflict = function(results) {
|
|
|
|
currentResolution = results;
|
|
|
|
if (results.conflicts === results.resolved) {
|
|
|
|
$("#node-diff-view-resolve-diff").removeClass('disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 00:37:19 +02:00
|
|
|
var trayOptions = {
|
|
|
|
title: title||"Compare Changes", //TODO: nls
|
|
|
|
width: Infinity,
|
|
|
|
overlay: true,
|
|
|
|
buttons: [
|
|
|
|
{
|
2017-11-22 00:31:41 +01:00
|
|
|
text: RED._((options.unmerged)?"common.label.cancel":"common.label.close"),
|
2017-10-10 00:37:19 +02:00
|
|
|
click: function() {
|
2017-11-22 00:31:41 +01:00
|
|
|
if (options.oncancel) {
|
|
|
|
options.oncancel();
|
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
RED.tray.close();
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
],
|
|
|
|
resize: function(dimensions) {
|
|
|
|
// trayWidth = dimensions.width;
|
|
|
|
},
|
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
|
|
|
var diffPanel = $('<div class="node-text-diff"></div>').appendTo(trayBody);
|
2017-10-25 16:26:24 +02:00
|
|
|
createUnifiedDiffTable(files,options).appendTo(diffPanel);
|
2017-10-09 01:11:07 +02:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
diffVisible = false;
|
|
|
|
},
|
|
|
|
show: function() {
|
2017-08-20 23:59:51 +02:00
|
|
|
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 00:31:41 +01:00
|
|
|
if (options.unmerged) {
|
|
|
|
trayOptions.buttons.push(
|
|
|
|
{
|
|
|
|
id: "node-diff-view-resolve-diff",
|
|
|
|
text: "Save conflict resolution",
|
|
|
|
class: "primary disabled",
|
|
|
|
click: function() {
|
|
|
|
if (!$("#node-diff-view-resolve-diff").hasClass('disabled')) {
|
2018-02-14 00:09:51 +01:00
|
|
|
if (options.currentDiff) {
|
|
|
|
// This is a flow file. Need to apply the diff
|
|
|
|
// and generate the new flow.
|
|
|
|
var result = applyDiff(options.currentDiff);
|
|
|
|
currentResolution = {
|
|
|
|
resolutions:{}
|
|
|
|
};
|
|
|
|
currentResolution.resolutions[options.project.files.flow] = JSON.stringify(result.config,"",4);
|
|
|
|
}
|
2017-11-22 00:31:41 +01:00
|
|
|
if (options.onresolve) {
|
|
|
|
options.onresolve(currentResolution);
|
|
|
|
}
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-10-09 01:11:07 +02:00
|
|
|
RED.tray.show(trayOptions);
|
2017-10-10 00:37:19 +02:00
|
|
|
}
|
2017-10-09 01:11:07 +02:00
|
|
|
|
2017-10-10 00:37:19 +02:00
|
|
|
function parseCommitDiff(diff) {
|
2017-10-25 16:26:24 +02:00
|
|
|
var result = {};
|
2017-10-10 00:37:19 +02:00
|
|
|
var lines = diff.split("\n");
|
2017-10-25 16:26:24 +02:00
|
|
|
var comment = [];
|
2017-10-10 00:37:19 +02:00
|
|
|
for (var i=0;i<lines.length;i++) {
|
2017-10-25 16:26:24 +02:00
|
|
|
if (/^commit /.test(lines[i])) {
|
|
|
|
result.sha = lines[i].substring(7);
|
|
|
|
} else if (/^Author: /.test(lines[i])) {
|
|
|
|
result.author = lines[i].substring(8);
|
|
|
|
var m = /^(.*) <(.*)>$/.exec(result.author);
|
|
|
|
if (m) {
|
|
|
|
result.authorName = m[1];
|
|
|
|
result.authorEmail = m[2];
|
|
|
|
}
|
|
|
|
} else if (/^Date: /.test(lines[i])) {
|
|
|
|
result.date = lines[i].substring(8);
|
|
|
|
} else if (/^ /.test(lines[i])) {
|
|
|
|
if (!result.title) {
|
|
|
|
result.title = lines[i].substring(4);
|
|
|
|
} else {
|
|
|
|
if (lines[i].length !== 4 || comment.length > 0) {
|
|
|
|
comment.push(lines[i].substring(4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (/^diff /.test(lines[i])) {
|
2017-10-10 00:37:19 +02:00
|
|
|
result.files = parseUnifiedDiff(lines.slice(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-25 16:26:24 +02:00
|
|
|
result.comment = comment.join("\n");
|
2017-10-10 00:37:19 +02:00
|
|
|
return result;
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
|
|
|
function parseUnifiedDiff(diff) {
|
2017-10-10 00:37:19 +02:00
|
|
|
var lines;
|
|
|
|
if (Array.isArray(diff)) {
|
|
|
|
lines = diff;
|
|
|
|
} else {
|
|
|
|
lines = diff.split("\n");
|
|
|
|
}
|
2018-02-08 23:22:58 +01:00
|
|
|
var diffHeader = /^diff (?:(?:--git a\/(.*) b\/(.*))|(?:--cc (.*)))$/;
|
2017-10-10 00:37:19 +02:00
|
|
|
var fileHeader = /^\+\+\+ b\/(.*)\t?/;
|
2017-12-11 18:05:27 +01:00
|
|
|
var binaryFile = /^Binary files /;
|
2017-10-10 00:37:19 +02:00
|
|
|
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
|
2017-11-22 00:31:41 +01:00
|
|
|
var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/;
|
2017-10-10 00:37:19 +02:00
|
|
|
var files = [];
|
|
|
|
var currentFile;
|
2017-10-09 01:11:07 +02:00
|
|
|
var hunks = [];
|
|
|
|
var currentHunk;
|
|
|
|
for (var i=0;i<lines.length;i++) {
|
2017-10-10 00:37:19 +02:00
|
|
|
var line = lines[i];
|
2017-12-11 18:05:27 +01:00
|
|
|
var diffLine = diffHeader.exec(line);
|
|
|
|
if (diffLine) {
|
2017-10-10 00:37:19 +02:00
|
|
|
if (currentHunk) {
|
|
|
|
currentFile.hunks.push(currentHunk);
|
|
|
|
files.push(currentFile);
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
currentHunk = null;
|
|
|
|
currentFile = {
|
2018-02-08 23:22:58 +01:00
|
|
|
file: diffLine[1]||diffLine[3],
|
2017-10-10 00:37:19 +02:00
|
|
|
hunks: []
|
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
} else if (binaryFile.test(line)) {
|
|
|
|
if (currentFile) {
|
|
|
|
currentFile.binary = true;
|
|
|
|
}
|
2017-10-10 00:37:19 +02:00
|
|
|
} else {
|
|
|
|
var fileLine = fileHeader.exec(line);
|
|
|
|
if (fileLine) {
|
|
|
|
currentFile.file = fileLine[1];
|
|
|
|
} else {
|
|
|
|
var hunkLine = hunkHeader.exec(line);
|
|
|
|
if (hunkLine) {
|
|
|
|
if (currentHunk) {
|
|
|
|
currentFile.hunks.push(currentHunk);
|
|
|
|
}
|
|
|
|
currentHunk = {
|
|
|
|
header: line,
|
|
|
|
localStartLine: hunkLine[2],
|
|
|
|
localLength: hunkLine[4]||1,
|
|
|
|
remoteStartLine: hunkLine[6],
|
|
|
|
remoteLength: hunkLine[8]||1,
|
2017-11-22 00:31:41 +01:00
|
|
|
lines: [],
|
|
|
|
conflict: false
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
hunkLine = conflictHunkHeader.exec(line);
|
|
|
|
if (hunkLine) {
|
|
|
|
if (currentHunk) {
|
|
|
|
currentFile.hunks.push(currentHunk);
|
2017-10-10 00:37:19 +02:00
|
|
|
}
|
2017-11-22 00:31:41 +01:00
|
|
|
currentHunk = {
|
|
|
|
header: line,
|
|
|
|
localStartLine: hunkLine[2],
|
|
|
|
localLength: hunkLine[4]||1,
|
|
|
|
remoteStartLine: hunkLine[6],
|
|
|
|
remoteLength: hunkLine[8]||1,
|
|
|
|
diffStart: parseInt(hunkLine[10]),
|
|
|
|
lines: [],
|
|
|
|
conflict: true
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (currentHunk) {
|
2017-10-10 00:37:19 +02:00
|
|
|
currentHunk.lines.push(line);
|
|
|
|
}
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentHunk) {
|
2017-10-10 00:37:19 +02:00
|
|
|
currentFile.hunks.push(currentHunk);
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
2017-12-11 18:05:27 +01:00
|
|
|
files.push(currentFile);
|
2017-10-10 00:37:19 +02:00
|
|
|
return files;
|
2017-10-09 01:11:07 +02:00
|
|
|
}
|
2017-08-20 23:59:51 +02:00
|
|
|
|
2016-12-07 14:51:20 +01:00
|
|
|
return {
|
2016-12-20 20:42:38 +01:00
|
|
|
init: init,
|
|
|
|
getRemoteDiff: getRemoteDiff,
|
2017-01-01 01:18:39 +01:00
|
|
|
showRemoteDiff: showRemoteDiff,
|
2017-10-09 01:11:07 +02:00
|
|
|
showUnifiedDiff: showUnifiedDiff,
|
2017-10-10 00:37:19 +02:00
|
|
|
showCommitDiff: showCommitDiff,
|
2017-01-01 01:18:39 +01:00
|
|
|
mergeDiff: mergeDiff
|
2016-12-07 14:51:20 +01:00
|
|
|
}
|
|
|
|
})();
|