mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-17 17:32:22 +00:00
Merge pull request #4044 from negue/apiUrlService
Use ApiUrlService in all services
This commit is contained in:
commit
a595880568
11 changed files with 73 additions and 74 deletions
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
|
||||
angular.module('authCtrl', [])
|
||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL', '$modal',
|
||||
function($scope, $rootScope, User, $http, $location, $window, API_URL, $modal) {
|
||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrlService', '$modal',
|
||||
function($scope, $rootScope, User, $http, $location, $window, ApiUrlService, $modal) {
|
||||
var runAuth;
|
||||
var showedFacebookMessage;
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('authCtrl', [])
|
|||
if ($scope.registrationForm.$invalid) {
|
||||
return;
|
||||
}
|
||||
var url = API_URL + "/api/v2/register";
|
||||
var url = ApiUrlService.get() + "/api/v2/register";
|
||||
if($rootScope.selectedLanguage) url = url + '?lang=' + $rootScope.selectedLanguage.code;
|
||||
$http.post(url, $scope.registerVals).success(function(data, status, headers, config) {
|
||||
runAuth(data.id, data.apiToken);
|
||||
|
|
@ -62,7 +62,7 @@ angular.module('authCtrl', [])
|
|||
if ($scope.useUUID) {
|
||||
runAuth($scope.loginUsername, $scope.loginPassword);
|
||||
} else {
|
||||
$http.post(API_URL + "/api/v2/user/auth/local", data)
|
||||
$http.post(ApiUrlService.get() + "/api/v2/user/auth/local", data)
|
||||
.success(function(data, status, headers, config) {
|
||||
runAuth(data.id, data.token);
|
||||
}).error(errorAlert);
|
||||
|
|
@ -82,7 +82,7 @@ angular.module('authCtrl', [])
|
|||
};
|
||||
|
||||
$scope.passwordReset = function(email){
|
||||
$http.post(API_URL + '/api/v2/user/reset-password', {email:email})
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/reset-password', {email:email})
|
||||
.success(function(){
|
||||
alert(window.env.t('newPassSent'));
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
(typeof habitrpg !== 'undefined' ? habitrpg : habitrpgStatic)
|
||||
.controller("FooterCtrl", ['$scope', '$rootScope', 'User', '$http', 'Notification', 'API_URL',
|
||||
function($scope, $rootScope, User, $http, Notification, API_URL) {
|
||||
.controller("FooterCtrl", ['$scope', '$rootScope', 'User', '$http', 'Notification', 'ApiUrlService',
|
||||
function($scope, $rootScope, User, $http, Notification, ApiUrlService) {
|
||||
|
||||
if(typeof habitrpg === "undefined"){
|
||||
$scope.languages = env.avalaibleLanguages;
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
Notification.text('-1 day, remember to refresh');
|
||||
}
|
||||
$scope.addTenGems = function(){
|
||||
$http.post(API_URL + '/api/v2/user/addTenGems').success(function(){
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/addTenGems').success(function(){
|
||||
User.log({});
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '$http', 'API_URL', '$q', 'User', 'Members', '$state',
|
||||
function($scope, $rootScope, Shared, Groups, $http, API_URL, $q, User, Members, $state) {
|
||||
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '$http', '$q', 'User', 'Members', '$state',
|
||||
function($scope, $rootScope, Shared, Groups, $http, $q, User, Members, $state) {
|
||||
$scope.isMemberOfPendingQuest = function(userid, group) {
|
||||
if (!group.quest || !group.quest.members) return false;
|
||||
if (group.quest.active) return false; // quest is started, not pending
|
||||
return userid in group.quest.members && group.quest.members[userid] != false;
|
||||
}
|
||||
|
||||
$scope.isMemberOfPendingQuest = function(userid, group){
|
||||
if (!group.quest || !group.quest.members) return false;
|
||||
if (group.quest.active) return false; // quest is started, not pending
|
||||
return userid in group.quest.members && group.quest.members[userid] != false;
|
||||
}
|
||||
$scope.isMemberOfRunningQuest = function(userid, group) {
|
||||
if (!group.quest || !group.quest.members) return false;
|
||||
if (!group.quest.active) return false; // quest is pending, not started
|
||||
return group.quest.members[userid];
|
||||
}
|
||||
|
||||
$scope.isMemberOfRunningQuest = function(userid, group){
|
||||
if (!group.quest || !group.quest.members) return false;
|
||||
if (!group.quest.active) return false; // quest is pending, not started
|
||||
return group.quest.members[userid];
|
||||
}
|
||||
|
||||
$scope.isMemberOfGroup = function(userid, group){
|
||||
if (!group.members) return false;
|
||||
var memberIds = _.map(group.members, function(x){return x._id});
|
||||
return ~(memberIds.indexOf(userid));
|
||||
}
|
||||
$scope.isMemberOfGroup = function(userid, group){
|
||||
if (!group.members) return false;
|
||||
var memberIds = _.map(group.members, function(x){return x._id});
|
||||
return ~(memberIds.indexOf(userid));
|
||||
}
|
||||
|
||||
$scope.isMember = function(user, group){
|
||||
return ~(group.members.indexOf(user._id));
|
||||
|
|
@ -145,7 +144,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
});
|
||||
}])
|
||||
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', '$http', 'API_URL', 'Notification', function($scope, Groups, User, $http, API_URL, Notification){
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', '$http', 'ApiUrlService', 'Notification', function($scope, Groups, User, $http, ApiUrlService, Notification){
|
||||
$scope.message = {content:''};
|
||||
$scope._sending = false;
|
||||
|
||||
|
|
@ -207,7 +206,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
}
|
||||
//Chat.Chat.like({gid:group._id,mid:message.id});
|
||||
|
||||
$http.post(API_URL + '/api/v2/groups/' + group._id + '/chat/' + message.id + '/like');
|
||||
$http.post(ApiUrlService.get() + '/api/v2/groups/' + group._id + '/chat/' + message.id + '/like');
|
||||
}
|
||||
|
||||
$scope.sync = function(group){
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource',
|
||||
function($scope, $rootScope, User, Notification, API_URL, $resource) {
|
||||
var Hero = $resource(API_URL + '/api/v2/hall/heroes/:uid', {uid:'@_id'});
|
||||
habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrlService', '$resource',
|
||||
function($scope, $rootScope, User, Notification, ApiUrlService, $resource) {
|
||||
var Hero = $resource(ApiUrlService.get() + '/api/v2/hall/heroes/:uid', {uid:'@_id'});
|
||||
$scope.hero = undefined;
|
||||
$scope.loadHero = function(uuid){
|
||||
$scope.hero = Hero.get({uid:uuid});
|
||||
|
|
@ -18,9 +18,9 @@ habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notifica
|
|||
$scope.heroes = Hero.query();
|
||||
}]);
|
||||
|
||||
habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource',
|
||||
function($scope, $rootScope, User, Notification, API_URL, $resource) {
|
||||
var Patron = $resource(API_URL + '/api/v2/hall/patrons/:uid', {uid:'@_id'});
|
||||
habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrlService', '$resource',
|
||||
function($scope, $rootScope, User, Notification, ApiUrlService, $resource) {
|
||||
var Patron = $resource(ApiUrlService.get() + '/api/v2/hall/patrons/:uid', {uid:'@_id'});
|
||||
|
||||
var page = 0;
|
||||
$scope.patrons = [];
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
/* Make user and settings available for everyone through root scope.
|
||||
*/
|
||||
|
||||
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout',
|
||||
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout) {
|
||||
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout', 'ApiUrlService'
|
||||
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout, ApiUrlService) {
|
||||
var user = User.user;
|
||||
|
||||
var initSticky = _.once(function(){
|
||||
|
|
@ -235,7 +235,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
|||
$scope.spell = null;
|
||||
$rootScope.applyingAction = false;
|
||||
|
||||
$http.post('/api/v2/user/class/cast/'+spell.key+'?targetType='+type+'&targetId='+targetId)
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/class/cast/'+spell.key+'?targetType='+type+'&targetId='+targetId)
|
||||
.success(function(){
|
||||
var msg = window.env.t('youCast', {spell: spell.text()});
|
||||
switch (type) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
// Make user and settings available for everyone through root scope.
|
||||
habitrpg.controller('SettingsCtrl',
|
||||
['$scope', 'User', '$rootScope', '$http', 'API_URL', 'Guide', '$location', '$timeout', 'Notification',
|
||||
function($scope, User, $rootScope, $http, API_URL, Guide, $location, $timeout, Notification) {
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrlService', 'Guide', '$location', '$timeout', 'Notification',
|
||||
function($scope, User, $rootScope, $http, ApiUrlService, Guide, $location, $timeout, Notification) {
|
||||
|
||||
// FIXME we have this re-declared everywhere, figure which is the canonical version and delete the rest
|
||||
// $scope.auth = function (id, token) {
|
||||
|
|
@ -79,7 +79,7 @@ habitrpg.controller('SettingsCtrl',
|
|||
if (!changeUser.newUsername || !changeUser.password) {
|
||||
return alert(window.env.t('fillAll'));
|
||||
}
|
||||
$http.post(API_URL + '/api/v2/user/change-username', changeUser)
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/change-username', changeUser)
|
||||
.success(function(){
|
||||
alert(window.env.t('usernameSuccess'));
|
||||
$scope.changeUser = {};
|
||||
|
|
@ -93,7 +93,7 @@ habitrpg.controller('SettingsCtrl',
|
|||
if (!changePass.oldPassword || !changePass.newPassword || !changePass.confirmNewPassword) {
|
||||
return alert(window.env.t('fillAll'));
|
||||
}
|
||||
$http.post(API_URL + '/api/v2/user/change-password', changePass)
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/change-password', changePass)
|
||||
.success(function(data, status, headers, config){
|
||||
if (data.err) return alert(data.err);
|
||||
alert(window.env.t('passSuccess'));
|
||||
|
|
@ -130,7 +130,7 @@ habitrpg.controller('SettingsCtrl',
|
|||
}
|
||||
|
||||
$scope['delete'] = function(){
|
||||
$http['delete'](API_URL + '/api/v2/user')
|
||||
$http['delete'](ApiUrlService.get() + '/api/v2/user')
|
||||
.success(function(res, code){
|
||||
if (res.err) return alert(res.err);
|
||||
localStorage.clear();
|
||||
|
|
@ -139,14 +139,14 @@ habitrpg.controller('SettingsCtrl',
|
|||
}
|
||||
|
||||
$scope.enterCoupon = function(code) {
|
||||
$http.post(API_URL + '/api/v2/user/coupon/' + code).success(function(res,code){
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/coupon/' + code).success(function(res,code){
|
||||
if (code!==200) return;
|
||||
User.sync();
|
||||
Notification.text('Coupon applied! Check your inventory');
|
||||
});
|
||||
}
|
||||
$scope.generateCodes = function(codes){
|
||||
$http.post(API_URL + '/api/v2/coupons/generate/'+codes.event+'?count='+(codes.count || 1))
|
||||
$http.post(ApiUrlService.get() + '/api/v2/coupons/generate/'+codes.event+'?count='+(codes.count || 1))
|
||||
.success(function(res,code){
|
||||
$scope._codes = {};
|
||||
if (code!==200) return;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','Notification', '$http', 'API_URL', '$timeout', 'Shared',
|
||||
function($scope, $rootScope, $location, User, Notification, $http, API_URL, $timeout, Shared) {
|
||||
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','Notification', '$http', 'ApiUrlService', '$timeout', 'Shared',
|
||||
function($scope, $rootScope, $location, User, Notification, $http, ApiUrlService, $timeout, Shared) {
|
||||
$scope.obj = User.user; // used for task-lists
|
||||
$scope.user = User.user;
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||
|
||||
$scope.unlink = function(task, keep) {
|
||||
// TODO move this to userServices, turn userSerivces.user into ng-resource
|
||||
$http.post(API_URL + '/api/v2/user/tasks/' + task.id + '/unlink?keep=' + keep)
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/tasks/' + task.id + '/unlink?keep=' + keep)
|
||||
.success(function(){
|
||||
User.log({});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ var facebook = {}
|
|||
|
||||
angular.module('authServices', ['userServices']).
|
||||
factory('Facebook',
|
||||
['$http', '$location', 'User', 'API_URL',
|
||||
function($http, $location, User, API_URL) {
|
||||
['$http', '$location', 'User', 'ApiUrlService',
|
||||
function($http, $location, User, ApiUrlService) {
|
||||
//TODO FB.init({appId: '${section.parameters['facebook.app.id']}', status: true, cookie: true, xfbml: true});
|
||||
var auth, user = User.user;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ factory('Facebook',
|
|||
email: response.email
|
||||
}
|
||||
|
||||
$http.post(API_URL + '/api/v2/user/auth/facebook', data).success(function(data, status, headers, config) {
|
||||
$http.post(ApiUrlService.get() + '/api/v2/user/auth/facebook', data).success(function(data, status, headers, config) {
|
||||
User.authenticate(data.id, data.token, function(err) {
|
||||
if (!err) {
|
||||
alert(window.env.t('loginSuccess'));
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@
|
|||
*/
|
||||
|
||||
angular.module('challengeServices', ['ngResource']).
|
||||
factory('Challenges', ['API_URL', '$resource', 'User', '$q', 'Members',
|
||||
function(API_URL, $resource, User, $q, Members) {
|
||||
var Challenge = $resource(API_URL + '/api/v2/challenges/:cid',
|
||||
factory('Challenges', ['ApiUrlService', '$resource', 'User', '$q', 'Members',
|
||||
function(ApiUrlService, $resource, User, $q, Members) {
|
||||
var Challenge = $resource(ApiUrlService.get() + '/api/v2/challenges/:cid',
|
||||
{cid:'@_id'},
|
||||
{
|
||||
//'query': {method: "GET", isArray:false}
|
||||
join: {method: "POST", url: API_URL + '/api/v2/challenges/:cid/join'},
|
||||
leave: {method: "POST", url: API_URL + '/api/v2/challenges/:cid/leave'},
|
||||
close: {method: "POST", params: {uid:''}, url: API_URL + '/api/v2/challenges/:cid/close'},
|
||||
getMember: {method: "GET", url: API_URL + '/api/v2/challenges/:cid/member/:uid'}
|
||||
join: {method: "POST", url: ApiUrlService.get() + '/api/v2/challenges/:cid/join'},
|
||||
leave: {method: "POST", url: ApiUrlService.get() + '/api/v2/challenges/:cid/leave'},
|
||||
close: {method: "POST", params: {uid:''}, url: ApiUrlService.get() + '/api/v2/challenges/:cid/close'},
|
||||
getMember: {method: "GET", url: ApiUrlService.get() + '/api/v2/challenges/:cid/member/:uid'}
|
||||
});
|
||||
|
||||
//var challenges = [];
|
||||
|
|
|
|||
|
|
@ -5,22 +5,22 @@
|
|||
*/
|
||||
|
||||
angular.module('groupServices', ['ngResource']).
|
||||
factory('Groups', ['API_URL', '$resource', '$q', '$http', 'User',
|
||||
function(API_URL, $resource, $q, $http, User) {
|
||||
var Group = $resource(API_URL + '/api/v2/groups/:gid',
|
||||
factory('Groups', ['ApiUrlService', '$resource', '$q', '$http', 'User',
|
||||
function(ApiUrlService, $resource, $q, $http, User) {
|
||||
var Group = $resource(ApiUrlService.get() + '/api/v2/groups/:gid',
|
||||
{gid:'@_id', messageId: '@_messageId'},
|
||||
{
|
||||
//query: {method: "GET", isArray:false},
|
||||
postChat: {method: "POST", url: API_URL + '/api/v2/groups/:gid/chat'},
|
||||
deleteChatMessage: {method: "DELETE", url: API_URL + '/api/v2/groups/:gid/chat/:messageId'},
|
||||
join: {method: "POST", url: API_URL + '/api/v2/groups/:gid/join'},
|
||||
leave: {method: "POST", url: API_URL + '/api/v2/groups/:gid/leave'},
|
||||
invite: {method: "POST", url: API_URL + '/api/v2/groups/:gid/invite'},
|
||||
removeMember: {method: "POST", url: API_URL + '/api/v2/groups/:gid/removeMember'},
|
||||
questAccept: {method: "POST", url: API_URL + '/api/v2/groups/:gid/questAccept'},
|
||||
questReject: {method: "POST", url: API_URL + '/api/v2/groups/:gid/questReject'},
|
||||
questCancel: {method: "POST", url: API_URL + '/api/v2/groups/:gid/questCancel'},
|
||||
questAbort: {method: "POST", url: API_URL + '/api/v2/groups/:gid/questAbort'}
|
||||
postChat: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat'},
|
||||
deleteChatMessage: {method: "DELETE", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId'},
|
||||
join: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/join'},
|
||||
leave: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/leave'},
|
||||
invite: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/invite'},
|
||||
removeMember: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/removeMember'},
|
||||
questAccept: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/questAccept'},
|
||||
questReject: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/questReject'},
|
||||
questCancel: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/questCancel'},
|
||||
questAbort: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/questAbort'}
|
||||
});
|
||||
|
||||
// Defer loading everything until they're requested
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('groupServices', ['ngResource']).
|
|||
|
||||
// On enter, set chat message to "seen"
|
||||
seenMessage: function(gid){
|
||||
$http.post('/api/v2/groups/'+gid+'/chat/seen');
|
||||
$http.post(ApiUrlService.get() + '/api/v2/groups/'+gid+'/chat/seen');
|
||||
if (User.user.newMessages) delete User.user.newMessages[gid];
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
|
||||
angular.module('memberServices', ['ngResource', 'sharedServices']).
|
||||
factory('Members', ['$rootScope', 'Shared', 'API_URL', '$resource',
|
||||
function($rootScope, Shared, API_URL, $resource) {
|
||||
factory('Members', ['$rootScope', 'Shared', 'ApiUrlService', '$resource',
|
||||
function($rootScope, Shared, ApiUrlService, $resource) {
|
||||
var members = {};
|
||||
var Member = $resource(API_URL + '/api/v2/members/:uid', {uid:'@_id'});
|
||||
var Member = $resource(ApiUrlService.get() + '/api/v2/members/:uid', {uid:'@_id'});
|
||||
var memberServices = {
|
||||
|
||||
Member: Member,
|
||||
|
|
|
|||
Loading…
Reference in a new issue