Move everything to models and services #17
|
@ -308,47 +308,9 @@
|
|||
},
|
||||
editTask(id) {
|
||||
// Find the selected 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
|
||||
}
|
||||
}
|
||||
|
||||
if (this.taskEditTask.reminderDates === null) {
|
||||
this.taskEditTask.reminderDates = []
|
||||
}
|
||||
this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
|
||||
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
|
||||
}
|
||||
|
||||
if(this.taskEditTask.subtasks === null) {
|
||||
this.taskEditTask.subtasks = [];
|
||||
}
|
||||
|
||||
let theTask = this.list.getTaskByID(id) // Somhow this does not work if we directly assign this to this.taskEditTask
|
||||
this.repeatAfter = theTask.getRepeatAfter()
|
||||
this.taskEditTask = theTask
|
||||
this.isTaskEdit = true
|
||||
},
|
||||
editTaskSubmit() {
|
||||
|
|
|
@ -7,7 +7,7 @@ export default class ListModel extends AbstractModel {
|
|||
super(data)
|
||||
|
||||
// Make all tasks to task models
|
||||
this.tasks.map(t => {
|
||||
this.tasks = this.tasks.map(t => {
|
||||
return new TaskModel(t)
|
||||
})
|
||||
this.sortTasks()
|
||||
|
@ -20,7 +20,7 @@ export default class ListModel extends AbstractModel {
|
|||
title: '',
|
||||
description: '',
|
||||
owner: {},
|
||||
tasks: [TaskModel],
|
||||
tasks: [],
|
||||
namespaceID: 0,
|
||||
|
||||
created: 0,
|
||||
|
|
|
@ -9,8 +9,8 @@ export default class TaskModel extends AbstractModel {
|
|||
this.dueDate = this.parseDateIfNessecary(this.dueDate)
|
||||
this.startDate = this.parseDateIfNessecary(this.startDate)
|
||||
this.endDate = this.parseDateIfNessecary(this.endDate)
|
||||
|
||||
this.reminderDates.map(d => {
|
||||
|
||||
this.reminderDates = this.reminderDates.map(d => {
|
||||
return this.parseDateIfNessecary(d)
|
||||
})
|
||||
}
|
||||
|
@ -57,8 +57,32 @@ export default class TaskModel extends AbstractModel {
|
|||
}
|
||||
return dateobj
|
||||
}
|
||||
|
||||
markAsDone() {
|
||||
|
||||
|
||||
/**
|
||||
* Returns an object which contains the amount and its type of amount to be used in a form.
|
||||
* @return {{amount: number, type: string}}
|
||||
*/
|
||||
getRepeatAfter() {
|
||||
let repeatAfterHours = (this.repeatAfter / 60) / 60
|
||||
let 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) {
|
||||
repeatAfter.type = 'weeks'
|
||||
repeatAfter.amount = repeatAfterDays / 7
|
||||
} else if (repeatAfterDays % 30 === 0) {
|
||||
repeatAfter.type = 'months'
|
||||
repeatAfter.amount = repeatAfterDays / 30
|
||||
} else if (repeatAfterDays % 365 === 0) {
|
||||
repeatAfter.type = 'years'
|
||||
repeatAfter.amount = repeatAfterDays / 365
|
||||
} else {
|
||||
repeatAfter.type = 'days'
|
||||
repeatAfter.amount = repeatAfterDays
|
||||
}
|
||||
}
|
||||
return repeatAfter
|
||||
}
|
||||
}
|
|
@ -3,7 +3,9 @@ import {reduce, replace} from 'lodash'
|
|||
|
||||
let config = require('../../public/config.json')
|
||||
|
||||
// TODO: Reject requests if they don't have route set
|
||||
// TODO: Define before{get|create|update} functions to be able to modify the model before sending
|
||||
// it, after send (=recieving) is handled by the constructor.
|
||||
// Needed to handle stuff like making unix timestamps from js dates
|
||||
|
||||
export default class AbstractService {
|
||||
|
||||
|
|
Reference in New Issue
Block a user