mirror of https://github.com/node-red/node-red.git
Handle no info.downloads use case for custom catalogues
parent
ea25406d00
commit
a2cb730a52
|
@ -597,10 +597,26 @@ RED.palette.editor = (function() {
|
|||
}
|
||||
}
|
||||
function sortModulesRelevance(A,B) {
|
||||
return sortModulesDownloads(A,B);
|
||||
const defaultSort = sortModulesDownloads(A,B);
|
||||
const currentFilter = searchInput.searchBox('value').trim();
|
||||
if (defaultSort === 0) {
|
||||
// same number of downloads
|
||||
if (currentFilter === "") {
|
||||
return sortModulesAZ(A,B);
|
||||
}
|
||||
var i = A.info.index.indexOf(currentFilter) - B.info.index.indexOf(currentFilter);
|
||||
if (i === 0) {
|
||||
return sortModulesAZ(A,B);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return defaultSort;
|
||||
}
|
||||
function sortModulesDownloads(A,B) {
|
||||
return B.info.downloads.week - A.info.downloads.week;
|
||||
// check A has the info.downloads property - if not exising, prioritise it (likely a custom user catalogue)
|
||||
const a = A.info && typeof A.info.downloads !== 'undefined' ? A.info.downloads.week : Number.MAX_SAFE_INTEGER;
|
||||
const b = B.info && typeof B.info.downloads !== 'undefined' ? B.info.downloads.week : Number.MAX_SAFE_INTEGER;
|
||||
return b - a;
|
||||
}
|
||||
function sortModulesAZ(A,B) {
|
||||
return A.info.id.localeCompare(B.info.id);
|
||||
|
|
Loading…
Reference in New Issue