refact toDo
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="!edit" class="flex items-center flex-1 todo">
|
<div v-if="!edit" class="flex items-center flex-1 todo">
|
||||||
<span v-bind:class="{ 'line-through' : checked }" class="border border-transparent flex-1 pl-1">{{ name }}</span>
|
<input type="checkbox" :checked="toDo.data.attributes.data.checked_at" @click="checkedIt" class="block mr-1">
|
||||||
|
<span v-bind:class="{ 'line-through' : toDo.data.attributes.data.checked_at }" class="border border-transparent flex-1 pl-1">{{ toDo.data.attributes.data.name }}</span>
|
||||||
<span @click="edit = !edit" >
|
<span @click="edit = !edit" >
|
||||||
<svg-vue icon="edit" class="edit-icon w-4 block cursor-pointer mx-2" />
|
<svg-vue icon="edit" class="edit-icon w-4 block cursor-pointer mx-2" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="flex items-center flex-1">
|
<div v-else class="flex items-center flex-1">
|
||||||
|
<input type="checkbox" :checked="toDo.data.attributes.data.checked_at" @click="checkedIt" class="block mr-1">
|
||||||
<input type="text"
|
<input type="text"
|
||||||
v-model="name"
|
v-model="toDo.data.attributes.data.name"
|
||||||
@keypress.enter="updateToDo"
|
@keypress.enter="updateToDo"
|
||||||
class="flex-1 rounded-sm border border-orange-600 pl-1">
|
class="flex-1 rounded-sm border border-orange-600 pl-1">
|
||||||
<span @click="edit = !edit">
|
<span @click="edit = !edit">
|
||||||
@@ -20,22 +22,14 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'ToDo',
|
name: 'ToDo',
|
||||||
props: {
|
props: {
|
||||||
name: {
|
toDo: {
|
||||||
type: String,
|
type: Object,
|
||||||
required: true
|
required: true,
|
||||||
},
|
|
||||||
checked: {
|
|
||||||
type: Number,
|
|
||||||
default: null,
|
|
||||||
},
|
},
|
||||||
idList: {
|
idList: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
idToDo: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@@ -45,7 +39,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
updateToDo: function () {
|
updateToDo: function () {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.idToDo, {name: this.name })
|
axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.toDo.data.to_do_id, {name: this.toDo.data.attributes.data.name })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.edit = false
|
this.edit = false
|
||||||
//this.toDoList.data.attributes.data.name = this.listName
|
//this.toDoList.data.attributes.data.name = this.listName
|
||||||
@@ -53,7 +47,18 @@ export default {
|
|||||||
.catch(errorRes => {
|
.catch(errorRes => {
|
||||||
console.log('Internal Error, Unable to delete list.' + errorRes)
|
console.log('Internal Error, Unable to delete list.' + errorRes)
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
checkedIt: function () {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.toDo.data.to_do_id + '/check')
|
||||||
|
.then(res => {
|
||||||
|
// this.toDoList.data.attributes.data.to_dos.data[position].data.attributes.data.checked_at = res.data.data.attributes.data.checked_at
|
||||||
|
this.toDo.data.attributes.data.checked_at = res.data.data.attributes.data.checked_at
|
||||||
|
})
|
||||||
|
.catch(errorRes => {
|
||||||
|
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -38,15 +38,14 @@
|
|||||||
draggable
|
draggable
|
||||||
@dragstart='startDrag($event, toDo)'
|
@dragstart='startDrag($event, toDo)'
|
||||||
class='drag-el todo flex justify-between items-center bg-white rounded-sm mb-1 px-2 py-1' >
|
class='drag-el todo flex justify-between items-center bg-white rounded-sm mb-1 px-2 py-1' >
|
||||||
<div class="flex flex-1">
|
<div class="flex items-center flex-1 todo">
|
||||||
<svg-vue icon="draggable" class="w-4 block mr-2 cursor-move" />
|
<svg-vue icon="draggable" class="w-4 block mr-2 cursor-move" />
|
||||||
<ToDo :name="toDo.data.attributes.data.name"
|
<ToDo :to-do="toDo"
|
||||||
:checked="toDo.data.attributes.data.checked_at"
|
|
||||||
:id-list="toDoList.data.to_do_list_id"
|
:id-list="toDoList.data.to_do_list_id"
|
||||||
:id-to-do="toDo.data.to_do_id"
|
|
||||||
class="flex-1 bg-blue" />
|
class="flex-1 bg-blue" />
|
||||||
<input type="checkbox" :checked="toDo.data.attributes.data.checked_at" @click="checked(toDo, index)">
|
<span @click="deleteToDo(toDo, index)" class="cursor-pointer ml-2 font-bold edit-icon">
|
||||||
<span @click="deleteToDo(toDo, index)" class="cursor-pointer ml-2 font-bold">X</span>
|
<svg-vue icon="close" class="w-4" />
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
@@ -149,16 +148,6 @@ export default {
|
|||||||
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
checked: function (toDo, position) {
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
axios.patch('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do/' + toDo.data.to_do_id + '/check')
|
|
||||||
.then(res => {
|
|
||||||
this.toDoList.data.attributes.data.to_dos.data[position].data.attributes.data.checked_at = res.data.data.attributes.data.checked_at
|
|
||||||
})
|
|
||||||
.catch(errorRes => {
|
|
||||||
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
axios.delete('/api/to-do-lists/' + this.$route.params.id)
|
axios.delete('/api/to-do-lists/' + this.$route.params.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user