summaryrefslogtreecommitdiffstats
path: root/afm-client/app/Frontend/pages/Home/DashboardModule.js
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-01-25 14:37:32 +0100
committerFulup Ar Foll <fulup@iot.bzh>2016-01-25 14:37:32 +0100
commit3ebdce373e134b70b129154d8033c1c628847a6c (patch)
tree76d84a1b1e6e6b474c7eecad2ea098ba0de69300 /afm-client/app/Frontend/pages/Home/DashboardModule.js
parent8d03b8c581ce64192e9d265597d262b59826cffd (diff)
First version
Diffstat (limited to 'afm-client/app/Frontend/pages/Home/DashboardModule.js')
-rw-r--r--afm-client/app/Frontend/pages/Home/DashboardModule.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/afm-client/app/Frontend/pages/Home/DashboardModule.js b/afm-client/app/Frontend/pages/Home/DashboardModule.js
new file mode 100644
index 0000000..f843df1
--- /dev/null
+++ b/afm-client/app/Frontend/pages/Home/DashboardModule.js
@@ -0,0 +1,118 @@
+(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 ($http, AppConfig, 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.ProcessResponse= function(data, errcode, headers, config) {
+ var apiname= 'API'+ data.request.api.replace('-','_');
+ scope.status = "err-ok";
+ scope.errcode= errcode;
+ scope.request = data.request;
+ scope.response = data.response;
+
+ // if token was refresh let's update AppConfig
+ if (data.request.token) AppConfig.session.token = data.request.token;
+ if (data.request.uuid) AppConfig.session.uuid = data.request.uuid;
+ if (data.request.timeout) AppConfig.session.timeout = data.request.timeout;
+
+ // Make sure we clean everything when Open/Close is called
+ if (apiname === "APIcreate" || apiname === "APIreset") {
+ scope.APIreset ='';
+ scope.APIcreate ='';
+ scope.APIrefresh='';
+ scope.APIcheck ='';
+ }
+ scope[apiname]="success";
+
+ // If we have a new token let's update it
+ if (data.request.token) scope.token=data.request.token;
+
+ console.log ("OK: "+ JSON.stringify(data));
+ };
+
+ scope.ProcessError= function(data, errcode, headers, config) {
+ var apiname= 'API'+data.request.api.replace('-','_');
+ scope.status = "err-fx";
+ scope.errcode = errcode;
+ scope.request = data.request;
+ scope.response = "";
+ scope[apiname]="fail";
+
+ console.log ("FX: "+ JSON.stringify(data));
+ };
+
+ scope.OpenSession = function() {
+ console.log ("OpenSession");
+ var handler = $http.get(AppConfig.session.create + '?token='+AppConfig.session.initial);
+
+ handler.success(scope.ProcessResponse);
+ handler.error(scope.ProcessError);
+ };
+
+ scope.CheckSession = function() {
+ console.log ("CloseSession");
+ var handler = $http.get(AppConfig.session.check + '?token='+AppConfig.session.token);
+
+ handler.success(scope.ProcessResponse);
+ handler.error(scope.ProcessError);
+ };
+
+ scope.RefreshSession = function() {
+ console.log ("RefreshSession");
+ var handler = $http.get(AppConfig.session.refresh + '?token='+AppConfig.session.token);
+
+ handler.success(scope.ProcessResponse);
+ handler.error(scope.ProcessError);
+ };
+
+ scope.ResetSession = function() {
+ console.log ("ResetSession");
+ var handler = $http.get(AppConfig.session.reset + '?token='+AppConfig.session.token);
+
+ handler.success(scope.ProcessResponse);
+ handler.error(scope.ProcessError);
+ };
+
+ scope.AppliCB = function (appliID) {
+ console.log ("Application Clicked ID=[%s]", appliID);
+
+ };
+
+ scope.AutoStart = function () {
+ console.log ("AutoStart requesting Apps list");
+ var handler = $http.get('/api/afm-main/runnables' + '?token='+AppConfig.session.token);
+ handler.success(function(result) {
+
+ // Check this is a valid response from Binder
+ if (result.request.jtype !== "AJB_reply" && result.request.api !== "runnables") {
+ Notification.error ({message: "Invalid Respond to /opa/afm-main/runnable result="+result, delay: 5000});
+ return;
+ }
+
+ // loop on runnable application to prepare for display
+ var appliIDs=[];
+ for (var idx=0; idx < result.response.length; idx ++) {
+ appliIDs[idx] = result.response [idx].id;
+ scope.appliStore [result.response [idx].id] = result.response [idx];
+ }
+ scope.appliIDs = appliIDs; // avoid partial update to limit UI refresh
+
+ });
+ };
+
+ });
+
+console.log ("Dashboard Controller Loaded");
+})(); \ No newline at end of file