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",
|
||||
"filterUnused":"unused",
|
||||
"filterAll":"all",
|
||||
"deleteUnused":"Delete unused",
|
||||
"filtered": "__count__ hidden"
|
||||
},
|
||||
"context": {
|
||||
|
@ -15,17 +15,16 @@
|
||||
**/
|
||||
RED.sidebar.config = (function() {
|
||||
|
||||
|
||||
var content = document.createElement("div");
|
||||
content.className = "sidebar-node-config";
|
||||
|
||||
$('<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 class="sidebar-header-button-toggle" id="workspace-config-node-filter-unused" href="#"><span data-i18n="sidebar.config.filterUnused"></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-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>'
|
||||
).appendTo(content);
|
||||
|
||||
|
||||
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-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 showUnusedOnly = false;
|
||||
|
||||
var unused = [];
|
||||
var categories = {};
|
||||
|
||||
function getOrCreateCategory(name,parent,label) {
|
||||
@ -110,6 +109,17 @@ RED.sidebar.config = (function() {
|
||||
if (A.type > B.type) { return 1;}
|
||||
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) {
|
||||
var hiddenCount = nodes.length;
|
||||
nodes = nodes.filter(function(n) {
|
||||
@ -152,6 +162,7 @@ RED.sidebar.config = (function() {
|
||||
entry.on('dblclick',function(e) {
|
||||
RED.editor.editConfig("", node.type, node.id);
|
||||
});
|
||||
|
||||
var userArray = node.users.map(function(n) { return n.id });
|
||||
entry.on('mouseover',function(e) {
|
||||
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) {
|
||||
e.preventDefault();
|
||||
if (showUnusedOnly) {
|
||||
@ -262,9 +308,8 @@ RED.sidebar.config = (function() {
|
||||
refreshConfigNodeList();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function show(id) {
|
||||
if (typeof id === 'boolean') {
|
||||
if (id) {
|
||||
@ -306,6 +351,7 @@ RED.sidebar.config = (function() {
|
||||
}
|
||||
RED.sidebar.show("config");
|
||||
}
|
||||
|
||||
return {
|
||||
init:init,
|
||||
show:show,
|
||||
|
Loading…
Reference in New Issue
Block a user