Multiple Reminders (#5)
This commit is contained in:
parent
e5eeaf0ea3
commit
409aff07a7
4 changed files with 134 additions and 42 deletions
|
@ -67,8 +67,21 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="columns">
|
<b>Reminder Dates</b>
|
||||||
<div class="column">
|
<div class="reminder-input" v-for="(r, index) in taskEditTask.reminderDates" v-bind:key="index">
|
||||||
|
<flat-pickr
|
||||||
|
:class="{ 'disabled': loading}"
|
||||||
|
:disabled="loading"
|
||||||
|
:v-model="taskEditTask.reminderDates"
|
||||||
|
:config="flatPickerConfig"
|
||||||
|
:id="'taskreminderdate' + index"
|
||||||
|
:value="r"
|
||||||
|
:data-index="index"
|
||||||
|
placeholder="Add a new reminder...">
|
||||||
|
</flat-pickr>
|
||||||
|
<a v-if="index !== (taskEditTask.reminderDates.length - 1)" @click="removeReminderByIndex(index)"><icon icon="times"></icon></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="taskduedate">Due Date</label>
|
<label class="label" for="taskduedate">Due Date</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
@ -83,24 +96,6 @@
|
||||||
</flat-pickr>
|
</flat-pickr>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="column">
|
|
||||||
<div class="field">
|
|
||||||
<label class="label" for="taskreminderdate">Reminder Date</label>
|
|
||||||
<div class="control">
|
|
||||||
<flat-pickr
|
|
||||||
:class="{ 'disabled': loading}"
|
|
||||||
class="input"
|
|
||||||
:disabled="loading"
|
|
||||||
v-model="taskEditTask.reminderDate"
|
|
||||||
:config="flatPickerConfig"
|
|
||||||
id="taskreminderdate"
|
|
||||||
placeholder="The tasks reminder date is here...">
|
|
||||||
</flat-pickr>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="button is-success is-fullwidth" :class="{ 'is-loading': loading}">
|
<button type="submit" class="button is-success is-fullwidth" :class="{ 'is-loading': loading}">
|
||||||
Save
|
Save
|
||||||
|
@ -133,12 +128,14 @@
|
||||||
loading: false,
|
loading: false,
|
||||||
isTaskEdit: false,
|
isTaskEdit: false,
|
||||||
taskEditTask: {},
|
taskEditTask: {},
|
||||||
|
lastReminder: 0,
|
||||||
flatPickerConfig:{
|
flatPickerConfig:{
|
||||||
altFormat: 'j M Y H:i',
|
altFormat: 'j M Y H:i',
|
||||||
altInput: true,
|
altInput: true,
|
||||||
dateFormat: 'Y-m-d H:i',
|
dateFormat: 'Y-m-d H:i',
|
||||||
enableTime: true,
|
enableTime: true,
|
||||||
defaultDate: new Date(),
|
onOpen: this.updateLastReminderDate,
|
||||||
|
onClose: this.addReminderDate,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -170,9 +167,15 @@
|
||||||
// Make date objects from timestamps
|
// Make date objects from timestamps
|
||||||
for (const t in response.data.tasks) {
|
for (const t in response.data.tasks) {
|
||||||
let dueDate = new Date(response.data.tasks[t].dueDate * 1000)
|
let dueDate = new Date(response.data.tasks[t].dueDate * 1000)
|
||||||
let reminderDate = new Date(response.data.tasks[t].reminderDate * 1000)
|
if (dueDate === 0) {
|
||||||
|
response.data.tasks[t].dueDate = null
|
||||||
|
} else {
|
||||||
response.data.tasks[t].dueDate = dueDate
|
response.data.tasks[t].dueDate = dueDate
|
||||||
response.data.tasks[t].reminderDate = reminderDate
|
}
|
||||||
|
|
||||||
|
for (const rd in response.data.tasks[t].reminderDates) {
|
||||||
|
response.data.tasks[t].reminderDates[rd] = new Date(response.data.tasks[t].reminderDates[rd] * 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This adds a new elemednt "list" to our object which contains all lists
|
// This adds a new elemednt "list" to our object which contains all lists
|
||||||
|
@ -213,7 +216,7 @@
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
editTask(id) {
|
editTask(id) {
|
||||||
// Find the slected task and set it to the current object
|
// Find the selected task and set it to the current object
|
||||||
for (const t in this.list.tasks) {
|
for (const t in this.list.tasks) {
|
||||||
if (this.list.tasks[t].id === id) {
|
if (this.list.tasks[t].id === id) {
|
||||||
this.taskEditTask = this.list.tasks[t]
|
this.taskEditTask = this.list.tasks[t]
|
||||||
|
@ -221,6 +224,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.taskEditTask.reminderDates === null) {
|
||||||
|
this.taskEditTask.reminderDates = []
|
||||||
|
}
|
||||||
|
this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
|
||||||
|
this.taskEditTask.reminderDates.push(null)
|
||||||
|
|
||||||
this.isTaskEdit = true
|
this.isTaskEdit = true
|
||||||
},
|
},
|
||||||
editTaskSubmit() {
|
editTaskSubmit() {
|
||||||
|
@ -228,16 +237,23 @@
|
||||||
|
|
||||||
// Convert the date in a unix timestamp
|
// Convert the date in a unix timestamp
|
||||||
let duedate = (+ new Date(this.taskEditTask.dueDate)) / 1000
|
let duedate = (+ new Date(this.taskEditTask.dueDate)) / 1000
|
||||||
let reminderdate = (+ new Date(this.taskEditTask.reminderDate)) / 1000
|
|
||||||
this.taskEditTask.dueDate = duedate
|
this.taskEditTask.dueDate = duedate
|
||||||
this.taskEditTask.reminderDate = reminderdate
|
|
||||||
|
// remove all nulls
|
||||||
|
this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
|
||||||
|
// Make normal timestamps from js timestamps
|
||||||
|
for (const t in this.taskEditTask.reminderDates) {
|
||||||
|
this.taskEditTask.reminderDates[t] = Math.round(this.taskEditTask.reminderDates[t] / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
HTTP.post(`tasks/` + this.taskEditTask.id, this.taskEditTask, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
HTTP.post(`tasks/` + this.taskEditTask.id, this.taskEditTask, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
response.data.dueDate = new Date(response.data.dueDate * 1000)
|
response.data.dueDate = new Date(response.data.dueDate * 1000)
|
||||||
response.data.reminderDate = new Date(response.data.reminderDate * 1000)
|
response.data.reminderDates = this.makeJSReminderDatesAfterUpdate(response.data.reminderDates)
|
||||||
|
|
||||||
// Update the task in the list
|
// Update the task in the list
|
||||||
this.updateTaskByID(this.taskEditTask.id, response.data)
|
this.updateTaskByID(this.taskEditTask.id, response.data)
|
||||||
|
|
||||||
// Also update the current taskedit object so the ui changes
|
// Also update the current taskedit object so the ui changes
|
||||||
this.$set(this, 'taskEditTask', response.data)
|
this.$set(this, 'taskEditTask', response.data)
|
||||||
this.handleSuccess({message: 'The task was successfully updated.'})
|
this.handleSuccess({message: 'The task was successfully updated.'})
|
||||||
|
@ -249,11 +265,57 @@
|
||||||
updateTaskByID(id, updatedTask) {
|
updateTaskByID(id, updatedTask) {
|
||||||
for (const t in this.list.tasks) {
|
for (const t in this.list.tasks) {
|
||||||
if (this.list.tasks[t].id === id) {
|
if (this.list.tasks[t].id === id) {
|
||||||
|
//updatedTask.reminderDates = this.makeJSReminderDatesAfterUpdate(updatedTask.reminderDates)
|
||||||
this.$set(this.list.tasks, t, updatedTask)
|
this.$set(this.list.tasks, t, updatedTask)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
updateLastReminderDate(selectedDates) {
|
||||||
|
this.lastReminder = +new Date(selectedDates[0])
|
||||||
|
},
|
||||||
|
addReminderDate(selectedDates, dateStr, instance) {
|
||||||
|
let newDate = +new Date(selectedDates[0])
|
||||||
|
|
||||||
|
// Don't update if nothing changed
|
||||||
|
if (newDate === this.lastReminder) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let index = parseInt(instance.input.dataset.index)
|
||||||
|
this.taskEditTask.reminderDates[index] = newDate
|
||||||
|
|
||||||
|
let lastIndex = this.taskEditTask.reminderDates.length - 1
|
||||||
|
// put a new null at the end if we changed something
|
||||||
|
if (lastIndex === index && !isNaN(newDate)) {
|
||||||
|
this.taskEditTask.reminderDates.push(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeReminderByIndex(index) {
|
||||||
|
this.taskEditTask.reminderDates.splice(index, 1)
|
||||||
|
// Reset the last to 0 to have the "add reminder" button
|
||||||
|
this.taskEditTask.reminderDates[this.taskEditTask.reminderDates.length - 1] = null
|
||||||
|
},
|
||||||
|
removeNullsFromArray(array) {
|
||||||
|
for (const index in array) {
|
||||||
|
if (array[index] === null) {
|
||||||
|
array.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array
|
||||||
|
},
|
||||||
|
makeJSReminderDatesAfterUpdate(dates) {
|
||||||
|
// Make js timestamps from normal timestamps
|
||||||
|
for (const rd in dates) {
|
||||||
|
dates[rd] = +new Date(dates[rd] * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dates == null) {
|
||||||
|
dates = []
|
||||||
|
}
|
||||||
|
dates.push(null)
|
||||||
|
return dates
|
||||||
|
},
|
||||||
handleError(e) {
|
handleError(e) {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
message.error(e, this)
|
message.error(e, this)
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { faUsers } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faLock } from '@fortawesome/free-solid-svg-icons'
|
import { faLock } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faPen } from '@fortawesome/free-solid-svg-icons'
|
import { faPen } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { faTimes } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||||
|
|
||||||
library.add(faSignOutAlt)
|
library.add(faSignOutAlt)
|
||||||
|
@ -43,6 +44,7 @@ library.add(faUsers)
|
||||||
library.add(faUser)
|
library.add(faUser)
|
||||||
library.add(faLock)
|
library.add(faLock)
|
||||||
library.add(faPen)
|
library.add(faPen)
|
||||||
|
library.add(faTimes)
|
||||||
|
|
||||||
Vue.component('icon', FontAwesomeIcon)
|
Vue.component('icon', FontAwesomeIcon)
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,29 @@ h1,h2,h3,h4,h5,h6{
|
||||||
.taskedit{
|
.taskedit{
|
||||||
min-height: calc(100% - 1rem);
|
min-height: calc(100% - 1rem);
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
|
|
||||||
|
.reminder-input{
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: $red;
|
||||||
|
vertical-align: sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 90%;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings{
|
.settings{
|
||||||
|
|
5
vue.config.js
Normal file
5
vue.config.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
configureWebpack: {
|
||||||
|
devtool: 'source-map'
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue