summaryrefslogtreecommitdiffstats
path: root/afm-client/app/Frontend/pages/Dashboard/DashboardModule.js
blob: dff21ed7700946dfa77345cc1973c405c48ad5ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function() {
'use strict';

// WARNING: make sure than app/frontend/services/AppConfig.js match your server

// list all rependencies within the page + controler if needed
angular.module('DashboardModule', ['SubmitButton', 'TokenRefresh', 'AppliButton'])

  .controller('DashboardController', function (AppCall, Notification) {
        var scope = this; // I hate JavaScript
        scope.uuid   ="none";
        scope.token  ="none";
        scope.session="none";
        scope.status ="err-no";
        scope.appliIDs =[]; // array to hold applications ID
        scope.appliStore={}; // array to hold applications json description

       
        scope.AppliCB = function(appliID, action, response) {
                // Action is done within Widget Controller only update debug UI zone
                scope.request  = action; 
                scope.errcode  = response.status;
                if (response.data) scope.response = response.data;
                
                // On app was removed let's update runnable list
                if (action === "uninstall")  scope.GetRunnables();
        };
        
        scope.GetRunnables = function() {
            console.log ("Dashboard GetRunnables");
            
            AppCall.get ("afm-main", "runnables", {/*query*/}, function(response) {
                
                // update debug UI zone
                scope.request  = "/api/afm-main/runnable"; 
                scope.response = response.data;
                scope.errcode  = response.status;
                
                if (response.status !== 200) {
                    console.log ("Hoop GetRunnable failed");
                    return;
                }
                
                // Check this is a valid response from Binder
                if (response.data.jtype != "afb-reply") {
                  Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable response.data="+response.data, delay: 5000}); 
                  return;
                }
                
                // loop on runnable application to prepare for display
                var  appliIDs=[];
                var  runnables = response.data.response.runnables;
                for (var idx=0; idx < runnables.length; idx ++) {
                    appliIDs[idx] = runnables [idx].id;
                    scope.appliStore [runnables [idx].id] =  runnables [idx];
                }
                scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
                
            });            
        };
        
        scope.FileUploaded = function (response) {
            console.log ("file Uploaded");
            // Cannot display post results as GetRunnable will overload them aynchronously
            scope.request  = "/api/afm-main/install"; 
            scope.response = response.headers;
            scope.errcode  = response.status;
            
            // everything looks OK update app list
            scope.GetRunnables();
        };
        
        scope.AutoStart = function () {
            console.log ("AutoStart requesting Apps list");
            scope.GetRunnables();
        };
          
   });

console.log ("Dashboard Controller Loaded");
})();