Add creating new related tasks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kolaente 2020-03-04 21:29:40 +01:00
parent e586c66095
commit 4408115f41
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 49 additions and 26 deletions

View File

@ -193,6 +193,7 @@
</h3> </h3>
<related-tasks <related-tasks
:task-i-d="taskID" :task-i-d="taskID"
:list-id="task.listID"
:initial-related-tasks="task.related_tasks" :initial-related-tasks="task.related_tasks"
:show-no-relations-notice="true" :show-no-relations-notice="true"
ref="relatedTasks" ref="relatedTasks"

View File

@ -128,6 +128,7 @@
<related-tasks <related-tasks
class="is-narrow" class="is-narrow"
:task-i-d="task.id" :task-i-d="task.id"
:list-id="task.listID"
:initial-related-tasks="task.related_tasks" :initial-related-tasks="task.related_tasks"
/> />

View File

@ -2,27 +2,31 @@
<div class="task-relations"> <div class="task-relations">
<label class="label">New Task Relation</label> <label class="label">New Task Relation</label>
<div class="columns"> <div class="columns">
<div class="column is-three-quarters"> <div class="column is-three-quarters">
<multiselect <multiselect
v-model="newTaskRelationTask" v-model="newTaskRelationTask"
:options="foundTasks" :options="foundTasks"
:multiple="false" :multiple="false"
:searchable="true" :searchable="true"
:loading="taskService.loading" :loading="taskService.loading"
:internal-search="true" :internal-search="true"
@search-change="findTasks" @search-change="findTasks"
placeholder="Type search for a new task to add as related..." placeholder="Type search for a new task to add as related..."
label="text" label="text"
track-by="id" track-by="id"
> :taggable="true"
<template slot="clear" slot-scope="props"> :showNoOptions="false"
<div class="multiselect__clear" @tag="createAndRelateTask"
v-if="newTaskRelationTask !== null && newTaskRelationTask.id !== 0" tag-placeholder="Add this as new related task"
@mousedown.prevent.stop="clearAllFoundTasks(props.search)"></div> >
</template> <template slot="clear" slot-scope="props">
<span slot="noResult">No task found. Consider changing the search query.</span> <div class="multiselect__clear"
</multiselect> v-if="newTaskRelationTask !== null && newTaskRelationTask.id !== 0"
</div> @mousedown.prevent.stop="clearAllFoundTasks(props.search)"></div>
</template>
<span slot="noResult">No task found. Consider changing the search query.</span>
</multiselect>
</div>
<div class="column field has-addons"> <div class="column field has-addons">
<div class="control is-expanded"> <div class="control is-expanded">
<div class="select is-fullwidth has-defaults"> <div class="select is-fullwidth has-defaults">
@ -57,7 +61,9 @@
</div> </div>
</template> </template>
</div> </div>
<p v-if="showNoRelationsNotice && Object.keys(relatedTasks).length === 0" class="none">No task relations yet.</p> <p v-if="showNoRelationsNotice && Object.keys(relatedTasks).length === 0" class="none">
No task relations yet.
</p>
<!-- Delete modal --> <!-- Delete modal -->
<modal <modal
@ -89,7 +95,7 @@
foundTasks: [], foundTasks: [],
relationKinds: relationKinds, relationKinds: relationKinds,
newTaskRelationTask: TaskModel, newTaskRelationTask: TaskModel,
newTaskRelationKind: 'unset', newTaskRelationKind: 'related',
taskRelationService: TaskRelationService, taskRelationService: TaskRelationService,
showDeleteModal: false, showDeleteModal: false,
relationToDelete: {}, relationToDelete: {},
@ -105,12 +111,17 @@
}, },
initialRelatedTasks: { initialRelatedTasks: {
type: Object, type: Object,
default: () => {}, default: () => {
},
}, },
showNoRelationsNotice: { showNoRelationsNotice: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
listId: {
type: Number,
default: 0,
}
}, },
created() { created() {
this.taskService = new TaskService() this.taskService = new TaskService()
@ -171,7 +182,7 @@
}) })
this.taskRelationService.delete(rel) this.taskRelationService.delete(rel)
.then(r => { .then(r => {
Object.keys(this.relatedTasks).forEach(relationKind => { Object.keys(this.relatedTasks).forEach(relationKind => {
for (const t in this.relatedTasks[relationKind]) { for (const t in this.relatedTasks[relationKind]) {
if (this.relatedTasks[relationKind][t].id === this.relationToDelete.other_task_id && relationKind === this.relationToDelete.relation_kind) { if (this.relatedTasks[relationKind][t].id === this.relationToDelete.other_task_id && relationKind === this.relationToDelete.relation_kind) {
this.relatedTasks[relationKind].splice(t, 1) this.relatedTasks[relationKind].splice(t, 1)
@ -187,7 +198,17 @@
this.showDeleteModal = false this.showDeleteModal = false
}) })
}, },
createAndRelateTask(text) {
const newTask = new TaskModel({text: text, listID: this.listId})
this.taskService.create(newTask)
.then(r => {
this.newTaskRelationTask = r
this.addTaskRelation()
})
.catch(e => {
this.error(e, this)
})
},
}, },
} }
</script> </script>