From e6d12f74be543056a439259b61ba40a9d0adcf5c Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Mon, 15 Feb 2016 15:56:36 +0100 Subject: Updated TokenRefresh and AppConfig --- afb-client/app/Backend/RestApis/TokenMockApi.js | 8 ++-- afb-client/app/Frontend/app.js | 4 +- afb-client/app/Frontend/etc/AppConfig.js | 48 ++++++++++++++++++++ afb-client/app/Frontend/etc/ConfigApp.js | 39 ---------------- afb-client/app/Frontend/pages/Home/HomeModule.js | 20 ++++----- .../app/Frontend/widgets/FormInput/UploadFiles.js | 52 +++++++++++----------- 6 files changed, 90 insertions(+), 81 deletions(-) create mode 100644 afb-client/app/Frontend/etc/AppConfig.js delete mode 100644 afb-client/app/Frontend/etc/ConfigApp.js (limited to 'afb-client/app') diff --git a/afb-client/app/Backend/RestApis/TokenMockApi.js b/afb-client/app/Backend/RestApis/TokenMockApi.js index 74b565a..9e6406e 100644 --- a/afb-client/app/Backend/RestApis/TokenMockApi.js +++ b/afb-client/app/Backend/RestApis/TokenMockApi.js @@ -37,7 +37,7 @@ function NewApi(handle, prefix) { scope.connected=false; // Simulate Client Context Session Creation - handle.app.post(prefix +'/create', function (req, res) { + handle.app.get(prefix +'/create', function (req, res) { handle.trace (scope, 1, "%s/create body=%s", prefix, req.body.action); var okResponse= '{ "jtype": "AJB_reply"' + ', "request": { "prefix": "afbs", "api": "create", "uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx", "status": "processed" }'+ @@ -57,7 +57,7 @@ function NewApi(handle, prefix) { // Simulate Client Context Check - handle.app.post(prefix +'/check', function (req, res) { + handle.app.get(prefix +'/check', function (req, res) { handle.trace (scope, 1, "%s/check query=%s", prefix, req.query.token); var okResponse= '{"jtype":"AJB_reply"'+ ',"request":{"prefix":"afbs","api":"check", "status":"processed"}'+ @@ -73,7 +73,7 @@ function NewApi(handle, prefix) { }); // Simulate Client Context Check - handle.app.post(prefix +'/refresh', function (req, res) { + handle.app.get(prefix +'/refresh', function (req, res) { handle.trace (scope, 1, "%s/refresh query=%s", prefix, req.query.token); var okResponse= '{"jtype":"AJB_reply"'+ ',"request":{"prefix":"afbs","api":"refresh","uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx","status":"processed"}'+ @@ -89,7 +89,7 @@ function NewApi(handle, prefix) { }); // Simulate Client Context Session Closing - handle.app.post(prefix +'/reset', function (req, res) { + handle.app.get(prefix +'/reset', function (req, res) { handle.trace (scope, 1, "%s/reset query=%s", prefix, req.query.token); var okResponse= '{"jtype":"AJB_reply"'+ ',"request":{"prefix":"afbs","api":"reset","uuid": "e4ef5e66-xxxx","status":"processed"}'+ diff --git a/afb-client/app/Frontend/app.js b/afb-client/app/Frontend/app.js index 6772243..91a8a72 100644 --- a/afb-client/app/Frontend/app.js +++ b/afb-client/app/Frontend/app.js @@ -24,7 +24,7 @@ 'ui-notification', // Application Components - 'ConfigApp', + 'AppConfig', 'JQueryEmu', 'HomeModule', 'SampleModule', @@ -41,7 +41,7 @@ config.$inject = ['$urlRouterProvider', '$locationProvider']; - function config($urlProvider, $locationProvider, ConfigApp) { + function config($urlProvider, $locationProvider, AppConfig) { $urlProvider.otherwise('/home'); // https://docs.angularjs.org/error/$location/nobase diff --git a/afb-client/app/Frontend/etc/AppConfig.js b/afb-client/app/Frontend/etc/AppConfig.js new file mode 100644 index 0000000..bd1aae0 --- /dev/null +++ b/afb-client/app/Frontend/etc/AppConfig.js @@ -0,0 +1,48 @@ +(function () { + 'use strict'; + + // _all modules only reference dependencies + angular.module('AppConfig', []) + + // Factory is a singleton and share its context within all instances. + .factory('AppConfig', function (urlquery) { + + var myConfig = { + paths: { // Warning paths should end with / + image : 'images/', + avatar: 'images/avatars/', + audio : 'images/audio/', + appli : 'images/appli/' + }, + + session: { // Those data are updated by session service + create : '/api/token/create', + refresh : '/api/token/refresh', + check : '/api/token/check', + reset : '/api/token/reset', + 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 + uuid : '', // uuid map with cookie or long term session access key + token : '' // will be returned from authentication + } + }; + + return myConfig; + }) + + // Factory is a singleton and share its context within all instances. + .factory('AppCall', function ($http, AppConfig) { + 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); + } + + }; + return myCalls; + }); + + +})(); \ No newline at end of file diff --git a/afb-client/app/Frontend/etc/ConfigApp.js b/afb-client/app/Frontend/etc/ConfigApp.js deleted file mode 100644 index a6a0cad..0000000 --- a/afb-client/app/Frontend/etc/ConfigApp.js +++ /dev/null @@ -1,39 +0,0 @@ -(function () { - 'use strict'; - - // _all modules only reference dependencies - angular.module('ConfigApp', []) - - // Factory is a singleton and share its context within all instances. - .factory('ConfigApp', function (urlquery) { - - var myConfig = { - paths: { // Warning paths should end with / - image : 'images/', - avatar: 'images/avatars/', - audio : 'images/audio/', - appli : 'images/appli/' - }, - - myapi: { // Warning paths should end with / - token : '/api/myplugin/xxxx' - }, - - session: { // Those data are updated by session service - create : '/api/token/create', - refresh : '/api/token/refresh', - check : '/api/token/check', - reset : '/api/token/reset', - 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 - uuid : '', // uuid map with cookie or long term session access key - token : '' // will be returned from authentication - } - }; - - return myConfig; - }); - -})(); \ No newline at end of file diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.js b/afb-client/app/Frontend/pages/Home/HomeModule.js index 6a73bdf..fb03ac8 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.js +++ b/afb-client/app/Frontend/pages/Home/HomeModule.js @@ -1,12 +1,12 @@ (function() { 'use strict'; -// WARNING: make sure than app/frontend/services/ConfigApp.js match your server +// WARNING: make sure than app/frontend/services/AppConfig.js match your server // list all rependencies within the page + controler if needed angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) - .controller('HomeController', function ($http, ConfigApp) { + .controller('HomeController', function ($http, AppConfig) { var scope = this; // I hate JavaScript scope.uuid ="none"; scope.token ="none"; @@ -22,10 +22,10 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) 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; + // 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") { @@ -56,7 +56,7 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) scope.OpenSession = function() { console.log ("OpenSession"); var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.create + '?token='+ConfigApp.session.initial, postdata); + var handler = $http.post(AppConfig.session.create + '?token='+AppConfig.session.initial, postdata); handler.success(scope.ProcessResponse); handler.error(scope.ProcessError); @@ -65,7 +65,7 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) scope.CheckSession = function() { console.log ("CloseSession"); var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.check + '?token='+ConfigApp.session.token, postdata); + var handler = $http.post(AppConfig.session.check + '?token='+AppConfig.session.token, postdata); handler.success(scope.ProcessResponse); handler.error(scope.ProcessError); @@ -74,7 +74,7 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) scope.RefreshSession = function() { console.log ("RefreshSession"); var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.refresh + '?token='+ConfigApp.session.token, postdata); + var handler = $http.post(AppConfig.session.refresh + '?token='+AppConfig.session.token, postdata); handler.success(scope.ProcessResponse); handler.error(scope.ProcessError); @@ -83,7 +83,7 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) scope.ResetSession = function() { console.log ("ResetSession"); var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.reset + '?token='+ConfigApp.session.token, postdata); + var handler = $http.post(AppConfig.session.reset + '?token='+AppConfig.session.token, postdata); handler.success(scope.ProcessResponse); handler.error(scope.ProcessError); diff --git a/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js b/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js index 8c0a4c2..a23809f 100644 --- a/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js +++ b/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js @@ -126,9 +126,9 @@ function LoadFileSvc (scope, elem, posturl, files, thumbnailCB) { xmlReq.send(xform); } -angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) +angular.module('UploadFiles',['AppConfig', 'ModalNotification', 'RangeSlider']) -.directive('uploadImage', function(ConfigApp, JQemu, Notification) { +.directive('uploadImage', function(AppConfig, JQemu, Notification) { function mymethods(scope, elem, attrs) { // get widget image handle from template @@ -152,7 +152,7 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) scope.imgElem[0].src = window.URL.createObjectURL(new Blob([upload.target.result], {type: "image"})); return true; // true activates post }; - var posturl = attrs.posturl + "?token=" + ConfigApp.session.token; + var posturl = attrs.posturl + "?token=" + AppConfig.session.token; new LoadFileSvc (scope, elem, posturl, files, readerCB); }; @@ -163,14 +163,14 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) scope.maxsize= attrs.maxsize || 100; // default max size 100KB scope.regexp = new RegExp (attrs.accept+ '.*','i'); - if (attrs.thumbnail) scope.thumbnail= ConfigApp.paths[scope.category] + attrs.thumbnail; - else scope.thumbnail=ConfigApp.paths[scope.category] + 'tux-bzh.png'; + if (attrs.thumbnail) scope.thumbnail= AppConfig.paths[scope.category] + attrs.thumbnail; + else scope.thumbnail=AppConfig.paths[scope.category] + 'tux-bzh.png'; - if (attrs.thumbnail) scope.isnotvalid= ConfigApp.paths[scope.category] + attrs.isnotvalid; - else scope.isnotvalid=ConfigApp.paths[scope.category] + 'isnotvalid.png'; + if (attrs.thumbnail) scope.isnotvalid= AppConfig.paths[scope.category] + attrs.isnotvalid; + else scope.isnotvalid=AppConfig.paths[scope.category] + 'isnotvalid.png'; - if (attrs.istoobig) scope.istoobig= ConfigApp.paths[scope.category] + attrs.istoobig; - else scope.istoobig=ConfigApp.paths[scope.category] + 'istoobig.png'; + if (attrs.istoobig) scope.istoobig= AppConfig.paths[scope.category] + attrs.istoobig; + else scope.istoobig=AppConfig.paths[scope.category] + 'istoobig.png'; scope.noslider = attrs.noslider || false; if (!attrs.posturl) throw new TypeError('file-upload %s posturl=/api/xxxx/xxxx required', scope.attrs); @@ -185,7 +185,7 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) }; }) -.directive('uploadAudio', function(ConfigApp, JQemu, Notification) { +.directive('uploadAudio', function(AppConfig, JQemu, Notification) { function mymethods(scope, elem, attrs) { // get widget image handle from template @@ -204,7 +204,7 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) // Upload is delegated to a shared function scope.UpLoadFile=function (files) { - var posturl = attrs.posturl + "?token=" + ConfigApp.session.token; + var posturl = attrs.posturl + "?token=" + AppConfig.session.token; new LoadFileSvc (scope, elem, posturl, files, false); }; @@ -215,14 +215,14 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) scope.maxsize= attrs.maxsize || 10000; // default max size 10MB scope.regexp = new RegExp (attrs.accept+ '.*','i'); - if (attrs.thumbnail) scope.thumbnail= ConfigApp.paths[scope.category] + attrs.thumbnail; - else scope.thumbnail=ConfigApp.paths[scope.category] + 'upload-music.png'; + if (attrs.thumbnail) scope.thumbnail= AppConfig.paths[scope.category] + attrs.thumbnail; + else scope.thumbnail=AppConfig.paths[scope.category] + 'upload-music.png'; - if (attrs.thumbnail) scope.isnotvalid= ConfigApp.paths[scope.category] + attrs.isnotvalid; - else scope.isnotvalid=ConfigApp.paths[scope.category] + 'isnotvalid.png'; + if (attrs.thumbnail) scope.isnotvalid= AppConfig.paths[scope.category] + attrs.isnotvalid; + else scope.isnotvalid=AppConfig.paths[scope.category] + 'isnotvalid.png'; - if (attrs.istoobig) scope.istoobig= ConfigApp.paths[scope.category] + attrs.istoobig; - else scope.istoobig=ConfigApp.paths[scope.category] + 'istoobig.png'; + if (attrs.istoobig) scope.istoobig= AppConfig.paths[scope.category] + attrs.istoobig; + else scope.istoobig=AppConfig.paths[scope.category] + 'istoobig.png'; scope.noslider = attrs.noslider || false; if (!attrs.posturl) throw new TypeError('file-upload %s posturl=/api/xxxx/xxxx required', scope.attrs); @@ -238,7 +238,7 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) }) -.directive('uploadAppli', function(ConfigApp, JQemu, Notification) { +.directive('uploadAppli', function(AppConfig, JQemu, Notification) { function mymethods(scope, elem, attrs) { // get widget image handle from template @@ -265,14 +265,14 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) // Check is we have a thumbnail within loaded Zipfile if (!thumbnail) { console.log ("This is not a valid Application Framework APP"); - scope.thumbnail=ConfigApp.paths[scope.category] + 'isnotvalid.png'; + scope.thumbnail=AppConfig.paths[scope.category] + 'isnotvalid.png'; scope.$apply('thumbnail'); // we short-circuit Angular resync Image return false; // do not post zip on binder } scope.imgElem[0].src = window.URL.createObjectURL(new Blob([thumbnail.asArrayBuffer()], {type: "image"})); return true; // true activates post }; - var posturl = attrs.posturl + "?token=" + ConfigApp.session.token; + var posturl = attrs.posturl + "?token=" + AppConfig.session.token; new LoadFileSvc (scope, elem, posturl, files, readerCB); }; @@ -283,14 +283,14 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider']) scope.maxsize= attrs.maxsize || 100000; // default max size 100MB scope.regexp = new RegExp (attrs.accept+ '.*','i'); - if (attrs.thumbnail) scope.thumbnail= ConfigApp.paths[scope.category] + attrs.thumbnail; - else scope.thumbnail=ConfigApp.paths[scope.category] + 'upload-appli.png'; + if (attrs.thumbnail) scope.thumbnail= AppConfig.paths[scope.category] + attrs.thumbnail; + else scope.thumbnail=AppConfig.paths[scope.category] + 'upload-appli.png'; - if (attrs.thumbnail) scope.isnotvalid= ConfigApp.paths[scope.category] + attrs.isnotvalid; - else scope.isnotvalid=ConfigApp.paths[scope.category] + 'isnotvalid.png'; + if (attrs.thumbnail) scope.isnotvalid= AppConfig.paths[scope.category] + attrs.isnotvalid; + else scope.isnotvalid=AppConfig.paths[scope.category] + 'isnotvalid.png'; - if (attrs.istoobig) scope.istoobig= ConfigApp.paths[scope.category] + attrs.istoobig; - else scope.istoobig=ConfigApp.paths[scope.category] + 'istoobig.png'; + if (attrs.istoobig) scope.istoobig= AppConfig.paths[scope.category] + attrs.istoobig; + else scope.istoobig=AppConfig.paths[scope.category] + 'istoobig.png'; scope.noslider = attrs.noslider || false; if (!attrs.posturl) throw new TypeError('file-upload %s posturl=/api/xxxx/xxxx required', scope.attrs); -- cgit 1.2.3-korg