v3: fix notifications

This commit is contained in:
Matteo Pagliazzi
2016-05-17 19:12:39 +02:00
parent 30c9458493
commit a757df9f5b
11 changed files with 27 additions and 33 deletions

View File

@@ -140,7 +140,6 @@
"notAccteptedType": "Type must be in [eggs, hatchingPotions, food, quests, gear]",
"contentKeyNotFound": "Key not found for Content <%= type %>",
"plusOneGem": "+1 Gem",
"purchased": "You purchsed a <%= key %> <%= type %>",
"notAllowedHourglass": "Pet/Mount not available for purchase with Mystic Hourglass.",
"readCard": "<%= cardType %> has been read",
"cardTypeRequired": "Card type required",
@@ -160,7 +159,6 @@
"mountsReleased": "Mounts released",
"typeNotSellable": "Type is not sellable. Must be one of the following <%= acceptedTypes %>",
"userItemsKeyNotFound": "Key not found for user.items <%= type %>",
"sold": "You sold a <%= key %> <%= type %>",
"pathRequired": "Path string is required",
"unlocked": "Items have been unlocked",
"alreadyUnlocked": "Full set already unlocked.",

View File

@@ -24,7 +24,7 @@ module.exports = function feed (user, req = {}) {
let pet = _.get(req, 'params.pet');
let foodK = _.get(req, 'params.food');
if (!pet || !foodK) throw new BadRequest(i18n.t('missingPetFoodFeed'));
if (!pet || !foodK) throw new BadRequest(i18n.t('missingPetFoodFeed', req.language));
if (pet.indexOf('-') === -1) {
throw new BadRequest(i18n.t('invalidPetName', req.language));
@@ -43,8 +43,8 @@ module.exports = function feed (user, req = {}) {
let [egg, potion] = pet.split('-');
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text(req.language) : potion;
let eggText = content.eggs[egg] ? content.eggs[egg].text(req.language) : egg;
let petDisplayName = i18n.t('petName', {
potion: potionText,

View File

@@ -122,7 +122,6 @@ module.exports = function purchase (user, req = {}, analytics) {
} else {
return [
_.pick(user, splitWhitespace('items balance')),
i18n.t('purchased', {type, key}),
];
}
};

View File

@@ -38,7 +38,6 @@ module.exports = function sell (user, req = {}) {
} else {
return [
_.pick(user, splitWhitespace('stats items')),
i18n.t('sold', {type, key}),
];
}
};

View File

@@ -28,9 +28,12 @@ angular.module('habitrpg')
localStorage.clear();
window.location.href = mobileApp ? '/app/login' : '/logout'; //location.reload()
// 400 range?
// 400 range
} else if (response.status < 400) {
// never triggered because we're in responseError
$rootScope.$broadcast('responseText', response.data.message);
} else if (response.status < 500) {
$rootScope.$broadcast('responseText', response.data.err || response.data.message);
$rootScope.$broadcast('responseError', response.data.message);
// Need to reject the prompse so the error is handled correctly
if (response.status === 401) {
return $q.reject(response);
@@ -41,7 +44,7 @@ angular.module('habitrpg')
window.env.t('error') + ' ' + (response.data.err || response.data || 'something went wrong') +
'" <br><br>' + window.env.t('seeConsole');
if (mobileApp) error = 'Error contacting the server. Please try again in a few minutes.';
$rootScope.$broadcast('responseError', error);
$rootScope.$broadcast('responseError500', error);
console.error(response);
}

View File

@@ -26,10 +26,9 @@ describe('POST /user/purchase/:type/:key', () => {
});
it('purchases a gem item', async () => {
let res = await user.post(`/user/purchase/${type}/${key}`);
await user.post(`/user/purchase/${type}/${key}`);
await user.sync();
expect(res.message).to.equal(t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
});

View File

@@ -33,10 +33,9 @@ describe('POST /user/sell/:type/:key', () => {
},
});
let response = await user.post(`/user/sell/${type}/${key}`);
await user.post(`/user/sell/${type}/${key}`);
await user.sync();
expect(response.message).to.equal(t('sold', {type, key}));
expect(user.stats.gp).to.equal(content[type][key].value);
});
});

View File

@@ -150,9 +150,8 @@ describe('shared.ops.purchase', () => {
let type = 'eggs';
let key = 'Wolf';
let [, message] = purchase(user, {params: {type, key}});
purchase(user, {params: {type, key}});
expect(message).to.equal(i18n.t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
@@ -160,9 +159,8 @@ describe('shared.ops.purchase', () => {
let type = 'hatchingPotions';
let key = 'Base';
let [, message] = purchase(user, {params: {type, key}});
purchase(user, {params: {type, key}});
expect(message).to.equal(i18n.t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
@@ -170,9 +168,8 @@ describe('shared.ops.purchase', () => {
let type = 'food';
let key = 'Meat';
let [, message] = purchase(user, {params: {type, key}});
purchase(user, {params: {type, key}});
expect(message).to.equal(i18n.t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
@@ -180,9 +177,8 @@ describe('shared.ops.purchase', () => {
let type = 'quests';
let key = 'gryphon';
let [, message] = purchase(user, {params: {type, key}});
purchase(user, {params: {type, key}});
expect(message).to.equal(i18n.t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
@@ -190,9 +186,8 @@ describe('shared.ops.purchase', () => {
let type = 'gear';
let key = 'headAccessory_special_tigerEars';
let [, message] = purchase(user, {params: {type, key}});
purchase(user, {params: {type, key}});
expect(message).to.equal(i18n.t('purchased', {type, key}));
expect(user.items.gear.owned[key]).to.be.true;
});
});

View File

@@ -66,16 +66,14 @@ describe('shared.ops.sell', () => {
});
it('reduces item count from user', () => {
let [, message] = sell(user, {params: { type, key } });
sell(user, {params: { type, key } });
expect(message).to.equal(i18n.t('sold', {type, key}));
expect(user.items[type][key]).to.equal(0);
});
it('increases user\'s gold', () => {
let [, message] = sell(user, {params: { type, key } });
sell(user, {params: { type, key } });
expect(message).to.equal(i18n.t('sold', {type, key}));
expect(user.stats.gp).to.equal(content[type][key].value);
});
});

View File

@@ -180,9 +180,13 @@ habitrpg.controller('NotificationCtrl',
$rootScope.openModal('questInvitation', {controller:'PartyCtrl'});
});
$rootScope.$on('responseError', function(ev, error){
$rootScope.$on('responseError500', function(ev, error){
Notification.error(error);
});
$rootScope.$on('responseError', function(ev, error){
Notification.error(error, true);
});
$rootScope.$on('responseText', function(ev, error){
Notification.text(error);
});

View File

@@ -54,8 +54,8 @@ angular.module("habitrpg").factory("Notification",
_notify(_sign(val) + " " + _round(val) + " " + window.env.t('experience'), 'xp', 'glyphicon glyphicon-star');
}
function error(error){
_notify(error, "danger", 'glyphicon glyphicon-exclamation-sign');
function error(error, canHide){
_notify(error, "danger", 'glyphicon glyphicon-exclamation-sign', canHide);
}
function gp(val, bonus) {
@@ -107,14 +107,14 @@ angular.module("habitrpg").factory("Notification",
// Used to stack notifications, must be outside of _notify
var stack_topright = {"dir1": "down", "dir2": "left", "spacing1": 15, "spacing2": 15, "firstpos1": 60};
function _notify(html, type, icon) {
function _notify(html, type, icon, canHide) {
var notice = $.pnotify({
type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit')
text: html,
opacity: 1,
addclass: 'alert-' + type,
delay: 7000,
hide: (type == 'error' || type == 'danger') ? false : true,
hide: ((type == 'error' || type == 'danger') && !canHide) ? false : true,
mouse_reset: false,
width: "250px",
stack: stack_topright,