2018-08-28 10:39:11 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
2018-09-13 14:51:41 -05:00
|
|
|
<h1 class="title is-3">
|
|
|
|
Tasks
|
|
|
|
<app-dropdown button-class="is-primary" :open="showListDropdown" :label="listSelectLabel" @open="showListDropdown = true" @close="showListDropdown = false">
|
2018-08-28 10:39:11 -05:00
|
|
|
|
2018-09-13 14:51:41 -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-09-13 14:51:41 -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>
|
|
|
|
</h1>
|
2018-09-05 11:00:35 -05:00
|
|
|
|
2018-09-13 14:51:41 -05:00
|
|
|
<div class="columns" v-if="currentTaskList !== null">
|
|
|
|
<div class="column is-6-widescreen is-8-desktop is-10-tablet">
|
2018-09-07 21:56:13 -05:00
|
|
|
<task-item-list :task-list="currentTaskList"></task-item-list>
|
|
|
|
</div>
|
2018-08-29 16:58:07 -05:00
|
|
|
</div>
|
|
|
|
|
2018-08-28 10:39:11 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
<script setup>
|
2018-08-28 10:39:11 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
import { computed, onBeforeMount, ref } from "vue";
|
2018-08-28 16:52:56 -05:00
|
|
|
import * as Errors from '../lib/Errors';
|
2024-09-28 20:58:25 -05:00
|
|
|
import { useTaskStore } from "../stores/task";
|
2018-09-06 18:16:13 -05:00
|
|
|
|
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";
|
2024-10-02 14:34:50 -05:00
|
|
|
import { useLoadResource } from "../lib/useLoadResource";
|
2018-08-28 16:52:56 -05:00
|
|
|
|
|
|
|
const newListTemplate = function() {
|
|
|
|
return {
|
|
|
|
name: ''
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
const { loadResource } = useLoadResource();
|
|
|
|
const taskStore = useTaskStore();
|
|
|
|
|
|
|
|
const showListDropdown = ref(false);
|
|
|
|
const newList = ref(newListTemplate());
|
|
|
|
const newListValidationErrors = ref({});
|
|
|
|
|
|
|
|
const taskLists = computed(() => taskStore.taskLists);
|
|
|
|
const currentTaskList = computed(() => taskStore.currentTaskList);
|
|
|
|
const listSelectLabel = computed(() => {
|
|
|
|
if (currentTaskList.value === null) {
|
|
|
|
return "Select or Create a List";
|
|
|
|
} else {
|
|
|
|
return currentTaskList.value.name;
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
2024-10-02 14:34:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
loadResource(taskStore.refreshTaskLists());
|
|
|
|
});
|
|
|
|
|
|
|
|
function selectList(list) {
|
|
|
|
taskStore.setCurrentTaskList(list);
|
|
|
|
showListDropdown.value = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveNewList() {
|
|
|
|
loadResource(
|
|
|
|
taskStore.createTaskList(newList.value)
|
|
|
|
.then(() => showListDropdown.value = false)
|
|
|
|
.then(() => { newList.value = newListTemplate(); newListValidationErrors.value = {}; } )
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => newListValidationErrors.value = err.validationErrors()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteList(list) {
|
|
|
|
loadResource(taskStore.deleteTaskList(list));
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteAllItems() {
|
|
|
|
loadResource(
|
|
|
|
taskStore.deleteTaskItems({
|
|
|
|
taskList: currentTaskList.value,
|
|
|
|
taskItems: currentTaskList.value.task_items
|
|
|
|
})
|
|
|
|
);
|
2018-08-28 10:39:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|