Repeating tasks (#7)

This commit is contained in:
konrad 2018-11-26 21:31:05 +00:00 committed by Gitea
parent fe1b5a1af8
commit 12f58bc1c6

View file

@ -107,6 +107,26 @@
</div> </div>
</div> </div>
<div class="field">
<label class="label" for="">Repeat after</label>
<div class="control repeat-after-input columns">
<div class="column">
<input class="input" placeholder="Specify an amount..." v-model="repeatAfter.amount"/>
</div>
<div class="column">
<div class="select">
<select v-model="repeatAfter.type">
<option value="hours">Hours</option>
<option value="days">Days</option>
<option value="weeks">Weeks</option>
<option value="months">Months</option>
<option value="years">Years</option>
</select>
</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
</button> </button>
@ -140,6 +160,7 @@
taskEditTask: {}, taskEditTask: {},
lastReminder: 0, lastReminder: 0,
nowUnix: new Date(), nowUnix: new Date(),
repeatAfter: {type: 'days', amount: null},
flatPickerConfig:{ flatPickerConfig:{
altFormat: 'j M Y H:i', altFormat: 'j M Y H:i',
altInput: true, altInput: true,
@ -241,6 +262,29 @@
this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates) this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
this.taskEditTask.reminderDates.push(null) this.taskEditTask.reminderDates.push(null)
// Re-convert the the amount from seconds to be used with our form
let repeatAfterHours = (this.taskEditTask.repeatAfter / 60) / 60
// if its dividable by 24, its something with days
if (repeatAfterHours % 24 === 0) {
let repeatAfterDays = repeatAfterHours / 24
if (repeatAfterDays % 7 === 0) {
this.repeatAfter.type = 'weeks'
this.repeatAfter.amount = repeatAfterDays / 7
} else if (repeatAfterDays % 30 === 0) {
this.repeatAfter.type = 'months'
this.repeatAfter.amount = repeatAfterDays / 30
} else if (repeatAfterDays % 365 === 0) {
this.repeatAfter.type = 'years'
this.repeatAfter.amount = repeatAfterDays / 365
} else {
this.repeatAfter.type = 'days'
this.repeatAfter.amount = repeatAfterDays
}
} else {
// otherwise hours
this.repeatAfter.type = 'hours'
this.repeatAfter.amount = repeatAfterHours
}
this.isTaskEdit = true this.isTaskEdit = true
}, },
editTaskSubmit() { editTaskSubmit() {
@ -257,6 +301,29 @@
this.taskEditTask.reminderDates[t] = Math.round(this.taskEditTask.reminderDates[t] / 1000) this.taskEditTask.reminderDates[t] = Math.round(this.taskEditTask.reminderDates[t] / 1000)
} }
// Make the repeating amount to seconds
let repeatAfterSeconds = 0
if (this.repeatAfter.amount !== null || this.repeatAfter.amount !== 0) {
switch (this.repeatAfter.type) {
case 'hours':
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60
break;
case 'days':
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24
break;
case 'weeks':
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 7
break;
case 'months':
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 30
break;
case 'years':
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 365
break;
}
}
this.taskEditTask.repeatAfter = repeatAfterSeconds
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)