2018-08-28 10:39:11 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<h1>Tasks</h1>
|
|
|
|
|
2018-08-28 16:52:56 -05:00
|
|
|
<app-dropdown button-class="is-primary" :open="showListDropdown" :label="listSelectLabel" @open="showListDropdown = true" @close="showListDropdown = false">
|
2018-09-05 11:00:35 -05:00
|
|
|
|
2018-09-06 18:16:13 -05:00
|
|
|
<task-list-dropdown-item v-for="l in taskLists" :key="l.id" :task-list="l" :active="currentTaskList !== null && currentTaskList.id === l.id" @select="selectList" @delete="deleteList"></task-list-dropdown-item>
|
2018-09-05 11:00:35 -05:00
|
|
|
|
2018-08-28 16:52:56 -05:00
|
|
|
<hr class="dropdown-divider" v-if="taskLists.length > 0">
|
|
|
|
<div class="dropdown-item">
|
|
|
|
<task-list-mini-form :task-list="newList" :validation-errors="newListValidationErrors" @save="saveNewList"></task-list-mini-form>
|
|
|
|
</div>
|
|
|
|
</app-dropdown>
|
|
|
|
|
2018-09-06 18:16:13 -05:00
|
|
|
<div v-if="currentTaskList !== null">
|
2018-09-05 17:49:21 -05:00
|
|
|
|
2018-09-06 18:16:13 -05:00
|
|
|
<task-item-list :task-list="currentTaskList"></task-item-list>
|
2018-09-05 17:49:21 -05:00
|
|
|
|
2018-08-29 16:58:07 -05:00
|
|
|
</div>
|
|
|
|
|
2018-08-28 10:39:11 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2018-08-28 16:52:56 -05:00
|
|
|
import api from "../lib/Api";
|
|
|
|
import * as Errors from '../lib/Errors';
|
2018-09-06 18:16:13 -05:00
|
|
|
import { mapActions, mapMutations, mapState } from "vuex";
|
|
|
|
|
2018-08-28 16:52:56 -05:00
|
|
|
import TaskListMiniForm from "./TaskListMiniForm";
|
2018-09-05 17:49:21 -05:00
|
|
|
import TaskListDropdownItem from "./TaskListDropdownItem";
|
|
|
|
import TaskItemList from "./TaskItemList";
|
2018-08-28 16:52:56 -05:00
|
|
|
|
|
|
|
const newListTemplate = function() {
|
|
|
|
return {
|
|
|
|
name: ''
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-08-28 10:39:11 -05:00
|
|
|
export default {
|
|
|
|
data() {
|
2018-08-28 16:52:56 -05:00
|
|
|
return {
|
|
|
|
showListDropdown: false,
|
|
|
|
newList: newListTemplate(),
|
2018-09-05 17:49:21 -05:00
|
|
|
newListValidationErrors: {}
|
2018-08-28 16:52:56 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2018-09-06 18:16:13 -05:00
|
|
|
...mapState([
|
|
|
|
'taskLists',
|
|
|
|
'currentTaskList'
|
|
|
|
]),
|
2018-08-28 16:52:56 -05:00
|
|
|
listSelectLabel() {
|
2018-09-06 18:16:13 -05:00
|
|
|
if (this.currentTaskList === null) {
|
2018-08-28 16:52:56 -05:00
|
|
|
return "Select or Create a List";
|
|
|
|
} else {
|
2018-09-06 18:16:13 -05:00
|
|
|
return this.currentTaskList.name;
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
2018-08-28 16:52:56 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2018-09-06 18:16:13 -05:00
|
|
|
...mapActions([
|
|
|
|
'refreshTaskLists',
|
|
|
|
'createTaskList',
|
|
|
|
'deleteTaskList'
|
|
|
|
]),
|
|
|
|
...mapMutations([
|
|
|
|
'setCurrentTaskList'
|
|
|
|
]),
|
|
|
|
|
2018-09-05 17:49:21 -05:00
|
|
|
selectList(list) {
|
2018-09-06 18:16:13 -05:00
|
|
|
this.setCurrentTaskList(list);
|
2018-08-29 16:58:07 -05:00
|
|
|
this.showListDropdown = false;
|
2018-08-28 16:52:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
saveNewList() {
|
|
|
|
this.loadResource(
|
2018-09-06 18:16:13 -05:00
|
|
|
this.createTaskList(this.newList)
|
2018-09-05 11:00:35 -05:00
|
|
|
.then(() => this.showListDropdown = false)
|
2018-08-28 16:52:56 -05:00
|
|
|
.then(() => { this.newList = newListTemplate(); this.newListValidationErrors = {}; } )
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.newListValidationErrors = err.validationErrors()))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-09-05 17:49:21 -05:00
|
|
|
deleteList(list) {
|
2018-09-05 11:00:35 -05:00
|
|
|
this.loadResource(
|
2018-09-06 18:16:13 -05:00
|
|
|
this.deleteTaskList(list)
|
2018-09-05 11:00:35 -05:00
|
|
|
);
|
2018-08-28 16:52:56 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2018-09-06 18:16:13 -05:00
|
|
|
this.loadResource(
|
|
|
|
this.refreshTaskLists()
|
|
|
|
);
|
2018-08-28 16:52:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
2018-09-05 17:49:21 -05:00
|
|
|
TaskListMiniForm,
|
|
|
|
TaskListDropdownItem,
|
|
|
|
TaskItemList
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|