feat(user): save quick add magic mode in api
This commit is contained in:
parent
77ee1bfc3e
commit
d8ad934643
@ -71,10 +71,10 @@ import {useBaseStore} from '@/stores/base'
|
|||||||
import {useProjectStore} from '@/stores/projects'
|
import {useProjectStore} from '@/stores/projects'
|
||||||
import {useLabelStore} from '@/stores/labels'
|
import {useLabelStore} from '@/stores/labels'
|
||||||
import {useTaskStore} from '@/stores/tasks'
|
import {useTaskStore} from '@/stores/tasks'
|
||||||
|
import {useAuthStore} from '@/stores/auth'
|
||||||
|
|
||||||
import {getHistory} from '@/modules/projectHistory'
|
import {getHistory} from '@/modules/projectHistory'
|
||||||
import {parseTaskText, PrefixMode, PREFIXES} from '@/modules/parseTaskText'
|
import {parseTaskText, PrefixMode, PREFIXES} from '@/modules/parseTaskText'
|
||||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
|
||||||
import {success} from '@/message'
|
import {success} from '@/message'
|
||||||
|
|
||||||
import type {ITeam} from '@/modelTypes/ITeam'
|
import type {ITeam} from '@/modelTypes/ITeam'
|
||||||
@ -88,6 +88,7 @@ const baseStore = useBaseStore()
|
|||||||
const projectStore = useProjectStore()
|
const projectStore = useProjectStore()
|
||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
const taskStore = useTaskStore()
|
const taskStore = useTaskStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
type DoAction<Type = any> = { type: ACTION_TYPE } & Type
|
type DoAction<Type = any> = { type: ACTION_TYPE } & Type
|
||||||
|
|
||||||
@ -242,7 +243,7 @@ const hintText = computed(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const prefixes =
|
const prefixes =
|
||||||
PREFIXES[getQuickAddMagicMode()] ?? PREFIXES[PrefixMode.Default]
|
PREFIXES[authStore.settings.frontendSettings.quickAddMagicMode] ?? PREFIXES[PrefixMode.Default]
|
||||||
return t('quickActions.hint', prefixes)
|
return t('quickActions.hint', prefixes)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -255,7 +256,7 @@ const availableCmds = computed(() => {
|
|||||||
return cmds
|
return cmds
|
||||||
})
|
})
|
||||||
|
|
||||||
const parsedQuery = computed(() => parseTaskText(query.value, getQuickAddMagicMode()))
|
const parsedQuery = computed(() => parseTaskText(query.value, authStore.settings.frontendSettings.quickAddMagicMode))
|
||||||
|
|
||||||
const searchMode = computed(() => {
|
const searchMode = computed(() => {
|
||||||
if (query.value === '') {
|
if (query.value === '') {
|
||||||
|
@ -116,12 +116,12 @@ async function addTask() {
|
|||||||
// This allows us to find the tasks with the title they had before being parsed
|
// This allows us to find the tasks with the title they had before being parsed
|
||||||
// by quick add magic.
|
// by quick add magic.
|
||||||
const createdTasks: { [key: ITask['title']]: ITask } = {}
|
const createdTasks: { [key: ITask['title']]: ITask } = {}
|
||||||
const tasksToCreate = parseSubtasksViaIndention(newTaskTitle.value)
|
const tasksToCreate = parseSubtasksViaIndention(newTaskTitle.value, authStore.settings.frontendSettings.quickAddMagicMode)
|
||||||
|
|
||||||
// We ensure all labels exist prior to passing them down to the create task method
|
// We ensure all labels exist prior to passing them down to the create task method
|
||||||
// In the store it will only ever see one task at a time so there's no way to reliably
|
// In the store it will only ever see one task at a time so there's no way to reliably
|
||||||
// check if a new label was created before (because everything happens async).
|
// check if a new label was created before (because everything happens async).
|
||||||
const allLabels = tasksToCreate.map(({title}) => getLabelsFromPrefix(title) ?? [])
|
const allLabels = tasksToCreate.map(({title}) => getLabelsFromPrefix(title, authStore.settings.frontendSettings.quickAddMagicMode) ?? [])
|
||||||
await taskStore.ensureLabelsExist(allLabels.flat())
|
await taskStore.ensureLabelsExist(allLabels.flat())
|
||||||
|
|
||||||
const newTasks = tasksToCreate.map(async ({title, project}) => {
|
const newTasks = tasksToCreate.map(async ({title, project}) => {
|
||||||
|
@ -99,11 +99,13 @@ import {ref, computed} from 'vue'
|
|||||||
|
|
||||||
import BaseButton from '@/components/base/BaseButton.vue'
|
import BaseButton from '@/components/base/BaseButton.vue'
|
||||||
|
|
||||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
|
||||||
import {PREFIXES} from '@/modules/parseTaskText'
|
import {PREFIXES} from '@/modules/parseTaskText'
|
||||||
|
import {useAuthStore} from '@/stores/auth'
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const mode = ref(getQuickAddMagicMode())
|
const mode = computed(() => authStore.settings.frontendSettings.quickAddMagicMode)
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
highlightHintIcon: boolean,
|
highlightHintIcon: boolean,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {getProjectFromPrefix} from '@/modules/parseTaskText'
|
import {getProjectFromPrefix, PrefixMode} from '@/modules/parseTaskText'
|
||||||
|
|
||||||
export interface TaskWithParent {
|
export interface TaskWithParent {
|
||||||
title: string,
|
title: string,
|
||||||
@ -16,7 +16,7 @@ const spaceRegex = /^ */
|
|||||||
* @param taskTitles should be multiple lines of task tiles with indention to declare their parent/subtask
|
* @param taskTitles should be multiple lines of task tiles with indention to declare their parent/subtask
|
||||||
* relation between each other.
|
* relation between each other.
|
||||||
*/
|
*/
|
||||||
export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[] {
|
export function parseSubtasksViaIndention(taskTitles: string, prefixMode: PrefixMode): TaskWithParent[] {
|
||||||
const titles = taskTitles.split(/[\r\n]+/)
|
const titles = taskTitles.split(/[\r\n]+/)
|
||||||
|
|
||||||
return titles.map((title, index) => {
|
return titles.map((title, index) => {
|
||||||
@ -26,7 +26,7 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
|
|||||||
project: null,
|
project: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
task.project = getProjectFromPrefix(task.title)
|
task.project = getProjectFromPrefix(task.title, prefixMode)
|
||||||
|
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
return task
|
return task
|
||||||
@ -49,7 +49,7 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
|
|||||||
task.parent = task.parent.replace(spaceRegex, '')
|
task.parent = task.parent.replace(spaceRegex, '')
|
||||||
if (task.project === null) {
|
if (task.project === null) {
|
||||||
// This allows to specify a project once for the parent task and inherit it to all subtasks
|
// This allows to specify a project once for the parent task and inherit it to all subtasks
|
||||||
task.project = getProjectFromPrefix(task.parent)
|
task.project = getProjectFromPrefix(task.parent, prefixMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,6 @@ import popSoundFile from '@/assets/audio/pop.mp3'
|
|||||||
|
|
||||||
export const playSoundWhenDoneKey = 'playSoundWhenTaskDone'
|
export const playSoundWhenDoneKey = 'playSoundWhenTaskDone'
|
||||||
|
|
||||||
export function playPop() {
|
|
||||||
const enabled = localStorage.getItem(playSoundWhenDoneKey) === 'true'
|
|
||||||
if (!enabled) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
playPopSound()
|
|
||||||
}
|
|
||||||
|
|
||||||
export function playPopSound() {
|
export function playPopSound() {
|
||||||
const popSound = new Audio(popSoundFile)
|
const popSound = new Audio(popSoundFile)
|
||||||
popSound.play()
|
popSound.play()
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import {PrefixMode} from '@/modules/parseTaskText'
|
|
||||||
|
|
||||||
const key = 'quickAddMagicMode'
|
|
||||||
|
|
||||||
export const setQuickAddMagicMode = (mode: PrefixMode) => {
|
|
||||||
localStorage.setItem(key, mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getQuickAddMagicMode = (): PrefixMode => {
|
|
||||||
const mode = localStorage.getItem(key)
|
|
||||||
|
|
||||||
switch (mode) {
|
|
||||||
case null:
|
|
||||||
case PrefixMode.Default:
|
|
||||||
return PrefixMode.Default
|
|
||||||
case PrefixMode.Todoist:
|
|
||||||
return PrefixMode.Todoist
|
|
||||||
}
|
|
||||||
|
|
||||||
return PrefixMode.Disabled
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
import {parseDate} from '../helpers/time/parseDate'
|
import {parseDate} from '../helpers/time/parseDate'
|
||||||
import {PRIORITIES} from '@/constants/priorities'
|
import {PRIORITIES} from '@/constants/priorities'
|
||||||
import {REPEAT_TYPES, type IRepeatAfter, type IRepeatType} from '@/types/IRepeatAfter'
|
import {REPEAT_TYPES, type IRepeatAfter, type IRepeatType} from '@/types/IRepeatAfter'
|
||||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
|
||||||
|
|
||||||
const VIKUNJA_PREFIXES: Prefixes = {
|
const VIKUNJA_PREFIXES: Prefixes = {
|
||||||
label: '*',
|
label: '*',
|
||||||
@ -72,10 +71,10 @@ export const parseTaskText = (text: string, prefixesMode: PrefixMode = PrefixMod
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
result.labels = getLabelsFromPrefix(text, prefixes.label) ?? []
|
result.labels = getLabelsFromPrefix(text, prefixesMode) ?? []
|
||||||
result.text = cleanupItemText(result.text, result.labels, prefixes.label)
|
result.text = cleanupItemText(result.text, result.labels, prefixes.label)
|
||||||
|
|
||||||
result.project = getProjectFromPrefix(result.text, prefixes.project)
|
result.project = getProjectFromPrefix(result.text, prefixesMode)
|
||||||
result.text = result.project !== null ? cleanupItemText(result.text, [result.project], prefixes.project) : result.text
|
result.text = result.project !== null ? cleanupItemText(result.text, [result.project], prefixes.project) : result.text
|
||||||
|
|
||||||
result.priority = getPriority(result.text, prefixes.priority)
|
result.priority = getPriority(result.text, prefixes.priority)
|
||||||
@ -131,26 +130,20 @@ const getItemsFromPrefix = (text: string, prefix: string): string[] => {
|
|||||||
return Array.from(new Set(items))
|
return Array.from(new Set(items))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getProjectFromPrefix = (text: string, projectPrefix: string | null = null): string | null => {
|
export const getProjectFromPrefix = (text: string, prefixMode: PrefixMode): string | null => {
|
||||||
if (projectPrefix === null) {
|
const projectPrefix = PREFIXES[prefixMode]?.project
|
||||||
const prefixes = PREFIXES[getQuickAddMagicMode()]
|
if(typeof projectPrefix === 'undefined') {
|
||||||
if (prefixes === undefined) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
projectPrefix = prefixes.project
|
|
||||||
}
|
|
||||||
const projects: string[] = getItemsFromPrefix(text, projectPrefix)
|
const projects: string[] = getItemsFromPrefix(text, projectPrefix)
|
||||||
return projects.length > 0 ? projects[0] : null
|
return projects.length > 0 ? projects[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getLabelsFromPrefix = (text: string, projectPrefix: string | null = null): string[] | null => {
|
export const getLabelsFromPrefix = (text: string, prefixMode: PrefixMode): string[] | null => {
|
||||||
if (projectPrefix === null) {
|
const projectPrefix = PREFIXES[prefixMode]?.project
|
||||||
const prefixes = PREFIXES[getQuickAddMagicMode()]
|
if(typeof projectPrefix === 'undefined') {
|
||||||
if (prefixes === undefined) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
projectPrefix = prefixes.label
|
|
||||||
}
|
|
||||||
return getItemsFromPrefix(text, projectPrefix)
|
return getItemsFromPrefix(text, projectPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ import TaskService from '@/services/task'
|
|||||||
import TaskAssigneeService from '@/services/taskAssignee'
|
import TaskAssigneeService from '@/services/taskAssignee'
|
||||||
import LabelTaskService from '@/services/labelTask'
|
import LabelTaskService from '@/services/labelTask'
|
||||||
|
|
||||||
import {playPop} from '@/helpers/playPop'
|
import {playPopSound} from '@/helpers/playPop'
|
||||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
|
||||||
import {cleanupItemText, parseTaskText, PREFIXES} from '@/modules/parseTaskText'
|
import {cleanupItemText, parseTaskText, PREFIXES} from '@/modules/parseTaskText'
|
||||||
|
|
||||||
import TaskAssigneeModel from '@/models/taskAssignee'
|
import TaskAssigneeModel from '@/models/taskAssignee'
|
||||||
@ -29,6 +28,7 @@ import {useAttachmentStore} from '@/stores/attachments'
|
|||||||
import {useKanbanStore} from '@/stores/kanban'
|
import {useKanbanStore} from '@/stores/kanban'
|
||||||
import {useBaseStore} from '@/stores/base'
|
import {useBaseStore} from '@/stores/base'
|
||||||
import ProjectUserService from '@/services/projectUsers'
|
import ProjectUserService from '@/services/projectUsers'
|
||||||
|
import {useAuthStore} from '@/stores/auth'
|
||||||
|
|
||||||
interface MatchedAssignee extends IUser {
|
interface MatchedAssignee extends IUser {
|
||||||
match: string,
|
match: string,
|
||||||
@ -106,6 +106,7 @@ export const useTaskStore = defineStore('task', () => {
|
|||||||
const attachmentStore = useAttachmentStore()
|
const attachmentStore = useAttachmentStore()
|
||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
const projectStore = useProjectStore()
|
const projectStore = useProjectStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const tasks = ref<{ [id: ITask['id']]: ITask }>({}) // TODO: or is this ITask[]
|
const tasks = ref<{ [id: ITask['id']]: ITask }>({}) // TODO: or is this ITask[]
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
@ -142,8 +143,8 @@ export const useTaskStore = defineStore('task', () => {
|
|||||||
try {
|
try {
|
||||||
const updatedTask = await taskService.update(task)
|
const updatedTask = await taskService.update(task)
|
||||||
kanbanStore.setTaskInBucket(updatedTask)
|
kanbanStore.setTaskInBucket(updatedTask)
|
||||||
if (task.done) {
|
if (task.done && useAuthStore().settings.frontendSettings.playSoundWhenDone) {
|
||||||
playPop()
|
playPopSound()
|
||||||
}
|
}
|
||||||
return updatedTask
|
return updatedTask
|
||||||
} finally {
|
} finally {
|
||||||
@ -398,7 +399,7 @@ export const useTaskStore = defineStore('task', () => {
|
|||||||
Partial<ITask>,
|
Partial<ITask>,
|
||||||
) {
|
) {
|
||||||
const cancel = setModuleLoading(setIsLoading)
|
const cancel = setModuleLoading(setIsLoading)
|
||||||
const quickAddMagicMode = getQuickAddMagicMode()
|
const quickAddMagicMode = authStore.settings.frontendSettings.quickAddMagicMode
|
||||||
const parsedTask = parseTaskText(title, quickAddMagicMode)
|
const parsedTask = parseTaskText(title, quickAddMagicMode)
|
||||||
|
|
||||||
const foundProjectId = await findProjectId({
|
const foundProjectId = await findProjectId({
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
{{ $t('user.settings.quickAddMagic.title') }}
|
{{ $t('user.settings.quickAddMagic.title') }}
|
||||||
</span>
|
</span>
|
||||||
<div class="select ml-2">
|
<div class="select ml-2">
|
||||||
<select v-model="quickAddMagicMode">
|
<select v-model="settings.frontendSettings.quickAddMagicMode">
|
||||||
<option v-for="set in PrefixMode" :key="set" :value="set">
|
<option v-for="set in PrefixMode" :key="set" :value="set">
|
||||||
{{ $t(`user.settings.quickAddMagic.${set}`) }}
|
{{ $t(`user.settings.quickAddMagic.${set}`) }}
|
||||||
</option>
|
</option>
|
||||||
@ -160,7 +160,6 @@ import ProjectSearch from '@/components/tasks/partials/projectSearch.vue'
|
|||||||
|
|
||||||
import {SUPPORTED_LOCALES} from '@/i18n'
|
import {SUPPORTED_LOCALES} from '@/i18n'
|
||||||
import {playSoundWhenDoneKey, playPopSound} from '@/helpers/playPop'
|
import {playSoundWhenDoneKey, playPopSound} from '@/helpers/playPop'
|
||||||
import {getQuickAddMagicMode, setQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
|
||||||
import {createRandomID} from '@/helpers/randomId'
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
import {success} from '@/message'
|
import {success} from '@/message'
|
||||||
import {AuthenticatedHTTPFactory} from '@/helpers/fetcher'
|
import {AuthenticatedHTTPFactory} from '@/helpers/fetcher'
|
||||||
@ -259,9 +258,6 @@ const loading = computed(() => authStore.isLoadingGeneralSettings)
|
|||||||
// )
|
// )
|
||||||
|
|
||||||
async function updateSettings() {
|
async function updateSettings() {
|
||||||
localStorage.setItem(playSoundWhenDoneKey, playSoundWhenDone.value ? 'true' : 'false')
|
|
||||||
setQuickAddMagicMode(quickAddMagicMode.value)
|
|
||||||
|
|
||||||
await authStore.saveUserSettings({
|
await authStore.saveUserSettings({
|
||||||
settings: {...settings.value},
|
settings: {...settings.value},
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user