Tasks sort delete fix (#8526)

* Fixed task sorting

* Add sync when group task is deleted

* Added sync when user tasks reorder

* Abstracted show logic and removed task grouping from group page

* Fixed scope typo

* Localized the default challenge short name

* Removed default shortName

* Fixed test for challenge shortName
This commit is contained in:
Keith Holliday
2017-03-07 14:28:49 -07:00
committed by GitHub
parent 28c93ea869
commit b75c57f130
7 changed files with 25 additions and 19 deletions

View File

@@ -117,9 +117,6 @@ describe('POST /challenges/:challengeId/leave', () => {
}); });
expect(testTask).to.not.be.undefined; expect(testTask).to.not.be.undefined;
expect(testTask.challenge).to.eql({
shortName: 'None',
});
}); });
}); });
}); });

View File

@@ -74,6 +74,7 @@ habitrpg.controller('GroupTasksCtrl', ['$scope', 'Shared', 'Tasks', 'User', '$ro
if (group._id) Tasks.deleteTask(task._id); if (group._id) Tasks.deleteTask(task._id);
var index = group[task.type + 's'].indexOf(task); var index = group[task.type + 's'].indexOf(task);
group[task.type + 's'].splice(index, 1); group[task.type + 's'].splice(index, 1);
$rootScope.$broadcast('obj-updated', $scope.group);
}; };
$scope.saveTask = function(task, stayOpen, isSaveAndClose) { $scope.saveTask = function(task, stayOpen, isSaveAndClose) {

View File

@@ -159,6 +159,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$scope.removeTask = function(task) { $scope.removeTask = function(task) {
if (!Tasks.removeTask(task)) return; if (!Tasks.removeTask(task)) return;
User.deleteTask({params:{id: task._id, taskType: task.type}}) User.deleteTask({params:{id: task._id, taskType: task.type}})
$rootScope.$broadcast('obj-updated', User.user);
}; };
$scope.unlink = function(task, keep) { $scope.unlink = function(task, keep) {

View File

@@ -65,14 +65,22 @@
return $scope.obj[list.type+'s']; return $scope.obj[list.type+'s'];
}; };
$scope.showNormalList = function () { function objIsGroup (obj) {
return !$state.includes("options.social.challenges") && !User.user.preferences.tasks.groupByChallenge; 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 () { $scope.showChallengeList = function () {
return $state.includes("options.social.challenges"); 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) { $scope.showDoubleTaskCounter = function (task, obj) {
var objectIsGroup = obj.type && (obj.type === 'guild' || obj.type === 'party'); var objectIsGroup = obj.type && (obj.type === 'guild' || obj.type === 'party');
var objectIsChallenge = $state.includes("options.social.challenges"); var objectIsChallenge = $state.includes("options.social.challenges");

View File

@@ -158,7 +158,7 @@ async function _addTaskFn (challenge, tasks, memberId) {
tasks.forEach(chalTask => { tasks.forEach(chalTask => {
let userTask = new Tasks[chalTask.type](Tasks.Task.sanitize(syncableAttrs(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.userId = memberId;
userTask.notes = chalTask.notes; // We want to sync the notes when the task is first added to the challenge userTask.notes = chalTask.notes; // We want to sync the notes when the task is first added to the challenge

View File

@@ -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 userId: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}, // When not set it belongs to a challenge
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 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 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 broken: {type: String, enum: ['CHALLENGE_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED', 'CHALLENGE_CLOSED', 'CHALLENGE_TASK_NOT_FOUND']}, // CHALLENGE_TASK_NOT_FOUND comes from v3 migration

View File

@@ -1,18 +1,17 @@
script(id='templates/task-list.html', type="text/ng-template") script(id='templates/task-list.html', type="text/ng-template")
ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list', ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list',
ng-show='obj[list.type+"s"].length > 0', ng-show='obj[list.type+"s"].length > 0',
hrpg-sort-tasks, ng-if='showNormalList(obj)')
ng-if='showNormalList()') task(hrpg-sort-tasks)
task
div(ng-init='setObj(obj);') div(ng-init='setObj(obj);')
div( div(
ng-repeat="(key, taskList) in groupedList[list.type]", ng-repeat="(key, taskList) in groupedList[list.type]",
ng-if='user.preferences.tasks.groupByChallenge && !$state.includes("options.social.challenges")') ng-if='showGroupedList(obj)')
h3 {{key}} h3 {{key}}
ul(class='{{::list.type}}s main-list', ul(class='{{::list.type}}s main-list',
ng-show='taskList.length > 0', hrpg-sort-tasks) ng-show='taskList.length > 0')
task task(hrpg-sort-tasks)
//Loads the non-sortable lists for challenges //Loads the non-sortable lists for challenges
ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list', ul(ng-init='setObj(obj)', class='{{::list.type}}s main-list',