Move task store functions to appropriate file

This commit is contained in:
Raimund Schlüßler 2019-04-30 19:00:46 +02:00
parent 2425f267ca
commit 87699c1f20
No known key found for this signature in database
GPG key ID: 036FA7EB1A599178
2 changed files with 47 additions and 48 deletions

View file

@ -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 }

View file

@ -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 }