diff options
author | Fulup Ar Foll <fulup@iot.bzh> | 2016-05-24 09:23:56 +0200 |
---|---|---|
committer | Fulup Ar Foll <fulup@iot.bzh> | 2016-05-24 09:23:56 +0200 |
commit | 7b8fe1b305a36f925fc2757a2c126c88fb0a5137 (patch) | |
tree | 05623effa06276b7ccff95658f1a1dda01b48388 /afb-client/app/Frontend/etc | |
parent | 35698424ab8973d91208df92471d18b1c901220e (diff) |
Started move to new framework version
Diffstat (limited to 'afb-client/app/Frontend/etc')
-rw-r--r-- | afb-client/app/Frontend/etc/AppConfig.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/afb-client/app/Frontend/etc/AppConfig.js b/afb-client/app/Frontend/etc/AppConfig.js index bd1aae0..5c9283e 100644 --- a/afb-client/app/Frontend/etc/AppConfig.js +++ b/afb-client/app/Frontend/etc/AppConfig.js @@ -23,7 +23,7 @@ ping : '/api/token/check', initial : urlquery.token || '123456789', // typical dev initial token timeout : 3600, // timeout is updated client sessin context creation - pingrate: 60, // Ping rate to check if server is still alive + pingrate: 30, // Ping rate to check if server is still alive uuid : '', // uuid map with cookie or long term session access key token : '' // will be returned from authentication } @@ -33,16 +33,28 @@ }) // Factory is a singleton and share its context within all instances. - .factory('AppCall', function ($http, AppConfig) { + .factory('AppCall', function ($http, AppConfig, $log) { var myCalls = { - get : function(plugin, action, query, callback) { - if (!query.token) query.token = AppConfig.session.token; // add token to provided query - $http.get('/api/' + plugin + '/' + action , {params: query}).then (callback, callback); + get : function(plugin, action, query, cbresponse, cberror) { + if (!query.token) query.token = AppConfig.session.token; // add token to provided query + var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then (onsuccess, onerror); + + handle.onsuccess (function(data, errcode, headers, config) { + // if token was updated keep it within application cache + 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; + + cbresponse(data, errcode, headers, config); + }); + + handle.onerror (function(data, errcode, headers, config) { + if (cberror) cberror(data, errcode, headers, config); + else cbresponse(data, errcode, headers, config); + }); } - }; return myCalls; }); - })();
\ No newline at end of file |