Skip to content

Instantly share code, notes, and snippets.

@jtomasek
Created February 12, 2013 15:20
Show Gist options
  • Save jtomasek/4770585 to your computer and use it in GitHub Desktop.
Save jtomasek/4770585 to your computer and use it in GitHub Desktop.
// winged_monkey_services.js
var wingedMonkeyServices = angular.module('wingedMonkeyServices', ['ngResource']);
wingedMonkeyServices.factory("ProviderApplication", function($resource){
return $resource('provider_applications/:id/:action', {id: "@id"}, {
pause:{ method:'POST', params:{ action:'pause'} }
});
});
// winged_monkey_controllers.js
var wingedMonkeyControllers = angular.module('wingedMonkeyControllers',[]);
wingedMonkeyControllers.controller("ProviderAppsCtrl", function($scope, $filter, ProviderApplication) {
$scope.appsLoaded = false;
$scope.refreshProviderApps = function() {
ProviderApplication.query(function(data){
$scope.providerApps = data;
$scope.appsLoaded = true;
setTimeout($scope.refreshProviderApps, 20000);
});
};
$scope.refreshProviderApps();
$scope.destroyProviderApp = function(app_id) {
$scope.providerApps.forEach(function(app, index) {
if (app_id === app.id) {
app.$delete({id: app.id}, function(response) {
response.state = "DELETING"
// $scope.providerApps.splice(index, 1);
}, function(response){
//failure
console.log(response);
});
}
});
};
$scope.pauseProviderApp = function(app_id) {
$scope.providerApps.forEach(function(app, index) {
if (app_id === app.id) {
app.$pause({id: app.id}, function(response) {
response.state = "PAUSING"
}, function(response){
//failure
console.log(response);
});
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment