mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
New client challenge tasks (#8915)
* Added get and create challenge tasks * Added challenge task edit
This commit is contained in:
@@ -93,6 +93,7 @@ export default {
|
|||||||
data () {
|
data () {
|
||||||
let tweet = this.$t('levelUpShare');
|
let tweet = this.$t('levelUpShare');
|
||||||
return {
|
return {
|
||||||
|
statsAllocationBoxIsOpen: true,
|
||||||
maxHealth,
|
maxHealth,
|
||||||
tweet,
|
tweet,
|
||||||
socialLevelLink: `${BASE_URL}/social/level-up`,
|
socialLevelLink: `${BASE_URL}/social/level-up`,
|
||||||
|
|||||||
@@ -26,7 +26,12 @@
|
|||||||
| {{challenge.prize}}
|
| {{challenge.prize}}
|
||||||
.details(v-once) {{$t('prize')}}
|
.details(v-once) {{$t('prize')}}
|
||||||
.row
|
.row
|
||||||
task-column.col-6(v-for="column in columns", :type="column", :key="column")
|
task-column.col-6(
|
||||||
|
v-for="column in columns",
|
||||||
|
:type="column",
|
||||||
|
:key="column",
|
||||||
|
:taskListOverride='tasksByType[column]',
|
||||||
|
v-on:editTask="editTask")
|
||||||
.col-4.sidebar.standard-page
|
.col-4.sidebar.standard-page
|
||||||
.acitons
|
.acitons
|
||||||
div(v-if='!isMember && !isLeader')
|
div(v-if='!isMember && !isLeader')
|
||||||
@@ -34,7 +39,19 @@
|
|||||||
div(v-if='isMember')
|
div(v-if='isMember')
|
||||||
button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}}
|
button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}}
|
||||||
div(v-if='isLeader')
|
div(v-if='isLeader')
|
||||||
button.btn.btn-success(v-once) {{$t('addTask')}}
|
b-dropdown(:text="$t('create')")
|
||||||
|
b-dropdown-item(v-for="type in columns", :key="type", @click="createTask(type)")
|
||||||
|
| {{$t(type)}}
|
||||||
|
//- button.btn.btn-success(v-once) {{$t('addTask')}}
|
||||||
|
task-modal(
|
||||||
|
:task="workingTask",
|
||||||
|
:purpose="taskFormPurpose",
|
||||||
|
@cancel="cancelTaskModal()",
|
||||||
|
ref="taskModal",
|
||||||
|
:challengeId="challengeId",
|
||||||
|
v-on:taskCreated='taskCreated',
|
||||||
|
v-on:taskEdited='taskEdited',
|
||||||
|
)
|
||||||
div(v-if='isLeader')
|
div(v-if='isLeader')
|
||||||
button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}}
|
button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}}
|
||||||
div(v-if='isLeader')
|
div(v-if='isLeader')
|
||||||
@@ -122,13 +139,20 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Vue from 'vue';
|
||||||
|
import bDropdown from 'bootstrap-vue/lib/components/dropdown';
|
||||||
|
import bDropdownItem from 'bootstrap-vue/lib/components/dropdown-item';
|
||||||
import findIndex from 'lodash/findIndex';
|
import findIndex from 'lodash/findIndex';
|
||||||
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
|
||||||
import { mapState } from 'client/libs/store';
|
import { mapState } from 'client/libs/store';
|
||||||
import closeChallengeModal from './closeChallengeModal';
|
import closeChallengeModal from './closeChallengeModal';
|
||||||
import Column from '../tasks/column';
|
import Column from '../tasks/column';
|
||||||
|
import TaskModal from '../tasks/taskModal';
|
||||||
import challengeModal from './challengeModal';
|
import challengeModal from './challengeModal';
|
||||||
|
|
||||||
|
import taskDefaults from 'common/script/libs/taskDefaults';
|
||||||
|
|
||||||
import gemIcon from 'assets/svg/gem.svg';
|
import gemIcon from 'assets/svg/gem.svg';
|
||||||
import memberIcon from 'assets/svg/member-icon.svg';
|
import memberIcon from 'assets/svg/member-icon.svg';
|
||||||
import calendarIcon from 'assets/svg/calendar.svg';
|
import calendarIcon from 'assets/svg/calendar.svg';
|
||||||
@@ -139,6 +163,9 @@ export default {
|
|||||||
closeChallengeModal,
|
closeChallengeModal,
|
||||||
challengeModal,
|
challengeModal,
|
||||||
TaskColumn: Column,
|
TaskColumn: Column,
|
||||||
|
TaskModal,
|
||||||
|
bDropdown,
|
||||||
|
bDropdownItem,
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@@ -150,6 +177,16 @@ export default {
|
|||||||
}),
|
}),
|
||||||
challenge: {},
|
challenge: {},
|
||||||
members: [],
|
members: [],
|
||||||
|
tasksByType: {
|
||||||
|
habit: [],
|
||||||
|
daily: [],
|
||||||
|
todo: [],
|
||||||
|
reward: [],
|
||||||
|
},
|
||||||
|
editingTask: {},
|
||||||
|
creatingTask: {},
|
||||||
|
workingTask: {},
|
||||||
|
taskFormPurpose: 'create',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -165,8 +202,43 @@ export default {
|
|||||||
async mounted () {
|
async mounted () {
|
||||||
this.challenge = await this.$store.dispatch('challenges:getChallenge', {challengeId: this.challengeId});
|
this.challenge = await this.$store.dispatch('challenges:getChallenge', {challengeId: this.challengeId});
|
||||||
this.members = await this.$store.dispatch('members:getChallengeMembers', {challengeId: this.challengeId});
|
this.members = await this.$store.dispatch('members:getChallengeMembers', {challengeId: this.challengeId});
|
||||||
|
let tasks = await this.$store.dispatch('tasks:getChallengeTasks', {challengeId: this.challengeId});
|
||||||
|
tasks.forEach((task) => {
|
||||||
|
this.tasksByType[task.type].push(task);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
editTask (task) {
|
||||||
|
this.taskFormPurpose = 'edit';
|
||||||
|
this.editingTask = cloneDeep(task);
|
||||||
|
this.workingTask = this.editingTask;
|
||||||
|
// Necessary otherwise the first time the modal is not rendered
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
this.$root.$emit('show::modal', 'task-modal');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
createTask (type) {
|
||||||
|
this.taskFormPurpose = 'create';
|
||||||
|
this.creatingTask = taskDefaults({type, text: ''});
|
||||||
|
this.workingTask = this.editingTask;
|
||||||
|
// Necessary otherwise the first time the modal is not rendered
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
this.$root.$emit('show::modal', 'task-modal');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
cancelTaskModal () {
|
||||||
|
this.editingTask = null;
|
||||||
|
this.creatingTask = null;
|
||||||
|
},
|
||||||
|
taskCreated (task) {
|
||||||
|
this.tasksByType[task.type].push(task);
|
||||||
|
},
|
||||||
|
taskEdited (task) {
|
||||||
|
let index = findIndex(this.tasksByType[task.type], (taskItem) => {
|
||||||
|
return taskItem._id === task._id;
|
||||||
|
});
|
||||||
|
this.tasksByType[task.type].splice(index, 1, task);
|
||||||
|
},
|
||||||
showMemberModal () {
|
showMemberModal () {
|
||||||
this.$store.state.viewingMembers = this.members;
|
this.$store.state.viewingMembers = this.members;
|
||||||
this.$root.$emit('show::modal', 'members-modal');
|
this.$root.$emit('show::modal', 'members-modal');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
) {{ $t(filter.label) }}
|
) {{ $t(filter.label) }}
|
||||||
.tasks-list
|
.tasks-list
|
||||||
task(
|
task(
|
||||||
v-for="task in tasks[`${type}s`]",
|
v-for="task in taskList",
|
||||||
:key="task.id", :task="task",
|
:key="task.id", :task="task",
|
||||||
v-if="filterTask(task)",
|
v-if="filterTask(task)",
|
||||||
@editTask="editTask",
|
@editTask="editTask",
|
||||||
@@ -145,7 +145,7 @@ export default {
|
|||||||
Task,
|
Task,
|
||||||
bModal,
|
bModal,
|
||||||
},
|
},
|
||||||
props: ['type', 'isUser', 'searchText', 'selectedTags'],
|
props: ['type', 'isUser', 'searchText', 'selectedTags', 'taskListOverride'],
|
||||||
data () {
|
data () {
|
||||||
const types = Object.freeze({
|
const types = Object.freeze({
|
||||||
habit: {
|
habit: {
|
||||||
@@ -201,6 +201,10 @@ export default {
|
|||||||
tasks: 'tasks.data',
|
tasks: 'tasks.data',
|
||||||
userPreferences: 'user.data.preferences',
|
userPreferences: 'user.data.preferences',
|
||||||
}),
|
}),
|
||||||
|
taskList () {
|
||||||
|
if (this.taskListOverride) return this.taskListOverride;
|
||||||
|
return this.tasks[`${this.type}s`];
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions({loadCompletedTodos: 'tasks:fetchCompletedTodos'}),
|
...mapActions({loadCompletedTodos: 'tasks:fetchCompletedTodos'}),
|
||||||
@@ -220,7 +224,7 @@ export default {
|
|||||||
// Tags
|
// Tags
|
||||||
const selectedTags = this.selectedTags;
|
const selectedTags = this.selectedTags;
|
||||||
|
|
||||||
if (selectedTags.length > 0) {
|
if (selectedTags && selectedTags.length > 0) {
|
||||||
const hasSelectedTag = task.tags.find(tagId => {
|
const hasSelectedTag = task.tags.find(tagId => {
|
||||||
return selectedTags.indexOf(tagId) !== -1;
|
return selectedTags.indexOf(tagId) !== -1;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ form(
|
|||||||
.option
|
.option
|
||||||
label(v-once) {{ $t('tags') }}
|
label(v-once) {{ $t('tags') }}
|
||||||
.category-wrap(@click="showTagsSelect = !showTagsSelect")
|
.category-wrap(@click="showTagsSelect = !showTagsSelect")
|
||||||
span.category-select(v-if='task.tags.length === 0') {{$t('none')}}
|
span.category-select(v-if='task.tags && task.tags.length === 0') {{$t('none')}}
|
||||||
span.category-select(v-else) {{getTagsFor(task)[0]}}
|
span.category-select(v-else) {{getTagsFor(task)[0]}}
|
||||||
.category-box(v-if="showTagsSelect")
|
.category-box(v-if="showTagsSelect")
|
||||||
.form-check(
|
.form-check(
|
||||||
@@ -343,7 +343,7 @@ export default {
|
|||||||
bDropdownItem,
|
bDropdownItem,
|
||||||
Datepicker,
|
Datepicker,
|
||||||
},
|
},
|
||||||
props: ['task', 'purpose'], // purpose is either create or edit, task is the task created or edited
|
props: ['task', 'purpose', 'challengeId'], // purpose is either create or edit, task is the task created or edited
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
showTagsSelect: false,
|
showTagsSelect: false,
|
||||||
@@ -438,9 +438,18 @@ export default {
|
|||||||
},
|
},
|
||||||
submit () {
|
submit () {
|
||||||
if (this.purpose === 'create') {
|
if (this.purpose === 'create') {
|
||||||
|
if (this.challengeId) {
|
||||||
|
this.$store.dispatch('tasks:createChallengeTasks', {
|
||||||
|
challengeId: this.challengeId,
|
||||||
|
tasks: [this.task],
|
||||||
|
});
|
||||||
|
this.$emit('taskCreated', this.task);
|
||||||
|
} else {
|
||||||
this.createTask(this.task);
|
this.createTask(this.task);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.saveTask(this.task);
|
this.saveTask(this.task);
|
||||||
|
this.$emit('taskEdited', this.task);
|
||||||
}
|
}
|
||||||
this.$root.$emit('hide::modal', 'task-modal');
|
this.$root.$emit('hide::modal', 'task-modal');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -112,11 +112,11 @@ export async function save (store, editedTask) {
|
|||||||
|
|
||||||
sanitizeChecklist(editedTask);
|
sanitizeChecklist(editedTask);
|
||||||
|
|
||||||
Object.assign(originalTask, editedTask);
|
if (originalTask) Object.assign(originalTask, editedTask);
|
||||||
|
|
||||||
const taskDataToSend = omit(originalTask, ['history']);
|
const taskDataToSend = omit(editedTask, ['history']);
|
||||||
const response = await axios.put(`/api/v3/tasks/${originalTask._id}`, taskDataToSend);
|
const response = await axios.put(`/api/v3/tasks/${editedTask._id}`, taskDataToSend);
|
||||||
Object.assign(originalTask, response.data.data);
|
if (originalTask) Object.assign(originalTask, response.data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function destroy (store, task) {
|
export async function destroy (store, task) {
|
||||||
@@ -129,3 +129,13 @@ export async function destroy (store, task) {
|
|||||||
|
|
||||||
await axios.delete(`/api/v3/tasks/${task._id}`);
|
await axios.delete(`/api/v3/tasks/${task._id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getChallengeTasks (store, payload) {
|
||||||
|
let response = await axios.get(`/api/v3/tasks/challenge/${payload.challengeId}`);
|
||||||
|
return response.data.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createChallengeTasks (store, payload) {
|
||||||
|
let response = await axios.post(`/api/v3/tasks/challenge/${payload.challengeId}`, payload.tasks);
|
||||||
|
return response.data.data;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { shouldDo } from 'common/script/cron';
|
|||||||
// Return all the tags belonging to an user task
|
// Return all the tags belonging to an user task
|
||||||
export function getTagsFor (store) {
|
export function getTagsFor (store) {
|
||||||
return (task) => store.state.user.data.tags
|
return (task) => store.state.user.data.tags
|
||||||
.filter(tag => task.tags.indexOf(tag.id) !== -1)
|
.filter(tag => task.tags && task.tags.indexOf(tag.id) !== -1)
|
||||||
.map(tag => tag.name);
|
.map(tag => tag.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user