diff --git a/test/api/v3/integration/challenges/POST-challenges_challengeId_leave.test.js b/test/api/v3/integration/challenges/POST-challenges_challengeId_leave.test.js index 0a0a89258a..bb366536cf 100644 --- a/test/api/v3/integration/challenges/POST-challenges_challengeId_leave.test.js +++ b/test/api/v3/integration/challenges/POST-challenges_challengeId_leave.test.js @@ -117,9 +117,6 @@ describe('POST /challenges/:challengeId/leave', () => { }); expect(testTask).to.not.be.undefined; - expect(testTask.challenge).to.eql({ - shortName: 'None', - }); }); }); }); diff --git a/website/client-old/js/components/groupTasks/groupTasksController.js b/website/client-old/js/components/groupTasks/groupTasksController.js index bbed386ee2..c8e03ab5f5 100644 --- a/website/client-old/js/components/groupTasks/groupTasksController.js +++ b/website/client-old/js/components/groupTasks/groupTasksController.js @@ -74,6 +74,7 @@ habitrpg.controller('GroupTasksCtrl', ['$scope', 'Shared', 'Tasks', 'User', '$ro if (group._id) Tasks.deleteTask(task._id); var index = group[task.type + 's'].indexOf(task); group[task.type + 's'].splice(index, 1); + $rootScope.$broadcast('obj-updated', $scope.group); }; $scope.saveTask = function(task, stayOpen, isSaveAndClose) { diff --git a/website/client-old/js/controllers/tasksCtrl.js b/website/client-old/js/controllers/tasksCtrl.js index 2936a8d476..3c42c48c9f 100644 --- a/website/client-old/js/controllers/tasksCtrl.js +++ b/website/client-old/js/controllers/tasksCtrl.js @@ -159,6 +159,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N $scope.removeTask = function(task) { if (!Tasks.removeTask(task)) return; User.deleteTask({params:{id: task._id, taskType: task.type}}) + $rootScope.$broadcast('obj-updated', User.user); }; $scope.unlink = function(task, keep) { diff --git a/website/client-old/js/directives/task-list.directive.js b/website/client-old/js/directives/task-list.directive.js index a1367d4c49..8406b8de65 100644 --- a/website/client-old/js/directives/task-list.directive.js +++ b/website/client-old/js/directives/task-list.directive.js @@ -65,14 +65,22 @@ return $scope.obj[list.type+'s']; }; - $scope.showNormalList = function () { - return !$state.includes("options.social.challenges") && !User.user.preferences.tasks.groupByChallenge; - }; + function objIsGroup (obj) { + return obj && obj.type && (obj.type === 'guild' || obj.type === 'party'); + } + + $scope.showNormalList = function (obj) { + return objIsGroup(obj) || (!$state.includes("options.social.challenges") && !User.user.preferences.tasks.groupByChallenge); + } $scope.showChallengeList = function () { return $state.includes("options.social.challenges"); }; + $scope.showGroupedList = function (obj) { + return User.user.preferences.tasks.groupByChallenge && !$state.includes("options.social.challenges") && !objIsGroup(obj); + } + $scope.showDoubleTaskCounter = function (task, obj) { var objectIsGroup = obj.type && (obj.type === 'guild' || obj.type === 'party'); var objectIsChallenge = $state.includes("options.social.challenges"); diff --git a/website/server/models/challenge.js b/website/server/models/challenge.js index 8e96fbffb5..464d4a8257 100644 --- a/website/server/models/challenge.js +++ b/website/server/models/challenge.js @@ -158,7 +158,7 @@ async function _addTaskFn (challenge, tasks, memberId) { tasks.forEach(chalTask => { let userTask = new Tasks[chalTask.type](Tasks.Task.sanitize(syncableAttrs(chalTask))); - userTask.challenge = {taskId: chalTask._id, id: challenge._id}; + userTask.challenge = {taskId: chalTask._id, id: challenge._id, shortName: challenge.shortName}; userTask.userId = memberId; userTask.notes = chalTask.notes; // We want to sync the notes when the task is first added to the challenge diff --git a/website/server/models/task.js b/website/server/models/task.js index 0e9250bc49..b28c8c08e1 100644 --- a/website/server/models/task.js +++ b/website/server/models/task.js @@ -58,7 +58,7 @@ export let TaskSchema = new Schema({ userId: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}, // When not set it belongs to a challenge challenge: { - shortName: {type: String, default: 'None'}, + shortName: {type: String}, id: {type: String, ref: 'Challenge', validate: [validator.isUUID, 'Invalid uuid.']}, // When set (and userId not set) it's the original task taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']}, // When not set but challenge.id defined it's the original task broken: {type: String, enum: ['CHALLENGE_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED', 'CHALLENGE_CLOSED', 'CHALLENGE_TASK_NOT_FOUND']}, // CHALLENGE_TASK_NOT_FOUND comes from v3 migration diff --git a/website/views/shared/tasks/task-list.jade b/website/views/shared/tasks/task-list.jade index aaab019cc0..c1a65a15dd 100644 --- a/website/views/shared/tasks/task-list.jade +++ b/website/views/shared/tasks/task-list.jade @@ -1,21 +1,20 @@ script(id='templates/task-list.html', type="text/ng-template") ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list', - ng-show='obj[list.type+"s"].length > 0', - hrpg-sort-tasks, - ng-if='showNormalList()') - task + ng-show='obj[list.type+"s"].length > 0', + ng-if='showNormalList(obj)') + task(hrpg-sort-tasks) div(ng-init='setObj(obj);') div( - ng-repeat="(key, taskList) in groupedList[list.type]", - ng-if='user.preferences.tasks.groupByChallenge && !$state.includes("options.social.challenges")') + ng-repeat="(key, taskList) in groupedList[list.type]", + ng-if='showGroupedList(obj)') h3 {{key}} - ul(class='{{::list.type}}s main-list', - ng-show='taskList.length > 0', hrpg-sort-tasks) - task + ul(class='{{::list.type}}s main-list', + ng-show='taskList.length > 0') + task(hrpg-sort-tasks) //Loads the non-sortable lists for challenges - ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list', - ng-show='obj[list.type + "s"].length > 0', + ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list', + ng-show='obj[list.type + "s"].length > 0', ng-if='showChallengeList()') task