fix(webui): don't fail when backend or frontend are empty.

This commit is contained in:
Fernandez Ludovic 2017-06-16 00:34:35 +02:00 committed by Emile Vauge
parent d87c4d89e9
commit 0fb63f4488

View file

@ -12,25 +12,27 @@ angular
function Providers($resource, $q) { function Providers($resource, $q) {
const resourceProvider = $resource('../api/providers'); const resourceProvider = $resource('../api/providers');
return { return {
get: function() { get: function () {
return $q((resolve, reject) => { return $q((resolve, reject) => {
resourceProvider.get().$promise.then((rawProviders) => { resourceProvider.get()
.$promise
.then((rawProviders) => {
for (let providerName in rawProviders) { for (let providerName in rawProviders) {
if (rawProviders.hasOwnProperty(providerName)) { if (rawProviders.hasOwnProperty(providerName)) {
if (!providerName.startsWith('$')) { if (!providerName.startsWith('$')) {
// BackEnds mapping // BackEnds mapping
let bckends = rawProviders[providerName].backends; let bckends = rawProviders[providerName].backends || {};
rawProviders[providerName].backends = Object.keys(bckends)
rawProviders[providerName].backends = Object.keys(bckends).map(key => { .map(key => {
const goodBackend = bckends[key]; const goodBackend = bckends[key];
goodBackend.backendId = key; goodBackend.backendId = key;
return goodBackend; return goodBackend;
}); });
// FrontEnds mapping // FrontEnds mapping
let frtends = rawProviders[providerName].frontends; let frtends = rawProviders[providerName].frontends || {};
rawProviders[providerName].frontends = Object.keys(frtends)
rawProviders[providerName].frontends = Object.keys(frtends).map(key => { .map(key => {
const goodFrontend = frtends[key]; const goodFrontend = frtends[key];
goodFrontend.frontendId = key; goodFrontend.frontendId = key;
return goodFrontend; return goodFrontend;
@ -39,7 +41,8 @@ function Providers($resource, $q) {
} }
} }
resolve(rawProviders); resolve(rawProviders);
}).catch(reject); })
.catch(reject);
}); });
} }
}; };