feat(task wizard): add quick add magic support
This commit is contained in:
parent
ec01f516a8
commit
bf027397b5
4 changed files with 57 additions and 32 deletions
23
src/helpers/findAssignees.ts
Normal file
23
src/helpers/findAssignees.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import UserService from '@/services/user'
|
||||
import {findPropertyByValue} from '@/helpers/findPropertyByValue'
|
||||
|
||||
// Check if the user exists
|
||||
function validateUsername(users: IUser[], username: IUser['username']) {
|
||||
return findPropertyByValue(users, 'username', username)
|
||||
}
|
||||
|
||||
export async function findAssignees(parsedTaskAssignees: string[]) {
|
||||
if (parsedTaskAssignees.length <= 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const userService = new UserService()
|
||||
const assignees = parsedTaskAssignees.map(async a => {
|
||||
const users = await userService.getAll({}, {s: a})
|
||||
return validateUsername(users, a)
|
||||
})
|
||||
|
||||
const validatedUsers = await Promise.all(assignees)
|
||||
return validatedUsers.filter((item) => Boolean(item))
|
||||
}
|
||||
|
7
src/helpers/findPropertyByValue.ts
Normal file
7
src/helpers/findPropertyByValue.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
// IDEA: maybe use a small fuzzy search here to prevent errors
|
||||
export function findPropertyByValue(object, key, value) {
|
||||
return Object.values(object).find(
|
||||
(l) => l[key]?.toLowerCase() === value.toLowerCase(),
|
||||
)
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import {formatISO} from 'date-fns'
|
|||
import TaskService from '@/services/task'
|
||||
import TaskAssigneeService from '@/services/taskAssignee'
|
||||
import LabelTaskService from '@/services/labelTask'
|
||||
import UserService from '@/services/user'
|
||||
|
||||
import {HAS_TASKS} from '../mutation-types'
|
||||
import {setLoading} from '../helper'
|
||||
|
@ -28,18 +27,8 @@ import type { RootStoreState, TaskState } from '@/store/types'
|
|||
import {useLabelStore} from '@/stores/labels'
|
||||
import {useListStore} from '@/stores/lists'
|
||||
import {playPop} from '@/helpers/playPop'
|
||||
|
||||
// IDEA: maybe use a small fuzzy search here to prevent errors
|
||||
function findPropertyByValue(object, key, value) {
|
||||
return Object.values(object).find(
|
||||
(l) => l[key]?.toLowerCase() === value.toLowerCase(),
|
||||
)
|
||||
}
|
||||
|
||||
// Check if the user exists
|
||||
function validateUsername(users: IUser[], username: IUser['username']) {
|
||||
return findPropertyByValue(users, 'username', username)
|
||||
}
|
||||
import {findPropertyByValue} from '@/helpers/findPropertyByValue'
|
||||
import {findAssignees} from '@/helpers/findAssignees'
|
||||
|
||||
// Check if the label exists
|
||||
function validateLabel(labels: ILabel[], label: ILabel) {
|
||||
|
@ -57,22 +46,6 @@ async function addLabelToTask(task: ITask, label: ILabel) {
|
|||
return response
|
||||
}
|
||||
|
||||
async function findAssignees(parsedTaskAssignees) {
|
||||
if (parsedTaskAssignees.length <= 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const userService = new UserService()
|
||||
const assignees = parsedTaskAssignees.map(async a => {
|
||||
const users = await userService.getAll({}, {s: a})
|
||||
return validateUsername(users, a)
|
||||
})
|
||||
|
||||
const validatedUsers = await Promise.all(assignees)
|
||||
return validatedUsers.filter((item) => Boolean(item))
|
||||
}
|
||||
|
||||
|
||||
const tasksStore : Module<TaskState, RootStoreState>= {
|
||||
namespaced: true,
|
||||
state: () => ({}),
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
v-model="newTask.title"
|
||||
v-focus
|
||||
/>
|
||||
<QuickAddMagic class="ml-4"/>
|
||||
<BaseButton
|
||||
v-if="!descriptionFormVisible"
|
||||
@click="() => descriptionFormVisible = true"
|
||||
|
@ -32,14 +33,21 @@
|
|||
<script lang="ts" setup>
|
||||
import {computed, ref} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {formatISO} from 'date-fns'
|
||||
|
||||
import CreateEdit from '@/components/misc/create-edit.vue'
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import TaskModel from '@/models/task'
|
||||
import Editor from '@/components/input/AsyncEditor'
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic.vue'
|
||||
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import TaskModel from '@/models/task'
|
||||
import TaskService from '@/services/task'
|
||||
import {useRouter} from 'vue-router'
|
||||
import {useListStore} from '@/stores/lists'
|
||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
import {parseTaskText} from '@/modules/parseTaskText'
|
||||
import {findAssignees} from '@/helpers/findAssignees'
|
||||
|
||||
const listStore = useListStore()
|
||||
const router = useRouter()
|
||||
|
@ -59,9 +67,23 @@ const descriptionFormVisible = ref(false)
|
|||
const newTask = ref<ITask>(new TaskModel({}))
|
||||
const taskService = ref(new TaskService())
|
||||
|
||||
const parsedTask = computed(() => parseTaskText(newTask.value.title, getQuickAddMagicMode()))
|
||||
|
||||
async function create() {
|
||||
newTask.value.listId = props.listId
|
||||
const task = await taskService.value.create(newTask.value)
|
||||
newTask.value.title = parsedTask.value.text
|
||||
const assignees = await findAssignees(parsedTask.value.assignees)
|
||||
const dueDate = parsedTask.value.date !== null ? formatISO(parsedTask.date) : null
|
||||
|
||||
const finalTask = new TaskModel({
|
||||
...newTask.value,
|
||||
title: parsedTask.value.text,
|
||||
dueDate,
|
||||
priority: parsedTask.value.priority,
|
||||
assignees: parsedTask.value.assignees,
|
||||
})
|
||||
|
||||
const task = await taskService.value.create(finalTask)
|
||||
return router.push({name: 'task.detail', params: {id: task.id}})
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue