mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
[#1394] move notifications from controller to service, lots of notification
fixes, put streak notification back in
This commit is contained in:
@@ -32,43 +32,9 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
|
||||
}
|
||||
];
|
||||
$scope.score = function(task, direction) {
|
||||
/*save current stats to compute the difference after scoring.
|
||||
*/
|
||||
|
||||
var oldStats, statsDiff;
|
||||
statsDiff = {};
|
||||
oldStats = _.clone(User.user.stats);
|
||||
if (task.type === "reward" && User.user.stats.gp < task.value)
|
||||
return Notification.text('Not enough GP.');
|
||||
Algos.score(User.user, task, direction);
|
||||
/*compute the stats change.
|
||||
*/
|
||||
|
||||
_.each(oldStats, function(value, key) {
|
||||
var newValue;
|
||||
newValue = User.user.stats[key];
|
||||
if (newValue !== value) {
|
||||
statsDiff[key] = newValue - value;
|
||||
}
|
||||
});
|
||||
/*notify user if there are changes in stats.
|
||||
*/
|
||||
|
||||
if (Object.keys(statsDiff).length > 0) {
|
||||
Notification.push({
|
||||
type: "stats",
|
||||
stats: statsDiff
|
||||
});
|
||||
}
|
||||
if (task.type === "reward" && _.isEmpty(statsDiff)) {
|
||||
Notification.push({
|
||||
type: "text",
|
||||
text: "Not enough GP."
|
||||
});
|
||||
}
|
||||
User.log({
|
||||
op: "score",
|
||||
data: task,
|
||||
dir: direction
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addTask = function(list) {
|
||||
@@ -129,26 +95,15 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
|
||||
$scope.itemStore = sorted;
|
||||
});
|
||||
$scope.buy = function(type) {
|
||||
var hasEnough;
|
||||
hasEnough = window.habitrpgShared.items.buyItem(User.user, type);
|
||||
var hasEnough = window.habitrpgShared.items.buyItem(User.user, type);
|
||||
if (hasEnough) {
|
||||
User.log({
|
||||
op: "buy",
|
||||
type: type
|
||||
});
|
||||
Notification.push({
|
||||
type: "text",
|
||||
text: "Item bought!"
|
||||
});
|
||||
User.log({op: "buy",type: type});
|
||||
Notification.text("Item purchased.");
|
||||
} else {
|
||||
Notification.push({
|
||||
type: "text",
|
||||
text: "Not enough GP."
|
||||
});
|
||||
Notification.text("Not enough GP.");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.clearCompleted = function() {
|
||||
User.user.todos = _.reject(User.user.todos, {completed:true});
|
||||
User.log({op: 'clear-completed'});
|
||||
|
||||
Reference in New Issue
Block a user