mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Redo Delete unused configs button for new dev layout
This commit is contained in:
parent
d887ab126b
commit
93d5db9752
@ -462,6 +462,7 @@
|
|||||||
"flows": "flows",
|
"flows": "flows",
|
||||||
"filterUnused":"unused",
|
"filterUnused":"unused",
|
||||||
"filterAll":"all",
|
"filterAll":"all",
|
||||||
|
"deleteUnused":"Delete unused",
|
||||||
"filtered": "__count__ hidden"
|
"filtered": "__count__ hidden"
|
||||||
},
|
},
|
||||||
"context": {
|
"context": {
|
||||||
|
@ -15,17 +15,16 @@
|
|||||||
**/
|
**/
|
||||||
RED.sidebar.config = (function() {
|
RED.sidebar.config = (function() {
|
||||||
|
|
||||||
|
|
||||||
var content = document.createElement("div");
|
var content = document.createElement("div");
|
||||||
content.className = "sidebar-node-config";
|
content.className = "sidebar-node-config";
|
||||||
|
|
||||||
$('<div class="button-group sidebar-header">'+
|
$('<div class="button-group sidebar-header">'+
|
||||||
'<a class="sidebar-header-button-toggle selected" id="workspace-config-node-filter-all" href="#"><span data-i18n="sidebar.config.filterAll"></span></a>'+
|
'<a style="float:left;" class="sidebar-header-button selected" id="workspace-config-node-delete-all" href="#"><span data-i18n="sidebar.config.deleteUnused"></a>'+
|
||||||
'<a class="sidebar-header-button-toggle" id="workspace-config-node-filter-unused" href="#"><span data-i18n="sidebar.config.filterUnused"></span></a> '+
|
'<a class="sidebar-header-button-toggle" id="workspace-config-node-filter-all" href="#"><span data-i18n="sidebar.config.filterAll"></span></a>'+
|
||||||
|
'<a class="sidebar-header-button-toggle selected" id="workspace-config-node-filter-unused" href="#"><span data-i18n="sidebar.config.filterUnused"></span></a> '+
|
||||||
'</div>'
|
'</div>'
|
||||||
).appendTo(content);
|
).appendTo(content);
|
||||||
|
|
||||||
|
|
||||||
var toolbar = $('<div>'+
|
var toolbar = $('<div>'+
|
||||||
'<a class="sidebar-footer-button" id="workspace-config-node-collapse-all" href="#"><i class="fa fa-angle-double-up"></i></a> '+
|
'<a class="sidebar-footer-button" id="workspace-config-node-collapse-all" href="#"><i class="fa fa-angle-double-up"></i></a> '+
|
||||||
'<a class="sidebar-footer-button" id="workspace-config-node-expand-all" href="#"><i class="fa fa-angle-double-down"></i></a>'+
|
'<a class="sidebar-footer-button" id="workspace-config-node-expand-all" href="#"><i class="fa fa-angle-double-down"></i></a>'+
|
||||||
@ -36,7 +35,7 @@ RED.sidebar.config = (function() {
|
|||||||
var subflowCategories = $("<div>").appendTo(content);
|
var subflowCategories = $("<div>").appendTo(content);
|
||||||
|
|
||||||
var showUnusedOnly = false;
|
var showUnusedOnly = false;
|
||||||
|
var unused = [];
|
||||||
var categories = {};
|
var categories = {};
|
||||||
|
|
||||||
function getOrCreateCategory(name,parent,label) {
|
function getOrCreateCategory(name,parent,label) {
|
||||||
@ -110,6 +109,17 @@ RED.sidebar.config = (function() {
|
|||||||
if (A.type > B.type) { return 1;}
|
if (A.type > B.type) { return 1;}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unused = nodes.filter(function(n) {
|
||||||
|
return n._def.hasUsers!==false && n.users.length === 0;
|
||||||
|
})
|
||||||
|
|
||||||
|
if (unused.length > 0) {
|
||||||
|
$('#workspace-config-node-delete-all').addClass("selected");
|
||||||
|
} else {
|
||||||
|
$('#workspace-config-node-delete-all').removeClass("selected");
|
||||||
|
}
|
||||||
|
|
||||||
if (showUnusedOnly) {
|
if (showUnusedOnly) {
|
||||||
var hiddenCount = nodes.length;
|
var hiddenCount = nodes.length;
|
||||||
nodes = nodes.filter(function(n) {
|
nodes = nodes.filter(function(n) {
|
||||||
@ -152,6 +162,7 @@ RED.sidebar.config = (function() {
|
|||||||
entry.on('dblclick',function(e) {
|
entry.on('dblclick',function(e) {
|
||||||
RED.editor.editConfig("", node.type, node.id);
|
RED.editor.editConfig("", node.type, node.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
var userArray = node.users.map(function(n) { return n.id });
|
var userArray = node.users.map(function(n) { return n.id });
|
||||||
entry.on('mouseover',function(e) {
|
entry.on('mouseover',function(e) {
|
||||||
RED.nodes.eachNode(function(node) {
|
RED.nodes.eachNode(function(node) {
|
||||||
@ -244,6 +255,41 @@ RED.sidebar.config = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$("#workspace-config-node-delete-all").on("click", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
unused.forEach(function(node) {
|
||||||
|
var configTypeDef = RED.nodes.getType(node.type);
|
||||||
|
if (configTypeDef.oneditdelete) {
|
||||||
|
configTypeDef.oneditdelete.call(node);
|
||||||
|
}
|
||||||
|
var historyEvent = {
|
||||||
|
t:'delete',
|
||||||
|
nodes:[node],
|
||||||
|
changes: {},
|
||||||
|
dirty: RED.nodes.dirty()
|
||||||
|
}
|
||||||
|
for (var i=0; i<node.users.length; i++) {
|
||||||
|
var user = node.users[i];
|
||||||
|
historyEvent.changes[user.id] = {
|
||||||
|
changed: user.changed,
|
||||||
|
valid: user.valid
|
||||||
|
};
|
||||||
|
for (var d in user._def.defaults) {
|
||||||
|
if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
|
||||||
|
historyEvent.changes[user.id][d] = configId
|
||||||
|
user[d] = "";
|
||||||
|
user.changed = true;
|
||||||
|
user.dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
validateNode(user);
|
||||||
|
}
|
||||||
|
RED.nodes.remove(node.id);
|
||||||
|
RED.nodes.dirty(true);
|
||||||
|
RED.view.redraw(true);
|
||||||
|
RED.history.push(historyEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
$('#workspace-config-node-filter-all').on("click",function(e) {
|
$('#workspace-config-node-filter-all').on("click",function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (showUnusedOnly) {
|
if (showUnusedOnly) {
|
||||||
@ -262,9 +308,8 @@ RED.sidebar.config = (function() {
|
|||||||
refreshConfigNodeList();
|
refreshConfigNodeList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(id) {
|
function show(id) {
|
||||||
if (typeof id === 'boolean') {
|
if (typeof id === 'boolean') {
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -306,6 +351,7 @@ RED.sidebar.config = (function() {
|
|||||||
}
|
}
|
||||||
RED.sidebar.show("config");
|
RED.sidebar.show("config");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init:init,
|
init:init,
|
||||||
show:show,
|
show:show,
|
||||||
|
Loading…
Reference in New Issue
Block a user