Allow TypeSearch to include a filter option

This commit is contained in:
Nick O'Leary 2018-12-18 10:57:33 +00:00
parent dc2d3bc7c0
commit 84cc2ad0fa
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 16 additions and 6 deletions

View File

@ -200,7 +200,7 @@ RED.typeSearch = (function() {
dialog.hide();
searchResultsDiv.hide();
}
refreshTypeList();
refreshTypeList(opts);
addCallback = opts.add;
closeCallback = opts.close;
RED.events.emit("type-search:open");
@ -254,21 +254,29 @@ RED.typeSearch = (function() {
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;
searchResults.editableList('empty');
searchInput.searchBox('value','');
selected = -1;
var common = [
'inject','debug','function','change','switch'
];
].filter(function(t) { return applyFilter(opts.filter,t,RED.nodes.getType(t)); });
var recentlyUsed = Object.keys(typesUsed);
recentlyUsed.sort(function(a,b) {
return typesUsed[b]-typesUsed[a];
});
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 = [];
@ -313,8 +321,10 @@ RED.typeSearch = (function() {
searchResults.editableList('addItem', item);
}
for (i=0;i<items.length;i++) {
items[i].i = index++;
searchResults.editableList('addItem', items[i]);
if (applyFilter(opts.filter,items[i].type,items[i].def)) {
items[i].i = index++;
searchResults.editableList('addItem', items[i]);
}
}
setTimeout(function() {
selected = 0;