front toDos almost position, checked, delete
This commit is contained in:
@@ -59,6 +59,18 @@ class ToDoController extends Controller
|
|||||||
->setStatusCode(200);
|
->setStatusCode(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkedToogle(ToDoList $toDoList, ToDo $toDo)
|
||||||
|
{
|
||||||
|
$this->authorize('update', $toDoList);
|
||||||
|
|
||||||
|
($toDo->checked_at) ? $toDo->checked_at = NULL : $toDo->checked_at = now();
|
||||||
|
$toDo->save();
|
||||||
|
|
||||||
|
return (new ToDoResource($toDo))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
private function validateData()
|
private function validateData()
|
||||||
{
|
{
|
||||||
return request()->validate([
|
return request()->validate([
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class ToDo extends JsonResource
|
|||||||
'data' => [
|
'data' => [
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'order' => (int) $this->order,
|
'order' => (int) $this->order,
|
||||||
'checked_at' => optional($this->checked_at)->diffForHumans(),
|
'checked_at' => ($this->checked_at) ? 1 : null,
|
||||||
'last_updated' => $this->updated_at->diffForHumans(),
|
'last_updated' => $this->updated_at->diffForHumans(),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
<template>
|
|
||||||
<li class="todo flex justify-between items-center bg-white rounded mb-1 px-2 py-1"
|
|
||||||
>
|
|
||||||
<div class="flex flex-1">
|
|
||||||
<svg-vue icon="draggable" class="w-4 block mr-2 cursor-move" />
|
|
||||||
{{ toDo.data.attributes.data.name }}
|
|
||||||
</div>
|
|
||||||
<div class="flex">
|
|
||||||
<svg-vue icon="edit" @click="edit = !edit" class="edit-icon z-10 w-4 block cursor-pointer mr-1" />
|
|
||||||
<input type="checkbox" v-model="checked">
|
|
||||||
<span v-if="edit" @click="deleteToDo(toDo, position)">X</span>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'ToDo',
|
|
||||||
data: function () {
|
|
||||||
return {
|
|
||||||
name: this.toDo.data.attributes.data.name,
|
|
||||||
errors: null,
|
|
||||||
edit: false,
|
|
||||||
checked: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
toDo: {
|
|
||||||
type: Object,
|
|
||||||
require: true
|
|
||||||
},
|
|
||||||
position: {
|
|
||||||
type: Number,
|
|
||||||
require: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
console.log(this.$key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.edit-icon {
|
|
||||||
opacity: 0;
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.todo:hover .edit-icon {
|
|
||||||
opacity: 1;
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
<div class="m-2 px-2 pt-2 bg-orange-400 rounded flex flex-col justify-between shadow">
|
|
||||||
<div>
|
|
||||||
<h1 class="text-2xl font-bold mb-2">{{ toDoList.data.attributes.data.name }}</h1>
|
|
||||||
<ul class="draggable-list drop-zone"
|
|
||||||
@drop='onDrop($event, toDoList)'
|
|
||||||
@dragover.prevent
|
|
||||||
@dragenter.prevent
|
|
||||||
>
|
|
||||||
<div v-if="toDoList.data.attributes.data.to_dos.to_dos_count < 1">
|
|
||||||
------- no to Do -------
|
|
||||||
</div>
|
|
||||||
<ToDo v-else
|
|
||||||
v-for="(toDo, indexToDo) in toDoList.data.attributes.data.to_dos.data"
|
|
||||||
:key="indexToDo"
|
|
||||||
:toDo="toDo"
|
|
||||||
:position="indexToDo"
|
|
||||||
draggable
|
|
||||||
@dragstart='startDrag($event, toDo)'
|
|
||||||
class='drag-el'
|
|
||||||
/>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center mt-2">
|
|
||||||
<InputField name="name" classes="py-1" placeholder="New To Do" required @update:field="name = $event" :errors="errors" />
|
|
||||||
<button class="btn-primary ml-1 mb-2 py-1" @click="addToDo">ADD</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import InputField from '../../components/InputField'
|
|
||||||
import ToDo from './ToDo'
|
|
||||||
//https://learnvue.co/2020/01/how-to-add-drag-and-drop-to-your-vuejs-project/
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'ToDoList',
|
|
||||||
components: {
|
|
||||||
InputField, ToDo
|
|
||||||
},
|
|
||||||
data: function () {
|
|
||||||
return {
|
|
||||||
name: '',
|
|
||||||
errors: null,
|
|
||||||
dragStartIndex: null,
|
|
||||||
edit: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
toDoList: {
|
|
||||||
type: Object,
|
|
||||||
require: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
addToDo: function () {
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
axios.post('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do', {name: this.name})
|
|
||||||
.then(res => {
|
|
||||||
this.toDoList.data.attributes.data.to_dos.data.push(res.data)
|
|
||||||
this.name = ''
|
|
||||||
})
|
|
||||||
.catch(errorRes => {
|
|
||||||
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
deleteToDo: function (toDo, position) {
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
axios.delete('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do/' + toDo.data.to_do_id)
|
|
||||||
.then(() => {
|
|
||||||
this.toDoList.data.attributes.data.to_dos.data.splice(position, 1)
|
|
||||||
})
|
|
||||||
.catch(errorRes => {
|
|
||||||
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
startDrag: (evt, item) => {
|
|
||||||
console.log('StartDrag', evt, item)
|
|
||||||
evt.dataTransfer.dropEffect = 'move'
|
|
||||||
evt.dataTransfer.effectAllowed = 'move'
|
|
||||||
evt.dataTransfer.setData('itemID', item.id)
|
|
||||||
},
|
|
||||||
onDrop (evt, list) {
|
|
||||||
console.log('onDrop', evt, list, this.toDoList)
|
|
||||||
const itemID = evt.dataTransfer.getData('itemID')
|
|
||||||
const item = this.toDoList.data.attributes.data.to_dos.data.find(item => item.id == itemID)
|
|
||||||
item.list = list
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,11 +17,14 @@
|
|||||||
<Loader v-if="loading" />
|
<Loader v-if="loading" />
|
||||||
<div v-else class="flex flex-wrap -m-2 mt-2">
|
<div v-else class="flex flex-wrap -m-2 mt-2">
|
||||||
<div v-if="toDoLists.length < 1">No List Yet</div>
|
<div v-if="toDoLists.length < 1">No List Yet</div>
|
||||||
<ToDoList v-else
|
<router-link v-else
|
||||||
v-for="(toDoList, index) in toDoLists"
|
v-for="(toDoList, index) in toDoLists"
|
||||||
:key="index"
|
:key="index"
|
||||||
:to-do-list="toDoList"
|
:to="'/to-do-lists/' + toDoList.data.to_do_list_id"
|
||||||
class="w-full sm:w-1/2 md:w-1/3 lg:w-1/4" />
|
:to-do-list="toDoList"
|
||||||
|
class="w-full sm:w-1/2 md:w-1/3 lg:w-1/4" >
|
||||||
|
{{ toDoList.data.attributes.data.name }}
|
||||||
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -29,12 +32,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import Loader from '../../components/Loader'
|
import Loader from '../../components/Loader'
|
||||||
import InputField from '../../components/InputField'
|
import InputField from '../../components/InputField'
|
||||||
import ToDoList from './ToDoList'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ToDoListIndex',
|
name: 'ToDoListIndex',
|
||||||
components: {
|
components: {
|
||||||
Loader, InputField, ToDoList
|
Loader, InputField
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,9 +1,145 @@
|
|||||||
<template>
|
<template>
|
||||||
<div></div>
|
<div class="p-4">
|
||||||
|
<div v-if="!loading" class="bg-orange-400 rounded p-1">
|
||||||
|
<h1 class="text-2xl font-bold mb-2 ml-2">{{ toDoList.data.attributes.data.name }}</h1>
|
||||||
|
<ul class='p-1'
|
||||||
|
v-for="(toDo, index) in toDoList.data.attributes.data.to_dos.data"
|
||||||
|
:key="index"
|
||||||
|
@drop='onDrop($event, toDo)'
|
||||||
|
@dragover.prevent
|
||||||
|
@dragenter.prevent >
|
||||||
|
<li
|
||||||
|
draggable
|
||||||
|
@dragstart='startDrag($event, toDo)'
|
||||||
|
class='drag-el todo flex justify-between items-center bg-white rounded-sm mb-1 px-2 py-1' >
|
||||||
|
<div class="flex flex-1">
|
||||||
|
<svg-vue icon="draggable" class="w-4 block mr-2 cursor-move" />
|
||||||
|
<span v-bind:class="{ 'line-through' : toDo.data.attributes.data.checked_at }">{{ toDo.data.attributes.data.name }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<svg-vue icon="edit" @click="edit = !edit" class="edit-icon z-10 w-4 block cursor-pointer mr-1" />
|
||||||
|
<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">X</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<div class="flex items-center mt-2 ml-2">
|
||||||
|
<InputField name="name" classes="py-1" placeholder="New To Do" required @update:field="name = $event" :errors="errors" @keyup.enter="addToDo" />
|
||||||
|
<button class="btn-primary ml-1 mb-2 py-1" @click="addToDo">ADD</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import InputField from '../../components/InputField'
|
||||||
|
//https://learnvue.co/2020/01/how-to-add-drag-and-drop-to-your-vuejs-project/
|
||||||
|
//https://jsfiddle.net/jf9nrtds/
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ToDoListShow'
|
name: 'ToDoListShow',
|
||||||
|
components: {
|
||||||
|
InputField
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
toDoList: null,
|
||||||
|
loading: true,
|
||||||
|
name: '',
|
||||||
|
errors: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
axios.get('/api/to-do-lists/' + this.$route.params.id)
|
||||||
|
.then(res => {
|
||||||
|
this.toDoList = res.data
|
||||||
|
this.loading = false
|
||||||
|
|
||||||
|
this.reorderList()
|
||||||
|
})
|
||||||
|
.catch(errorRes => {
|
||||||
|
this.loading = false
|
||||||
|
if (errorRes.response.status === 404) {
|
||||||
|
this.$router.push('/')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
startDrag: (evt, item) => {
|
||||||
|
evt.dataTransfer.dropEffect = 'move'
|
||||||
|
evt.dataTransfer.effectAllowed = 'move'
|
||||||
|
evt.dataTransfer.setData('toDoID', item.data.to_do_id)
|
||||||
|
evt.dataTransfer.setData('toDoOrder', item.data.attributes.data.order)
|
||||||
|
},
|
||||||
|
onDrop (evt, toDoEnd) {
|
||||||
|
const toDoID = parseInt(evt.dataTransfer.getData('toDoID'), 10)
|
||||||
|
const toDoOrder = parseInt(evt.dataTransfer.getData('toDoOrder'), 10)
|
||||||
|
let toDoMove = this.toDoList.data.attributes.data.to_dos.data.find(toDo => toDo.data.to_do_id === toDoID)
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
axios.patch('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do/' + toDoMove.data.to_do_id + '/change', { 'new-order': toDoEnd.data.attributes.data.order })
|
||||||
|
.then(() => {
|
||||||
|
toDoMove.data.attributes.data.order = toDoEnd.data.attributes.data.order
|
||||||
|
toDoEnd.data.attributes.data.order = toDoOrder
|
||||||
|
this.reorderList()
|
||||||
|
})
|
||||||
|
.catch(errorRes => {
|
||||||
|
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
reorderList() {
|
||||||
|
this.toDoList.data.attributes.data.to_dos.data.sort(function(a, b) {
|
||||||
|
return a.data.attributes.data.order - b.data.attributes.data.order
|
||||||
|
})
|
||||||
|
},
|
||||||
|
addToDo: function () {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
axios.post('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do', {name: this.name})
|
||||||
|
.then(res => {
|
||||||
|
this.toDoList.data.attributes.data.to_dos.data.push(res.data)
|
||||||
|
this.name = ''
|
||||||
|
})
|
||||||
|
.catch(errorRes => {
|
||||||
|
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
deleteToDo: function (toDo, position) {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
axios.delete('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do/' + toDo.data.to_do_id)
|
||||||
|
.then(() => {
|
||||||
|
this.toDoList.data.attributes.data.to_dos.data.splice(position, 1)
|
||||||
|
})
|
||||||
|
.catch(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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
.edit-icon {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo:hover .edit-icon {
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -32,5 +32,6 @@ Route::middleware('auth:api')->group(function () {
|
|||||||
Route::post('/images/users/{users}', 'ImageController@users');
|
Route::post('/images/users/{users}', 'ImageController@users');
|
||||||
Route::post('/images/memos/{memo}', 'ImageController@memos');
|
Route::post('/images/memos/{memo}', 'ImageController@memos');
|
||||||
Route::patch('/to-do-lists/{toDoList}/to-do/{toDo}/change', 'ToDoController@changeOrder');
|
Route::patch('/to-do-lists/{toDoList}/to-do/{toDo}/change', 'ToDoController@changeOrder');
|
||||||
|
Route::patch('/to-do-lists/{toDoList}/to-do/{toDo}/check', 'ToDoController@checkedToogle');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user