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