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">
|
|
|
|
<a class="dropdown-item" href="#" v-for="l in taskLists" @click="selectList(l)">{{l.name}}</a>
|
|
|
|
<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-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';
|
|
|
|
import TaskListMiniForm from "./TaskListMiniForm";
|
|
|
|
|
|
|
|
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 {
|
|
|
|
taskLists: [],
|
|
|
|
showListDropdown: false,
|
|
|
|
currentList: null,
|
|
|
|
newList: newListTemplate(),
|
|
|
|
newListValidationErrors: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
listSelectLabel() {
|
|
|
|
if (this.currentList === null) {
|
|
|
|
return "Select or Create a List";
|
|
|
|
} else {
|
|
|
|
return this.currentList.name;
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
2018-08-28 16:52:56 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
selectList(l) {
|
|
|
|
this.currentList = l;
|
|
|
|
},
|
|
|
|
|
|
|
|
saveNewList() {
|
|
|
|
this.loadResource(
|
|
|
|
api.postTaskList(this.newList)
|
|
|
|
.then(() => this.updateData())
|
|
|
|
.then(() => { this.newList = newListTemplate(); this.newListValidationErrors = {}; } )
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.newListValidationErrors = err.validationErrors()))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateData() {
|
|
|
|
return this.loadResource(api.getTaskLists(data => this.taskLists = data));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.updateData()
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
TaskListMiniForm
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|