mirror of https://github.com/node-red/node-red.git
Ensure the order matches the flow file order
parent
f380744483
commit
a4875bf5f6
|
|
@ -233,6 +233,35 @@ var RED = (function() {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of [A,C,B,D,E] and [B,C] is [A,B,C,D,E].
|
||||
*
|
||||
* @param {string[]} storedOrder
|
||||
* @param {string[]} currentOrder
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function mergeTabOrder(storedOrder, currentOrder) {
|
||||
const result = [...storedOrder];
|
||||
|
||||
for (let i = 0; i < currentOrder.length; i++) {
|
||||
const current = currentOrder[i];
|
||||
const currentIndex = result.indexOf(current);
|
||||
|
||||
for (let j = i + 1; j < currentOrder.length; j++) {
|
||||
const next = currentOrder[j];
|
||||
const nextIndex = result.indexOf(next);
|
||||
|
||||
if (nextIndex < currentIndex) {
|
||||
result.splice(nextIndex, 1);
|
||||
const newIndex = result.indexOf(current) + 1;
|
||||
result.splice(newIndex, 0, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function loadFlows(done) {
|
||||
loader.reportProgress(RED._("event.loadFlows"),80 )
|
||||
$.ajax({
|
||||
|
|
@ -288,20 +317,17 @@ var RED = (function() {
|
|||
const tabOrder = JSON.parse(RED.settings.getLocal("tabOrder") || "[]");
|
||||
|
||||
if (tabOrder.length) {
|
||||
// Checks that the last session order contains all current flows
|
||||
// Otherwise, ignore the reorder
|
||||
const currentOrder = RED.nodes.getWorkspaceOrder();
|
||||
const orderNotUpToDate = currentOrder.some((t) => !tabOrder.includes(t));
|
||||
if (!orderNotUpToDate) {
|
||||
for (const tab of tabOrder) {
|
||||
// Add missing tabs
|
||||
RED.workspaces.show(tab, true);
|
||||
}
|
||||
// Restore the order from the last session
|
||||
RED.workspaces.order(tabOrder);
|
||||
// Select the active workspace again because adding missing tab has changed it
|
||||
RED.workspaces.show(activeWorkspace, true);
|
||||
// Ensure the order from last session matches the current order
|
||||
const newOrder = mergeTabOrder(tabOrder, currentOrder);
|
||||
for (const tab of newOrder) {
|
||||
// Add missing tabs
|
||||
RED.workspaces.show(tab, true);
|
||||
}
|
||||
// Restore the order from the last session
|
||||
RED.workspaces.order(newOrder);
|
||||
// Select the active workspace again because adding missing tab has changed it
|
||||
RED.workspaces.show(activeWorkspace, true);
|
||||
}
|
||||
|
||||
const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");
|
||||
|
|
|
|||
Loading…
Reference in New Issue