diff --git a/src/components/tasks/partials/relatedTasks.vue b/src/components/tasks/partials/relatedTasks.vue index 3badac6cc..beec2bf6a 100644 --- a/src/components/tasks/partials/relatedTasks.vue +++ b/src/components/tasks/partials/relatedTasks.vue @@ -29,7 +29,7 @@ :placeholder="$t('task.relation.searchPlaceholder')" @search="findTasks" :loading="taskService.loading" - :search-results="foundTasks" + :search-results="mappedFoundTasks" label="title" v-model="newTaskRelationTask" :creatable="true" @@ -41,8 +41,17 @@ - {{ $store.getters['lists/getListById'](props.option.listId) === null ? '' : $store.getters['lists/getListById'](props.option.listId).title }} > + > + + {{ props.option.differentNamespace }} > + + + {{ props.option.differentList }} > + {{ props.option.title }} @@ -70,33 +79,36 @@ -

{{ $t('task.relation.noneYet') }} @@ -110,10 +122,10 @@ v-if="showDeleteModal" > - + @@ -183,6 +195,19 @@ export default { showCreate() { return Object.keys(this.relatedTasks).length === 0 || this.showNewRelationForm }, + namespace() { + return this.$store.getters['namespaces/getListAndNamespaceById'](this.listId, true)?.namespace + }, + mappedRelatedTasks() { + return Object.entries(this.relatedTasks).map(([kind, tasks]) => ({ + title: this.$tc(`task.relation.kinds.${kind}`, tasks.length), + tasks: this.mapRelatedTasks(tasks), + kind, + })) + }, + mappedFoundTasks() { + return this.mapRelatedTasks(this.foundTasks.filter(t => t.id !== this.taskId)) + }, }, methods: { async findTasks(query) { @@ -217,15 +242,14 @@ export default { try { await this.taskRelationService.delete(rel) - Object.entries(this.relatedTasks).some(([relationKind, t]) => { - const found = typeof this.relatedTasks[relationKind][t] !== 'undefined' && - this.relatedTasks[relationKind][t].id === this.relationToDelete.otherTaskId && - relationKind === this.relationToDelete.relationKind - if (!found) return false + const kind = this.relationToDelete.relationKind + for (const t in this.relatedTasks[kind]) { + if (this.relatedTasks[kind][t].id === this.relationToDelete.otherTaskId) { + this.relatedTasks[kind].splice(t, 1) - this.relatedTasks[relationKind].splice(t, 1) - return true - }) + break + } + } this.saved = true setTimeout(() => { @@ -245,13 +269,34 @@ export default { relationKindTitle(kind, length) { return this.$tc(`task.relation.kinds.${kind}`, length) }, + + mapRelatedTasks(tasks) { + return tasks + .map(task => { + // by doing this here once we can save a lot of duplicate calls in the template + const { + list, + namespace, + } = this.$store.getters['namespaces/getListAndNamespaceById'](task.listId, true) + + return { + ...task, + differentNamespace: + (namespace !== null && + namespace.id !== this.namespace.id && + namespace?.title) || null, + differentList: + (list !== null && + task.listId !== this.listId && + list?.title) || null, + } + }) + }, }, } \ No newline at end of file diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index 934348861..11319b16d 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -656,6 +656,7 @@ "searchPlaceholder": "Type search for a new task to add as related…", "createPlaceholder": "Add this as new related task", "differentList": "This task belongs to a different list.", + "differentNamespace": "This task belongs to a different namespace.", "noneYet": "No task relations yet.", "delete": "Delete Task Relation", "deleteText1": "Are you sure you want to delete this task relation?", diff --git a/src/store/modules/namespaces.js b/src/store/modules/namespaces.js index cb78f5600..553f236fa 100644 --- a/src/store/modules/namespaces.js +++ b/src/store/modules/namespaces.js @@ -76,8 +76,13 @@ export default { }, }, getters: { - getListAndNamespaceById: state => listId => { + getListAndNamespaceById: state => (listId, ignorePseudoNamespaces = false) => { for (const n in state.namespaces) { + + if(ignorePseudoNamespaces && state.namespaces[n].id < 0) { + continue + } + for (const l in state.namespaces[n].lists) { if (state.namespaces[n].lists[l].id === listId) { return {