Move everything to models and services #17
|
@ -140,11 +140,11 @@
|
|||
<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"/>
|
||||
<input class="input" placeholder="Specify an amount..." v-model="taskEditTask.repeatAfter.amount"/>
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
<div class="select">
|
||||
<select v-model="repeatAfter.type">
|
||||
<select v-model="taskEditTask.repeatAfter.type">
|
||||
<option value="hours">Hours</option>
|
||||
<option value="days">Days</option>
|
||||
<option value="weeks">Weeks</option>
|
||||
|
@ -202,7 +202,6 @@
|
|||
<script>
|
||||
import auth from '../../auth'
|
||||
import router from '../../router'
|
||||
import {HTTP} from '../../http-common'
|
||||
import message from '../../message'
|
||||
import flatPickr from 'vue-flatpickr-component'
|
||||
import 'flatpickr/dist/flatpickr.css'
|
||||
|
@ -229,7 +228,6 @@
|
|||
},
|
||||
lastReminder: 0,
|
||||
nowUnix: new Date(),
|
||||
repeatAfter: {type: 'days', amount: null},
|
||||
flatPickerConfig:{
|
||||
altFormat: 'j M Y H:i',
|
||||
altInput: true,
|
||||
|
@ -309,64 +307,23 @@
|
|||
editTask(id) {
|
||||
// Find the selected task and set it to the current object
|
||||
let theTask = this.list.getTaskByID(id) // Somhow this does not work if we directly assign this to this.taskEditTask
|
||||
this.repeatAfter = theTask.getRepeatAfter()
|
||||
//this.repeatAfter = theTask.getRepeatAfter()
|
||||
this.taskEditTask = theTask
|
||||
this.isTaskEdit = true
|
||||
},
|
||||
editTaskSubmit() {
|
||||
/*const cancel = message.setLoading(this)
|
||||
|
||||
// Convert the date in a unix timestamp
|
||||
this.taskEditTask.dueDate = (+ new Date(this.taskEditTask.dueDate)) / 1000
|
||||
this.taskEditTask.startDate = (+ new Date(this.taskEditTask.startDate)) / 1000
|
||||
this.taskEditTask.endDate = (+ new Date(this.taskEditTask.endDate)) / 1000
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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')}})
|
||||
.then(response => {
|
||||
// Update the task in the list
|
||||
this.taskService.update(this.taskEditTask)
|
||||
.then(r => {
|
||||
// Update the task in the list
|
||||
// FIXME:
|
||||
//this.updateTaskByID(this.taskEditTask.id, response.data)
|
||||
//this.updateTaskByID(this.taskEditTask.id, response.data)
|
||||
|
||||
// Also update the current taskedit object so the ui changes
|
||||
response.data.reminderDates.push(null) // To be able to add a new one
|
||||
this.$set(this, 'taskEditTask', response.data)
|
||||
this.handleSuccess({message: 'The task was successfully updated.'})
|
||||
cancel() // cancel the timers
|
||||
})
|
||||
.catch(e => {
|
||||
cancel()
|
||||
this.$set(this, 'taskEditTask', r)
|
||||
this.handleSuccess({message: 'The task was successfully updated.'})
|
||||
})
|
||||
.catch(e => {
|
||||
this.handleError(e)
|
||||
})*/
|
||||
})
|
||||
},
|
||||
addSubtask() {
|
||||
this.newTask.parentTaskID = this.taskEditTask.id
|
||||
|
|
|
@ -82,4 +82,8 @@ export default class ListModel extends AbstractModel {
|
|||
}
|
||||
return {} // FIXME: This should probably throw something to make it clear to the user noting was found
|
||||
}
|
||||
|
||||
updateTaskByID(task, id) {
|
||||
|
||||
}
|
||||
}
|
|
@ -14,6 +14,9 @@ export default class TaskModel extends AbstractModel {
|
|||
return this.parseDateIfNessecary(d)
|
||||
})
|
||||
this.reminderDates.push(null) // To trigger the datepicker
|
||||
|
||||
// Parse the repeat after into something usable
|
||||
this.parseRepeatAfter()
|
||||
}
|
||||
|
||||
defaults() {
|
||||
|
@ -39,7 +42,6 @@ export default class TaskModel extends AbstractModel {
|
|||
updated: 0,
|
||||
|
||||
listID: 0, // Meta, only used when creating a new task
|
||||
repeatAfterObj: {type: '', amount: 0}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,31 +63,29 @@ export default class TaskModel extends AbstractModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an object which contains the amount and its type of amount to be used in a form.
|
||||
* @return {{amount: number, type: string}}
|
||||
* Parses the "repeat after x seconds" from the task into a usable js object inside the task.
|
||||
* This function should only be called from the constructor.
|
||||
*/
|
||||
getRepeatAfter() {
|
||||
// TODO: make sure this is used properly -> Not having repeatAfterObj saved elesewhere
|
||||
parseRepeatAfter() {
|
||||
let repeatAfterHours = (this.repeatAfter / 60) / 60
|
||||
this.repeatAfterObj = {type: 'hours', amount: repeatAfterHours}
|
||||
this.repeatAfter = {type: 'hours', amount: repeatAfterHours}
|
||||
|
||||
// if its dividable by 24, its something with days, otherwise hours
|
||||
if (repeatAfterHours % 24 === 0) {
|
||||
let repeatAfterDays = repeatAfterHours / 24
|
||||
if (repeatAfterDays % 7 === 0) {
|
||||
this.repeatAfterObj.type = 'weeks'
|
||||
this.repeatAfterObj.amount = repeatAfterDays / 7
|
||||
this.repeatAfter.type = 'weeks'
|
||||
this.repeatAfter.amount = repeatAfterDays / 7
|
||||
} else if (repeatAfterDays % 30 === 0) {
|
||||
this.repeatAfterObj.type = 'months'
|
||||
this.repeatAfterObj.amount = repeatAfterDays / 30
|
||||
this.repeatAfter.type = 'months'
|
||||
this.repeatAfter.amount = repeatAfterDays / 30
|
||||
} else if (repeatAfterDays % 365 === 0) {
|
||||
this.repeatAfterObj.type = 'years'
|
||||
this.repeatAfterObj.amount = repeatAfterDays / 365
|
||||
this.repeatAfter.type = 'years'
|
||||
this.repeatAfter.amount = repeatAfterDays / 365
|
||||
} else {
|
||||
this.repeatAfterObj.type = 'days'
|
||||
this.repeatAfterObj.amount = repeatAfterDays
|
||||
this.repeatAfter.type = 'days'
|
||||
this.repeatAfter.amount = repeatAfterDays
|
||||
}
|
||||
}
|
||||
return this.repeatAfterObj
|
||||
}
|
||||
}
|
|
@ -21,10 +21,14 @@ export default class TaskService extends AbstractService {
|
|||
model.startDate = (+ new Date(model.startDate)) / 1000
|
||||
model.endDate = (+ new Date(model.endDate)) / 1000
|
||||
|
||||
// remove all nulls
|
||||
// TODO: check if we still need this
|
||||
//this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
|
||||
// Make normal timestamps from js timestamps
|
||||
// remove all nulls, these would create empty reminders
|
||||
for (const index in model.reminderDates) {
|
||||
if (model.reminderDates[index] === null) {
|
||||
model.reminderDates.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
// Make normal timestamps from js dates
|
||||
model.reminderDates = model.reminderDates.map(r => {
|
||||
return Math.round(r / 1000)
|
||||
})
|
||||
|
@ -32,22 +36,22 @@ export default class TaskService extends AbstractService {
|
|||
// Make the repeating amount to seconds
|
||||
let repeatAfterSeconds = 0
|
||||
if (model.repeatAfter.amount !== null || model.repeatAfter.amount !== 0) {
|
||||
switch (this.repeatAfter.type) {
|
||||
switch (model.repeatAfter.type) {
|
||||
case 'hours':
|
||||
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60
|
||||
break;
|
||||
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60
|
||||
break
|
||||
case 'days':
|
||||
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24
|
||||
break;
|
||||
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24
|
||||
break
|
||||
case 'weeks':
|
||||
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 7
|
||||
break;
|
||||
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 7
|
||||
break
|
||||
case 'months':
|
||||
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 30
|
||||
break;
|
||||
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 30
|
||||
break
|
||||
case 'years':
|
||||
repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 365
|
||||
break;
|
||||
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 365
|
||||
break
|
||||
}
|
||||
}
|
||||
model.repeatAfter = repeatAfterSeconds
|
||||
|
|
Reference in New Issue
Block a user