Add comments and correct some bugs

This commit is contained in:
Loic GUEGAN 2016-04-17 18:42:15 +02:00
parent 21b68f1da1
commit 8e700c2b7d
6 changed files with 59 additions and 68 deletions

View file

@ -25,7 +25,7 @@ mainApp.config(['$routeProvider', function($routeProvider){
controller: 'imageCtrl' controller: 'imageCtrl'
}) })
.otherwise({ .otherwise({
redirectTo: '/' redirectTo: '/home'
}); });
}]); }]);

View file

@ -3,58 +3,52 @@
* *
* @param {$scope} $scope The $scope service from angular * @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){ // Function to call after pull all data about machines
console.log(data); var callMeAfterPullData = function (data) {
$scope.machines=Compute.getData().machines; $scope.machines = Compute.getData().machines;
Loading.stop(); Loading.stop();
} };
; // Function to call to try to retrieve data and update the view
if(Compute.getData().machines == null && Identity.isAlreadyLogin()){ var tryToRetrieveData = function () {
Loading.start(); // If no data retrieve about machine and user is logged
Compute.pullData(callMeAfterPullData); if (Compute.getData().machines == null && Identity.isAlreadyLogin()) {
} Loading.start(); // Show loading gif
else{ Compute.pullData(callMeAfterPullData); // Retrieve data and call the callback
if(Identity.isAlreadyLogin()){ } else {
callMeAfterPullData(); // 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(){ // Stop loading gif and display overlay
Loading.stop(); var callback = function () {
var data=Compute.getData(); Loading.stop();
$rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms); var data = Compute.getData();
$rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
} };
Loading.start(); Loading.start(); // Show loading gif
Compute.pullMachines(callback); Compute.pullMachines(callback); // Retrieve machine info and display overlay
} };
// Try to retrieve data for the first time
tryToRetrieveData();
}]);
if(Identity.isAlreadyLogin()){
if(Compute.getData().machines == null){
Loading.start();
Compute.pullData(callMeAfterPullData);
}
else{
if(Identity.isAlreadyLogin()){
callMeAfterPullData();
}
}
Image.getImages(function(){});
}
}]);

View file

@ -7,7 +7,7 @@
* @param {Identity} The Identity service * @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 // Check for login and define default states
if (!Identity.isAlreadyLogin()) { if (!Identity.isAlreadyLogin()) {
@ -51,12 +51,14 @@ mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope,
} else { } else {
// Else the user is online ! // Else the user is online !
$('#loginModal').modal('hide'); $('#loginModal').modal('hide');
// Send login event
$rootScope.$broadcast("loginEvent");
} }
// Reset button state // Reset button state
$('#loginButton').show(); $('#loginButton').show();
$('#loadingLoginButton').hide(); $('#loadingLoginButton').hide();
} };
// Try to login // Try to login
Identity.login(username, password, projectname, responseCallback); Identity.login(username, password, projectname, responseCallback);

View file

@ -6,16 +6,14 @@
* @param {$scope} $scope The $scope service from angular * @param {$scope} $scope The $scope service from angular
* @param {Identity} The Identity service * @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();
// Function to logout
// Give profile to model $scope.logout = function () {
$scope.profile=Identity.getProfile(); Identity.logout();
};
// Function to logout
$scope.logout=function(){
Identity.logout();
};
}]); }]);

View file

@ -101,8 +101,6 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// Wait and handle the response // Wait and handle the response
result.then(function (response){ result.then(function (response){
alert(Identity.getToken());
callback(parsePullImagesAnswer(response, false)); callback(parsePullImagesAnswer(response, false));
},function(response){ },function(response){

View file

@ -1,12 +1,11 @@
<div class="panel panel-default" ng-controller="homeCtrl"> <div class="panel panel-default" ng-controller="homeCtrl">
<div class="panel-heading"> <div class="panel-heading">
Home Home
</div> </div>
<div class="panel-body"> <div class="panel-body">
Pour charger les machines, recharger la page (temporaire)<br /> Selectionner une machine:
Selectionner une machine: <div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name}}</a></div>
<div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name }}</a></div>
</div> </div>
</div> </div>