mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
fix searching by type when type name has a space
This commit is contained in:
parent
5365786386
commit
598bcf675f
@ -175,9 +175,19 @@ RED.palette = (function() {
|
|||||||
$('<button type="button" onclick="RED.workspaces.show(\''+type.substring(8).replace(/'/g,"\\'")+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-pencil"></i></button>').appendTo(popOverContent)
|
$('<button type="button" onclick="RED.workspaces.show(\''+type.substring(8).replace(/'/g,"\\'")+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-pencil"></i></button>').appendTo(popOverContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
var safeType = type.replace(/'/g,"\\'");
|
const safeType = type.replace(/'/g,"\\'");
|
||||||
|
function wrapStr(str) {
|
||||||
|
if(str.indexOf(' ') >= 0) {
|
||||||
|
return '"' + str + '"'
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
$('<button type="button" onclick="RED.search.show(\'type:'+safeType+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-search"></i></button>').appendTo(popOverContent)
|
$('<button type="button"; return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-search"></i></button>')
|
||||||
|
.appendTo(popOverContent)
|
||||||
|
.on('click', function() {
|
||||||
|
RED.search.show('type:' + wrapStr(safeType))
|
||||||
|
})
|
||||||
$('<button type="button" onclick="RED.sidebar.help.show(\''+safeType+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-book"></i></button>').appendTo(popOverContent)
|
$('<button type="button" onclick="RED.sidebar.help.show(\''+safeType+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-book"></i></button>').appendTo(popOverContent)
|
||||||
|
|
||||||
$('<p>',{style:"font-size: 0.8em"}).text(metaData).appendTo(popOverContent);
|
$('<p>',{style:"font-size: 0.8em"}).text(metaData).appendTo(popOverContent);
|
||||||
|
@ -106,14 +106,26 @@ RED.search = (function() {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractType(val, flags) {
|
||||||
|
// extracts: type:XYZ & type:"X Y Z"
|
||||||
|
console.log(`extractType(val, flags): val:${val}`)
|
||||||
|
const regEx = /(?:type):\s*(?:"([^"]+)"|([^" ]+))/;
|
||||||
|
let m
|
||||||
|
while ((m = regEx.exec(val)) !== null) {
|
||||||
|
// avoid infinite loops with zero-width matches
|
||||||
|
if (m.index === regEx.lastIndex) {
|
||||||
|
regEx.lastIndex++;
|
||||||
|
}
|
||||||
|
val = val.replace(m[0]," ").trim()
|
||||||
|
const flag = m[2] || m[1] // quoted entries in capture group 1, unquoted in capture group 2
|
||||||
|
flags.type = flags.type || [];
|
||||||
|
flags.type.push(flag);
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
function search(val) {
|
function search(val) {
|
||||||
var results = [];
|
var results = [];
|
||||||
var typeFilter;
|
|
||||||
var m = /(?:^| )type:([^ ]+)/.exec(val);
|
|
||||||
if (m) {
|
|
||||||
val = val.replace(/(?:^| )type:[^ ]+/,"");
|
|
||||||
typeFilter = m[1];
|
|
||||||
}
|
|
||||||
var flags = {};
|
var flags = {};
|
||||||
val = extractFlag(val,"invalid",flags);
|
val = extractFlag(val,"invalid",flags);
|
||||||
val = extractFlag(val,"unused",flags);
|
val = extractFlag(val,"unused",flags);
|
||||||
@ -121,18 +133,20 @@ RED.search = (function() {
|
|||||||
val = extractFlag(val,"subflow",flags);
|
val = extractFlag(val,"subflow",flags);
|
||||||
val = extractFlag(val,"hidden",flags);
|
val = extractFlag(val,"hidden",flags);
|
||||||
val = extractFlag(val,"modified",flags);
|
val = extractFlag(val,"modified",flags);
|
||||||
val = extractValue(val,"flow",flags);// flow:active or flow:<flow-id>
|
val = extractValue(val,"flow",flags);// flow:current or flow:<flow-id>
|
||||||
val = extractValue(val,"uses",flags);// uses:<node-id>
|
val = extractValue(val,"uses",flags);// uses:<node-id>
|
||||||
|
val = extractType(val,flags);// uses:<node-id>
|
||||||
val = val.trim();
|
val = val.trim();
|
||||||
var hasFlags = Object.keys(flags).length > 0;
|
var hasFlags = Object.keys(flags).length > 0;
|
||||||
if (flags.flow && flags.flow.indexOf("current") >= 0) {
|
if (flags.flow && flags.flow.indexOf("current") >= 0) {
|
||||||
let idx = flags.flow.indexOf("current");
|
let idx = flags.flow.indexOf("current");
|
||||||
flags.flow[idx] = RED.workspaces.active();//convert active to flow ID
|
flags.flow[idx] = RED.workspaces.active();//convert 'current' to active flow ID
|
||||||
}
|
}
|
||||||
if (flags.flow && flags.flow.length) {
|
if (flags.flow && flags.flow.length) {
|
||||||
flags.flow = [ ...new Set(flags.flow) ]; //deduplicate
|
flags.flow = [ ...new Set(flags.flow) ]; //deduplicate
|
||||||
}
|
}
|
||||||
if (val.length > 0 || typeFilter || hasFlags) {
|
const hasTypeFilter = flags.type && flags.type.length > 0
|
||||||
|
if (val.length > 0 || hasFlags) {
|
||||||
val = val.toLowerCase();
|
val = val.toLowerCase();
|
||||||
var i;
|
var i;
|
||||||
var j;
|
var j;
|
||||||
@ -146,8 +160,8 @@ RED.search = (function() {
|
|||||||
}
|
}
|
||||||
for (i=0;i<keys.length;i++) {
|
for (i=0;i<keys.length;i++) {
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
var kpos = keys[i].indexOf(val);
|
var kpos = val ? keys[i].indexOf(val) : -1;
|
||||||
if (kpos > -1) {
|
if (kpos > -1 || (val === "" && hasTypeFilter)) {
|
||||||
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]];
|
||||||
@ -197,12 +211,16 @@ RED.search = (function() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!typeFilter || node.node.type === typeFilter) {
|
let typeIndex = -1
|
||||||
nodes[node.node.id] = nodes[node.node.id] = {
|
if(hasTypeFilter) {
|
||||||
|
typeIndex = flags.type.indexOf(node.node.type)
|
||||||
|
}
|
||||||
|
if (!hasTypeFilter || typeIndex > -1) {
|
||||||
|
nodes[node.node.id] = nodes[node.node.id] || {
|
||||||
node: node.node,
|
node: node.node,
|
||||||
label: node.label
|
label: node.label
|
||||||
};
|
};
|
||||||
nodes[node.node.id].index = Math.min(nodes[node.node.id].index||Infinity,kpos);
|
nodes[node.node.id].index = Math.min(nodes[node.node.id].index || Infinity, typeIndex > -1 ? typeIndex : kpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user