From a8e890a6dfebf6d517129235b9200ee04261a973 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Fri, 21 Feb 2014 17:25:29 -0800 Subject: [PATCH] feat(premium): mystery items --- public/js/controllers/notificationCtrl.js | 14 ++++++++------ src/controllers/user.js | 21 +++++++++++++-------- src/models/user.js | 3 ++- views/options/inventory/inventory.jade | 3 ++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/public/js/controllers/notificationCtrl.js b/public/js/controllers/notificationCtrl.js index 82c42af8a7..d5fbb3c32d 100644 --- a/public/js/controllers/notificationCtrl.js +++ b/public/js/controllers/notificationCtrl.js @@ -53,13 +53,15 @@ habitrpg.controller('NotificationCtrl', $rootScope.$watch('user._tmp.drop', function(after, before){ // won't work when getting the same item twice? if (after == before || !after) return; - var type = (after.type == 'Food') ? 'food' : - (after.type == 'HatchingPotion') ? 'hatchingPotions' : // can we use camelcase and remove this line? - (after.type.toLowerCase() + 's'); - if(!User.user.items[type][after.key]){ - User.user.items[type][after.key] = 0; + if (after.type !== 'gear') { + var type = (after.type == 'Food') ? 'food' : + (after.type == 'HatchingPotion') ? 'hatchingPotions' : // can we use camelcase and remove this line? + (after.type.toLowerCase() + 's'); + if(!User.user.items[type][after.key]){ + User.user.items[type][after.key] = 0; + } + User.user.items[type][after.key]++; } - User.user.items[type][after.key]++; Notification.drop(User.user._tmp.drop.dialog); }); diff --git a/src/controllers/user.js b/src/controllers/user.js index 70cc0cd7c4..3dfd9630fa 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -310,13 +310,18 @@ api.buyGems = function(req, res, next) { function(response, cb) { //user.purchased.ads = true; if (req.query.plan) { - user.purchased.plan = { - planId:'basic_earned', - customerId: response.id, - dateCreated: new Date, - dateUpdated: new Date, - gemsBought: 0 - }; + if (!user.purchased.plan) user.purchased.plan = {} + _(user.purchased.plan) + .merge({ // override with these values + planId:'basic_earned', + customerId: response.id, + dateUpdated: new Date, + gemsBought: 0 + }) + .defaults({ // allow non-override if a plan was previously used + dateCreated: new Date, + mysteryItems: [] + }); ga.event('subscribe', 'Stripe').send() ga.transaction(response.id, 5).item(5, 1, "stripe-subscription", "Subscription > Stripe").send() } else { @@ -345,7 +350,7 @@ api.cancelSubscription = function(req, res, next) { stripe.customers.del(user.purchased.plan.customerId, cb); }, function(response, cb) { - user.purchased.plan = {}; + _.merge(user.purchased.plan, {planId:null, customerId:null}); user.markModified('purchased.plan'); user.save(cb); } diff --git a/src/models/user.js b/src/models/user.js index a78956fae0..6df68df083 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -87,7 +87,8 @@ var UserSchema = new Schema({ customerId: String, dateCreated: Date, dateUpdated: Date, - gemsBought: {type: Number, 'default': 0} + gemsBought: {type: Number, 'default': 0}, + mysteryItems: {type: Array, 'default': []} } }, diff --git a/views/options/inventory/inventory.jade b/views/options/inventory/inventory.jade index 536220dac7..ac4f1b3f18 100644 --- a/views/options/inventory/inventory.jade +++ b/views/options/inventory/inventory.jade @@ -73,7 +73,8 @@ script(type='text/ng-template', id='partials/options.inventory.drops.html') li.customize-menu(ng-if='user.purchased.plan.customerId') menu.pets-menu(label=env.t('subscriberItem')) div - button.customize-option(popover=env.t('subscriberItemText'), popover-trigger='mouseenter', popover-placement='right', class='inventory_present') + button.customize-option(popover=env.t('subscriberItemText'), popover-trigger='mouseenter', popover-placement='right', class='inventory_present', ng-click="user.ops.openMysteryItem({})") + .badge.badge-info.stack-count {{user.purchased.plan.mysteryItems.length}} .col-md-6 h2=env.t('market')