mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Group plan fixes (#9518)
* Fixed group plan editing * Added translations * Abstracted query for group or challenge tasks
This commit is contained in:
@@ -345,7 +345,10 @@ export default {
|
||||
if (editingGroup.summary) this.workingGroup.summary = editingGroup.summary;
|
||||
if (editingGroup.description) this.workingGroup.description = editingGroup.description;
|
||||
if (editingGroup._id) this.workingGroup.id = editingGroup._id;
|
||||
if (editingGroup.leader._id) this.workingGroup.newLeader = editingGroup.leader._id;
|
||||
if (editingGroup.leader._id) {
|
||||
this.workingGroup.newLeader = editingGroup.leader._id;
|
||||
this.workingGroup.currentLeaderId = editingGroup.leader._id;
|
||||
}
|
||||
if (editingGroup._id) this.getMembers();
|
||||
},
|
||||
},
|
||||
@@ -424,14 +427,19 @@ export default {
|
||||
});
|
||||
this.workingGroup.categories = serverCategories;
|
||||
|
||||
let groupData = Object.assign({}, this.workingGroup);
|
||||
if (groupData.newLeader === this.workingGroup.currentLeaderId) {
|
||||
groupData.leader = this.workingGroup.currentLeaderId;
|
||||
}
|
||||
|
||||
let newgroup;
|
||||
if (this.workingGroup.id) {
|
||||
await this.$store.dispatch('guilds:update', {group: this.workingGroup});
|
||||
if (groupData.id) {
|
||||
await this.$store.dispatch('guilds:update', {group: groupData});
|
||||
this.$root.$emit('updatedGroup', this.workingGroup);
|
||||
// @TODO: this doesn't work because of the async resource
|
||||
// if (updatedGroup.type === 'party') this.$store.state.party = {data: updatedGroup};
|
||||
} else {
|
||||
newgroup = await this.$store.dispatch('guilds:create', {group: this.workingGroup});
|
||||
newgroup = await this.$store.dispatch('guilds:create', {group: groupData});
|
||||
this.$store.state.user.data.balance -= 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,15 +63,15 @@ export default {
|
||||
}
|
||||
|
||||
if (assignedUsersLength === 1 && !this.userIsAssigned) {
|
||||
return `Assigned to ${assignedUsersNames[0]}`;
|
||||
return this.$t('assignedToUser', {userName: assignedUsersNames[0]});
|
||||
} else if (assignedUsersLength > 1 && !this.userIsAssigned) {
|
||||
return `Assigned to ${assignedUsersLength} members`;
|
||||
return this.$t('assignedToMembers', {userCount: assignedUsersLength});
|
||||
} else if (assignedUsersLength > 1 && this.userIsAssigned) {
|
||||
return `Assigned to you and ${assignedUsersLength} members`;
|
||||
return this.$t('assignedToYouAndMembers', {userCount: assignedUsersLength});
|
||||
} else if (this.userIsAssigned) {
|
||||
return 'You are assigned to this task';
|
||||
return this.$t('youAreAssigned');
|
||||
} else if (assignedUsersLength === 0) {
|
||||
return 'This task is unassigned';
|
||||
return this.$t('taskIsUnassigned');
|
||||
}
|
||||
},
|
||||
approvalRequested () {
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async claim () {
|
||||
if (!confirm('Are you sure you want to claim this task?')) return;
|
||||
if (!confirm(this.$t('confirmClaim'))) return;
|
||||
|
||||
let taskId = this.task._id;
|
||||
// If we are on the user task
|
||||
@@ -98,7 +98,7 @@ export default {
|
||||
this.task.group.assignedUsers.push(this.user._id);
|
||||
},
|
||||
async unassign () {
|
||||
if (!confirm('Are you sure you want to unclaim this task?')) return;
|
||||
if (!confirm(this.$t('confirmUnClaim'))) return;
|
||||
|
||||
let taskId = this.task._id;
|
||||
// If we are on the user task
|
||||
@@ -114,7 +114,7 @@ export default {
|
||||
this.task.group.assignedUsers.splice(index, 1);
|
||||
},
|
||||
approve () {
|
||||
if (!confirm('Are you sure you want to approve this task?')) return;
|
||||
if (!confirm(this.$t('confirmApproval'))) return;
|
||||
let userIdToApprove = this.task.group.assignedUsers[0];
|
||||
this.$store.dispatch('tasks:unassignTask', {
|
||||
taskId: this.task._id,
|
||||
|
||||
@@ -27,11 +27,11 @@ export default {
|
||||
let userIsRequesting = this.task.group.approvals && this.task.group.approvals.indexOf(this.user._id) !== -1;
|
||||
|
||||
if (approvalsLength === 1 && !userIsRequesting) {
|
||||
return `${approvals[0].userId.profile.name} requests approval`;
|
||||
return this.$t('youAreRequestingApproval', {userName: approvals[0].userId.profile.name});
|
||||
} else if (approvalsLength > 1 && !userIsRequesting) {
|
||||
return `${approvalsLength} request approval`;
|
||||
return this.$t('youAreRequestingApproval', {userCount: approvalsLength});
|
||||
} else if (approvalsLength === 1 && userIsRequesting) {
|
||||
return 'You are requesting approval';
|
||||
return this.$t('youAreRequestingApproval');
|
||||
}
|
||||
},
|
||||
userIsAdmin () {
|
||||
|
||||
@@ -234,6 +234,17 @@
|
||||
"onlyCreatorOrAdminCanDeleteChat": "Not authorized to delete this message!",
|
||||
"onlyGroupLeaderCanEditTasks": "Not authorized to manage tasks!",
|
||||
"onlyGroupTasksCanBeAssigned": "Only group tasks can be assigned",
|
||||
"assignedToUser": "Assigned to <%= userName %>",
|
||||
"assignedToMembers": "Assigned to <%= userCount %> members",
|
||||
"assignedToYouAndMembers": "Assigned to you and <%= userCount %> members",
|
||||
"youAreAssigned": "You are assigned to this task",
|
||||
"taskIsUnassigned": "This task is unassigned",
|
||||
"confirmClaim": "Are you sure you want to claim this task?",
|
||||
"confirmUnClaim": "Are you sure you want to unclaim this task?",
|
||||
"confirmApproval": "Are you sure you want to approve this task?",
|
||||
"userRequestsApproval": "<%= userName %> requests approval",
|
||||
"userCountRequestsApproval": "<%= userCount %> request approval",
|
||||
"youAreRequestingApproval": "You are requesting approval",
|
||||
"chatPrivilegesRevoked": "Your chat privileges have been revoked.",
|
||||
"newChatMessagePlainNotification": "New message in <%= groupName %> by <%= authorName %>. Click here to open the chat page!",
|
||||
"newChatMessageTitle": "New message in <%= groupName %>",
|
||||
|
||||
@@ -617,20 +617,7 @@ api.castSpell = {
|
||||
} else if (targetType === 'tasks') { // new target type in v3: when all the user's tasks are necessary
|
||||
let tasks = await Tasks.Task.find({
|
||||
userId: user._id,
|
||||
$and: [ // exclude challenge and group tasks
|
||||
{
|
||||
$or: [
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{'group.id': {$exists: false}},
|
||||
{'group.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
],
|
||||
...Tasks.taskIsGroupOrChallengeQuery,
|
||||
}).exec();
|
||||
|
||||
spell.cast(user, tasks, req);
|
||||
@@ -1654,20 +1641,7 @@ api.userRebirth = {
|
||||
let tasks = await Tasks.Task.find({
|
||||
userId: user._id,
|
||||
type: {$in: ['daily', 'habit', 'todo']},
|
||||
$and: [ // exclude challenge and group tasks
|
||||
{
|
||||
$or: [
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{'group.id': {$exists: false}},
|
||||
{'group.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
],
|
||||
...Tasks.taskIsGroupOrChallengeQuery,
|
||||
}).exec();
|
||||
|
||||
let rebirthRes = common.ops.rebirth(user, tasks, req, res.analytics);
|
||||
@@ -1825,20 +1799,7 @@ api.userReroll = {
|
||||
let query = {
|
||||
userId: user._id,
|
||||
type: {$in: ['daily', 'habit', 'todo']},
|
||||
$and: [ // exclude challenge and group tasks
|
||||
{
|
||||
$or: [
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{'group.id': {$exists: false}},
|
||||
{'group.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
],
|
||||
...Tasks.taskIsGroupOrChallengeQuery,
|
||||
};
|
||||
let tasks = await Tasks.Task.find(query).exec();
|
||||
let rerollRes = common.ops.reroll(user, tasks, req, res.analytics);
|
||||
@@ -1882,20 +1843,7 @@ api.userReset = {
|
||||
|
||||
let tasks = await Tasks.Task.find({
|
||||
userId: user._id,
|
||||
$and: [ // exclude challenge and group tasks
|
||||
{
|
||||
$or: [
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{'group.id': {$exists: false}},
|
||||
{'group.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
],
|
||||
...Tasks.taskIsGroupOrChallengeQuery,
|
||||
}).select('_id type challenge group').exec();
|
||||
|
||||
let resetRes = common.ops.reset(user, tasks);
|
||||
|
||||
@@ -18,6 +18,22 @@ let subDiscriminatorOptions = _.defaults(_.cloneDeep(discriminatorOptions), {
|
||||
});
|
||||
|
||||
export let tasksTypes = ['habit', 'daily', 'todo', 'reward'];
|
||||
export const taskIsGroupOrChallengeQuery = {
|
||||
$and: [ // exclude challenge and group tasks
|
||||
{
|
||||
$or: [
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{'group.id': {$exists: false}},
|
||||
{'group.broken': {$exists: true}},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Important
|
||||
// When something changes here remember to update the client side model at common/script/libs/taskDefaults
|
||||
|
||||
Reference in New Issue
Block a user