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:
parent
21866634b3
commit
7006c00233
@ -26,7 +26,6 @@ RED.search = (function() {
|
|||||||
var currentResults = [];
|
var currentResults = [];
|
||||||
var previousActiveElement;
|
var previousActiveElement;
|
||||||
|
|
||||||
|
|
||||||
function indexProperty(node,label,property) {
|
function indexProperty(node,label,property) {
|
||||||
if (typeof property === 'string' || typeof property === 'number') {
|
if (typeof property === 'string' || typeof property === 'number') {
|
||||||
property = (""+property).toLowerCase();
|
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) {
|
function search(val) {
|
||||||
var results = [];
|
var results = [];
|
||||||
var keys = Object.keys(index);
|
var keys = Object.keys(index);
|
||||||
@ -74,11 +85,17 @@ RED.search = (function() {
|
|||||||
val = val.replace(/(?:^| )type:[^ ]+/,"");
|
val = val.replace(/(?:^| )type:[^ ]+/,"");
|
||||||
typeFilter = m[1];
|
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();
|
val = val.trim();
|
||||||
|
|
||||||
|
if (val.length > 0 || typeFilter || hasFlags) {
|
||||||
if (val.length > 0 || typeFilter) {
|
|
||||||
val = val.toLowerCase();
|
val = val.toLowerCase();
|
||||||
var i;
|
var i;
|
||||||
var j;
|
var j;
|
||||||
@ -91,6 +108,31 @@ RED.search = (function() {
|
|||||||
var ids = Object.keys(index[key]);
|
var ids = Object.keys(index[key]);
|
||||||
for (j=0;j<ids.length;j++) {
|
for (j=0;j<ids.length;j++) {
|
||||||
var node = index[key][ids[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) {
|
if (!typeFilter || node.node.type === typeFilter) {
|
||||||
nodes[node.node.id] = nodes[node.node.id] = {
|
nodes[node.node.id] = nodes[node.node.id] = {
|
||||||
node: node.node,
|
node: node.node,
|
||||||
@ -370,15 +412,15 @@ RED.search = (function() {
|
|||||||
$("#red-ui-sidebar-shade").on('mousedown',hide);
|
$("#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:add", addItemToIndex);
|
||||||
RED.events.on("flows:remove", removeItemFromIndex)
|
RED.events.on("flows:remove", removeItemFromIndex);
|
||||||
RED.events.on("flows:change", updateItemOnIndex)
|
RED.events.on("flows:change", updateItemOnIndex);
|
||||||
|
|
||||||
RED.events.on("subflows:add", addItemToIndex)
|
RED.events.on("subflows:add", addItemToIndex);
|
||||||
RED.events.on("subflows:remove", removeItemFromIndex)
|
RED.events.on("subflows:remove", removeItemFromIndex);
|
||||||
RED.events.on("subflows:change", updateItemOnIndex)
|
RED.events.on("subflows:change", updateItemOnIndex);
|
||||||
|
|
||||||
RED.events.on("nodes:add",addItemToIndex);
|
RED.events.on("nodes:add",addItemToIndex);
|
||||||
RED.events.on("nodes:remove",removeItemFromIndex);
|
RED.events.on("nodes:remove",removeItemFromIndex);
|
||||||
|
Loading…
Reference in New Issue
Block a user