f4330cf214192f039f23068cdb1e529207ac8070
[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         
26         scope.GetRunnables = function() {
27             console.log ("Dashboard GetRunnables");
28             
29             AppCall.get ("afm-main", "runnables", {/*query*/}, function(response) {
30                 
31                 // update debug UI zone
32                 scope.request  = "/api/afm-main/runnable"; 
33                 scope.response = response.data;
34                 scope.errcode  = response.status;
35                 
36                 if (response.status !== 200) {
37                     console.log ("Hoop GetRunnable failed");
38                     return;
39                 }
40                 
41                 // Check this is a valid response from Binder
42                 if (response.data.request.jtype !== "AJB_reply" && response.data.request.api !== "runnables") {
43                   Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable response.data="+response.data, delay: 5000}); 
44                   return;
45                 }
46                 
47                 // loop on runnable application to prepare for display
48                 var  appliIDs=[];
49                 var  runnables = response.data.response.runnables;
50                 for (var idx=0; idx < runnables.length; idx ++) {
51                     appliIDs[idx] = runnables [idx].id;
52                     scope.appliStore [runnables [idx].id] =  runnables [idx];
53                 }
54                 scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
55                 
56             });            
57         };
58         
59         scope.FileUploaded = function (response) {
60             console.log ("file Uploaded");
61             // Cannot display post results as GetRunnable will overload them aynchronously
62             scope.request  = "/api/afm-main/install"; 
63             scope.response = response.headers;
64             scope.errcode  = response.status;
65             
66             // everything looks OK update app list
67             scope.GetRunnables();
68         };
69         
70         scope.AutoStart = function () {
71             console.log ("AutoStart requesting Apps list");
72             scope.GetRunnables();
73         };
74           
75    });
76
77 console.log ("Dashboard Controller Loaded");
78 })();