Move everything to models and services #17
|
@ -207,7 +207,7 @@
|
|||
import flatPickr from 'vue-flatpickr-component';
|
||||
import 'flatpickr/dist/flatpickr.css';
|
||||
|
||||
import {ListService} from '../../services/list';
|
||||
import ListService from '../../services/list';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
|
@ -255,7 +255,6 @@
|
|||
methods: {
|
||||
loadList() {
|
||||
this.isTaskEdit = false
|
||||
//const cancel = message.setLoading(this)
|
||||
|
||||
this.listService.get({id: this.$route.params.id}, {})
|
||||
.then(r => {
|
||||
|
@ -264,28 +263,6 @@
|
|||
.catch(e => {
|
||||
message.error(e, this)
|
||||
})
|
||||
|
||||
/*
|
||||
|
||||
HTTP.get(`lists/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
.then(response => {
|
||||
for (const t in response.data.tasks) {
|
||||
response.data.tasks[t] = this.fixStuffComingFromAPI(response.data.tasks[t])
|
||||
}
|
||||
|
||||
// This adds a new elemednt "list" to our object which contains all lists
|
||||
response.data.tasks = this.sortTasks(response.data.tasks)
|
||||
this.$set(this, 'list', response.data)
|
||||
if (this.list.tasks === null) {
|
||||
this.list.tasks = []
|
||||
}
|
||||
cancel() // cancel the timer
|
||||
})
|
||||
.catch(e => {
|
||||
cancel()
|
||||
this.handleError(e)
|
||||
})
|
||||
*/
|
||||
},
|
||||
addTask() {
|
||||
const cancel = message.setLoading(this)
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
import AbstractModel from './abstractModel'
|
||||
import TaskModel from "./task";
|
||||
|
||||
export default class ListModel extends AbstractModel {
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
|
||||
// Make all tasks to task models
|
||||
this.tasks.map(t => {
|
||||
return new TaskModel(t)
|
||||
})
|
||||
this.sortTasks()
|
||||
|
||||
// TODO: fixStuffComingFromAPI (see ShowList.vue)
|
||||
|
@ -16,7 +22,7 @@ export default class ListModel extends AbstractModel {
|
|||
title: '',
|
||||
description: '',
|
||||
owner: {},
|
||||
tasks: [],
|
||||
tasks: [TaskModel],
|
||||
namespaceID: 0,
|
||||
|
||||
created: 0,
|
||||
|
|
59
src/models/task.js
Normal file
59
src/models/task.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import AbstractModel from './abstractModel';
|
||||
|
||||
export default class TaskModel extends AbstractModel {
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
|
||||
// Make date objects from timestamps
|
||||
this.dueDate = this.parseDateIfNessecary(this.dueDate)
|
||||
this.startDate = this.parseDateIfNessecary(this.startDate)
|
||||
this.endDate = this.parseDateIfNessecary(this.endDate)
|
||||
|
||||
this.reminderDates.map(d => {
|
||||
return this.parseDateIfNessecary(d)
|
||||
})
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
listID: 0,
|
||||
text: '',
|
||||
description: '',
|
||||
done: false,
|
||||
priority: 0,
|
||||
labels: [],
|
||||
assignees: [],
|
||||
|
||||
dueDate: 0,
|
||||
endDate: 0,
|
||||
repeatAfter: 0,
|
||||
reminderDates: [],
|
||||
startDate: 0,
|
||||
subtasks: [],
|
||||
parentTaskID: 0,
|
||||
|
||||
createdBy: {},
|
||||
created: 0,
|
||||
updated: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Helper functions
|
||||
///////////////
|
||||
|
||||
/**
|
||||
* Makes a js date object from a unix timestamp (in seconds).
|
||||
* @param unixTimestamp
|
||||
* @returns {*}
|
||||
*/
|
||||
parseDateIfNessecary(unixTimestamp) {
|
||||
let dateobj = new Date(unixTimestamp * 1000)
|
||||
if (unixTimestamp === 0) {
|
||||
return null
|
||||
}
|
||||
return dateobj
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import AbstractService from './abstractService'
|
||||
import ListModel from '../models/list'
|
||||
|
||||
export class ListService extends AbstractService {
|
||||
export default class ListService extends AbstractService {
|
||||
constructor() {
|
||||
super({
|
||||
create: '/namespaces/{namespaceID}/lists',
|
||||
|
@ -12,8 +12,6 @@ export class ListService extends AbstractService {
|
|||
}
|
||||
|
||||
get = (pathparams, params) => {
|
||||
//return this.getData(params);
|
||||
// You can get the Promise response here to create a Model object
|
||||
return this.getData(pathparams, params).then(
|
||||
response => {
|
||||
return Promise.resolve(new ListModel(response))
|
||||
|
|
24
src/services/task.js
Normal file
24
src/services/task.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
import AbstractService from './abstractService'
|
||||
import TaskModel from '../models/task'
|
||||
|
||||
export class TaskService extends AbstractService {
|
||||
constructor() {
|
||||
super({
|
||||
create: '/lists/{listID}',
|
||||
getAll: '/tasks/all',
|
||||
update: '/tasks/{id}',
|
||||
delete: '/tasks/{id}',
|
||||
});
|
||||
|
||||
// eslint-disable-next-line
|
||||
console.log('called task constructor')
|
||||
}
|
||||
|
||||
get = (pathparams, params) => {
|
||||
return this.getData(pathparams, params).then(
|
||||
response => {
|
||||
return Promise.resolve(new TaskModel(response))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user