diff --git a/src/js/client.js b/src/js/client.js index 08699574f..6e9a1f17c 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -693,6 +693,20 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }).error(defaultErrorHandler(callback)); }; + Client.prototype.startAddon = function (addon, callback) { + post('/api/v1/addons/' + addon + '/start').success(function (data, status) { + if (status !== 202) return callback(new ClientError(status, data)); + callback(null); + }).error(defaultErrorHandler(callback)); + }; + + Client.prototype.stopAddon = function (addon, callback) { + post('/api/v1/addons/' + addon + '/stop').success(function (data, status) { + if (status !== 202) return callback(new ClientError(status, data)); + callback(null); + }).error(defaultErrorHandler(callback)); + }; + Client.prototype.getUsers = function (callback) { get('/api/v1/users').success(function (data, status) { if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); diff --git a/src/views/addons.html b/src/views/addons.html index 2eab05a87..16a94ae21 100644 --- a/src/views/addons.html +++ b/src/views/addons.html @@ -26,7 +26,7 @@
-

+

@@ -36,14 +36,14 @@ Addon - Status + Memory Actions - + {{ addon.name }} @@ -52,9 +52,9 @@ - - - - + + + diff --git a/src/views/addons.js b/src/views/addons.js index bd1781b6a..98b0b80c8 100644 --- a/src/views/addons.js +++ b/src/views/addons.js @@ -1,17 +1,37 @@ 'use strict'; +/* global angular */ + angular.module('Application').controller('AddonsController', ['$scope', '$location', 'Client', function ($scope, $location, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); }); $scope.ready = false; $scope.addons = []; - Client.onReady(function () { + function refresh() { Client.getAddons(function (error, result) { if (error) return Client.error(error); - $scope.addons = result.map(function (a) { return { name: a }; }); + $scope.addons = result.map(function (a) { return { name: a, state: 'active' }; }); $scope.ready = true; }); - }); + } + + $scope.startAddon = function (addonName) { + Client.startAddon(addonName, function (error) { + if (error) return Client.error(error); + + refresh(); + }); + }; + + $scope.stopAddon = function (addonName) { + Client.stopAddon(addonName, function (error) { + if (error) return Client.error(error); + + refresh(); + }); + }; + + Client.onReady(refresh); }]);