Fixed adding and removing tags on tasks

This commit is contained in:
Keith Holliday
2016-05-14 10:00:10 -05:00
parent 6222c23810
commit 409dfbb2b0
3 changed files with 20 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ habitrpg.controller("FiltersCtrl", ['$scope', '$rootScope', 'User', 'Shared',
} else {
user.filters[tag.id] = !user.filters[tag.id];
}
// no longer persisting this, it was causing a lot of confusion - users thought they'd permanently lost tasks
// Note: if we want to persist for just this computer, easy method is:
// User.save();

View File

@@ -33,9 +33,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
var newTask = {
text: task,
type: listDef.type,
// tags: _.transform(User.user.filters, function(m, v, k) {
// if (v) m.push(v);
// }),
tags: _.keys(User.user.filters),
};
User.addTask({body: newTask});
@@ -272,4 +270,21 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$rootScope.playSound('Reward');
}
}
/*
------------------------
Tags
------------------------
*/
$scope.updateTaskTags = function (tagId, task) {
var tagIndex = task.tags.indexOf(tagId);
if (tagIndex === -1) {
Tasks.addTagToTask(task._id, tagId);
task.tags.push(tagId);
} else {
Tasks.removeTagFromTask(task._id, tagId);
task.tags.splice(tagIndex, 0);
}
}
}]);

View File

@@ -1,5 +1,5 @@
fieldset.option-group(ng-if='!$state.includes("options.social.challenges")')
p.option-title.mega(ng-class='{active: task._tags}', ng-click='task._tags = !task._tags', tooltip=env.t('expandCollapse'))=env.t('tags')
label.checkbox(ng-repeat='tag in user.tags', ng-if='task._tags')
input(type='checkbox', ng-model='task.tags[tag.id]', ng-checked="task.tags.indexOf(tag.id) !== -1")
input(type='checkbox', ng-checked="task.tags.indexOf(tag.id) !== -1", ng-click="updateTaskTags(tag.id, task)")
markdown(text='tag.name')