Clean code, add comment etc..
This commit is contained in:
parent
968eda48cc
commit
bb1598713c
7 changed files with 251 additions and 232 deletions
|
@ -11,14 +11,14 @@ mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$
|
||||||
$scope.machine = {};
|
$scope.machine = {};
|
||||||
$scope.machineIsStarting = false; // For loading icon
|
$scope.machineIsStarting = false; // For loading icon
|
||||||
|
|
||||||
|
// When we need to show details of machine
|
||||||
$scope.$on('showMachineDetailsEvent', function (eventName, machine, axioms) {
|
$scope.$on('showMachineDetailsEvent', function (eventName, machine, axioms) {
|
||||||
$scope.machine = machine;
|
$scope.machine = machine;
|
||||||
$scope.axioms = axioms;
|
$scope.axioms = axioms;
|
||||||
$('#machineDetailsModal').modal({backdrop: false, keyboard: true});
|
$('#machineDetailsModal').modal({backdrop: false, keyboard: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Try to stop or start a machine
|
||||||
$scope.toggleMachineState = function () {
|
$scope.toggleMachineState = function () {
|
||||||
// Display gif
|
// Display gif
|
||||||
$scope.machineIsStarting = true;
|
$scope.machineIsStarting = true;
|
||||||
|
@ -35,9 +35,10 @@ mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Apply modifications
|
||||||
$scope.applyModifications = function () {
|
$scope.applyModifications = function () {
|
||||||
//Todo
|
//Todo
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,19 @@
|
||||||
mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', function ($scope, Image, Loading, Identity)
|
mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', function ($scope, Image, Loading, Identity)
|
||||||
{
|
{
|
||||||
|
|
||||||
var callbackTest=function(){
|
// Update view
|
||||||
|
var callMeAfterGetImage = function () {
|
||||||
$scope.images = Image.getData().images;
|
$scope.images = Image.getData().images;
|
||||||
Loading.stop();
|
Loading.stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If user is login try to retrieve data
|
||||||
if (Identity.isAlreadyLogin()) {
|
if (Identity.isAlreadyLogin()) {
|
||||||
|
|
||||||
if (Image.getData().images == null) {
|
if (Image.getData().images == null) {
|
||||||
Loading.start();
|
Loading.start();
|
||||||
Image.getImages(callbackTest);
|
Image.getImages(callMeAfterGetImage);
|
||||||
|
} else {
|
||||||
|
callMeAfterGetImage();
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
callbackTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -23,7 +23,9 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity',
|
||||||
|
|
||||||
$scope.doUpload = function () {
|
$scope.doUpload = function () {
|
||||||
console.log($('#imageToUpload').prop('files')[0]);
|
console.log($('#imageToUpload').prop('files')[0]);
|
||||||
Image.uploadImage($('#imageToUpload').prop('files')[0], function(){alert("done")})
|
Image.uploadImage($('#imageToUpload').prop('files')[0], function () {
|
||||||
|
alert("done")
|
||||||
|
})
|
||||||
/*$("#drop-area-div").dmUploader({
|
/*$("#drop-area-div").dmUploader({
|
||||||
extraData: {
|
extraData: {
|
||||||
"token" : Identity.getToken(),
|
"token" : Identity.getToken(),
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
*/
|
*/
|
||||||
mainApp.controller('networkCtrl', function ($scope)
|
mainApp.controller('networkCtrl', function ($scope)
|
||||||
{
|
{
|
||||||
|
|
||||||
});
|
});
|
|
@ -1,10 +1,16 @@
|
||||||
|
|
||||||
mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
|
mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
|
||||||
|
|
||||||
|
// Data object
|
||||||
var data = {};
|
var data = {};
|
||||||
data.images=null;
|
data.images = null; // Images
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse uploadImage anwser
|
||||||
|
* @param {type} response
|
||||||
|
* @param {type} failedToSendRequest
|
||||||
|
* @returns {Image_L2.parseUploadImageAnswer.requestParserResult}
|
||||||
|
*/
|
||||||
var parseUploadImageAnswer = function (response, failedToSendRequest) {
|
var parseUploadImageAnswer = function (response, failedToSendRequest) {
|
||||||
|
|
||||||
// Defined return object
|
// Defined return object
|
||||||
|
@ -18,17 +24,20 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
||||||
requestParserResult.status = 0;
|
requestParserResult.status = 0;
|
||||||
data.images = response.data.Images;
|
data.images = response.data.Images;
|
||||||
|
|
||||||
}
|
} else if (failedToSendRequest) {
|
||||||
else if(failedToSendRequest){
|
|
||||||
requestParserResult.failReason = "Failed to send request";
|
requestParserResult.failReason = "Failed to send request";
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
requestParserResult.failReason = "Error";
|
requestParserResult.failReason = "Error";
|
||||||
}
|
}
|
||||||
return requestParserResult;
|
return requestParserResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get images
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
var getImages = function (callback) {
|
var getImages = function (callback) {
|
||||||
|
|
||||||
var result = $http.post('../server/index.php',
|
var result = $http.post('../server/index.php',
|
||||||
|
@ -44,6 +53,12 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload an image
|
||||||
|
* @param {type} fileToUpload
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
var uploadImage = function (fileToUpload, callback) {
|
var uploadImage = function (fileToUpload, callback) {
|
||||||
var form_data = new FormData();
|
var form_data = new FormData();
|
||||||
form_data.append('file', fileToUpload);
|
form_data.append('file', fileToUpload);
|
||||||
|
@ -81,10 +96,7 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
||||||
},function(response){
|
},function(response){
|
||||||
callback(parseUploadImageAnswer(response, true));
|
callback(parseUploadImageAnswer(response, true));
|
||||||
});*/
|
});*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var getData = function (response) {
|
var getData = function (response) {
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Loading service
|
||||||
|
* @param {type} param1
|
||||||
|
* @param {type} param2
|
||||||
|
*/
|
||||||
mainApp.factory('Loading', [function () {
|
mainApp.factory('Loading', [function () {
|
||||||
/**
|
/**
|
||||||
* Display Loading modal
|
* Display Loading modal
|
||||||
|
@ -12,8 +16,7 @@ mainApp.factory('Loading',[ function(){
|
||||||
*/
|
*/
|
||||||
var stop = function () {
|
var stop = function () {
|
||||||
$('#loadingModal').modal('hide');
|
$('#loadingModal').modal('hide');
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
// Service returns
|
// Service returns
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
|
|
||||||
mainApp.factory('Network', ['$http', 'Identity', function ($http, Identity) {
|
mainApp.factory('Network', ['$http', 'Identity', function ($http, Identity) {
|
||||||
|
|
||||||
|
// Data object
|
||||||
var data = {};
|
var data = {};
|
||||||
data.networks=null;
|
data.networks = null; // Networks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ListId
|
||||||
|
* @param {type} fileToUpload
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
var ListId = function (fileToUpload, callback) {
|
var ListId = function (fileToUpload, callback) {
|
||||||
|
|
||||||
|
|
||||||
var result = $http.post('../server/index.php',
|
var result = $http.post('../server/index.php',
|
||||||
$.param({"token": Identity.getToken(), "task": "network", 'action': 'list_network_ids'}));
|
$.param({"token": Identity.getToken(), "task": "network", 'action': 'list_network_ids'}));
|
||||||
|
|
||||||
|
@ -16,10 +21,7 @@ var ListId=function(fileToUpload, callback) {
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(parseUploadImageAnswer(response, true));
|
callback(parseUploadImageAnswer(response, true));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
console.log(result)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue