Implement deleting a task

This commit is contained in:
Raimund Schlüßler 2018-12-31 14:40:03 +01:00
parent 97cc04ae21
commit 639a6f064c
No known key found for this signature in database
GPG key ID: 036FA7EB1A599178
2 changed files with 47 additions and 7 deletions

View file

@ -264,7 +264,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<div class="footer">
<a v-show="!task.calendar.readOnly"
class="left close-all reactive"
@click="deleteTask(task.uri)"
@click="removeTask"
>
<span class="icon icon-bw icon-trash" />
</a>
@ -479,6 +479,12 @@ export default {
'deleteStartDate',
'toggleAllDay'
]),
removeTask: function() {
this.deleteTask({ task: this.task, dav: true })
this.closeDetails()
},
closeDetails: function() {
if (this.$route.params.calendarId) {
this.$router.push({ path: `/calendars/${this.$route.params.calendarId}` })

View file

@ -192,13 +192,26 @@ const mutations = {
},
/**
* Deletes a task
* Delete a task from the store
*
* @param {Object} state the store data
* @param {string} taskId The task id
* @param {string} task The task to delete
*/
deleteTask(state, taskId) {
console.debug('Delete task with uri ' + taskId)
deleteTask(state, task) {
if (state.tasks[task.key] && task instanceof Task) {
// Remove task from parents subTask list if necessary
if (task.related) {
let tasks = task.calendar.tasks
let parent = Object.values(tasks).find(search => search.uid === task.related)
if (parent) {
let index = parent.subTasks.findIndex(search => search.key === task.key)
parent.subTasks.splice(index, 1)
}
}
// Remove the task from the calendar
Vue.delete(task.calendar.tasks, task.uid)
}
},
/**
@ -326,9 +339,30 @@ const actions = {
}
},
deleteTask(context, taskId) {
context.commit('deleteTask', taskId)
/**
* Delete a task
*
* @param {Object} context the store mutations
* @param {Object} data destructuring object
* @param {Task} data.task the task to delete
* @param {boolean} [data.dav = true] trigger a dav deletion
*/
async deleteTask(context, { task, dav = true }) {
// delete all subtasks first
await Promise.all(task.subTasks.map(async(subTask) => {
await context.dispatch('deleteTask', { task: subTask, dav: true })
}))
// only local delete if the task doesn't exists on the server
if (task.dav && dav) {
await task.dav.delete()
.catch((error) => {
console.debug(error)
OC.Notification.showTemporary(t('tasks', 'Could not delete the task.'))
})
}
context.commit('deleteTask', task)
},
toggleCompleted(context, taskId) {
context.commit('toggleCompleted', taskId)
},