From 87f39b4273f1cb68f157bcf848cf4082fa974d34 Mon Sep 17 00:00:00 2001 From: negue Date: Mon, 14 Aug 2017 19:15:32 +0200 Subject: [PATCH] item pinning (#8918) * toggle pinned state of items server + client * pin quests / add pin src * add officially pinned items and api to get in app rewards * update schema and get items deatils * update pin actions to the new logic * show countBadge only with a number * extract getPinKey - pin seasonal items * togglePinned in buy-dialogs * add pinKey to shop items * wip * wip * fix path * togglePinnedItem as common.op / use in client * fix linting * pinning: getItemInfo and save in db path and type * make api more consistent, fix bugs * updates * fix bugs * update actions to current api * marketGear * change to pinType * add mystery_set to getItemInfo * fix isPinned * ignore animals * list shopItems (initial) * shopItem now has default popoverconent, itemclass and price / currency - list pinned items as rewards - attributes to gear * show buyModal for the rewards * show mystery_set icon * add info whether item is suggested * write migration, fix style issues * pin potion and armoire * make potion, armoire not unpinnable * show notes for armoire and potion, add default items for new users * show unpin notification * add/remove pinned gear on class-change * remove pinned & add new gear on purchase - refactoring pinning methods - fixes * always allow to purchase armoire * highlight item if suggested --- migrations/20170811_pinned_items.js | 108 ++++++++ test/common/ops/buyArmoire.js | 17 -- .../inventory/equipment/attributesPopover.vue | 18 +- website/client/components/shops/_isPinned.js | 6 + website/client/components/shops/buyModal.vue | 16 +- website/client/components/shops/index.vue | 7 + .../client/components/shops/market/index.vue | 75 +++--- .../components/shops/quests/buyQuestModal.vue | 14 +- .../client/components/shops/quests/index.vue | 32 ++- .../components/shops/seasonal/index.vue | 54 ++-- website/client/components/shops/shopItem.vue | 47 +++- .../components/shops/timeTravelers/index.vue | 23 +- website/client/components/tasks/column.vue | 33 +++ website/client/components/tasks/user.vue | 62 +++++ website/client/components/ui/countBadge.vue | 2 +- website/client/store/actions/shops.js | 17 -- website/client/store/actions/user.js | 16 ++ website/common/locales/en/newClient.json | 4 + .../script/content/appearance/backgrounds.js | 8 +- website/common/script/content/index.js | 9 +- website/common/script/content/mystery-sets.js | 1 + .../script/content/officialPinnedItems.js | 1 + website/common/script/index.js | 5 + website/common/script/libs/getItemInfo.js | 247 ++++++++++++++++++ website/common/script/libs/inAppRewards.js | 18 ++ website/common/script/libs/shops.js | 141 ++-------- website/common/script/ops/buyGear.js | 3 + website/common/script/ops/changeClass.js | 5 + website/common/script/ops/index.js | 2 + website/common/script/ops/pinnedGearUtils.js | 119 +++++++++ website/server/controllers/api-v3/user.js | 84 ++++++ website/server/libs/collectionManipulators.js | 6 +- website/server/models/user/hooks.js | 18 ++ website/server/models/user/schema.js | 11 + 34 files changed, 955 insertions(+), 274 deletions(-) create mode 100644 migrations/20170811_pinned_items.js create mode 100644 website/client/components/shops/_isPinned.js create mode 100644 website/common/script/content/officialPinnedItems.js create mode 100644 website/common/script/libs/getItemInfo.js create mode 100644 website/common/script/libs/inAppRewards.js create mode 100644 website/common/script/ops/pinnedGearUtils.js diff --git a/migrations/20170811_pinned_items.js b/migrations/20170811_pinned_items.js new file mode 100644 index 0000000000..3c12a01531 --- /dev/null +++ b/migrations/20170811_pinned_items.js @@ -0,0 +1,108 @@ +var updateStore = require('../website/common/script/libs/updateStore'); +var getItemInfo = require('../website/common/script/libs/getItemInfo'); + +var migrationName = '20170811_pinned_items.js'; +var authorName = 'paglias'; // in case script author needs to know when their ... +var authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; //... own data is done + +/* + * Migrate existing in app rewards lists to pinned items + */ + +var monk = require('monk'); +var connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE +var dbUsers = monk(connectionString).get('users', { castIds: false }); + +function processUsers(lastId) { + // specify a query to limit the affected users (empty for all users): + var query = { + 'migration':{$ne:migrationName}, + }; + + if (lastId) { + query._id = { + $gt: lastId + } + } + + return dbUsers.find(query, { + sort: {_id: 1}, + limit: 250, + }) + .then(updateUsers) + .catch(function (err) { + console.log(err); + return exiting(1, 'ERROR! ' + err); + }); +} + +var progressCount = 1000; +var count = 0; + +function updateUsers (users) { + if (!users || users.length === 0) { + console.warn('All appropriate users found and modified.'); + displayData(); + return; + } + + var userPromises = users.map(updateUser); + var lastUser = users[users.length - 1]; + + return Promise.all(userPromises) + .then(function () { + processUsers(lastUser._id); + }); +} + +function updateUser (user) { + count++; + + var set = {'migration': migrationName}; + + var oldRewardsList = updateStore(user); + var newPinnedItems = [ + { + type: 'armoire', + path: 'armoire', + }, + { + type: 'potion', + path: 'potion', + }, + ]; + + oldRewardsList.forEach(item => { + var type = 'marketGear'; + + var itemInfo = getItemInfo(user, 'marketGear', item); + newPinnedItems.push({ + type, + path: itemInfo.path, + }) + }); + + set.pinnedItems = newPinnedItems; + + if (count % progressCount == 0) console.warn(count + ' ' + user._id); + if (user._id == authorUuid) console.warn(authorName + ' processed'); + + return dbUsers.update({_id: user._id}, {$set:set}); +} + +function displayData() { + console.warn('\n' + count + ' users processed\n'); + return exiting(0); +} + +function exiting(code, msg) { + code = code || 0; // 0 = success + if (code && !msg) { msg = 'ERROR!'; } + if (msg) { + if (code) { console.error(msg); } + else { console.log( msg); } + } + process.exit(code); +} + +module.exports = processUsers; diff --git a/test/common/ops/buyArmoire.js b/test/common/ops/buyArmoire.js index 22dcc8a442..facf87132c 100644 --- a/test/common/ops/buyArmoire.js +++ b/test/common/ops/buyArmoire.js @@ -68,23 +68,6 @@ describe('shared.ops.buyArmoire', () => { done(); } }); - - it('does not open without Ultimate Gear achievement', (done) => { - user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false}; - - try { - buyArmoire(user); - } catch (err) { - expect(err).to.be.an.instanceof(NotAuthorized); - expect(err.message).to.equal(i18n.t('cannotBuyItem')); - expect(user.items.gear.owned).to.eql({ - weapon_warrior_0: true, - }); - expect(user.items.food).to.be.empty; - expect(user.stats.exp).to.eql(0); - done(); - } - }); }); context('non-gear awards', () => { diff --git a/website/client/components/inventory/equipment/attributesPopover.vue b/website/client/components/inventory/equipment/attributesPopover.vue index 1beca9046c..a65347bd65 100644 --- a/website/client/components/inventory/equipment/attributesPopover.vue +++ b/website/client/components/inventory/equipment/attributesPopover.vue @@ -1,7 +1,7 @@