1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/**
* The home controller
*
* @param {$scope} $scope The $scope service from angular
*/
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();
}]);
|