summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/js/controllers/home/main.js14
-rw-r--r--client/js/services/Compute.js36
2 files changed, 38 insertions, 12 deletions
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index 4e3bcda..805bc63 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -10,14 +10,18 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($s
// TODO Update graph etc...
}
- // Retrieve all Data
- Compute.pullData(updatePage);
- Compute.getMachines(function(adzda){});
+
+
$scope.raiseShowMachineDetailsEvent=function(){
- var machine={name: "Machine 1", online:true};
- $rootScope.$broadcast("showMachineDetailsEvent", machine);
+ var callback=function(){
+ var data=Compute.getData();
+ console.log(data.machines[Object.keys(data.machines)[0]]);
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[Object.keys(data.machines)[0]]);
+
+ }
+ Compute.pullMachines(callback);
}
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index e0c28ae..7c9df26 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -10,18 +10,36 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// Parser
var parseGetMachinesAnswer=function(response, failedToSendRequest){
+ // Defined return object
+ var requestParserResult={};
+ requestParserResult.status=1;
+ requestParserResult.failReason=null;
+
+ if (typeof response.data.Servers !== 'undefined') {
+ // Set status code
+ requestParserResult.status=0;
+ data.machines=response.data.Servers;
+ }
+ else if(failedToSendRequest){
+ requestParserResult.failReason="Failed to send request";
+ }
+ else{
+ requestParserResult.failReason="Error";
+ }
+
+ return requestParserResult;
+
};
// Get Machine
- var getMachines=function(callback){
+ var pullMachines=function(callback){
var params={
"token" : Identity.getToken(),
"task" : "compute",
- "action":"getServer",
- "serverId":"a2926ce3-501b-4285-82ce-c6e451295599"
+ "action":"listServers"
};
var result=$http.post('../server/index.php',
@@ -29,7 +47,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// Wait and handle the response
result.then(function (response){
- console.log(response.data.MyServer.image);
+
callback(parseGetMachinesAnswer(response, false));
},function(response){
alert(response.status);
@@ -45,12 +63,16 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// TODO call getMachines etc...
}
-
+
+ var getData=function(){
+ return data;
+ }
+
// Return services objects
return {
- getMachines: getMachines,
+ pullMachines: pullMachines,
pullData: pullData,
- data:data
+ getData: getData
};