-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.js
50 lines (43 loc) · 1.57 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
// There's an error while initializing content-member-algo.php. It creates a 'not defined' error on the coder object. Problem exists in other pages as well.
// Solving this is out of scope. So, just stopping that error instead
var coder = {
initMemberBadges : function(){}
}
window.tc = angular.module('tc', [
'restangular',
'tc.challengeService',
'tc.memberProfileService',
'ngGrid'
])
.constant("API_URL", "https://api.topcoder.com/v2")
.constant("PHOTO_LINK_LOCATION", "http://community.topcoder.com")
.constant("MEMBER_PROFILE_TEMPLATE_URL", "/js/app/member-profile/partials/memberProfile.tpl.html")
.config(['$httpProvider', 'RestangularProvider', 'API_URL', function($httpProvider, RestangularProvider, API_URL) {
/*
* Enable CORS
* http://stackoverflow.com/questions/17289195/angularjs-post-data-to-external-rest-api
*/
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
// Base API url
RestangularProvider.setBaseUrl(API_URL);
// Format restangular response
// add a response intereceptor
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
var extractedData;
// .. to look for getList operations
if (operation === "getList") {
// .. and handle the data and meta data
extractedData = data.data;
extractedData.pagination = {
total: data.total,
pageIndex: data.pageIndex,
pageSize: data.pageSize
};
} else {
extractedData = data;
}
return extractedData;
});
}]);