mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +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 () {
|
||||
let tweet = this.$t('levelUpShare');
|
||||
return {
|
||||
statsAllocationBoxIsOpen: true,
|
||||
maxHealth,
|
||||
tweet,
|
||||
socialLevelLink: `${BASE_URL}/social/level-up`,
|
||||
|
||||
@@ -26,7 +26,12 @@
|
||||
| {{challenge.prize}}
|
||||
.details(v-once) {{$t('prize')}}
|
||||
.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
|
||||
.acitons
|
||||
div(v-if='!isMember && !isLeader')
|
||||
@@ -34,7 +39,19 @@
|
||||
div(v-if='isMember')
|
||||
button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}}
|
||||
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')
|
||||
button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}}
|
||||
div(v-if='isLeader')
|
||||
@@ -122,13 +139,20 @@
|
||||
</style>
|
||||
|
||||
<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 cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
import { mapState } from 'client/libs/store';
|
||||
import closeChallengeModal from './closeChallengeModal';
|
||||
import Column from '../tasks/column';
|
||||
import TaskModal from '../tasks/taskModal';
|
||||
import challengeModal from './challengeModal';
|
||||
|
||||
import taskDefaults from 'common/script/libs/taskDefaults';
|
||||
|
||||
import gemIcon from 'assets/svg/gem.svg';
|
||||
import memberIcon from 'assets/svg/member-icon.svg';
|
||||
import calendarIcon from 'assets/svg/calendar.svg';
|
||||
@@ -139,6 +163,9 @@ export default {
|
||||
closeChallengeModal,
|
||||
challengeModal,
|
||||
TaskColumn: Column,
|
||||
TaskModal,
|
||||
bDropdown,
|
||||
bDropdownItem,
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
@@ -150,6 +177,16 @@ export default {
|
||||
}),
|
||||
challenge: {},
|
||||
members: [],
|
||||
tasksByType: {
|
||||
habit: [],
|
||||
daily: [],
|
||||
todo: [],
|
||||
reward: [],
|
||||
},
|
||||
editingTask: {},
|
||||
creatingTask: {},
|
||||
workingTask: {},
|
||||
taskFormPurpose: 'create',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -165,8 +202,43 @@ export default {
|
||||
async mounted () {
|
||||
this.challenge = await this.$store.dispatch('challenges:getChallenge', {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: {
|
||||
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 () {
|
||||
this.$store.state.viewingMembers = this.members;
|
||||
this.$root.$emit('show::modal', 'members-modal');
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
) {{ $t(filter.label) }}
|
||||
.tasks-list
|
||||
task(
|
||||
v-for="task in tasks[`${type}s`]",
|
||||
v-for="task in taskList",
|
||||
:key="task.id", :task="task",
|
||||
v-if="filterTask(task)",
|
||||
@editTask="editTask",
|
||||
@@ -145,7 +145,7 @@ export default {
|
||||
Task,
|
||||
bModal,
|
||||
},
|
||||
props: ['type', 'isUser', 'searchText', 'selectedTags'],
|
||||
props: ['type', 'isUser', 'searchText', 'selectedTags', 'taskListOverride'],
|
||||
data () {
|
||||
const types = Object.freeze({
|
||||
habit: {
|
||||
@@ -201,6 +201,10 @@ export default {
|
||||
tasks: 'tasks.data',
|
||||
userPreferences: 'user.data.preferences',
|
||||
}),
|
||||
taskList () {
|
||||
if (this.taskListOverride) return this.taskListOverride;
|
||||
return this.tasks[`${this.type}s`];
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapActions({loadCompletedTodos: 'tasks:fetchCompletedTodos'}),
|
||||
@@ -220,7 +224,7 @@ export default {
|
||||
// Tags
|
||||
const selectedTags = this.selectedTags;
|
||||
|
||||
if (selectedTags.length > 0) {
|
||||
if (selectedTags && selectedTags.length > 0) {
|
||||
const hasSelectedTag = task.tags.find(tagId => {
|
||||
return selectedTags.indexOf(tagId) !== -1;
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ form(
|
||||
.option
|
||||
label(v-once) {{ $t('tags') }}
|
||||
.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]}}
|
||||
.category-box(v-if="showTagsSelect")
|
||||
.form-check(
|
||||
@@ -343,7 +343,7 @@ export default {
|
||||
bDropdownItem,
|
||||
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 () {
|
||||
return {
|
||||
showTagsSelect: false,
|
||||
@@ -438,9 +438,18 @@ export default {
|
||||
},
|
||||
submit () {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
this.saveTask(this.task);
|
||||
this.$emit('taskEdited', this.task);
|
||||
}
|
||||
this.$root.$emit('hide::modal', 'task-modal');
|
||||
},
|
||||
|
||||
@@ -112,11 +112,11 @@ export async function save (store, editedTask) {
|
||||
|
||||
sanitizeChecklist(editedTask);
|
||||
|
||||
Object.assign(originalTask, editedTask);
|
||||
if (originalTask) Object.assign(originalTask, editedTask);
|
||||
|
||||
const taskDataToSend = omit(originalTask, ['history']);
|
||||
const response = await axios.put(`/api/v3/tasks/${originalTask._id}`, taskDataToSend);
|
||||
Object.assign(originalTask, response.data.data);
|
||||
const taskDataToSend = omit(editedTask, ['history']);
|
||||
const response = await axios.put(`/api/v3/tasks/${editedTask._id}`, taskDataToSend);
|
||||
if (originalTask) Object.assign(originalTask, response.data.data);
|
||||
}
|
||||
|
||||
export async function destroy (store, task) {
|
||||
@@ -129,3 +129,13 @@ export async function destroy (store, task) {
|
||||
|
||||
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
|
||||
export function getTagsFor (store) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user