diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index 5533f6a79..3c81b6e2c 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -389,9 +389,39 @@ RED.palette.editor = (function() { 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) { const url = catalog.url - catalogueLoadStatus.push(err||v); + catalogueLoadStatus.push(err); if (!err) { if (v.modules) { v.modules = v.modules.filter(function(m) { @@ -421,9 +451,6 @@ RED.palette.editor = (function() { } else { catalogueLoadErrors = true; } - if (catalogueCount > 1) { - $(".red-ui-palette-module-shade-status").html(RED._('palette.editor.loading')+"
"+catalogueLoadStatus.length+"/"+catalogueCount); - } if (catalogueLoadStatus.length === catalogueCount) { if (catalogueLoadErrors) { RED.notify(RED._('palette.editor.errors.catalogLoadFailed',{url: url}),"error",false,8000); @@ -444,37 +471,18 @@ RED.palette.editor = (function() { packageList.editableList('empty'); $(".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')+"
0/"+catalogues.length); - } $("#red-ui-palette-module-install-shade").show(); - catalogueLoadStart = Date.now(); - var handled = 0; - loadedCatalogs.length = 0; // clear the loadedCatalogs array - 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); - refreshNodeModuleList(); - }).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) - updateCatalogFilter(loadedCatalogs) - } - }) - } - // Now all catalogs have been loaded, refresh the update status - refreshUpdateStatus(); + refreshCatalogues(function () { + refreshNodeModuleList(); + updateCatalogFilter(loadedCatalogs) + const delta = 250-(Date.now() - catalogueLoadStart); + setTimeout(function() { + $("#red-ui-palette-module-install-shade").hide(); + },Math.max(delta,0)); + }) + } else { + refreshNodeModuleList(); + updateCatalogFilter(loadedCatalogs) } } @@ -488,7 +496,6 @@ RED.palette.editor = (function() { if (catalogSelection.length === 0) { // sidebar not yet loaded (red-catalogue-filter-select is not in dom) if (maxRetry > 0) { - // console.log("updateCatalogFilter: sidebar not yet loaded, retrying in 100ms") // try again in 100ms setTimeout(() => { updateCatalogFilter(catalogEntries, maxRetry - 1) @@ -629,8 +636,8 @@ RED.palette.editor = (function() { // Add the update status to the status bar addUpdateInfoToStatusBar(); - // Load the catalogue and check for updates - getSettingsPane(); + + refreshCatalogues() RED.actions.add("core:manage-palette",function() { RED.userSettings.show('palette'); @@ -1499,26 +1506,29 @@ RED.palette.editor = (function() { updateStatus({ count: 0 }); } + let pendingRefreshTimeout function refreshUpdateStatus() { - updateAvailable = []; - - for (const module of Object.keys(nodeEntries)) { - if (loadedIndex.hasOwnProperty(module)) { - const moduleInfo = nodeEntries[module].info; - if (moduleInfo.pending_version) { - // Module updated - continue; - } - if (updateAllowed && - semVerCompare(loadedIndex[module].version, moduleInfo.version) > 0 && - RED.utils.checkModuleAllowed(module, null, updateAllowList, updateDenyList) - ) { - updateAvailable.push(module); + clearTimeout(pendingRefreshTimeout) + pendingRefreshTimeout = setTimeout(() => { + updateAvailable = []; + for (const module of Object.keys(nodeEntries)) { + if (loadedIndex.hasOwnProperty(module)) { + const moduleInfo = nodeEntries[module].info; + if (moduleInfo.pending_version) { + // Module updated + continue; + } + if (updateAllowed && + semVerCompare(loadedIndex[module].version, moduleInfo.version) > 0 && + RED.utils.checkModuleAllowed(module, null, updateAllowList, updateDenyList) + ) { + updateAvailable.push(module); + } } } - } - updateStatus({ count: updateAvailable.length }); + updateStatus({ count: updateAvailable.length }); + }, 200) } function updateStatus(opts) {