Move task store functions to appropriate file
This commit is contained in:
parent
2425f267ca
commit
87699c1f20
2 changed files with 47 additions and 48 deletions
|
@ -37,7 +37,6 @@ import Task from '../models/task'
|
|||
import pLimit from 'p-limit'
|
||||
import { isParentInList, searchSubTasks } from './storeHelper'
|
||||
import { findVTODObyState } from './cdav-requests'
|
||||
import TaskStatus from '../models/taskStatus'
|
||||
|
||||
const calendarModel = {
|
||||
id: '',
|
||||
|
@ -596,52 +595,6 @@ const actions = {
|
|||
// Share a calendar with the entered group or user
|
||||
context.commit('shareCalendar', { calendar, sharee, id, group })
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves a task to the provided calendar
|
||||
*
|
||||
* @param {Object} context The store mutations
|
||||
* @param {Object} data Destructuring object
|
||||
* @param {Task} data.task The task to move
|
||||
* @param {Calendar} data.calendar The calendar to move the task to
|
||||
* @param {Boolean} data.removeParent If the task has a parent, remove the link to the parent
|
||||
* @returns {Task} The moved task
|
||||
*/
|
||||
async moveTaskToCalendar(context, { task, calendar, removeParent = true }) {
|
||||
// Only local move if the task doesn't exist on the server.
|
||||
// Don't move if source and target calendar are the same.
|
||||
if (task.dav && task.calendar !== calendar) {
|
||||
// Move all subtasks first
|
||||
await Promise.all(Object.values(task.subTasks).map(async(subTask) => {
|
||||
await context.dispatch('moveTaskToCalendar', { task: subTask, calendar: calendar, removeParent: false })
|
||||
}))
|
||||
|
||||
// If a task has a parent task which is not moved, remove the reference to it.
|
||||
if (removeParent && task.related !== null) {
|
||||
// Remove the task from the parents subtask list
|
||||
context.commit('deleteTaskFromParent', task)
|
||||
// Unlink the related parent task
|
||||
context.commit('setTaskParent', { task: task, related: null })
|
||||
// We have to send an update.
|
||||
await context.dispatch('updateTask', task)
|
||||
}
|
||||
|
||||
await task.dav.move(calendar.dav)
|
||||
.then((response) => {
|
||||
context.commit('deleteTaskFromCalendar', task)
|
||||
// Update the calendar of the task
|
||||
context.commit('setTaskCalendar', { task: task, calendar: calendar })
|
||||
// Remove the task from the calendar, add it to the new one
|
||||
context.commit('addTaskToCalendar', task)
|
||||
task.syncstatus = new TaskStatus('success', 'Task successfully moved to new calendar.')
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
OC.Notification.showTemporary(t('calendars', 'An error occurred'))
|
||||
})
|
||||
}
|
||||
return task
|
||||
}
|
||||
}
|
||||
|
||||
export default { state, getters, mutations, actions }
|
||||
|
|
|
@ -826,7 +826,53 @@ const actions = {
|
|||
context.commit('updateTask', newTask)
|
||||
})
|
||||
.catch((error) => { throw error })
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves a task to the provided calendar
|
||||
*
|
||||
* @param {Object} context The store mutations
|
||||
* @param {Object} data Destructuring object
|
||||
* @param {Task} data.task The task to move
|
||||
* @param {Calendar} data.calendar The calendar to move the task to
|
||||
* @param {Boolean} data.removeParent If the task has a parent, remove the link to the parent
|
||||
* @returns {Task} The moved task
|
||||
*/
|
||||
async moveTaskToCalendar(context, { task, calendar, removeParent = true }) {
|
||||
// Only local move if the task doesn't exist on the server.
|
||||
// Don't move if source and target calendar are the same.
|
||||
if (task.dav && task.calendar !== calendar) {
|
||||
// Move all subtasks first
|
||||
await Promise.all(Object.values(task.subTasks).map(async(subTask) => {
|
||||
await context.dispatch('moveTaskToCalendar', { task: subTask, calendar: calendar, removeParent: false })
|
||||
}))
|
||||
|
||||
// If a task has a parent task which is not moved, remove the reference to it.
|
||||
if (removeParent && task.related !== null) {
|
||||
// Remove the task from the parents subtask list
|
||||
context.commit('deleteTaskFromParent', task)
|
||||
// Unlink the related parent task
|
||||
context.commit('setTaskParent', { task: task, related: null })
|
||||
// We have to send an update.
|
||||
await context.dispatch('updateTask', task)
|
||||
}
|
||||
|
||||
await task.dav.move(calendar.dav)
|
||||
.then((response) => {
|
||||
context.commit('deleteTaskFromCalendar', task)
|
||||
// Update the calendar of the task
|
||||
context.commit('setTaskCalendar', { task: task, calendar: calendar })
|
||||
// Remove the task from the calendar, add it to the new one
|
||||
context.commit('addTaskToCalendar', task)
|
||||
task.syncstatus = new TaskStatus('success', 'Task successfully moved to new calendar.')
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
OC.Notification.showTemporary(t('calendars', 'An error occurred'))
|
||||
})
|
||||
}
|
||||
return task
|
||||
},
|
||||
}
|
||||
|
||||
export default { state, getters, mutations, actions }
|
||||
|
|
Loading…
Reference in a new issue