Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirezg committed Aug 10, 2015
1 parent f9e2ae8 commit 4143ff3
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 381 deletions.
92 changes: 47 additions & 45 deletions static/app/cloudfoundry.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,50 +174,52 @@
};

// Tells whether the web app should poll for newer app statuses.
// Useful for when we are in the middle of updating the app status ourselves and we don't
// want a poll to interrupt the UI.
var pollAppStatus = true;
// Getter function for pollAppStatus.
this.getPollAppStatusProperty = function() {
return pollAppStatus;
};
// Setter function for pollAppStatus.
var setPollAppStatusProperty = function(value) {
pollAppStatus = value;
}
// Internal generic function that actually submits the request to backend to change the app.
this.changeAppState = function(app, desired_state) {
setPollAppStatusProperty(false); // prevent UI from refreshing.
return $http.put("/v2/apps/" + app.guid + "?async=false&inline-relations-depth=1", {"state":desired_state})
.then(function(response) {
// Success
// Set the state immediately to stop so that UI will force a load of the new options.
// UI will change the buttons based on the state.
app.state = desired_state;
}, function(response) {
// Failure
}).finally(function() {
setPollAppStatusProperty(true); // allow UI to refresh via polling again.
});
}
// Wrapper function that will submit a request to start an app.
this.startApp = function(app) {
return this.changeAppState(app, "STARTED");
};
// Wrapper function that will submit a request to stop an app.
this.stopApp = function(app) {
return this.changeAppState(app, "STOPPED");
};
// Wrapper function that will submit a request to restart an app.
this.restartApp = function(app) {
// _this = this allows us to access another service method again within a promise.
_this = this;
return this.changeAppState(app, "STOPPED")
.then(function() {
return _this.changeAppState(app, "STARTED");
});
};

});
// Useful for when we are in the middle of updating the app status ourselves and we don't
// want a poll to interrupt the UI.
var pollAppStatus = true;
// Getter function for pollAppStatus.
this.getPollAppStatusProperty = function() {
return pollAppStatus;
};
// Setter function for pollAppStatus.
var setPollAppStatusProperty = function(value) {
pollAppStatus = value;
};
// Internal generic function that actually submits the request to backend to change the app.
this.changeAppState = function(app, desired_state) {
setPollAppStatusProperty(false); // prevent UI from refreshing.
return $http.put("/v2/apps/" + app.guid + "?async=false&inline-relations-depth=1", {
"state": desired_state
})
.then(function(response) {
// Success
// Set the state immediately to stop so that UI will force a load of the new options.
// UI will change the buttons based on the state.
app.state = desired_state;
}, function(response) {
// Failure
}).finally(function() {
setPollAppStatusProperty(true); // allow UI to refresh via polling again.
});
};
// Wrapper function that will submit a request to start an app.
this.startApp = function(app) {
return this.changeAppState(app, "STARTED");
};
// Wrapper function that will submit a request to stop an app.
this.stopApp = function(app) {
return this.changeAppState(app, "STOPPED");
};
// Wrapper function that will submit a request to restart an app.
this.restartApp = function(app) {
// _this = this allows us to access another service method again within a promise.
_this = this;
return this.changeAppState(app, "STOPPED")
.then(function() {
return _this.changeAppState(app, "STARTED");
});
};

});

}());
99 changes: 46 additions & 53 deletions static/app/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$cloudfoundry.findActiveOrg($routeParams['orgguid'], renderOrg);
};

app.controller('HomeCtrl', function($scope, $cloudfoundry, MenuData) {
app.controller('HomeCtrl', function($scope, $cloudfoundry) {
//Render the auth status of the backend
var renderStatus = function(status) {
$scope.backendStatus = status;
Expand All @@ -29,7 +29,7 @@
.then(renderStatus);
});

app.controller('MainCtrl', function($scope, $cloudfoundry, $location, MenuData) {
app.controller('MainCtrl', function($scope, $cloudfoundry, MenuData) {
// Render the orgs on the page
var renderOrgs = function(orgs) {
$scope.orgs = orgs;
Expand All @@ -44,7 +44,7 @@
$scope.MenuData = MenuData;
});

app.controller('OrgCtrl', function($scope, $cloudfoundry, $location, $routeParams, MenuData) {
app.controller('OrgCtrl', function($scope, $cloudfoundry, $routeParams, MenuData) {
loadOrg(MenuData, $routeParams, $cloudfoundry, $scope);
});

Expand Down Expand Up @@ -118,65 +118,59 @@
if ($cloudfoundry.getPollAppStatusProperty() === true) {
$scope.appSummary = appSummary;
}
}
};
var renderAppStats = function(appStats) {
// Only render while we are not updating an app ourselves.
if ($cloudfoundry.getPollAppStatusProperty() === true) {
$scope.appStats = appStats;
}
}
var resetAppStatsPoll = function() {
};
var resetAppStatsPoll = function() {
$scope.statsPromise = $interval(function() {
$cloudfoundry.getAppSummary($routeParams['appguid']).then(renderAppSummary);
$cloudfoundry.getAppStats($routeParams['appguid']).then(renderAppStats);
}, 5000);
// Make sure to clean up afterwards when the page is naviageted away.
$scope.$on('$destroy', function () { $interval.cancel($scope.statsPromise); });
}
// Stop a specified app
$scope.stopApp = function(app) {
// Only stop if we are currently not restarting.
if ($scope.restarting != true) {
// Grey out the UI buttons while waiting.
$scope.stopping = true;
$cloudfoundry.stopApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.stopping = false;
});
}
};
// Restart a specified app
$scope.restartApp = function(app) {
// Only restart if we are currently not stopping.
if ($scope.stopping != true) {
// Grey out the UI buttons while waiting.
$scope.restarting = true;
$cloudfoundry.restartApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.restarting = false;
});
}
};
// Start a specified app
$scope.startApp = function(app) {
// Grey out the UI buttons while waiting.
$scope.starting = true;
$cloudfoundry.startApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.starting = false;
});
};
$cloudfoundry.getAppSummary($routeParams['appguid']).then(renderAppSummary);
// TODO: Make it so it won't request stats if the state in the summary is not STARTED.
$cloudfoundry.getAppStats($routeParams['appguid']).then(renderAppStats);
resetAppStatsPoll();
// Show the `service.html` view
$scope.visibleTab = 'app';
});

$scope.$on('$destroy', function() {
$interval.cancel($scope.statsPromise);
});
};
// Stop a specified app
$scope.stopApp = function(app) {
// Only stop if we are currently not restarting.
if ($scope.restarting != true) {
// Grey out the UI buttons while waiting.
$scope.stopping = true;
$cloudfoundry.stopApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.stopping = false;
});
};
};
// Restart a specified app
$scope.restartApp = function(app) {
// Only restart if we are currently not stopping.
if ($scope.stopping != true) {
// Grey out the UI buttons while waiting.
$scope.restarting = true;
$cloudfoundry.restartApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.restarting = false;
});
}
};
// Start a specified app
$scope.startApp = function(app) {
// Grey out the UI buttons while waiting.
$scope.starting = true;
$cloudfoundry.startApp(app)
.then(function() {
// Re-enable the UI buttons.
$scope.starting = false;
});
};
// Bind a service
$scope.bindService = function(service) {
$scope.disableServiceBinder = true;
Expand Down Expand Up @@ -207,5 +201,4 @@
resetAppStatsPoll();
});


}());
Loading

0 comments on commit 4143ff3

Please sign in to comment.