mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Made default group for a challenge the selected group filter if there is only one filter selected.
This commit is contained in:
@@ -25,6 +25,25 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
|||||||
* Create
|
* Create
|
||||||
*/
|
*/
|
||||||
$scope.create = function() {
|
$scope.create = function() {
|
||||||
|
|
||||||
|
//If the user has one filter selected, assume that the user wants to default to that group
|
||||||
|
var defaultGroup;
|
||||||
|
//Our filters contain all groups, but we only want groups that have atleast one challenge
|
||||||
|
var groupsWithChallenges = _.uniq(_.pluck($scope.groupsFilter, '_id'));
|
||||||
|
var len = groupsWithChallenges.length;
|
||||||
|
var filterCount = 0;
|
||||||
|
|
||||||
|
for ( var i = 0; i < len; i += 1 ) {
|
||||||
|
if ( $scope.search.group[groupsWithChallenges[i]] == true ) {
|
||||||
|
filterCount += 1;
|
||||||
|
defaultGroup = groupsWithChallenges[i];
|
||||||
|
}
|
||||||
|
if (filterCount > 1) {
|
||||||
|
defaultGroup = $scope.groups[0]._id
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
|
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
@@ -33,7 +52,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
|||||||
todos: [],
|
todos: [],
|
||||||
rewards: [],
|
rewards: [],
|
||||||
leader: User.user._id,
|
leader: User.user._id,
|
||||||
group: $scope.groups[0]._id,
|
group: defaultGroup,
|
||||||
timestamp: +(new Date),
|
timestamp: +(new Date),
|
||||||
members: [],
|
members: [],
|
||||||
official: false
|
official: false
|
||||||
|
|||||||
Reference in New Issue
Block a user