[#1444] add filters back to use schema. Allow editing of top-level tags

object in PUT /user, WARNING! We want to get away from that ASAP and
instead have a nested resource for managing tags. Set default task tags
if not present, will revisit after tasks are a subdoc too
This commit is contained in:
Tyler Renelle
2013-09-08 23:28:34 -04:00
parent 9690c7112f
commit f99b496a29
4 changed files with 9 additions and 7 deletions

View File

@@ -4,7 +4,6 @@ habitrpg.controller("FiltersCtrl", ['$scope', '$rootScope', 'User',
function($scope, $rootScope, User) { function($scope, $rootScope, User) {
var user = User.user; var user = User.user;
$scope._editing = false; $scope._editing = false;
user.filters = {}; // FIXME run a migration instead
$scope.saveOrEdit = function(){ $scope.saveOrEdit = function(){
if ($scope._editing) { if ($scope._editing) {
@@ -13,11 +12,11 @@ habitrpg.controller("FiltersCtrl", ['$scope', '$rootScope', 'User',
$scope._editing = !$scope._editing; $scope._editing = !$scope._editing;
} }
$scope.toggleFilter = function(tag) { $scope.toggleFilter = function(tag) {
// no longer persisting this, it was causing a lot of confusion - users thought they'd permanently lost tasks
user.filters = user.filters ? user.filters : {};
user.filters[tag.id] = !user.filters[tag.id]; 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();
}; };
$scope.createTag = function(name) { $scope.createTag = function(name) {

View File

@@ -168,6 +168,8 @@ angular.module('userServices', []).
userServices.log(log); userServices.log(log);
}, },
save: save,
settings: settings settings: settings
}; };

View File

@@ -454,7 +454,7 @@ api.updateUser = function(req, res, next) {
# Note: custom is for 3rd party apps # Note: custom is for 3rd party apps
*/ */
acceptableAttrs = 'tasks. achievements. filters. flags. invitations. items. lastCron party. preferences. profile. stats. tags. custom.'.split(' '); acceptableAttrs = 'tasks. achievements. filters. flags. invitations. items. lastCron party. preferences. profile. stats. tags custom.'.split(' ');
_.each(req.body, function(v, k) { _.each(req.body, function(v, k) {
if ((_.find(acceptableAttrs, function(attr) { if ((_.find(acceptableAttrs, function(attr) {
return k.indexOf(attr) === 0; return k.indexOf(attr) === 0;

View File

@@ -57,7 +57,7 @@ var UserSchema = new Schema({
dailyIds: Array, dailyIds: Array,
todoIds: Array, todoIds: Array,
rewardIds: Array, rewardIds: Array,
/* Removed `filters`, no longer persisting to the database*/ filters: {type: Schema.Types.Mixed, 'default': {}},
flags: { flags: {
ads: String, ads: String,
@@ -218,6 +218,7 @@ function transformTaskLists(doc) {
_.each(['habit', 'daily', 'todo', 'reward'], function(type) { _.each(['habit', 'daily', 'todo', 'reward'], function(type) {
// we use _.transform instead of a simple _.where in order to maintain sort-order // we use _.transform instead of a simple _.where in order to maintain sort-order
doc[type + "s"] = _.reduce(doc[type + "Ids"], function(m, tid) { doc[type + "s"] = _.reduce(doc[type + "Ids"], function(m, tid) {
if (!doc.tasks[tid].tags) doc.tasks[tid].tags = {}; // FIXME remove this when we switch tasks to subdocs and can define tags default in schema
m.push(doc.tasks[tid]); m.push(doc.tasks[tid]);
return m; return m;
}, []); }, []);
@@ -238,7 +239,7 @@ UserSchema.methods.toJSON = function() {
delete doc["#{type}Ids"] delete doc["#{type}Ids"]
}); });
delete doc.tasks delete doc.tasks
doc.filters = {}; //doc.filters = {};
return doc; return doc;
}; };