feat: show namespace of related tasks if they are different than the current one (#923)
Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/923 Reviewed-by: dpschen <dpschen@noreply.kolaente.de> Co-authored-by: konrad <k@knt.li> Co-committed-by: konrad <k@knt.li>
This commit is contained in:
parent
0fe433891a
commit
db605e0d21
3 changed files with 134 additions and 99 deletions
|
@ -29,7 +29,7 @@
|
||||||
:placeholder="$t('task.relation.searchPlaceholder')"
|
:placeholder="$t('task.relation.searchPlaceholder')"
|
||||||
@search="findTasks"
|
@search="findTasks"
|
||||||
:loading="taskService.loading"
|
:loading="taskService.loading"
|
||||||
:search-results="foundTasks"
|
:search-results="mappedFoundTasks"
|
||||||
label="title"
|
label="title"
|
||||||
v-model="newTaskRelationTask"
|
v-model="newTaskRelationTask"
|
||||||
:creatable="true"
|
:creatable="true"
|
||||||
|
@ -41,8 +41,17 @@
|
||||||
<span
|
<span
|
||||||
class="different-list"
|
class="different-list"
|
||||||
v-if="props.option.listId !== listId"
|
v-if="props.option.listId !== listId"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-if="props.option.differentNamespace !== null"
|
||||||
|
v-tooltip="$t('task.relation.differentNamespace')">
|
||||||
|
{{ props.option.differentNamespace }} >
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="props.option.differentList !== null"
|
||||||
v-tooltip="$t('task.relation.differentList')">
|
v-tooltip="$t('task.relation.differentList')">
|
||||||
{{ $store.getters['lists/getListById'](props.option.listId) === null ? '' : $store.getters['lists/getListById'](props.option.listId).title }} >
|
{{ props.option.differentList }} >
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
{{ props.option.title }}
|
{{ props.option.title }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -70,33 +79,36 @@
|
||||||
</template>
|
</template>
|
||||||
</transition-group>
|
</transition-group>
|
||||||
|
|
||||||
<div :key="kind" class="related-tasks" v-for="(rts, kind ) in relatedTasks">
|
<div :key="rts.kind" class="related-tasks" v-for="rts in mappedRelatedTasks">
|
||||||
<template v-if="rts.length > 0">
|
<span class="title">{{ rts.title }}</span>
|
||||||
<span class="title">{{ relationKindTitle(kind, rts.length) }}</span>
|
<div class="tasks">
|
||||||
<div class="tasks noborder">
|
<div :key="t.id" class="task" v-for="t in rts.tasks">
|
||||||
<div :key="t.id" class="task" v-for="t in rts.filter(t => t)">
|
<router-link :to="{ name: $route.name, params: { id: t.id } }" :class="{ 'done': t.done}">
|
||||||
<router-link :to="{ name: $route.name, params: { id: t.id } }">
|
|
||||||
<span :class="{ 'done': t.done}" class="tasktext">
|
|
||||||
<span
|
<span
|
||||||
class="different-list"
|
class="different-list"
|
||||||
v-if="t.listId !== listId"
|
v-if="t.listId !== listId"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-if="t.differentNamespace !== null"
|
||||||
|
v-tooltip="$t('task.relation.differentNamespace')">
|
||||||
|
{{ t.differentNamespace }} >
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="t.differentList !== null"
|
||||||
v-tooltip="$t('task.relation.differentList')">
|
v-tooltip="$t('task.relation.differentList')">
|
||||||
{{
|
{{ t.differentList }} >
|
||||||
$store.getters['lists/getListById'](t.listId) === null ? '' : $store.getters['lists/getListById'](t.listId).title
|
</span>
|
||||||
}} >
|
|
||||||
</span>
|
</span>
|
||||||
{{ t.title }}
|
{{ t.title }}
|
||||||
</span>
|
|
||||||
</router-link>
|
</router-link>
|
||||||
<a
|
<a
|
||||||
@click="() => {showDeleteModal = true; relationToDelete = {relationKind: kind, otherTaskId: t.id}}"
|
@click="() => {showDeleteModal = true; relationToDelete = {relationKind: rts.kind, otherTaskId: t.id}}"
|
||||||
class="remove"
|
class="remove"
|
||||||
v-if="editEnabled">
|
v-if="editEnabled">
|
||||||
<icon icon="trash-alt"/>
|
<icon icon="trash-alt"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
<p class="none" v-if="showNoRelationsNotice && Object.keys(relatedTasks).length === 0">
|
<p class="none" v-if="showNoRelationsNotice && Object.keys(relatedTasks).length === 0">
|
||||||
{{ $t('task.relation.noneYet') }}
|
{{ $t('task.relation.noneYet') }}
|
||||||
|
@ -183,6 +195,19 @@ export default {
|
||||||
showCreate() {
|
showCreate() {
|
||||||
return Object.keys(this.relatedTasks).length === 0 || this.showNewRelationForm
|
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: {
|
methods: {
|
||||||
async findTasks(query) {
|
async findTasks(query) {
|
||||||
|
@ -217,15 +242,14 @@ export default {
|
||||||
try {
|
try {
|
||||||
await this.taskRelationService.delete(rel)
|
await this.taskRelationService.delete(rel)
|
||||||
|
|
||||||
Object.entries(this.relatedTasks).some(([relationKind, t]) => {
|
const kind = this.relationToDelete.relationKind
|
||||||
const found = typeof this.relatedTasks[relationKind][t] !== 'undefined' &&
|
for (const t in this.relatedTasks[kind]) {
|
||||||
this.relatedTasks[relationKind][t].id === this.relationToDelete.otherTaskId &&
|
if (this.relatedTasks[kind][t].id === this.relationToDelete.otherTaskId) {
|
||||||
relationKind === this.relationToDelete.relationKind
|
this.relatedTasks[kind].splice(t, 1)
|
||||||
if (!found) return false
|
|
||||||
|
|
||||||
this.relatedTasks[relationKind].splice(t, 1)
|
break
|
||||||
return true
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
this.saved = true
|
this.saved = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -245,13 +269,34 @@ export default {
|
||||||
relationKindTitle(kind, length) {
|
relationKindTitle(kind, length) {
|
||||||
return this.$tc(`task.relation.kinds.${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,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
$remove-icon-width: 24px;
|
|
||||||
|
|
||||||
.add-task-relation-button {
|
.add-task-relation-button {
|
||||||
margin-top: -3rem;
|
margin-top: -3rem;
|
||||||
|
|
||||||
|
@ -264,52 +309,27 @@ $remove-icon-width: 24px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-relations {
|
.different-list {
|
||||||
&.is-narrow .columns {
|
|
||||||
display: block;
|
|
||||||
|
|
||||||
.column {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.different-list {
|
|
||||||
color: $grey-500;
|
color: $grey-500;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.related-tasks {
|
.title {
|
||||||
.title {
|
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks {
|
.task {
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
a:not(.remove) {
|
|
||||||
width: calc(100% - #{$remove-icon-width});
|
|
||||||
}
|
|
||||||
|
|
||||||
.task .tasktext {
|
|
||||||
width: calc(100% - .25rem); // Magic .25rem extra space
|
|
||||||
}
|
|
||||||
|
|
||||||
.remove {
|
|
||||||
width: $remove-icon-width;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.task {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
padding: .4rem;
|
justify-content: space-between;
|
||||||
|
padding: .75rem;
|
||||||
transition: background-color $transition;
|
transition: background-color $transition;
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: $radius;
|
border-radius: $radius;
|
||||||
border: 2px solid transparent;
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $grey-200;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: $text;
|
color: $text;
|
||||||
|
@ -321,14 +341,23 @@ $remove-icon-width: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.remove {
|
.remove {
|
||||||
color: $red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.none {
|
|
||||||
font-style: italic;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
color: $red;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity $transition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.related-tasks:hover .tasks .task .remove {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.none {
|
||||||
|
font-style: italic;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.multiselect .search-results button) {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
|
@ -656,6 +656,7 @@
|
||||||
"searchPlaceholder": "Type search for a new task to add as related…",
|
"searchPlaceholder": "Type search for a new task to add as related…",
|
||||||
"createPlaceholder": "Add this as new related task",
|
"createPlaceholder": "Add this as new related task",
|
||||||
"differentList": "This task belongs to a different list.",
|
"differentList": "This task belongs to a different list.",
|
||||||
|
"differentNamespace": "This task belongs to a different namespace.",
|
||||||
"noneYet": "No task relations yet.",
|
"noneYet": "No task relations yet.",
|
||||||
"delete": "Delete Task Relation",
|
"delete": "Delete Task Relation",
|
||||||
"deleteText1": "Are you sure you want to delete this task relation?",
|
"deleteText1": "Are you sure you want to delete this task relation?",
|
||||||
|
|
|
@ -76,8 +76,13 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
getListAndNamespaceById: state => listId => {
|
getListAndNamespaceById: state => (listId, ignorePseudoNamespaces = false) => {
|
||||||
for (const n in state.namespaces) {
|
for (const n in state.namespaces) {
|
||||||
|
|
||||||
|
if(ignorePseudoNamespaces && state.namespaces[n].id < 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for (const l in state.namespaces[n].lists) {
|
for (const l in state.namespaces[n].lists) {
|
||||||
if (state.namespaces[n].lists[l].id === listId) {
|
if (state.namespaces[n].lists[l].id === listId) {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue