mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow TypeSearch to include a filter option
This commit is contained in:
parent
dc2d3bc7c0
commit
84cc2ad0fa
@ -200,7 +200,7 @@ RED.typeSearch = (function() {
|
|||||||
dialog.hide();
|
dialog.hide();
|
||||||
searchResultsDiv.hide();
|
searchResultsDiv.hide();
|
||||||
}
|
}
|
||||||
refreshTypeList();
|
refreshTypeList(opts);
|
||||||
addCallback = opts.add;
|
addCallback = opts.add;
|
||||||
closeCallback = opts.close;
|
closeCallback = opts.close;
|
||||||
RED.events.emit("type-search:open");
|
RED.events.emit("type-search:open");
|
||||||
@ -254,21 +254,29 @@ RED.typeSearch = (function() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function refreshTypeList() {
|
function applyFilter(filter,type,def) {
|
||||||
|
return !filter ||
|
||||||
|
(
|
||||||
|
(!filter.type || type === filter.type) &&
|
||||||
|
(!filter.input || def.inputs > 0) &&
|
||||||
|
(!filter.output || def.outputs > 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
function refreshTypeList(opts) {
|
||||||
var i;
|
var i;
|
||||||
searchResults.editableList('empty');
|
searchResults.editableList('empty');
|
||||||
searchInput.searchBox('value','');
|
searchInput.searchBox('value','');
|
||||||
selected = -1;
|
selected = -1;
|
||||||
var common = [
|
var common = [
|
||||||
'inject','debug','function','change','switch'
|
'inject','debug','function','change','switch'
|
||||||
];
|
].filter(function(t) { return applyFilter(opts.filter,t,RED.nodes.getType(t)); });
|
||||||
|
|
||||||
var recentlyUsed = Object.keys(typesUsed);
|
var recentlyUsed = Object.keys(typesUsed);
|
||||||
recentlyUsed.sort(function(a,b) {
|
recentlyUsed.sort(function(a,b) {
|
||||||
return typesUsed[b]-typesUsed[a];
|
return typesUsed[b]-typesUsed[a];
|
||||||
});
|
});
|
||||||
recentlyUsed = recentlyUsed.filter(function(t) {
|
recentlyUsed = recentlyUsed.filter(function(t) {
|
||||||
return common.indexOf(t) === -1;
|
return applyFilter(opts.filter,t,RED.nodes.getType(t)) && common.indexOf(t) === -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = [];
|
var items = [];
|
||||||
@ -313,8 +321,10 @@ RED.typeSearch = (function() {
|
|||||||
searchResults.editableList('addItem', item);
|
searchResults.editableList('addItem', item);
|
||||||
}
|
}
|
||||||
for (i=0;i<items.length;i++) {
|
for (i=0;i<items.length;i++) {
|
||||||
items[i].i = index++;
|
if (applyFilter(opts.filter,items[i].type,items[i].def)) {
|
||||||
searchResults.editableList('addItem', items[i]);
|
items[i].i = index++;
|
||||||
|
searchResults.editableList('addItem', items[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
selected = 0;
|
selected = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user