Handle addon state correctly

This commit is contained in:
Johannes Zellner
2018-11-18 20:01:53 +01:00
parent c07224cab5
commit 082323511a
2 changed files with 24 additions and 11 deletions
+20 -8
View File
@@ -6,14 +6,13 @@ angular.module('Application').controller('AddonsController', ['$scope', '$locati
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
$scope.ready = false;
$scope.addons = [];
$scope.addons = {};
function refresh() {
Client.getAddons(function (error, result) {
function refresh(addonName) {
Client.getAddon(addonName, function (error, result) {
if (error) return Client.error(error);
$scope.addons = result.map(function (a) { return { name: a, state: 'active' }; });
$scope.ready = true;
$scope.addons[addonName] = result;
});
}
@@ -21,7 +20,7 @@ angular.module('Application').controller('AddonsController', ['$scope', '$locati
Client.startAddon(addonName, function (error) {
if (error) return Client.error(error);
refresh();
refresh(addonName);
});
};
@@ -29,9 +28,22 @@ angular.module('Application').controller('AddonsController', ['$scope', '$locati
Client.stopAddon(addonName, function (error) {
if (error) return Client.error(error);
refresh();
refresh(addonName);
});
};
Client.onReady(refresh);
Client.onReady(function () {
Client.getAddons(function (error, result) {
if (error) return Client.error(error);
result.forEach(function (a) {
$scope.addons[a] = { name: a };
// just kick off the status fetching
refresh(a);
});
$scope.ready = true;
});
});
}]);