2015-04-30 21:41:52 +00:00
|
|
|
(function () {
|
|
|
|
|
|
|
|
function AgentsCtrl($scope, $window, users, agents) {
|
2015-05-18 22:47:13 +00:00
|
|
|
// this is the address that agents should connect with.
|
|
|
|
$scope.addr = $window.location.origin;
|
|
|
|
|
|
|
|
// Gets the currently authenticated user
|
2015-04-30 21:41:52 +00:00
|
|
|
users.getCached().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
|
|
|
|
2015-05-18 22:47:13 +00:00
|
|
|
// Generages a remote agents.
|
|
|
|
agents.getAgents().then(function(payload){
|
|
|
|
$scope.agents = payload.data;
|
2015-04-30 21:41:52 +00:00
|
|
|
});
|
2015-05-18 22:47:13 +00:00
|
|
|
|
|
|
|
$scope.onDelete = function(agent) {
|
|
|
|
console.log("delete agent", agent)
|
|
|
|
agents.deleteAgent(agent).then(function(payload){
|
|
|
|
var index = $scope.agents.indexOf(agent);
|
|
|
|
$scope.agents.splice(index, 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.newAgent={address: ""};
|
|
|
|
$scope.onAdd = function(agent) {
|
|
|
|
agents.postAgent(agent).then(function(payload){
|
|
|
|
$scope.agents.push(payload.data);
|
|
|
|
$scope.newAgent={address: ""};
|
|
|
|
});
|
|
|
|
}
|
2015-04-30 21:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('drone')
|
|
|
|
.controller('AgentsCtrl', AgentsCtrl);
|
|
|
|
})();
|