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/'
16 session: { // Those data are updated by session service
17 initial : urlquery.token || '123456789', // typical dev initial token
18 timeout : 3600, // timeout is updated client sessin context creation
19 pingrate: 30, // Ping rate to check if server is still alive
20 uuid : '', // uuid map with cookie or long term session access key
21 token : '' // will be returned from authentication
28 // Factory is a singleton and share its context within all instances.
29 .factory('AppCall', function ($http, AppConfig, $log) {
32 get : function(plugin, action, query, cbresponse, cberror) {
34 var onerror = function(response) {
35 if (cberror) cberror(response.data, response.status, response.config);
36 else cbresponse(response.data, response.status, response.config);
39 var onsuccess =function(response) {
40 if (!response.data || !response.data.request) {
45 var request=response.data.request;
47 // if token was updated keep it within application cache
48 if (request.token) AppConfig.session.token = request.token;
49 if (request.uuid) AppConfig.session.uuid = request.uuid;
50 if (request.timeout) AppConfig.session.timeout = request.timeout;
52 cbresponse(response.data, response.status, response.config);
56 if (!query.token) query.token = AppConfig.session.token; // add token to provided query
57 if (!query.reqid) query.reqid = action; // use action as default requestID
58 var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then(onsuccess, onerror);