1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add support for is:XYZ search flags

- is:unused
 - is:config
 - is:subflow
 - is:invalid
This commit is contained in:
Nick O'Leary 2020-06-08 11:55:24 +01:00
parent 21866634b3
commit 7006c00233
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -26,7 +26,6 @@ RED.search = (function() {
var currentResults = [];
var previousActiveElement;
function indexProperty(node,label,property) {
if (typeof property === 'string' || typeof property === 'number') {
property = (""+property).toLowerCase();
@ -65,6 +64,18 @@ RED.search = (function() {
}
}
function extractFlag(val, flagName, flags) {
// is:XYZ
var regEx = new RegExp("(?:^| )is:"+flagName+"(?: |$)");
var m = regEx.exec(val);
if (m) {
val = val.replace(regEx," ").trim();
flags[flagName] = true;
}
return val;
}
function search(val) {
var results = [];
var keys = Object.keys(index);
@ -74,11 +85,17 @@ RED.search = (function() {
val = val.replace(/(?:^| )type:[^ ]+/,"");
typeFilter = m[1];
}
var flags = {};
val = extractFlag(val,"invalid",flags);
val = extractFlag(val,"unused",flags);
val = extractFlag(val,"config",flags);
val = extractFlag(val,"subflow",flags);
var hasFlags = Object.keys(flags).length > 0;
val = val.trim();
if (val.length > 0 || typeFilter) {
if (val.length > 0 || typeFilter || hasFlags) {
val = val.toLowerCase();
var i;
var j;
@ -91,6 +108,31 @@ RED.search = (function() {
var ids = Object.keys(index[key]);
for (j=0;j<ids.length;j++) {
var node = index[key][ids[j]];
var isConfigNode = node.node._def.category === "config" && node.node.type !== 'group';
if (flags.hasOwnProperty("invalid")) {
var nodeIsValid = !node.node.hasOwnProperty("valid") || node.node.valid;
if (flags.invalid === nodeIsValid) {
continue;
}
}
if (flags.hasOwnProperty("config")) {
if (flags.config !== isConfigNode) {
continue;
}
}
if (flags.hasOwnProperty("subflow")) {
if (flags.subflow !== (node.node.type === 'subflow')) {
continue;
}
}
if (flags.hasOwnProperty("unused")) {
var isUnused = (node.node.type === 'subflow' && node.node.instances.length === 0) ||
(isConfigNode && node.node.users.length === 0)
if (flags.unused !== isUnused) {
continue;
}
}
if (!typeFilter || node.node.type === typeFilter) {
nodes[node.node.id] = nodes[node.node.id] = {
node: node.node,
@ -370,15 +412,15 @@ RED.search = (function() {
$("#red-ui-sidebar-shade").on('mousedown',hide);
RED.events.on("workspace:clear", clearIndex)
RED.events.on("workspace:clear", clearIndex);
RED.events.on("flows:add", addItemToIndex)
RED.events.on("flows:remove", removeItemFromIndex)
RED.events.on("flows:change", updateItemOnIndex)
RED.events.on("flows:add", addItemToIndex);
RED.events.on("flows:remove", removeItemFromIndex);
RED.events.on("flows:change", updateItemOnIndex);
RED.events.on("subflows:add", addItemToIndex)
RED.events.on("subflows:remove", removeItemFromIndex)
RED.events.on("subflows:change", updateItemOnIndex)
RED.events.on("subflows:add", addItemToIndex);
RED.events.on("subflows:remove", removeItemFromIndex);
RED.events.on("subflows:change", updateItemOnIndex);
RED.events.on("nodes:add",addItemToIndex);
RED.events.on("nodes:remove",removeItemFromIndex);