From 3b77fff4c999d2c95788da602b11e7b91189727d Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 11 Mar 2024 14:21:42 +0100 Subject: [PATCH] fix(project): correctly show the number of tasks and projects when deleting a project --- frontend/src/i18n/lang/en.json | 1 + .../src/views/project/settings/delete.vue | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/frontend/src/i18n/lang/en.json b/frontend/src/i18n/lang/en.json index b7747ecb7..8516f6812 100644 --- a/frontend/src/i18n/lang/en.json +++ b/frontend/src/i18n/lang/en.json @@ -248,6 +248,7 @@ "text2": "This includes all tasks and CANNOT BE UNDONE!", "success": "The project was successfully deleted.", "tasksToDelete": "This will irrevocably remove approx. {count} tasks.", + "tasksAndChildProjectsToDelete": "This will irrevocably remove approx. {tasks} tasks and {projects} projects.", "noTasksToDelete": "This project does not contain any tasks, it should be safe to delete." }, "duplicate": { diff --git a/frontend/src/views/project/settings/delete.vue b/frontend/src/views/project/settings/delete.vue index 2ee998672..059099bdb 100644 --- a/frontend/src/views/project/settings/delete.vue +++ b/frontend/src/views/project/settings/delete.vue @@ -16,9 +16,7 @@ v-if="totalTasks !== null" class="has-text-weight-bold" > - {{ - totalTasks > 0 ? $t('project.delete.tasksToDelete', {count: totalTasks}) : $t('project.delete.noTasksToDelete') - }} + {{ deleteNotice }}

(null) const project = computed(() => projectStore.projects[route.params.projectId]) +const childProjectIds = ref([]) watchEffect( () => { @@ -58,15 +57,32 @@ watchEffect( return } - const taskCollectionService = new TaskCollectionService() - taskCollectionService.getAll({projectId: route.params.projectId}).then(() => { - totalTasks.value = taskCollectionService.totalPages * taskCollectionService.resultCount + childProjectIds.value = projectStore.getChildProjects(parseInt(route.params.projectId)).map(p => p.id) + if (childProjectIds.value.length === 0) { + childProjectIds.value = [parseInt(route.params.projectId)] + } + + const taskService = new TaskService() + taskService.getAll({}, {filter: `project in '${childProjectIds.value.join(',')}'`}).then(() => { + totalTasks.value = taskService.totalPages * taskService.resultCount }) }, ) useTitle(() => t('project.delete.title', {project: project?.value?.title})) +const deleteNotice = computed(() => { + if(totalTasks.value && totalTasks.value > 0 && childProjectIds.value.length <= 1) { + return t('project.delete.tasksToDelete', {count: totalTasks.value}) + } + + if(totalTasks.value && totalTasks.value > 0 && childProjectIds.value.length > 1) { + return t('project.delete.tasksAndChildProjectsToDelete', {tasks: totalTasks.value, projects: childProjectIds.value.length}) + } + + return t('project.delete.noTasksToDelete') +}) + async function deleteProject() { if (!project.value) { return