From 1e37fed90b3556c33c0b9240e52ae773a57bd70b Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 8 Jan 2017 20:51:31 +0000 Subject: [PATCH] Report node catalogue load errors Closes #1009 --- editor/js/ui/palette-editor.js | 50 +++++++++++++++++++------------ red/api/locales/en-US/editor.json | 1 + 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/editor/js/ui/palette-editor.js b/editor/js/ui/palette-editor.js index f93d007ce..6646c10b1 100644 --- a/editor/js/ui/palette-editor.js +++ b/editor/js/ui/palette-editor.js @@ -338,36 +338,45 @@ RED.palette.editor = (function() { var catalogueCount; var catalogueLoadStatus = []; var catalogueLoadStart; + var catalogueLoadErrors = false; var activeSort = sortModulesAZ; - function handleCatalogResponse(catalog,index,v) { - catalogueLoadStatus.push(v); - if (v.modules) { - v.modules.forEach(function(m) { - loadedIndex[m.id] = m; - m.index = [m.id]; - if (m.keywords) { - m.index = m.index.concat(m.keywords); - } - if (m.updated_at) { - m.timestamp = new Date(m.updated_at).getTime(); - } else { - m.timestamp = 0; - } - m.index = m.index.join(",").toLowerCase(); - }) - loadedList = loadedList.concat(v.modules); + function handleCatalogResponse(err,catalog,index,v) { + catalogueLoadStatus.push(err||v); + if (!err) { + if (v.modules) { + v.modules.forEach(function(m) { + loadedIndex[m.id] = m; + m.index = [m.id]; + if (m.keywords) { + m.index = m.index.concat(m.keywords); + } + if (m.updated_at) { + m.timestamp = new Date(m.updated_at).getTime(); + } else { + m.timestamp = 0; + } + m.index = m.index.join(",").toLowerCase(); + }) + loadedList = loadedList.concat(v.modules); + } + searchInput.searchBox('count',loadedList.length); + } else { + catalogueLoadErrors = true; } - searchInput.searchBox('count',loadedList.length); if (catalogueCount > 1) { $(".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: catalog}),"error",false,8000); + } var delta = 250-(Date.now() - catalogueLoadStart); setTimeout(function() { $("#palette-module-install-shade").hide(); },Math.max(delta,0)); + } } @@ -379,6 +388,7 @@ RED.palette.editor = (function() { $(".palette-module-shade-status").html(RED._('palette.editor.loading')); var catalogues = RED.settings.theme('palette.catalogues')||['https://catalogue.nodered.org/catalogue.json']; catalogueLoadStatus = []; + catalogueLoadErrors = false; catalogueCount = catalogues.length; if (catalogues.length > 1) { $(".palette-module-shade-status").html(RED._('palette.editor.loading')+"
0/"+catalogues.length); @@ -387,8 +397,10 @@ RED.palette.editor = (function() { catalogueLoadStart = Date.now(); catalogues.forEach(function(catalog,index) { $.getJSON(catalog, {_: new Date().getTime()},function(v) { - handleCatalogResponse(catalog,index,v); + handleCatalogResponse(null,catalog,index,v); refreshNodeModuleList(); + }).fail(function(jqxhr, textStatus, error) { + handleCatalogResponse(jqxhr,catalog,index); }) }); } diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index fdb737d07..0b855955c 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -292,6 +292,7 @@ "sortRecent": "recent", "more": "+ __count__ more", "errors": { + "catalogLoadFailed": "Failed to load node catalogue.
Check the browser console for more information", "installFailed": "Failed to install: __module__
__message__
Check the log for more information", "removeFailed": "Failed to remove: __module__
__message__
Check the log for more information" }