From 8f94c64e10215eb10ef574501b1f12b15d25591e Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 30 May 2021 17:29:23 +0200 Subject: [PATCH] Add creating a new task cmd --- src/components/home/contentAuth.vue | 2 +- .../quick-actions/quick-actions.vue | 22 +++++++++++++++++++ src/store/index.js | 6 +++++ src/views/tasks/TaskDetailView.vue | 5 ++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/home/contentAuth.vue b/src/components/home/contentAuth.vue index 8366e5d0f..cee4fadbd 100644 --- a/src/components/home/contentAuth.vue +++ b/src/components/home/contentAuth.vue @@ -86,7 +86,7 @@ export default { this.$route.name === 'user.settings' || this.$route.name === 'namespaces.index' ) { - this.$store.commit(CURRENT_LIST, {}) + this.$store.commit(CURRENT_LIST, null) } }, renewTokenOnFocus() { diff --git a/src/components/quick-actions/quick-actions.vue b/src/components/quick-actions/quick-actions.vue index c7573a9cd..03f964e58 100644 --- a/src/components/quick-actions/quick-actions.vue +++ b/src/components/quick-actions/quick-actions.vue @@ -50,9 +50,12 @@ import ListService from '@/services/list' import NamespaceService from '@/services/namespace' import TeamService from '@/services/team' +import TaskModel from '@/models/task' import NamespaceModel from '@/models/namespace' import TeamModel from '@/models/team' +import {CURRENT_LIST} from '@/store/mutation-types' + const TYPE_LIST = 'list' const TYPE_TASK = 'task' const TYPE_CMD = 'cmd' @@ -157,6 +160,9 @@ export default { return 'Type a command or search...' }, + currentList() { + return Object.keys(this.$store.state[CURRENT_LIST]).length === 0 ? null : this.$store.state[CURRENT_LIST] + }, }, created() { this.taskService = new TaskService() @@ -229,6 +235,22 @@ export default { } }, newTask() { + if (this.currentList === null) { + return + } + + const newTask = new TaskModel({ + title: this.query, + listId: this.currentList.id, + }) + this.taskService.create(newTask) + .then(r => { + this.success({message: 'The task was successfully created.'}, this) + this.$router.push({name: 'task.detail', params: {id: r.id}}) + }) + .catch((e) => { + this.error(e, this) + }) }, newList() { }, diff --git a/src/store/index.js b/src/store/index.js index 4cc6eaab0..260d02705 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -61,6 +61,12 @@ export const store = new Vuex.Store({ }, [CURRENT_LIST](state, currentList) { + if (currentList === null) { + state.currentList = {} + state.background = null + return + } + setTitle(currentList.title) // Not sure if this is the right way to do it but hey, it works diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index 02cb5c65f..6a8918e1e 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -429,6 +429,7 @@ import heading from '@/components/tasks/partials/heading' import Datepicker from '@/components/input/datepicker' import {playPop} from '@/helpers/playPop' import TaskSubscription from '@/components/misc/subscription' +import {CURRENT_LIST} from '@/store/mutation-types' export default { name: 'TaskDetailView', @@ -520,7 +521,9 @@ export default { return null } - return this.$store.getters['namespaces/getListAndNamespaceById'](this.task.listId) + const list = this.$store.getters['namespaces/getListAndNamespaceById'](this.task.listId) + this.$store.commit(CURRENT_LIST, list) + return list }, canWrite() { return this.task && this.task.maxRight && this.task.maxRight > rights.READ