Api v3 fixes continued (#7205)

* Added timzeone offset back

* Added APIToken back to settings page

* Fixed fetch recent messages for party

* Fixed returning group description

* Fixed check if user is member of challenge

* Fixed party members appearing in header

* Updated get myGroups param to include public groups. Fixed isMemberOf group

* Fixed hourglass purchase

* Fixed challenge addding tasks on first creating

* Updated tests to accomidate new changes
This commit is contained in:
Keith Holliday
2016-05-13 16:36:25 -05:00
committed by Matteo Pagliazzi
parent cc20812674
commit 1fd7df7521
12 changed files with 72 additions and 49 deletions

View File

@@ -30,6 +30,10 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
});
};
$scope.isUserMemberOf = function (challenge) {
return User.user.challenges.indexOf(challenge._id) !== -1;
}
$scope.editTask = Tasks.editTask;
/**
@@ -124,21 +128,25 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
}
if (isNew) {
var _challenge;
Challenges.createChallenge(challenge)
.then(function (response) {
var _challenge = response.data.data;
_challenge = response.data.data;
Notification.text(window.env.t('challengeCreated'));
User.sync();
var challengeTasks = [];
challengeTasks = challengeTasks.concat(challenge.todos);
challengeTasks = challengeTasks.concat(challenge.habits);
challengeTasks = challengeTasks.concat(challenge.dailys);
challengeTasks = challengeTasks.concat(challenge.rewards);
return Tasks.createChallengeTasks(_challenge._id, challengeTasks);
})
.then(function (response) {
$state.transitionTo('options.social.challenges.detail', { cid: _challenge._id }, {
reload: true, inherit: false, notify: true
});
var challengeTasks = [];
challengeTasks.concat(challenge.todos);
challengeTasks.concat(challenge.habits);
challengeTasks.concat(challenge.dailys);
challengeTasks.concat(challenge.reqards);
Tasks.createChallengeTasks(_challenge._id, challengeTasks);
});
} else {
Challenges.updateChallenge(challenge._id, challenge)
@@ -169,6 +177,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
challenge.winner = undefined;
};
//@TODO: change to $scope.remove
$scope["delete"] = function(challenge) {
var warningMsg;
@@ -232,7 +241,8 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
//------------------------------------------------------------
$scope.addTask = function(addTo, listDef, challenge) {
var task = Shared.taskDefaults({text: listDef.newTask, type: listDef.type});
Tasks.createChallengeTasks(challenge._id, task);
//If the challenge has not been created, we bulk add tasks on save
if (challenge._id) Tasks.createChallengeTasks(challenge._id, task);
if (!challenge[task.type + 's']) challenge[task.type + 's'] = [];
challenge[task.type + 's'].unshift(task);
delete listDef.newTask;