First version
[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         scope.AppliCB = function (appliID) {
19             console.log ("Application Clicked ID=[%s]", appliID);
20             
21         };
22         
23         scope.AppliCB = function(appliID, action, response) {
24                 // Action is done within Widget Controller only update debug UI zone
25                 scope.request  = action; 
26                 scope.errcode  = response.status;
27                 if (response.data) scope.response = response.data;
28         };
29         
30         scope.GetRunnables = function() {
31             console.log ("Dashboard GetRunnables");
32             
33             AppCall.get ("afm-main", "runnables", {/*query*/}, function(response) {
34                 
35                 // update debug UI zone
36                 scope.request  = "/api/afm-main/runnable"; 
37                 scope.response = response.data;
38                 scope.errcode  = response.status;
39                 
40                 if (response.status !== 200) {
41                     console.log ("Hoop GetRunnable failed");
42                     return;
43                 }
44                 
45                 // Check this is a valid response from Binder
46                 if (response.data.request.jtype !== "AJB_reply" && response.data.request.api !== "runnables") {
47                   Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable response.data="+response.data, delay: 5000}); 
48                   return;
49                 }
50                 
51                 // loop on runnable application to prepare for display
52                 var  appliIDs=[];
53                 for (var idx=0; idx < response.data.response.length; idx ++) {
54                     appliIDs[idx] = response.data.response [idx].id;
55                     scope.appliStore [response.data.response [idx].id] =  response.data.response [idx];
56                 }
57                 scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
58                 
59             });            
60         };
61         
62         scope.FileUploaded = function (status) {
63             console.log ("file Uploaded");
64             scope.GetRunnables();
65         };
66         
67         scope.AutoStart = function () {
68             console.log ("AutoStart requesting Apps list");
69             scope.GetRunnables();
70         };
71           
72    });
73
74 console.log ("Dashboard Controller Loaded");
75 })();