4 // WARNING: make sure than app/frontend/services/AppConfig.js match your server
6 // list all rependencies within the page + controler if needed
7 angular.module('DashboardModule', ['SubmitButton', 'TokenRefresh', 'AppliButton'])
9 .controller('DashboardController', function ($http, AppConfig, Notification) {
10 var scope = this; // I hate JavaScript
14 scope.status ="err-no";
15 scope.appliIDs =[]; // array to hold applications ID
16 scope.appliStore={}; // array to hold applications json description
18 scope.ProcessResponse= function(data, errcode, headers, config) {
19 var apiname= 'API'+ data.request.api.replace('-','_');
20 scope.status = "err-ok";
21 scope.errcode= errcode;
22 scope.request = data.request;
23 scope.response = data.response;
25 // if token was refresh let's update AppConfig
26 if (data.request.token) AppConfig.session.token = data.request.token;
27 if (data.request.uuid) AppConfig.session.uuid = data.request.uuid;
28 if (data.request.timeout) AppConfig.session.timeout = data.request.timeout;
30 // Make sure we clean everything when Open/Close is called
31 if (apiname === "APIcreate" || apiname === "APIreset") {
37 scope[apiname]="success";
39 // If we have a new token let's update it
40 if (data.request.token) scope.token=data.request.token;
42 console.log ("OK: "+ JSON.stringify(data));
45 scope.ProcessError= function(data, errcode, headers, config) {
46 var apiname= 'API'+data.request.api.replace('-','_');
47 scope.status = "err-fx";
48 scope.errcode = errcode;
49 scope.request = data.request;
51 scope[apiname]="fail";
53 console.log ("FX: "+ JSON.stringify(data));
56 scope.OpenSession = function() {
57 console.log ("OpenSession");
58 var handler = $http.get(AppConfig.session.create + '?token='+AppConfig.session.initial);
60 handler.success(scope.ProcessResponse);
61 handler.error(scope.ProcessError);
64 scope.CheckSession = function() {
65 console.log ("CloseSession");
66 var handler = $http.get(AppConfig.session.check + '?token='+AppConfig.session.token);
68 handler.success(scope.ProcessResponse);
69 handler.error(scope.ProcessError);
72 scope.RefreshSession = function() {
73 console.log ("RefreshSession");
74 var handler = $http.get(AppConfig.session.refresh + '?token='+AppConfig.session.token);
76 handler.success(scope.ProcessResponse);
77 handler.error(scope.ProcessError);
80 scope.ResetSession = function() {
81 console.log ("ResetSession");
82 var handler = $http.get(AppConfig.session.reset + '?token='+AppConfig.session.token);
84 handler.success(scope.ProcessResponse);
85 handler.error(scope.ProcessError);
88 scope.AppliCB = function (appliID) {
89 console.log ("Application Clicked ID=[%s]", appliID);
93 scope.AutoStart = function () {
94 console.log ("AutoStart requesting Apps list");
95 var handler = $http.get('/api/afm-main/runnables' + '?token='+AppConfig.session.token);
96 handler.success(function(result) {
98 // Check this is a valid response from Binder
99 if (result.request.jtype !== "AJB_reply" && result.request.api !== "runnables") {
100 Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable result="+result, delay: 5000});
104 // loop on runnable application to prepare for display
106 for (var idx=0; idx < result.response.length; idx ++) {
107 appliIDs[idx] = result.response [idx].id;
108 scope.appliStore [result.response [idx].id] = result.response [idx];
110 scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
117 console.log ("Dashboard Controller Loaded");