Clean code, add comment etc..
This commit is contained in:
parent
968eda48cc
commit
bb1598713c
7 changed files with 251 additions and 232 deletions
|
@ -3,42 +3,43 @@
|
||||||
*
|
*
|
||||||
* @param {$scope} $scope The $scope service from angular
|
* @param {$scope} $scope The $scope service from angular
|
||||||
*/
|
*/
|
||||||
mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', 'Identity', function ($scope, Compute, $rootScope, $timeout, Identity)
|
mainApp.controller('machineDetailsCtrl', ['$scope', 'Compute', '$rootScope', '$timeout', 'Identity', function ($scope, Compute, $rootScope, $timeout, Identity)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Init scope
|
// Init scope
|
||||||
$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.machine = machine;
|
||||||
|
$scope.axioms = axioms;
|
||||||
|
$('#machineDetailsModal').modal({backdrop: false, keyboard: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Try to stop or start a machine
|
||||||
|
$scope.toggleMachineState = function () {
|
||||||
|
// Display gif
|
||||||
|
$scope.machineIsStarting = true;
|
||||||
|
|
||||||
|
// Fake timeout
|
||||||
|
$timeout(function () {
|
||||||
|
$scope.machineIsStarting = false;
|
||||||
|
}, 3000);
|
||||||
|
$timeout(function () {
|
||||||
|
$scope.machine.online = !$scope.machine.online;
|
||||||
|
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
|
||||||
$scope.$on('showMachineDetailsEvent', function(eventName ,machine, axioms){
|
};
|
||||||
$scope.machine=machine;
|
|
||||||
$scope.axioms=axioms;
|
// Apply modifications
|
||||||
$('#machineDetailsModal').modal({backdrop: false, keyboard: true});
|
$scope.applyModifications = function () {
|
||||||
});
|
//Todo
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.toggleMachineState=function(){
|
|
||||||
// Display gif
|
|
||||||
$scope.machineIsStarting=true;
|
|
||||||
|
|
||||||
// Fake timeout
|
}]);
|
||||||
$timeout(function(){
|
|
||||||
$scope.machineIsStarting=false;
|
|
||||||
}, 3000);
|
|
||||||
$timeout(function(){
|
|
||||||
$scope.machine.online=!$scope.machine.online;
|
|
||||||
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.applyModifications=function(){
|
|
||||||
//Todo
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}]);
|
|
||||||
|
|
|
@ -4,23 +4,21 @@
|
||||||
* @param {$scope} $scope The $scope service from angular
|
* @param {$scope} $scope The $scope service from angular
|
||||||
*/
|
*/
|
||||||
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
|
||||||
$scope.images=Image.getData().images;
|
var callMeAfterGetImage = function () {
|
||||||
Loading.stop();
|
$scope.images = Image.getData().images;
|
||||||
};
|
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(callMeAfterGetImage);
|
||||||
Image.getImages(callbackTest);
|
} else {
|
||||||
}
|
callMeAfterGetImage();
|
||||||
else{
|
}
|
||||||
callbackTest();
|
}
|
||||||
}
|
}]);
|
||||||
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
|
@ -3,58 +3,60 @@
|
||||||
*
|
*
|
||||||
* @param {$scope} $scope The $scope service from angular
|
* @param {$scope} $scope The $scope service from angular
|
||||||
*/
|
*/
|
||||||
mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity,upload)
|
mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload)
|
||||||
{
|
{
|
||||||
/*$scope.uploader = new FileUploader({
|
/*$scope.uploader = new FileUploader({
|
||||||
"token" : Identity.getToken(),
|
"token" : Identity.getToken(),
|
||||||
"task" : "image",
|
"task" : "image",
|
||||||
'action':'uploadImage',
|
'action':'uploadImage',
|
||||||
'id':'6564'
|
'id':'6564'
|
||||||
});
|
});
|
||||||
$scope.uploader.url='../server/index.php'
|
$scope.uploader.url='../server/index.php'
|
||||||
$scope.uploader.alias='file_name'
|
$scope.uploader.alias='file_name'
|
||||||
$scope.uploader.formData={
|
$scope.uploader.formData={
|
||||||
"token" : Identity.getToken(),
|
"token" : Identity.getToken(),
|
||||||
"task" : "image",
|
"task" : "image",
|
||||||
'action':'uploadImage',
|
'action':'uploadImage',
|
||||||
'id':'6564'
|
'id':'6564'
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$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 () {
|
||||||
/*$("#drop-area-div").dmUploader({
|
alert("done")
|
||||||
extraData: {
|
})
|
||||||
"token" : Identity.getToken(),
|
/*$("#drop-area-div").dmUploader({
|
||||||
"task" : "image",
|
extraData: {
|
||||||
'action':'uploadImage',
|
"token" : Identity.getToken(),
|
||||||
'id':'6564'},
|
"task" : "image",
|
||||||
url:"../server/index.php"
|
'action':'uploadImage',
|
||||||
});
|
'id':'6564'},
|
||||||
*/
|
url:"../server/index.php"
|
||||||
|
});
|
||||||
/*upload({
|
*/
|
||||||
url: '../server/index.php',
|
|
||||||
method: 'POST',
|
/*upload({
|
||||||
data: {
|
url: '../server/index.php',
|
||||||
"token" : Identity.getToken(),
|
method: 'POST',
|
||||||
"task" : "image",
|
data: {
|
||||||
'action':'uploadImage',
|
"token" : Identity.getToken(),
|
||||||
'id':'6564',
|
"task" : "image",
|
||||||
"file_name": $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
|
'action':'uploadImage',
|
||||||
}
|
'id':'6564',
|
||||||
}).then(
|
"file_name": $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
|
||||||
function (response) {
|
}
|
||||||
console.log(response.data); // will output whatever you choose to return from the server on a successful upload
|
}).then(
|
||||||
},
|
function (response) {
|
||||||
function (response) {
|
console.log(response.data); // will output whatever you choose to return from the server on a successful upload
|
||||||
console.error(response); // Will return if status code is above 200 and lower than 300, same as $http
|
},
|
||||||
}
|
function (response) {
|
||||||
);*/
|
console.error(response); // Will return if status code is above 200 and lower than 300, same as $http
|
||||||
|
}
|
||||||
|
);*/
|
||||||
};
|
|
||||||
|
|
||||||
$scope.token=Identity.getToken();
|
};
|
||||||
}]);
|
|
||||||
|
$scope.token = Identity.getToken();
|
||||||
|
}]);
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
*/
|
*/
|
||||||
mainApp.controller('networkCtrl', function ($scope)
|
mainApp.controller('networkCtrl', function ($scope)
|
||||||
{
|
{
|
||||||
|
|
||||||
});
|
});
|
|
@ -1,102 +1,114 @@
|
||||||
|
|
||||||
mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
|
||||||
|
|
||||||
var data={};
|
// Data object
|
||||||
data.images=null;
|
var data = {};
|
||||||
|
data.images = null; // Images
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse uploadImage anwser
|
||||||
|
* @param {type} response
|
||||||
|
* @param {type} failedToSendRequest
|
||||||
|
* @returns {Image_L2.parseUploadImageAnswer.requestParserResult}
|
||||||
|
*/
|
||||||
|
var parseUploadImageAnswer = function (response, failedToSendRequest) {
|
||||||
|
|
||||||
|
// Defined return object
|
||||||
|
var requestParserResult = {};
|
||||||
|
requestParserResult.status = 1;
|
||||||
|
requestParserResult.failReason = null;
|
||||||
|
|
||||||
|
|
||||||
var parseUploadImageAnswer=function(response, failedToSendRequest){
|
if (typeof response.data.Images !== 'undefined') {
|
||||||
|
// Set status code
|
||||||
|
requestParserResult.status = 0;
|
||||||
|
data.images = response.data.Images;
|
||||||
|
|
||||||
// Defined return object
|
} else if (failedToSendRequest) {
|
||||||
var requestParserResult={};
|
requestParserResult.failReason = "Failed to send request";
|
||||||
requestParserResult.status=1;
|
} else {
|
||||||
requestParserResult.failReason=null;
|
requestParserResult.failReason = "Error";
|
||||||
|
}
|
||||||
|
return requestParserResult;
|
||||||
if (typeof response.data.Images !== 'undefined') {
|
};
|
||||||
// Set status code
|
|
||||||
requestParserResult.status=0;
|
|
||||||
data.images=response.data.Images;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(failedToSendRequest){
|
|
||||||
requestParserResult.failReason="Failed to send request";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
requestParserResult.failReason="Error";
|
|
||||||
}
|
|
||||||
return requestParserResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var getImages=function(callback){
|
/**
|
||||||
|
* Get images
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
var getImages = function (callback) {
|
||||||
|
|
||||||
var result=$http.post('../server/index.php',
|
var result = $http.post('../server/index.php',
|
||||||
$.param({"token" : Identity.getToken(), "task" : "image", 'action':'listImage'}));
|
$.param({"token": Identity.getToken(), "task": "image", 'action': 'listImage'}));
|
||||||
|
|
||||||
// Wait and handle the response
|
// Wait and handle the response
|
||||||
result.then(function (response){
|
result.then(function (response) {
|
||||||
callback(parseUploadImageAnswer(response, false));
|
callback(parseUploadImageAnswer(response, false));
|
||||||
},function(response){
|
}, function (response) {
|
||||||
callback(parseUploadImageAnswer(response, true));
|
callback(parseUploadImageAnswer(response, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var uploadImage=function(fileToUpload, callback) {
|
|
||||||
var form_data = new FormData();
|
|
||||||
form_data.append('file', fileToUpload);
|
|
||||||
console.log(fileToUpload);
|
|
||||||
form_data.append("task" , "image");
|
|
||||||
form_data.append("token" , Identity.getToken());
|
|
||||||
form_data.append('action',"uploadImage");
|
|
||||||
form_data.append('id','6564');
|
|
||||||
form_data.append('file_name', fileToUpload);
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: "../server/index.php", // Url to which the request is send
|
|
||||||
type: "POST", // Type of request to be send, called as method
|
|
||||||
data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
|
|
||||||
file_name:fileToUpload,
|
|
||||||
token : Identity.getToken(),
|
|
||||||
task : "image",
|
|
||||||
action:'uploadImage',
|
|
||||||
id:'6564',
|
|
||||||
contentType: false, // The content type used when sending data to the server.
|
|
||||||
cache: false, // To unable request pages to be cached
|
|
||||||
processData:false, // To send DOMDocument or non processed data file it is set to false
|
|
||||||
success: function(data) // A function to be called if request succeeds
|
|
||||||
{
|
|
||||||
alert("success");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//var result=$http.post('../server/index.php',
|
|
||||||
// $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
|
|
||||||
|
|
||||||
// Wait and handle the response
|
|
||||||
/* result.then(function (response){
|
|
||||||
callback(parseUploadImageAnswer(response, false));
|
|
||||||
},function(response){
|
|
||||||
callback(parseUploadImageAnswer(response, true));
|
|
||||||
});*/
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Upload an image
|
||||||
|
* @param {type} fileToUpload
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
var uploadImage = function (fileToUpload, callback) {
|
||||||
|
var form_data = new FormData();
|
||||||
|
form_data.append('file', fileToUpload);
|
||||||
|
console.log(fileToUpload);
|
||||||
|
form_data.append("task", "image");
|
||||||
|
form_data.append("token", Identity.getToken());
|
||||||
|
form_data.append('action', "uploadImage");
|
||||||
|
form_data.append('id', '6564');
|
||||||
|
form_data.append('file_name', fileToUpload);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "../server/index.php", // Url to which the request is send
|
||||||
|
type: "POST", // Type of request to be send, called as method
|
||||||
|
data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
|
||||||
|
file_name: fileToUpload,
|
||||||
|
token: Identity.getToken(),
|
||||||
|
task: "image",
|
||||||
|
action: 'uploadImage',
|
||||||
|
id: '6564',
|
||||||
|
contentType: false, // The content type used when sending data to the server.
|
||||||
|
cache: false, // To unable request pages to be cached
|
||||||
|
processData: false, // To send DOMDocument or non processed data file it is set to false
|
||||||
|
success: function (data) // A function to be called if request succeeds
|
||||||
|
{
|
||||||
|
alert("success");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//var result=$http.post('../server/index.php',
|
||||||
|
// $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
|
||||||
|
|
||||||
|
// Wait and handle the response
|
||||||
|
/* result.then(function (response){
|
||||||
|
callback(parseUploadImageAnswer(response, false));
|
||||||
|
},function(response){
|
||||||
|
callback(parseUploadImageAnswer(response, true));
|
||||||
|
});*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var getData=function(response){
|
var getData = function (response) {
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return services objects
|
|
||||||
return {
|
|
||||||
getImages:getImages,
|
|
||||||
getData:getData,
|
|
||||||
uploadImage:uploadImage
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Return services objects
|
||||||
}]);
|
return {
|
||||||
|
getImages: getImages,
|
||||||
|
getData: getData,
|
||||||
|
uploadImage: uploadImage
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}]);
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
|
/**
|
||||||
|
* Loading service
|
||||||
|
* @param {type} param1
|
||||||
|
* @param {type} param2
|
||||||
|
*/
|
||||||
|
mainApp.factory('Loading', [function () {
|
||||||
|
/**
|
||||||
|
* Display Loading modal
|
||||||
|
*/
|
||||||
|
var start = function () {
|
||||||
|
$('#loadingModal').modal({backdrop: 'static', keyboard: false});
|
||||||
|
};
|
||||||
|
|
||||||
mainApp.factory('Loading',[ function(){
|
/**
|
||||||
/**
|
* Hide Loading modal
|
||||||
* Display Loading modal
|
*/
|
||||||
*/
|
var stop = function () {
|
||||||
var start=function(){
|
$('#loadingModal').modal('hide');
|
||||||
$('#loadingModal').modal({backdrop: 'static', keyboard: false});
|
};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
// Service returns
|
||||||
* Hide Loading modal
|
return {
|
||||||
*/
|
start: start,
|
||||||
var stop=function(){
|
stop: stop
|
||||||
$('#loadingModal').modal('hide');
|
};
|
||||||
}
|
}]);
|
||||||
|
|
||||||
|
|
||||||
// Service returns
|
|
||||||
return {
|
|
||||||
start:start,
|
|
||||||
stop:stop
|
|
||||||
};
|
|
||||||
}]);
|
|
||||||
|
|
|
@ -1,27 +1,29 @@
|
||||||
|
|
||||||
mainApp.factory('Network',[ '$http', 'Identity', function($http, Identity){
|
mainApp.factory('Network', ['$http', 'Identity', function ($http, Identity) {
|
||||||
|
|
||||||
var data={};
|
// Data object
|
||||||
data.networks=null;
|
var data = {};
|
||||||
|
data.networks = null; // Networks
|
||||||
|
|
||||||
var ListId=function(fileToUpload, callback) {
|
/**
|
||||||
|
* ListId
|
||||||
|
* @param {type} fileToUpload
|
||||||
|
* @param {type} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
var ListId = function (fileToUpload, callback) {
|
||||||
|
var result = $http.post('../server/index.php',
|
||||||
|
$.param({"token": Identity.getToken(), "task": "network", 'action': 'list_network_ids'}));
|
||||||
|
|
||||||
|
// Wait and handle the response
|
||||||
|
result.then(function (response) {
|
||||||
|
callback(parseUploadImageAnswer(response, false));
|
||||||
|
}, function (response) {
|
||||||
|
callback(parseUploadImageAnswer(response, true));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var result=$http.post('../server/index.php',
|
}]);
|
||||||
$.param({"token" : Identity.getToken(), "task" : "network", 'action':'list_network_ids'}));
|
|
||||||
|
|
||||||
// Wait and handle the response
|
|
||||||
result.then(function (response){
|
|
||||||
callback(parseUploadImageAnswer(response, false));
|
|
||||||
},function(response){
|
|
||||||
callback(parseUploadImageAnswer(response, true));
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(result)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue