Added functions to edit a task
This commit is contained in:
@ -8,31 +8,95 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
<h1>{{ list.title }}</h1>
|
||||
</div>
|
||||
<form @submit.prevent="addTask()">
|
||||
<div class="field is-grouped">
|
||||
<p class="control has-icons-left is-expanded" v-bind:class="{ 'is-loading': loading}">
|
||||
<input class="input" v-bind:class="{ 'disabled': loading}" v-model="newTask" type="text" placeholder="Add a new task...">
|
||||
<span class="icon is-small is-left">
|
||||
<icon icon="tasks"/>
|
||||
</span>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button type="submit" class="button is-success">
|
||||
<span class="icon is-small">
|
||||
<icon icon="plus"/>
|
||||
</span>
|
||||
Add
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form @submit.prevent="addTask()">
|
||||
<div class="field is-grouped">
|
||||
<p class="control has-icons-left is-expanded" v-bind:class="{ 'is-loading': loading}">
|
||||
<input class="input" v-bind:class="{ 'disabled': loading}" v-model="newTask" type="text" placeholder="Add a new task...">
|
||||
<span class="icon is-small is-left">
|
||||
<icon icon="tasks"/>
|
||||
</span>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button type="submit" class="button is-success">
|
||||
<span class="icon is-small">
|
||||
<icon icon="plus"/>
|
||||
</span>
|
||||
Add
|
||||
</button>
|
||||
</p>
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="box tasks" v-if="this.list.tasks && this.list.tasks.length > 0">
|
||||
<div class="task" v-for="l in list.tasks" v-bind:key="l.id">
|
||||
<label v-bind:for="l.id">
|
||||
<input @change="markAsDone" type="checkbox" v-bind:id="l.id" v-bind:checked="l.done">
|
||||
{{l.text}}
|
||||
</label>
|
||||
<div @click="editTask(l.id)" class="icon settings">
|
||||
<icon icon="cog"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column is-4" v-if="isTaskEdit">
|
||||
<div class="card taskedit">
|
||||
<header class="card-header">
|
||||
<p class="card-header-title">
|
||||
Edit Task
|
||||
</p>
|
||||
<a class="card-header-icon" @click="isTaskEdit = false">
|
||||
<span class="icon">
|
||||
<icon icon="angle-right"/>
|
||||
</span>
|
||||
</a>
|
||||
</header>
|
||||
<div class="card-content">
|
||||
<div class="content">
|
||||
<form @submit.prevent="editTaskSubmit()">
|
||||
<div class="field">
|
||||
<label class="label" for="tasktext">Task Text</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" id="tasktext" placeholder="The task text is here..." v-model="taskEditTask.text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="taskdescription">Description</label>
|
||||
<div class="control">
|
||||
<textarea class="textarea" placeholder="The tasks description goes here..." id="taskdescription" v-model="taskEditTask.description"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box tasks" v-if="this.list.tasks && this.list.tasks.length > 0">
|
||||
<label class="task" v-for="l in list.tasks" v-bind:key="l.id" v-bind:for="l.id">
|
||||
<input @change="markAsDone" type="checkbox" v-bind:id="l.id" v-bind:checked="l.done">
|
||||
{{l.text}}
|
||||
</label>
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label" for="taskduedate">Due Date</label>
|
||||
<div class="control">
|
||||
<input type="date" class="input" id="taskduedate" placeholder="The tasks due date is here..." v-model="taskEditTask.dueDate">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label" for="taskreminderdate">Reminder Date</label>
|
||||
<div class="control">
|
||||
<input type="date" class="input" id="taskreminderdate" placeholder="The tasks reminder date is here..." v-model="taskEditTask.reminderDate">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button is-success is-fullwidth">
|
||||
Save
|
||||
</button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -43,15 +107,21 @@
|
||||
import router from '../../router'
|
||||
import {HTTP} from '../../http-common'
|
||||
import message from '../../message'
|
||||
import Datepicker from 'vue-bulma-datepicker'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Datepicker
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
listID: this.$route.params.id,
|
||||
list: {},
|
||||
newTask: '',
|
||||
error: '',
|
||||
loading: false
|
||||
loading: false,
|
||||
isTaskEdit: false,
|
||||
taskEditTask: {},
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
@ -69,6 +139,7 @@
|
||||
},
|
||||
methods: {
|
||||
loadList() {
|
||||
this.isTaskEdit = false
|
||||
this.loading = true
|
||||
|
||||
HTTP.get(`lists/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
@ -104,18 +175,50 @@
|
||||
|
||||
HTTP.post(`tasks/` + e.target.id, {done: e.target.checked}, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
.then(response => {
|
||||
for (const t in this.list.tasks) {
|
||||
if (this.list.tasks[t].id === response.data.id) {
|
||||
this.$set(this.list.tasks, t, response.data)
|
||||
break
|
||||
}
|
||||
}
|
||||
this.updateTaskByID(e.target.id, response.data)
|
||||
this.handleSuccess({message: 'The task was successfully ' + (e.target.checked ? 'un-' :'') + 'marked as done.'})
|
||||
})
|
||||
.catch(e => {
|
||||
this.handleError(e)
|
||||
})
|
||||
},
|
||||
editTask(id) {
|
||||
// Find the slected task and set it to the current object
|
||||
for (const t in this.list.tasks) {
|
||||
if (this.list.tasks[t].id === id) {
|
||||
this.taskEditTask = this.list.tasks[t]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.isTaskEdit = true
|
||||
},
|
||||
editTaskSubmit() {
|
||||
this.loading = true
|
||||
|
||||
// Convert the date in a unix timestamp
|
||||
let duedate = (+ new Date(this.taskEditTask.dueDate)) / 1000
|
||||
let reminderdate = (+ new Date(this.taskEditTask.reminderDate)) / 1000
|
||||
this.taskEditTask.dueDate = duedate
|
||||
this.taskEditTask.reminderDate = reminderdate
|
||||
|
||||
HTTP.post(`tasks/` + this.taskEditTask.id, this.taskEditTask, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
.then(response => {
|
||||
this.updateTaskByID(this.taskEditTask.id, response.data)
|
||||
this.handleSuccess({message: 'The task was successfully updated.'})
|
||||
})
|
||||
.catch(e => {
|
||||
this.handleError(e)
|
||||
})
|
||||
},
|
||||
updateTaskByID(id, updatedTask) {
|
||||
for (const t in this.list.tasks) {
|
||||
if (this.list.tasks[t].id === id) {
|
||||
this.$set(this.list.tasks, t, updatedTask)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
handleError(e) {
|
||||
this.loading = false
|
||||
message.error(e, this)
|
||||
@ -137,15 +240,31 @@
|
||||
display: block;
|
||||
padding: 0.5rem 1rem;
|
||||
border-bottom: 1px solid darken(#fff, 10%);
|
||||
cursor: pointer;
|
||||
|
||||
label{
|
||||
width: 96%;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.settings{
|
||||
float: right;
|
||||
width: 4%;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.task:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.taskedit{
|
||||
min-height: calc(100% - 1rem);
|
||||
margin-top: 1rem;
|
||||
}
|
||||
</style>
|
@ -17,12 +17,16 @@ import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faPlus } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faListOl } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faTasks } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faCog } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faAngleRight } from '@fortawesome/free-solid-svg-icons'
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||
|
||||
library.add(faSignOutAlt)
|
||||
library.add(faPlus)
|
||||
library.add(faListOl)
|
||||
library.add(faTasks)
|
||||
library.add(faCog)
|
||||
library.add(faAngleRight)
|
||||
|
||||
Vue.component('icon', FontAwesomeIcon)
|
||||
|
||||
|
Reference in New Issue
Block a user