Move everything to models and services #17

Merged
konrad merged 82 commits from refactor/models into master 2019-03-02 10:25:10 +00:00
3 changed files with 50 additions and 7 deletions
Showing only changes of commit a2f74c062c - Show all commits

View File

@ -283,14 +283,25 @@
this.newTask = {}
},
markAsDone(e) {
let context = this
if (e.target.checked) {
setTimeout(doTheDone, 300); // Delay it to show the animation when marking a task as done
} else {
doTheDone() // Don't delay it when un-marking it as it doesn't have an animation the other way around
//let context = this
let updateFunc = () => {
this.taskService.update({id: e.target.id}, {done: e.target.checked})
.then(() => {
this.list.sortTasks()
this.handleSuccess({message: 'The task was successfully ' + (e.target.checked ? '' : 'un-') + 'marked as done.'})
})
.catch(e => {
this.handleError(e)
})
}
function doTheDone() {
if (e.target.checked) {
setTimeout(updateFunc(), 300); // Delay it to show the animation when marking a task as done
} else {
updateFunc() // Don't delay it when un-marking it as it doesn't have an animation the other way around
}
/*function doTheDone() {
const cancel = message.setLoading(context)
HTTP.post(`tasks/` + e.target.id, {done: e.target.checked}, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
@ -303,7 +314,7 @@
cancel()
context.handleError(e)
})
}
}*/
},
editTask(id) {
// Find the selected task and set it to the current object

View File

@ -56,4 +56,8 @@ export default class TaskModel extends AbstractModel {
}
return dateobj
}
markAsDone() {
}
}

View File

@ -162,6 +162,12 @@ export default class AbstractService {
})
}
/**
* Performs a put request to the url specified before
* @param pathparams
* @param data
* @returns {Promise<any | never>}
*/
create(pathparams, data) {
const cancel = this.setLoading()
@ -177,4 +183,26 @@ export default class AbstractService {
cancel()
})
}
/**
* Performs a post request to the update url
* @param pathparams
* @param data
* @returns {Q.Promise<any>}
*/
update(pathparams, data) {
const cancel = this.setLoading()
// Finally make the request and get our data.
return this.http.post(this.getReplacedRoute(this.paths.update, pathparams), data)
.catch(error => {
return this.errorHandler(error)
})
.then(response => {
return Promise.resolve(this.modelFactory(response.data))
})
.finally(() => {
cancel()
})
}
}