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