New client challenge tasks (#8915)

* Added get and create challenge tasks

* Added challenge task edit
This commit is contained in:
Keith Holliday
2017-08-02 10:57:57 -06:00
committed by GitHub
parent e3b10cdc2a
commit cf0ce90968
8 changed files with 467 additions and 371 deletions

View File

@@ -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');