summaryrefslogtreecommitdiffstats
path: root/afb-client/app/Frontend
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-02-15 15:56:36 +0100
committerFulup Ar Foll <fulup@iot.bzh>2016-02-15 15:56:36 +0100
commite6d12f74be543056a439259b61ba40a9d0adcf5c (patch)
tree06042b26cc2745b749ea1ff99370acaf58e12223 /afb-client/app/Frontend
parentfb1353dbc12ae889c17a6aa1572b917f57de0f9d (diff)
Updated TokenRefresh and AppConfig
Diffstat (limited to 'afb-client/app/Frontend')
-rw-r--r--afb-client/app/Frontend/app.js4
-rw-r--r--afb-client/app/Frontend/etc/AppConfig.js (renamed from afb-client/app/Frontend/etc/ConfigApp.js)23
-rw-r--r--afb-client/app/Frontend/pages/Home/HomeModule.js20
-rw-r--r--afb-client/app/Frontend/widgets/FormInput/UploadFiles.js52
4 files changed, 54 insertions, 45 deletions
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/ConfigApp.js b/afb-client/app/Frontend/etc/AppConfig.js
index a6a0cad..bd1aae0 100644
--- a/afb-client/app/Frontend/etc/ConfigApp.js
+++ b/afb-client/app/Frontend/etc/AppConfig.js
@@ -2,10 +2,10 @@
'use strict';
// _all modules only reference dependencies
- angular.module('ConfigApp', [])
+ angular.module('AppConfig', [])
// Factory is a singleton and share its context within all instances.
- .factory('ConfigApp', function (urlquery) {
+ .factory('AppConfig', function (urlquery) {
var myConfig = {
paths: { // Warning paths should end with /
@@ -14,11 +14,7 @@
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',
@@ -34,6 +30,19 @@
};
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/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);