From 51de1fe8800a97c5e781744f52f4def6c3a042f2 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 Mar 2020 23:24:14 +0100 Subject: [PATCH] Enable marking tasks as done from the task overview --- src/components/tasks/ShowListTasks.vue | 80 +++--------- src/components/tasks/ShowTasks.vue | 52 ++++---- .../tasks/reusable/singleTaskInList.vue | 118 ++++++++++++++++++ 3 files changed, 162 insertions(+), 88 deletions(-) create mode 100644 src/components/tasks/reusable/singleTaskInList.vue diff --git a/src/components/tasks/ShowListTasks.vue b/src/components/tasks/ShowListTasks.vue index fd077062..309337d1 100644 --- a/src/components/tasks/ShowListTasks.vue +++ b/src/components/tasks/ShowListTasks.vue @@ -57,42 +57,9 @@
-
- -
- - -
- - - - - > - - {{l.text}} - - {{ label.title }} - - - - Due {{formatDateSince(l.dueDate)}} - - -
-
+
+ +
@@ -140,8 +107,8 @@ import ListModel from '../../models/list' import EditTask from './edit-task' import TaskModel from '../../models/task' - import PriorityLabel from './reusable/priorityLabel' import TaskCollectionService from '../../services/taskCollection' + import SingleTaskInList from './reusable/singleTaskInList' export default { data() { @@ -165,7 +132,7 @@ } }, components: { - PriorityLabel, + SingleTaskInList, EditTask, }, props: { @@ -267,34 +234,6 @@ } this.initTasks(page, search) }, - markAsDone(e) { - let updateFunc = () => { - // We get the task, update the 'done' property and then push it to the api. - let task = this.getTaskByID(e.target.id) - task.done = e.target.checked - this.taskService.update(task) - .then(() => { - this.sortTasks() - this.success( - {message: 'The task was successfully ' + (task.done ? '' : 'un-') + 'marked as done.'}, - this, - [{ - title: 'Undo', - callback: () => this.markAsDone({target: {id: e.target.id, checked: !e.target.checked}}), - }] - ) - }) - .catch(e => { - this.error(e, this) - }) - } - - if (e.target.checked) { - setTimeout(updateFunc(), 300); // Delay it to show the animation when marking a task as done - } else { - updateFunc() // Don't delay it when un-marking it as it doesn't have an animation the other way around - } - }, editTask(id) { // Find the selected task and set it to the current object let theTask = this.getTaskByID(id) // Somehow this does not work if we directly assign this to this.taskEditTask @@ -326,6 +265,15 @@ return 0 }) }, + updateTasks(updatedTask) { + for (const t in this.tasks) { + if (this.tasks[t].id === updatedTask.id) { + this.$set(this.tasks, t, updatedTask) + break + } + } + this.sortTasks() + }, searchTasks() { if (this.searchTerm === '') { return diff --git a/src/components/tasks/ShowTasks.vue b/src/components/tasks/ShowTasks.vue index 1baad5a8..6cf9a5c7 100644 --- a/src/components/tasks/ShowTasks.vue +++ b/src/components/tasks/ShowTasks.vue @@ -8,36 +8,20 @@
-
- +
+