diff options
Diffstat (limited to 'afb-client/app')
8 files changed, 140 insertions, 4 deletions
diff --git a/afb-client/app/Frontend/app.js b/afb-client/app/Frontend/app.js index dc1d489..e539062 100644 --- a/afb-client/app/Frontend/app.js +++ b/afb-client/app/Frontend/app.js @@ -20,6 +20,7 @@ 'SampleModule', 'UploadFile', 'LinkButton', + 'TokenRefresh', 'ModalNotification' ]) .config(config) diff --git a/afb-client/app/Frontend/pages/Home/Home.html b/afb-client/app/Frontend/pages/Home/Home.html index 9803b63..9b9cc01 100644 --- a/afb-client/app/Frontend/pages/Home/Home.html +++ b/afb-client/app/Frontend/pages/Home/Home.html @@ -12,6 +12,7 @@ animationIn: slideInRight App Framework Binder Simple Client </h3> +<token-refresh></token-refresh> <div class="button-box box-content "> diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.js b/afb-client/app/Frontend/pages/Home/HomeModule.js index 11b3882..ba6c5ea 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.js +++ b/afb-client/app/Frontend/pages/Home/HomeModule.js @@ -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); diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.scss b/afb-client/app/Frontend/pages/Home/HomeModule.scss index 34e1181..8bf04a1 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.scss +++ b/afb-client/app/Frontend/pages/Home/HomeModule.scss @@ -21,6 +21,12 @@ $COLOR_SUCCESS: green; $COLOR_FAIL: red; +token-refresh { + display: block; + float: right; + margin: .5rem 1rem 0 0; +} + .button-box { height : 4.5rem; diff --git a/afb-client/app/Frontend/pages/Sample/Sample.html b/afb-client/app/Frontend/pages/Sample/Sample.html index 00a6f3b..e7e9164 100644 --- a/afb-client/app/Frontend/pages/Sample/Sample.html +++ b/afb-client/app/Frontend/pages/Sample/Sample.html @@ -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"> diff --git a/afb-client/app/Frontend/services/ConfigApp.js b/afb-client/app/Frontend/services/ConfigApp.js index f36d79b..cafda3f 100644 --- a/afb-client/app/Frontend/services/ConfigApp.js +++ b/afb-client/app/Frontend/services/ConfigApp.js @@ -16,6 +16,15 @@ 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 } }; diff --git a/afb-client/app/Frontend/widgets/Notifications/Notifications.scss b/afb-client/app/Frontend/widgets/Notifications/Notifications.scss index 5d42d2a..5a4adc1 100644 --- a/afb-client/app/Frontend/widgets/Notifications/Notifications.scss +++ b/afb-client/app/Frontend/widgets/Notifications/Notifications.scss @@ -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 index 0000000..1671748 --- /dev/null +++ b/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js @@ -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"); + |