From f99b496a2962672f60cae4d9d61512c37a429e15 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 8 Sep 2013 23:28:34 -0400 Subject: [PATCH] [#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 --- public/js/controllers/filtersCtrl.js | 7 +++---- public/js/services/userServices.js | 2 ++ src/controllers/user.js | 2 +- src/models/user.js | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/public/js/controllers/filtersCtrl.js b/public/js/controllers/filtersCtrl.js index a9d783a814..955b3d3f5b 100644 --- a/public/js/controllers/filtersCtrl.js +++ b/public/js/controllers/filtersCtrl.js @@ -4,7 +4,6 @@ habitrpg.controller("FiltersCtrl", ['$scope', '$rootScope', 'User', function($scope, $rootScope, User) { var user = User.user; $scope._editing = false; - user.filters = {}; // FIXME run a migration instead $scope.saveOrEdit = function(){ if ($scope._editing) { @@ -13,11 +12,11 @@ habitrpg.controller("FiltersCtrl", ['$scope', '$rootScope', 'User', $scope._editing = !$scope._editing; } - $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]; + // 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) { diff --git a/public/js/services/userServices.js b/public/js/services/userServices.js index 77302c45cc..4c2e261a87 100644 --- a/public/js/services/userServices.js +++ b/public/js/services/userServices.js @@ -168,6 +168,8 @@ angular.module('userServices', []). userServices.log(log); }, + save: save, + settings: settings }; diff --git a/src/controllers/user.js b/src/controllers/user.js index b9d494fb54..c5cf389e50 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -454,7 +454,7 @@ api.updateUser = function(req, res, next) { # 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) { if ((_.find(acceptableAttrs, function(attr) { return k.indexOf(attr) === 0; diff --git a/src/models/user.js b/src/models/user.js index 1c368d57ec..cfbb7729bc 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -57,7 +57,7 @@ var UserSchema = new Schema({ dailyIds: Array, todoIds: Array, rewardIds: Array, - /* Removed `filters`, no longer persisting to the database*/ + filters: {type: Schema.Types.Mixed, 'default': {}}, flags: { ads: String, @@ -218,6 +218,7 @@ function transformTaskLists(doc) { _.each(['habit', 'daily', 'todo', 'reward'], function(type) { // we use _.transform instead of a simple _.where in order to maintain sort-order 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]); return m; }, []); @@ -238,7 +239,7 @@ UserSchema.methods.toJSON = function() { delete doc["#{type}Ids"] }); delete doc.tasks - doc.filters = {}; + //doc.filters = {}; return doc; };