diff --git a/common/locales/en/settings.json b/common/locales/en/settings.json index b85f4719b1..934ed81408 100644 --- a/common/locales/en/settings.json +++ b/common/locales/en/settings.json @@ -14,6 +14,11 @@ "startCollapsedPop": "With this option set, the list of task tags will be hidden when you first open a task for editing.", "startAdvCollapsed": "Advanced Options in tasks start collapsed", "startAdvCollapsedPop": "With this option set, Advanced Options will be hidden when you first open a task for editing.", + "dontShowAgain": "Don't show this again", + "suppressLevelUpModal": "Don't show popup when gaining a level", + "suppressHatchPetModal": "Don't show popup when hatching a pet", + "suppressRaisePetModal": "Don't show popup when raising a pet into a mount", + "suppressStreakModal": "Don't show popup when attaining a Streak achievement", "showTour": "Show Tour", "restartTour": "Restart the introductory tour from when you first joined Habitica.", "showBailey": "Show Bailey", diff --git a/test/spec/controllers/inventoryCtrlSpec.js b/test/spec/controllers/inventoryCtrlSpec.js index 7456598e7b..dd5525b86e 100644 --- a/test/spec/controllers/inventoryCtrlSpec.js +++ b/test/spec/controllers/inventoryCtrlSpec.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Inventory Controller', function() { +describe.only('Inventory Controller', function() { var scope, ctrl, user, rootScope; beforeEach(function() { @@ -18,6 +18,9 @@ describe('Inventory Controller', function() { food: { Meat: 1 }, pets: {}, mounts: {} + }, + preferences: { + suppressModals: {} } }); @@ -53,14 +56,36 @@ describe('Inventory Controller', function() { expect(scope.selectedPotion.key).to.eql('Base'); }); - it('hatches a pet', function(){ - scope.chooseEgg('Cactus'); - scope.choosePotion('Base'); - expect(user.items.eggs).to.eql({Cactus: 0}); - expect(user.items.hatchingPotions).to.eql({Base: 0}); - expect(user.items.pets).to.eql({'Cactus-Base': 5}); - expect(scope.selectedEgg).to.eql(null); - expect(scope.selectedPotion).to.eql(null); + describe('Hatching Pets', function(){ + beforeEach(function() { + sandbox.stub(rootScope, 'openModal'); + }); + + it('hatches a pet', function(){ + scope.chooseEgg('Cactus'); + scope.choosePotion('Base'); + expect(user.items.eggs).to.eql({Cactus: 0}); + expect(user.items.hatchingPotions).to.eql({Base: 0}); + expect(user.items.pets).to.eql({'Cactus-Base': 5}); + expect(scope.selectedEgg).to.eql(null); + expect(scope.selectedPotion).to.eql(null); + }); + + it('shows a modal for pet hatching', function(){ + scope.chooseEgg('Cactus'); + scope.choosePotion('Base'); + + expect(rootScope.openModal).to.have.been.calledOnce; + expect(rootScope.openModal).to.have.been.calledWith('hatchPet'); + }); + + it('does not show pet hatching modal if user has opted out', function(){ + user.preferences.suppressModals.hatchPet = true; + scope.chooseEgg('Cactus'); + scope.choosePotion('Base'); + + expect(rootScope.openModal).to.not.be.called; + }); }); it('sells an egg', function(){ diff --git a/website/public/js/controllers/inventoryCtrl.js b/website/public/js/controllers/inventoryCtrl.js index 414c8409c2..82034a7672 100644 --- a/website/public/js/controllers/inventoryCtrl.js +++ b/website/public/js/controllers/inventoryCtrl.js @@ -112,8 +112,10 @@ habitrpg.controller("InventoryCtrl", var potName = Content.hatchingPotions[potion.key].text(); if (!$window.confirm(window.env.t('hatchAPot', {potion: potName, egg: eggName}))) return; user.ops.hatch({params:{egg:egg.key, hatchingPotion:potion.key}}); - $rootScope.hatchedPet = {egg: eggName, potion: potName, pet: 'Pet-' + egg.key + '-' + potion.key}; - $rootScope.openModal('hatchPet', {controller: 'InventoryCtrl', size: 'sm'}); + if (!user.preferences.suppressModals.hatchPet) { + $rootScope.hatchedPet = {egg: eggName, potion: potName, pet: 'Pet-' + egg.key + '-' + potion.key}; + $rootScope.openModal('hatchPet', {controller: 'InventoryCtrl', size: 'sm'}); + } $scope.selectedEgg = null; $scope.selectedPotion = null; diff --git a/website/src/models/user.js b/website/src/models/user.js index fbcf62ec8c..3b3c8d0267 100644 --- a/website/src/models/user.js +++ b/website/src/models/user.js @@ -377,6 +377,12 @@ var UserSchema = new Schema({ // Those importantAnnouncements are in fact the recapture emails importantAnnouncements: {type: Boolean, 'default': true}, weeklyRecaps: {type: Boolean, 'default': true} + }, + suppressModals: { + levelUp: {type: Boolean, 'default': false}, + hatchPet: {type: Boolean, 'default': false}, + raisePet: {type: Boolean, 'default': false}, + streak: {type: Boolean, 'default': false} } }, profile: { diff --git a/website/src/routes/pages.js b/website/src/routes/pages.js index f17e688998..1504ef1701 100644 --- a/website/src/routes/pages.js +++ b/website/src/routes/pages.js @@ -33,7 +33,7 @@ _.each(pages, function(name){ // -------- Social Media Sharing -------- -var shareables = ['level-up']; +var shareables = ['level-up','hatch-pet']; _.each(shareables, function(name){ router.get('/social/' + name, i18n.getUserLanguage, locals, function(req, res) { diff --git a/website/views/options/settings.jade b/website/views/options/settings.jade index ebe96e9ae2..9a0808b2eb 100644 --- a/website/views/options/settings.jade +++ b/website/views/options/settings.jade @@ -75,7 +75,18 @@ script(type='text/ng-template', id='partials/options.settings.settings.html') label input(type='checkbox', ng-model='user.preferences.displayInviteToPartyWhenPartyIs1', ng-change='set({"preferences.displayInviteToPartyWhenPartyIs1": user.preferences.displayInviteToPartyWhenPartyIs1 ? true : false})') span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('displayInviteToPartyWhenPartyIs1'))=env.t('displayInviteToPartyWhenPartyIs1') - // button.btn.btn-default(ng-click='showTour()', popover-placement='right', popover-trigger='mouseenter', popover=env.t('restartTour'))= env.t('showTour') + .checkbox + label=env.t('suppressLevelUpModal') + input(type='checkbox', ng-model='user.preferences.suppressModals.levelUp', ng-change='set({"preferences.suppressModals.levelUp": user.preferences.suppressModals.levelUp?true: false})') + .checkbox + label=env.t('suppressHatchPetModal') + input(type='checkbox', ng-model='user.preferences.suppressModals.hatchPet', ng-change='set({"preferences.suppressModals.hatchPet": user.preferences.suppressModals.hatchPet?true: false})') + .checkbox + label=env.t('suppressRaisePetModal') + input(type='checkbox', ng-model='user.preferences.suppressModals.raisePet', ng-change='set({"preferences.suppressModals.raisePet": user.preferences.suppressModals.raisePet?true: false})') + .checkbox + label=env.t('suppressStreakModal') + input(type='checkbox', ng-model='user.preferences.suppressModals.streak', ng-change='set({"preferences.suppressModals.streak": user.preferences.suppressModals.streak?true: false})') hr diff --git a/website/views/shared/modals/hatch-pet.jade b/website/views/shared/modals/hatch-pet.jade index 54a3cb135f..b3b6993ae9 100644 --- a/website/views/shared/modals/hatch-pet.jade +++ b/website/views/shared/modals/hatch-pet.jade @@ -1,8 +1,9 @@ include ../avatar/generated_avatar script(type='text/ng-template', id='modals/hatchPet.html') + div(id='fb-root') .modal-content(style='min-width:28em') - .modal-body.text-center + .modal-body.text-center(style='padding-bottom:0') h3(style='margin-bottom: 0')=env.t('hatchedPet',{egg:'{{::hatchedPet.egg}}', potion:'{{::hatchedPet.potion}}'}) .container-fluid .row(style='margin-bottom:1em', ng-controller='UserCtrl') @@ -15,6 +16,18 @@ script(type='text/ng-template', id='modals/hatchPet.html') .character-sprites(style='width:0; margin-top:.5em') +generatedAvatar p=env.t('earnedCompanion') - .modal-footer(style='margin-top:0') + br button.btn.btn-primary(ng-click='choosePet(hatchedPet.egg, hatchedPet.potion); $close()')=env.t('displayNow') button.btn.btn-default(ng-click='$close()')=env.t('displayLater') + .checkbox + label(style='display:inline-block')=env.t('dontShowAgain') + input(type='checkbox', ng-model='user.preferences.suppressModals.hatchPet', ng-change='set({"preferences.suppressModals.hatchPet": user.preferences.suppressModals.hatchPet?true: false})') + .modal-footer(style='margin-top:0', ng-init='loadWidgets()') + .container-fluid + .row + .col-xs-3 + a.twitter-share-button(href='https://twitter.com/intent/tweet?text=I+just+hatched+a+{{::hatchedPet.potion}}+{{::hatchedPet.egg}}+by+completing+my+real-life+tasks!&via=habitica&url=https://habitrpg-gamma.herokuapp.com/social/hatch-pet&count=none')=env.t('tweet') + .col-xs-4(style='margin-left:.8em') + .fb-share-button(data-href='https://habitrpg-gamma.herokuapp.com/social/hatch-pet', data-layout='button') + .col-xs-4(style='margin-left:.8em') + a.tumblr-share-button(data-href='https://habitrpg-gamma.herokuapp.com/social/hatch-pet', data-notes='none') diff --git a/website/views/shared/modals/level-up.jade b/website/views/shared/modals/level-up.jade index a61e6af72d..3f8ab411e9 100644 --- a/website/views/shared/modals/level-up.jade +++ b/website/views/shared/modals/level-up.jade @@ -17,6 +17,9 @@ script(type='text/ng-template', id='modals/levelUp.html') p=env.t('fullyHealed') br button.btn.btn-primary(ng-click='$close()')=env.t('huzzah') + .checkbox + label(style='display:inline-block')=env.t('dontShowAgain') + input(type='checkbox', ng-model='user.preferences.suppressModals.levelUp', ng-change='set({"preferences.suppressModals.levelUp": user.preferences.suppressModals.levelUp?true: false})') .modal-footer(style='margin-top:0', ng-init='loadWidgets()') .container-fluid .row diff --git a/website/views/social/hatch-pet.jade b/website/views/social/hatch-pet.jade new file mode 100644 index 0000000000..ac534ba4ef --- /dev/null +++ b/website/views/social/hatch-pet.jade @@ -0,0 +1,15 @@ +doctype html +html + head + meta(name='twitter:card' content='summary') + meta(name='twitter:site' content='@habitica') + meta(name='twitter:title' content='New Pet!') + meta(name='twitter:description' content='In Habitica, you earn cute companions as you accomplish real-world tasks. I\'ve worked hard and gotten myself a new pet!') + meta(name='twitter:image' content='https://s3.amazonaws.com/habitica-assets/assets/gryphon_logo.png') + meta(property='og:url', content='https://habitica.com/social/hatch-pet') + meta(property='og:type', content='website') + meta(property='og:title', content='Level Up!') + meta(property='og:description', content='In Habitica, you earn cute companions as you accomplish real-world tasks. I\'ve worked hard and gotten myself a new pet!') + meta(property='og:site_name', content='Habitica') + meta(property='og:image', content='https://s3.amazonaws.com/habitica-assets/assets/gryphon_logo_300x300.png') + meta(property='fb:app_id', content='128307497299777') diff --git a/website/views/social/level-up.jade b/website/views/social/level-up.jade index 72d27a22dd..e88c5b7bca 100644 --- a/website/views/social/level-up.jade +++ b/website/views/social/level-up.jade @@ -5,11 +5,11 @@ html meta(name='twitter:site' content='@habitica') meta(name='twitter:title' content='Level Up!') meta(name='twitter:description' content='In Habitica, your avatar grows in strength as you improve your real-life habits. I\'ve attained a new level with what I\'ve accomplished!') - meta(name='twitter:image' content='') + meta(name='twitter:image' content='https://s3.amazonaws.com/habitica-assets/assets/gryphon_logo.png') meta(property='og:url', content='https://habitica.com/social/level-up') meta(property='og:type', content='website') meta(property='og:title', content='Level Up!') meta(property='og:description', content='In Habitica, your avatar grows in strength as you improve your real-life habits. I\'ve attained a new level with what I\'ve accomplished!') meta(property='og:site_name', content='Habitica') - meta(property='og:image', content='') + meta(property='og:image', content='https://s3.amazonaws.com/habitica-assets/assets/gryphon_logo_300x300.png') meta(property='fb:app_id', content='128307497299777')