4 // _all modules only reference dependencies
5 angular.module('AppConfig', [])
7 // Factory is a singleton and share its context within all instances.
8 .factory('AppConfig', function (urlquery) {
11 paths: { // Warning paths should end with /
13 avatar: 'images/avatars/',
14 audio : 'images/audio/',
15 appli : 'images/appli/'
18 session: { // Those data are updated by session service
19 initial : urlquery.token || '123456789', // typical dev initial token
20 timeout : 3600, // timeout is updated client sessin context creation
21 pingrate: 30, // Ping rate to check if server is still alive
22 uuid : '', // uuid map with cookie or long term session access key
23 token : '' // will be returned from authentication
30 // Factory is a singleton and share its context within all instances.
31 .factory('AppCall', function ($http, AppConfig, $log) {
34 get : function(plugin, action, query, cbresponse, cberror) {
36 var onerror = function(response) {
37 if (cberror) cberror(response.data, response.status, response.config);
38 else cbresponse(response.data, response.status, response.config);
41 var onsuccess =function(response) {
42 if (!response.data || !response.data.request) {
47 var request=response.data.request;
49 // if token was updated keep it within application cache
50 if (request.token) AppConfig.session.token = request.token;
51 if (request.uuid) AppConfig.session.uuid = request.uuid;
52 if (request.timeout) AppConfig.session.timeout = request.timeout;
54 cbresponse(response.data, response.status, response.config);
58 if (!query.token) query.token = AppConfig.session.token; // add token to provided query
59 if (!query.reqid) query.reqid = action; // use action as default requestID
60 var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then(onsuccess, onerror);