Clean up to prepare new version of API
[src/app-framework-demo.git] / afm-client / app / Frontend / pages / Dashboard / DashboardModule.js
1 (function() {
2 'use strict';
3
4 // WARNING: make sure than app/frontend/services/AppConfig.js match your server
5
6 // list all rependencies within the page + controler if needed
7 angular.module('DashboardModule', ['SubmitButton', 'TokenRefresh', 'AppliButton'])
8
9   .controller('DashboardController', function (AppCall, Notification) {
10         var scope = this; // I hate JavaScript
11         scope.uuid   ="none";
12         scope.token  ="none";
13         scope.session="none";
14         scope.status ="err-no";
15         scope.appliIDs =[]; // array to hold applications ID
16         scope.appliStore={}; // array to hold applications json description
17
18        
19         scope.AppliCB = function(appliID, action, response) {
20                 // Action is done within Widget Controller only update debug UI zone
21                 scope.request  = action; 
22                 scope.errcode  = response.status;
23                 if (response.data) scope.response = response.data;
24                 
25                 // On app was removed let's update runnable list
26                 if (action === "uninstall")  scope.GetRunnables();
27         };
28         
29         scope.GetRunnables = function() {
30             console.log ("Dashboard GetRunnables");
31             
32             AppCall.get ("afm-main", "runnables", {/*query*/}, function(jresp, errcode) {
33                 
34                 // update debug UI zone
35                 scope.request  = "/api/afm-main/runnable"; 
36                 scope.response = jresp.response;
37                 scope.errcode  = jresp.request.status;
38
39                 // Check if this is a response from AGL application framework binder
40                 if (jresp.jtype !== "afb-reply") {
41                   Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable response.data="+response.data, delay: 5000}); 
42                   return;
43                 }
44
45                 // Check for success
46                 if (jresp.request.status !== "success") {
47                     Notification.error ({message: "afm-main/runnable" + jresp.request.info, delay: 5000});
48                     return;
49                 }
50                                    
51                 
52                 // loop on runnable application to prepare for display
53                 var  appliIDs=[];
54                 var  runnables = jresp.response.runnables;
55                 for (var idx=0; idx < runnables.length; idx ++) {
56                     appliIDs[idx] = runnables [idx].id;
57                     scope.appliStore [runnables [idx].id] =  runnables [idx];
58                 }
59                 scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
60                 
61             });            
62         };
63         
64         scope.FileUploaded = function (response) {
65             console.log ("file Uploaded");
66             // Cannot display post results as GetRunnable will overload them aynchronously
67             scope.request  = "/api/afm-main/install"; 
68             scope.response = response.headers;
69             scope.errcode  = response.status;
70             
71             // everything looks OK update app list
72             scope.GetRunnables();
73         };
74         
75         scope.AutoStart = function () {
76             console.log ("AutoStart requesting Apps list");
77             scope.GetRunnables();
78         };
79           
80    });
81
82 console.log ("Dashboard Controller Loaded");
83 })();