Move everything to models and services #17
|
@ -204,18 +204,22 @@
|
|||
import router from '../../router'
|
||||
import {HTTP} from '../../http-common'
|
||||
import message from '../../message'
|
||||
import flatPickr from 'vue-flatpickr-component';
|
||||
import 'flatpickr/dist/flatpickr.css';
|
||||
import flatPickr from 'vue-flatpickr-component'
|
||||
import 'flatpickr/dist/flatpickr.css'
|
||||
|
||||
import ListService from '../../services/list';
|
||||
import ListService from '../../services/list'
|
||||
import TaskService from '../../services/task'
|
||||
import TaskModel from '../../models/task'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
listID: this.$route.params.id,
|
||||
listService: ListService,
|
||||
taskService: TaskService,
|
||||
|
||||
list: {},
|
||||
newTask: {text: ''},
|
||||
newTask: TaskModel,
|
||||
error: '',
|
||||
loading: false,
|
||||
isTaskEdit: false,
|
||||
|
@ -246,6 +250,8 @@
|
|||
},
|
||||
created() {
|
||||
this.listService = new ListService()
|
||||
this.taskService = new TaskService()
|
||||
this.newTask = new TaskModel()
|
||||
this.loadList()
|
||||
},
|
||||
watch: {
|
||||
|
@ -265,18 +271,14 @@
|
|||
})
|
||||
},
|
||||
addTask() {
|
||||
const cancel = message.setLoading(this)
|
||||
|
||||
HTTP.put(`lists/` + this.$route.params.id, this.newTask, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
.then(response => {
|
||||
this.addTaskToList(response.data)
|
||||
this.handleSuccess({message: 'The task was successfully created.'})
|
||||
cancel() // cancel the timer
|
||||
})
|
||||
.catch(e => {
|
||||
cancel()
|
||||
this.taskService.create({listID: this.$route.params.id}, this.newTask)
|
||||
.then(r => {
|
||||
this.addTaskToList(r)
|
||||
this.handleSuccess({message: 'The task was successfully created.'})
|
||||
})
|
||||
.catch(e => {
|
||||
this.handleError(e)
|
||||
})
|
||||
})
|
||||
|
||||
this.newTask = {}
|
||||
},
|
||||
|
|
Reference in New Issue
Block a user