Add comments and correct some bugs
This commit is contained in:
parent
21b68f1da1
commit
8e700c2b7d
6 changed files with 59 additions and 68 deletions
|
@ -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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
// Function to call after pull all data about machines
|
||||
var callMeAfterPullData = function (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();
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Image.getImages(function(){});
|
||||
// On user login
|
||||
$scope.$on('loginEvent', function () {
|
||||
tryToRetrieveData();
|
||||
});
|
||||
|
||||
|
||||
|
||||
$scope.raiseShowMachineDetailsEvent=function(id){
|
||||
// Function to call from view to display the details of a machine
|
||||
$scope.raiseShowMachineDetailsEvent = function (id) {
|
||||
|
||||
var callback=function(){
|
||||
Loading.stop();
|
||||
var data=Compute.getData();
|
||||
$rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
|
||||
// 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();
|
||||
Compute.pullMachines(callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(Identity.isAlreadyLogin()){
|
||||
if(Compute.getData().machines == null){
|
||||
Loading.start();
|
||||
Compute.pullData(callMeAfterPullData);
|
||||
}
|
||||
else{
|
||||
if(Identity.isAlreadyLogin()){
|
||||
callMeAfterPullData();
|
||||
}
|
||||
}
|
||||
Image.getImages(function(){});
|
||||
}
|
||||
|
||||
}]);
|
||||
};
|
||||
Loading.start(); // Show loading gif
|
||||
Compute.pullMachines(callback); // Retrieve machine info and display overlay
|
||||
};
|
||||
|
||||
// Try to retrieve data for the first time
|
||||
tryToRetrieveData();
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue