Work in Progress
authorFulup Ar Foll <fulup@iot.bzh>
Wed, 16 Dec 2015 18:17:46 +0000 (19:17 +0100)
committerFulup Ar Foll <fulup@iot.bzh>
Wed, 16 Dec 2015 18:17:46 +0000 (19:17 +0100)
afb-client/app/Frontend/app.js
afb-client/app/Frontend/pages/Home/Home.html
afb-client/app/Frontend/pages/Home/HomeModule.js
afb-client/app/Frontend/pages/Home/HomeModule.scss
afb-client/app/Frontend/pages/Sample/Sample.html
afb-client/app/Frontend/services/ConfigApp.js
afb-client/app/Frontend/widgets/Notifications/Notifications.scss
afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js [new file with mode: 0644]
afb-client/nbproject/project.xml
afb-client/package.json

index dc1d489..e539062 100644 (file)
@@ -20,6 +20,7 @@
     'SampleModule',
     'UploadFile',
     'LinkButton',
+    'TokenRefresh',
     'ModalNotification'
   ])
     .config(config)
index 9803b63..9b9cc01 100644 (file)
@@ -12,6 +12,7 @@ animationIn: slideInRight
   App Framework Binder Simple Client 
 </h3>
 
+<token-refresh></token-refresh>
 
 
 <div class="button-box box-content ">
index 11b3882..ba6c5ea 100644 (file)
@@ -1,10 +1,10 @@
 (function() {
 'use strict';
 
-  var INITIAL_TOKEN=123456789;  // should match with --token=xxxx binder command line
+// WARNING: make sure than app/frontend/services/ConfigApp.js match your server
 
 // list all rependencies within the page + controler if needed
-angular.module('HomeModule', ['SubmitButton'])
+angular.module('HomeModule', ['SubmitButton', 'TokenRefresh'])
 
   .controller('HomeController', function ($http, ConfigApp) {
         var scope = this; // I hate JavaScript
@@ -21,6 +21,11 @@ angular.module('HomeModule', ['SubmitButton'])
             scope.errcode= errcode;
             scope.request  = data.request;
             scope.response = data.response;
+            
+            // if token was refresh let's update ConfigApp
+            if (data.request.token) ConfigApp.session.token = data.request.token;
+            if (data.request.uuid)  ConfigApp.session.uuid  = data.request.uuid;
+            if (data.request.timeout)  ConfigApp.session.timeout  = data.request.timeout;
 
             // Make sure we clean everything when Open/Close is called
             if (apiname === "APIcreate" || apiname === "APIreset") {
@@ -51,7 +56,7 @@ angular.module('HomeModule', ['SubmitButton'])
         scope.OpenSession = function() {
             console.log ("OpenSession"); 
             var postdata= {/* any json your application may need */};
-            var handler = $http.post(ConfigApp.api.token + 'create?token='+INITIAL_TOKEN, postdata);
+            var handler = $http.post(ConfigApp.api.token + 'create?token='+ConfigApp.session.token, postdata);
             
             handler.success(scope.ProcessResponse);
             handler.error(scope.ProcessError);
index 34e1181..8bf04a1 100644 (file)
 $COLOR_SUCCESS: green;
 $COLOR_FAIL: red;
 
+token-refresh {
+    display: block;
+    float: right;
+    margin: .5rem 1rem 0 0;
+}
+
 .button-box {
     height  : 4.5rem;
     
index 00a6f3b..e7e9164 100644 (file)
@@ -7,7 +7,9 @@ controller:   SampleController as ctrl
 animationIn: slideInRight
 ---
 
-<h1><img class="logo" src="images/logo/triskel_iot_bzhx250.png" alt="IoT.bzh Logo" style="height:150px;"> Sample Page</h1>
+<h1><img class="logo" src="images/logo/triskel_iot_bzhx250.png" alt="IoT.bzh Logo" style="height:150px;">
+    Not Working
+</h1>
 
 <div class="sample-box box-content">
     
index f36d79b..cafda3f 100644 (file)
                     
                     api: { // Warning paths should end with /
                        token : '/api/token/'
+                    },
+                    
+                    session: { // Those data are updated by session service
+                       refresh : '/api/token/refresh',
+                       check : '/api/token/check',
+                       token   : '123456789',  // typical dev initial token
+                       timeout : 3600,         // timeout is updated client sessin context creation
+                       uuid    : '',           // uuid map with cookie or long term session access key
+                       pingrate: 60            // Ping rate to check if server is still alive
                     }
                 };
 
index 5d42d2a..5a4adc1 100644 (file)
@@ -45,3 +45,11 @@ tip-modal {
         display: inline;
     }
 }
+
+token-refresh.online {
+    color: blue;
+}
+
+token-refresh.offline {
+    color: red;
+}
diff --git a/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js b/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js
new file mode 100644 (file)
index 0000000..1671748
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ alsa-gateway -- provide a REST/HTTP interface to ALSA-Mixer
+
+ Copyright (C) 2015, Fulup Ar Foll
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with scope program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ References:
+
+ */
+
+(function () {
+    'use strict';
+
+    var template =
+          '<div class="afb-monitor">'
+        + '<span class="afb-refresh-token" ng-click="getping" >afb://{{hostname}}:{{httpdport}}</span>'
+        + '<i class="{{icon}}"></i>'
+        + '</div>'
+        ;
+
+
+// scope module is load statically before any route is cativated
+angular.module('TokenRefresh', [])
+
+    .directive ('tokenRefresh', function($timeout, $http, $location, Notification, ConfigApp) {
+
+    function mymethods(scope, elem, attrs) {
+        
+        scope.status;
+    
+        scope.online = function () {
+            elem.addClass    ("online");
+            elem.removeClass ("offline");
+        };
+
+        scope.offline = function(){
+            elem.addClass    ("offline");
+            elem.removeClass ("online");
+        };
+
+        // Check Binder status
+        scope.getping = function() {
+
+            var handler = $http.get(ConfigApp.api.ping+'xx?token='+ ConfigApp.session.token);
+            handler.success(function(response, errcode, headers, config) {
+                if (!scope.status)  {
+                    Notification.success ({message: "AFB Back to Live", delay: 3000});
+                    scope.online();
+                }
+                scope.status = 1;
+            });
+
+            handler.error(function(response, errcode, headers) {
+                if (scope.status)  {
+                    Notification.warning ({message: "AFB Lost", delay: 5000});
+                    scope.offline();
+                }
+                scope.status = 0;
+            });
+
+            // restart a new timer for next ping
+            $timeout (scope.getping, ConfigApp.session.pingrate*1000);
+        };
+        
+        // Check Binder status
+        scope.refresh = function() {
+            var handler = $http.get(ConfigApp.api.refresh+'?token='+ ConfigApp.session.token);
+            $timeout (scope.refresh, ConfigApp.session.timeout *800);
+        };
+        scope.icon      = attrs.icon   || "fi-lightbulb";
+        scope.hostname  = $location.host();
+        scope.httpdport = $location.port();
+        
+        scope.getping();
+        scope.refresh();
+    }
+
+    return {
+        template: template,
+        scope: {
+            callback : "="
+        },
+        restrict: 'E',
+        link: mymethods
+    };
+});
+
+})();
+console.log ("Token Refresh Loaded");
+
index 438e3ff..4979f19 100644 (file)
@@ -3,7 +3,7 @@
     <type>org.netbeans.modules.web.clientproject</type>
     <configuration>
         <data xmlns="http://www.netbeans.org/ns/clientside-project/1">
-            <name>AFBclient</name>
+            <name>afb-client</name>
         </data>
         <libraries xmlns="http://www.netbeans.org/ns/cdnjs-libraries/1"/>
     </configuration>
index 26cf47f..e8198f6 100644 (file)
@@ -1,5 +1,5 @@
 {
-  "name": "AFBclient",
+  "name": "afb-client",
   "private": true,
   "version": "0.0.1",
   "repository": {