mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Separate catalogue refresh logic from UI creation
This commit is contained in:
parent
83c4ac5f65
commit
a69a35aacf
@ -389,9 +389,39 @@ RED.palette.editor = (function() {
|
|||||||
|
|
||||||
var activeSort = sortModulesRelevance;
|
var activeSort = sortModulesRelevance;
|
||||||
|
|
||||||
|
function refreshCatalogues (done) {
|
||||||
|
catalogueLoadStatus = [];
|
||||||
|
catalogueLoadErrors = false;
|
||||||
|
catalogueCount = catalogues.length;
|
||||||
|
loadedList = []
|
||||||
|
loadedIndex = {}
|
||||||
|
loadedCatalogs.length = 0
|
||||||
|
let handled = 0
|
||||||
|
for (let index = 0; index < catalogues.length; index++) {
|
||||||
|
const url = catalogues[index];
|
||||||
|
$.getJSON(url, {_: new Date().getTime()},function(v) {
|
||||||
|
loadedCatalogs.push({ index: index, url: url, name: v.name, updated_at: v.updated_at, modules_count: (v.modules || []).length })
|
||||||
|
handleCatalogResponse(null,{ url: url, name: v.name},index,v);
|
||||||
|
}).fail(function(jqxhr, textStatus, error) {
|
||||||
|
console.warn("Error loading catalog",url,":",error);
|
||||||
|
handleCatalogResponse(jqxhr,url,index);
|
||||||
|
}).always(function() {
|
||||||
|
handled++;
|
||||||
|
if (handled === catalogueCount) {
|
||||||
|
//sort loadedCatalogs by e.index ascending
|
||||||
|
loadedCatalogs.sort((a, b) => a.index - b.index)
|
||||||
|
refreshUpdateStatus();
|
||||||
|
if (done) {
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleCatalogResponse(err,catalog,index,v) {
|
function handleCatalogResponse(err,catalog,index,v) {
|
||||||
const url = catalog.url
|
const url = catalog.url
|
||||||
catalogueLoadStatus.push(err||v);
|
catalogueLoadStatus.push(err);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (v.modules) {
|
if (v.modules) {
|
||||||
v.modules = v.modules.filter(function(m) {
|
v.modules = v.modules.filter(function(m) {
|
||||||
@ -421,9 +451,6 @@ RED.palette.editor = (function() {
|
|||||||
} else {
|
} else {
|
||||||
catalogueLoadErrors = true;
|
catalogueLoadErrors = true;
|
||||||
}
|
}
|
||||||
if (catalogueCount > 1) {
|
|
||||||
$(".red-ui-palette-module-shade-status").html(RED._('palette.editor.loading')+"<br>"+catalogueLoadStatus.length+"/"+catalogueCount);
|
|
||||||
}
|
|
||||||
if (catalogueLoadStatus.length === catalogueCount) {
|
if (catalogueLoadStatus.length === catalogueCount) {
|
||||||
if (catalogueLoadErrors) {
|
if (catalogueLoadErrors) {
|
||||||
RED.notify(RED._('palette.editor.errors.catalogLoadFailed',{url: url}),"error",false,8000);
|
RED.notify(RED._('palette.editor.errors.catalogLoadFailed',{url: url}),"error",false,8000);
|
||||||
@ -444,37 +471,18 @@ RED.palette.editor = (function() {
|
|||||||
packageList.editableList('empty');
|
packageList.editableList('empty');
|
||||||
|
|
||||||
$(".red-ui-palette-module-shade-status").text(RED._('palette.editor.loading'));
|
$(".red-ui-palette-module-shade-status").text(RED._('palette.editor.loading'));
|
||||||
|
|
||||||
catalogueLoadStatus = [];
|
|
||||||
catalogueLoadErrors = false;
|
|
||||||
catalogueCount = catalogues.length;
|
|
||||||
if (catalogues.length > 1) {
|
|
||||||
$(".red-ui-palette-module-shade-status").html(RED._('palette.editor.loading')+"<br>0/"+catalogues.length);
|
|
||||||
}
|
|
||||||
$("#red-ui-palette-module-install-shade").show();
|
$("#red-ui-palette-module-install-shade").show();
|
||||||
catalogueLoadStart = Date.now();
|
refreshCatalogues(function () {
|
||||||
var handled = 0;
|
refreshNodeModuleList();
|
||||||
loadedCatalogs.length = 0; // clear the loadedCatalogs array
|
updateCatalogFilter(loadedCatalogs)
|
||||||
for (let index = 0; index < catalogues.length; index++) {
|
const delta = 250-(Date.now() - catalogueLoadStart);
|
||||||
const url = catalogues[index];
|
setTimeout(function() {
|
||||||
$.getJSON(url, {_: new Date().getTime()},function(v) {
|
$("#red-ui-palette-module-install-shade").hide();
|
||||||
loadedCatalogs.push({ index: index, url: url, name: v.name, updated_at: v.updated_at, modules_count: (v.modules || []).length })
|
},Math.max(delta,0));
|
||||||
handleCatalogResponse(null,{ url: url, name: v.name},index,v);
|
})
|
||||||
refreshNodeModuleList();
|
} else {
|
||||||
}).fail(function(jqxhr, textStatus, error) {
|
refreshNodeModuleList();
|
||||||
console.warn("Error loading catalog",url,":",error);
|
updateCatalogFilter(loadedCatalogs)
|
||||||
handleCatalogResponse(jqxhr,url,index);
|
|
||||||
}).always(function() {
|
|
||||||
handled++;
|
|
||||||
if (handled === catalogueCount) {
|
|
||||||
//sort loadedCatalogs by e.index ascending
|
|
||||||
loadedCatalogs.sort((a, b) => a.index - b.index)
|
|
||||||
updateCatalogFilter(loadedCatalogs)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Now all catalogs have been loaded, refresh the update status
|
|
||||||
refreshUpdateStatus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +496,6 @@ RED.palette.editor = (function() {
|
|||||||
if (catalogSelection.length === 0) {
|
if (catalogSelection.length === 0) {
|
||||||
// sidebar not yet loaded (red-catalogue-filter-select is not in dom)
|
// sidebar not yet loaded (red-catalogue-filter-select is not in dom)
|
||||||
if (maxRetry > 0) {
|
if (maxRetry > 0) {
|
||||||
// console.log("updateCatalogFilter: sidebar not yet loaded, retrying in 100ms")
|
|
||||||
// try again in 100ms
|
// try again in 100ms
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updateCatalogFilter(catalogEntries, maxRetry - 1)
|
updateCatalogFilter(catalogEntries, maxRetry - 1)
|
||||||
@ -629,8 +636,8 @@ RED.palette.editor = (function() {
|
|||||||
|
|
||||||
// Add the update status to the status bar
|
// Add the update status to the status bar
|
||||||
addUpdateInfoToStatusBar();
|
addUpdateInfoToStatusBar();
|
||||||
// Load the catalogue and check for updates
|
|
||||||
getSettingsPane();
|
refreshCatalogues()
|
||||||
|
|
||||||
RED.actions.add("core:manage-palette",function() {
|
RED.actions.add("core:manage-palette",function() {
|
||||||
RED.userSettings.show('palette');
|
RED.userSettings.show('palette');
|
||||||
@ -1499,26 +1506,29 @@ RED.palette.editor = (function() {
|
|||||||
updateStatus({ count: 0 });
|
updateStatus({ count: 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pendingRefreshTimeout
|
||||||
function refreshUpdateStatus() {
|
function refreshUpdateStatus() {
|
||||||
updateAvailable = [];
|
clearTimeout(pendingRefreshTimeout)
|
||||||
|
pendingRefreshTimeout = setTimeout(() => {
|
||||||
for (const module of Object.keys(nodeEntries)) {
|
updateAvailable = [];
|
||||||
if (loadedIndex.hasOwnProperty(module)) {
|
for (const module of Object.keys(nodeEntries)) {
|
||||||
const moduleInfo = nodeEntries[module].info;
|
if (loadedIndex.hasOwnProperty(module)) {
|
||||||
if (moduleInfo.pending_version) {
|
const moduleInfo = nodeEntries[module].info;
|
||||||
// Module updated
|
if (moduleInfo.pending_version) {
|
||||||
continue;
|
// Module updated
|
||||||
}
|
continue;
|
||||||
if (updateAllowed &&
|
}
|
||||||
semVerCompare(loadedIndex[module].version, moduleInfo.version) > 0 &&
|
if (updateAllowed &&
|
||||||
RED.utils.checkModuleAllowed(module, null, updateAllowList, updateDenyList)
|
semVerCompare(loadedIndex[module].version, moduleInfo.version) > 0 &&
|
||||||
) {
|
RED.utils.checkModuleAllowed(module, null, updateAllowList, updateDenyList)
|
||||||
updateAvailable.push(module);
|
) {
|
||||||
|
updateAvailable.push(module);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
updateStatus({ count: updateAvailable.length });
|
updateStatus({ count: updateAvailable.length });
|
||||||
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatus(opts) {
|
function updateStatus(opts) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user