summaryrefslogtreecommitdiff
path: root/client/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'client/js/controllers')
-rwxr-xr-xclient/js/controllers/home/home.js104
-rw-r--r--client/js/controllers/login.js6
-rw-r--r--client/js/controllers/status.js20
3 files changed, 62 insertions, 68 deletions
diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js
index 10142c9..7880e12 100755
--- a/client/js/controllers/home/home.js
+++ b/client/js/controllers/home/home.js
@@ -3,58 +3,52 @@
*
* @param {$scope} $scope The $scope service from angular
*/
-mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image)
-{
-
- var callMeAfterPullData=function(data){
- console.log(data);
- $scope.machines=Compute.getData().machines;
- Loading.stop();
- }
-
- ;
- if(Compute.getData().machines == null && Identity.isAlreadyLogin()){
- Loading.start();
- Compute.pullData(callMeAfterPullData);
- }
- else{
- if(Identity.isAlreadyLogin()){
- callMeAfterPullData();
- }
- }
-
-
- Image.getImages(function(){});
-
-
-
- $scope.raiseShowMachineDetailsEvent=function(id){
-
- var callback=function(){
- Loading.stop();
- var data=Compute.getData();
- $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
-
- }
- Loading.start();
- Compute.pullMachines(callback);
- }
-
-
-
-
-
- if(Identity.isAlreadyLogin()){
- if(Compute.getData().machines == null){
- Loading.start();
- Compute.pullData(callMeAfterPullData);
- }
- else{
- if(Identity.isAlreadyLogin()){
- callMeAfterPullData();
- }
- }
- Image.getImages(function(){});
- }
-
-}]);
+mainApp.controller('homeCtrl', ['$scope', 'Compute', '$rootScope', 'Loading', 'Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image)
+ {
+
+ // Function to call after pull all data about machines
+ var callMeAfterPullData = function (data) {
+ $scope.machines = Compute.getData().machines;
+ Loading.stop();
+ };
+
+ // Function to call to try to retrieve data and update the view
+ var tryToRetrieveData = function () {
+ // If no data retrieve about machine and user is logged
+ if (Compute.getData().machines == null && Identity.isAlreadyLogin()) {
+ Loading.start(); // Show loading gif
+ Compute.pullData(callMeAfterPullData); // Retrieve data and call the callback
+ } else {
+ // Else if user is logged and data is already retrieve
+ // simply display data
+ if (Identity.isAlreadyLogin()) {
+ callMeAfterPullData(); // Display data
+ }
+ }
+ };
+
+
+ // On user login
+ $scope.$on('loginEvent', function () {
+ tryToRetrieveData();
+ });
+
+
+
+ // Function to call from view to display the details of a machine
+ $scope.raiseShowMachineDetailsEvent = function (id) {
+
+ // Stop loading gif and display overlay
+ var callback = function () {
+ Loading.stop();
+ var data = Compute.getData();
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
+
+ };
+ Loading.start(); // Show loading gif
+ Compute.pullMachines(callback); // Retrieve machine info and display overlay
+ };
+
+ // Try to retrieve data for the first time
+ tryToRetrieveData();
+ }]);
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 93a373e..4a0de42 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -7,7 +7,7 @@
* @param {Identity} The Identity service
*/
-mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope, $sce, Identity)
+mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', '$rootScope', function ($scope, $sce, Identity, $rootScope)
{
// Check for login and define default states
if (!Identity.isAlreadyLogin()) {
@@ -51,12 +51,14 @@ mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope,
} else {
// Else the user is online !
$('#loginModal').modal('hide');
+ // Send login event
+ $rootScope.$broadcast("loginEvent");
}
// Reset button state
$('#loginButton').show();
$('#loadingLoginButton').hide();
- }
+ };
// Try to login
Identity.login(username, password, projectname, responseCallback);
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index 15850f4..c3e634b 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -6,16 +6,14 @@
* @param {$scope} $scope The $scope service from angular
* @param {Identity} The Identity service
*/
-mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($scope, Identity, $rootScope)
-{
+mainApp.controller('statusCtrl', ['$scope', 'Identity', '$rootScope', function ($scope, Identity, $rootScope)
+ {
+ // Give profile to model
+ $scope.profile = Identity.getProfile();
-
- // Give profile to model
- $scope.profile=Identity.getProfile();
-
- // Function to logout
- $scope.logout=function(){
- Identity.logout();
- };
+ // Function to logout
+ $scope.logout = function () {
+ Identity.logout();
+ };
-}]);
+ }]);