mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
WIP(teams): fix initial assignment sync, add Daily handling
This commit is contained in:
@@ -10,8 +10,8 @@
|
|||||||
:purpose="taskFormPurpose"
|
:purpose="taskFormPurpose"
|
||||||
:group-id="groupId"
|
:group-id="groupId"
|
||||||
@cancel="cancelTaskModal()"
|
@cancel="cancelTaskModal()"
|
||||||
@taskCreated="taskCreated"
|
@taskCreated="loadTasks"
|
||||||
@taskEdited="taskEdited"
|
@taskEdited="loadTasks"
|
||||||
@taskDestroyed="taskDestroyed"
|
@taskDestroyed="taskDestroyed"
|
||||||
/>
|
/>
|
||||||
<div class="row tasks-navigation">
|
<div class="row tasks-navigation">
|
||||||
@@ -327,15 +327,6 @@ export default {
|
|||||||
this.$root.$emit('bv::show::modal', 'task-modal');
|
this.$root.$emit('bv::show::modal', 'task-modal');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
taskCreated (task) {
|
|
||||||
task.group.id = this.group._id;
|
|
||||||
this.tasksByType[task.type].unshift(task);
|
|
||||||
},
|
|
||||||
taskEdited (task) {
|
|
||||||
const index = findIndex(this.tasksByType[task.type], taskItem => taskItem._id === task._id);
|
|
||||||
this.tasksByType[task.type].splice(index, 1, task);
|
|
||||||
this.loadTasks();
|
|
||||||
},
|
|
||||||
taskDestroyed (task) {
|
taskDestroyed (task) {
|
||||||
const index = findIndex(this.tasksByType[task.type], taskItem => taskItem._id === task._id);
|
const index = findIndex(this.tasksByType[task.type], taskItem => taskItem._id === task._id);
|
||||||
this.tasksByType[task.type].splice(index, 1);
|
this.tasksByType[task.type].splice(index, 1);
|
||||||
|
|||||||
@@ -293,13 +293,31 @@ export default function scoreTask (options = {}, req = {}, analytics) {
|
|||||||
_gainMP(user, max([1, 0.01 * statsComputed(user).maxMP]) * (direction === 'down' ? -1 : 1));
|
_gainMP(user, max([1, 0.01 * statsComputed(user).maxMP]) * (direction === 'down' ? -1 : 1));
|
||||||
|
|
||||||
if (direction === 'up') {
|
if (direction === 'up') {
|
||||||
|
if (task.group.id) {
|
||||||
|
if (!task.group.assignedUsers) {
|
||||||
|
task.group.completedBy = {
|
||||||
|
userId: user._id,
|
||||||
|
date: new Date(),
|
||||||
|
};
|
||||||
|
task.completed = true;
|
||||||
|
task.streak += 1;
|
||||||
|
} else {
|
||||||
|
task.group.assignedUsers[user._id].completed = true;
|
||||||
|
task.group.assignedUsers[user._id].completedDate = new Date();
|
||||||
|
if (!find(task.group.assignedUsers, assignedUser => !assignedUser.completed)) {
|
||||||
|
task.dateCompleted = new Date();
|
||||||
|
task.completed = true;
|
||||||
|
task.streak += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (task.markModified) task.markModified('group');
|
||||||
|
} else {
|
||||||
task.streak += 1;
|
task.streak += 1;
|
||||||
// Give a streak achievement when the streak is a multiple of 21
|
// Give a streak achievement when the streak is a multiple of 21
|
||||||
if (task.streak !== 0 && task.streak % 21 === 0) {
|
if (task.streak !== 0 && task.streak % 21 === 0) {
|
||||||
user.achievements.streak = user.achievements.streak ? user.achievements.streak + 1 : 1;
|
user.achievements.streak = user.achievements.streak ? user.achievements.streak + 1 : 1;
|
||||||
if (user.addNotification) user.addNotification('STREAK_ACHIEVEMENT');
|
if (user.addNotification) user.addNotification('STREAK_ACHIEVEMENT');
|
||||||
}
|
}
|
||||||
if (task.group) task.group.completedBy = user._id;
|
|
||||||
task.completed = true;
|
task.completed = true;
|
||||||
|
|
||||||
// Save history entry for daily
|
// Save history entry for daily
|
||||||
@@ -311,13 +329,27 @@ export default function scoreTask (options = {}, req = {}, analytics) {
|
|||||||
completed: true,
|
completed: true,
|
||||||
};
|
};
|
||||||
task.history.push(historyEntry);
|
task.history.push(historyEntry);
|
||||||
|
}
|
||||||
} else if (direction === 'down') {
|
} else if (direction === 'down') {
|
||||||
|
if (task.group.id) {
|
||||||
|
if (!task.group.assignedUsers
|
||||||
|
|| !find(task.group.assignedUsers, assignedUser => !assignedUser.completed)
|
||||||
|
) {
|
||||||
|
task.streak -= 1;
|
||||||
|
task.completed = false;
|
||||||
|
}
|
||||||
|
if (task.group.completedBy) task.group.completedBy = {};
|
||||||
|
if (task.group.assignedUsers && task.group.assignedUsers[user._id]) {
|
||||||
|
task.group.assignedUsers[user._id].completed = false;
|
||||||
|
task.group.assignedUsers[user._id].completedDate = undefined;
|
||||||
|
}
|
||||||
|
if (task.markModified) task.markModified('group');
|
||||||
|
} else {
|
||||||
// Remove a streak achievement if streak was a multiple of 21 and the daily was undone
|
// Remove a streak achievement if streak was a multiple of 21 and the daily was undone
|
||||||
if (task.streak !== 0 && task.streak % 21 === 0) {
|
if (task.streak !== 0 && task.streak % 21 === 0) {
|
||||||
user.achievements.streak = user.achievements.streak ? user.achievements.streak - 1 : 0;
|
user.achievements.streak = user.achievements.streak ? user.achievements.streak - 1 : 0;
|
||||||
}
|
}
|
||||||
task.streak -= 1;
|
task.streak -= 1;
|
||||||
if (task.group && task.group.completedBy) task.group.completedBy = undefined;
|
|
||||||
task.completed = false;
|
task.completed = false;
|
||||||
|
|
||||||
// Delete history entry when daily unchecked
|
// Delete history entry when daily unchecked
|
||||||
@@ -326,6 +358,7 @@ export default function scoreTask (options = {}, req = {}, analytics) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (task.type === 'todo') {
|
} else if (task.type === 'todo') {
|
||||||
if (cron) { // don't touch stats on cron
|
if (cron) { // don't touch stats on cron
|
||||||
delta += _changeTaskValue(user, task, direction, times, cron);
|
delta += _changeTaskValue(user, task, direction, times, cron);
|
||||||
|
|||||||
Reference in New Issue
Block a user