Fixed getting tasks (#27)

This commit is contained in:
konrad 2019-03-10 12:59:17 +00:00 committed by Gitea
parent fee5acda01
commit 2631b39678
2 changed files with 14 additions and 34 deletions

View File

@ -2,11 +2,11 @@
<div> <div>
<h3 v-if="showAll">Current tasks</h3> <h3 v-if="showAll">Current tasks</h3>
<h3 v-else>Tasks from {{startDate.toLocaleDateString()}} until {{endDate.toLocaleDateString()}}</h3> <h3 v-else>Tasks from {{startDate.toLocaleDateString()}} until {{endDate.toLocaleDateString()}}</h3>
<template v-if="!loading && (!hasUndoneTasks || !tasks)"> <template v-if="!taskService.loading && (!hasUndoneTasks || !tasks)">
<h3 class="nothing">Nothing to to - Have a nice day!</h3> <h3 class="nothing">Nothing to to - Have a nice day!</h3>
<img src="/images/cool.svg" alt=""/> <img src="/images/cool.svg" alt=""/>
</template> </template>
<div class="spinner" :class="{ 'is-loading': loading}"></div> <div class="spinner" :class="{ 'is-loading': taskService.loading}"></div>
<div class="tasks" v-if="tasks && tasks.length > 0"> <div class="tasks" v-if="tasks && tasks.length > 0">
<div @click="gotoList(l.listID)" class="task" v-for="l in tasks" :key="l.id" v-if="!l.done"> <div @click="gotoList(l.listID)" class="task" v-for="l in tasks" :key="l.id" v-if="!l.done">
<label :for="l.id"> <label :for="l.id">
@ -41,7 +41,6 @@
</template> </template>
<script> <script>
import router from '../../router' import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message' import message from '../../message'
import TaskService from '../../services/task' import TaskService from '../../services/task'
import priorities from '../../models/priorities' import priorities from '../../models/priorities'
@ -50,7 +49,6 @@
name: "ShowTasks", name: "ShowTasks",
data() { data() {
return { return {
loading: true,
tasks: [], tasks: [],
hasUndoneTasks: false, hasUndoneTasks: false,
taskService: TaskService, taskService: TaskService,
@ -68,41 +66,26 @@
}, },
methods: { methods: {
loadPendingTasks() { loadPendingTasks() {
// We can't really make this code work until 0.6 is released which will make this exact thing a lot easier. let params = {'sort': 'duedate'}
// Because the feature we need here (specifying sort order and start/end date via query parameters) is already in master, we'll just wait and use the legacy method until then.
/*
let taskDummy = new TaskModel() // Used to specify options for the request
this.taskService.getAll(taskDummy)
.then(r => {
this.tasks = r
})
.catch(e => {
message.error(e, this)
})*/
const cancel = message.setLoading(this)
let url = `tasks/all/duedate`
if (!this.showAll) { if (!this.showAll) {
url += `/` + Math.round(+ this.startDate / 1000) + `/` + Math.round(+ this.endDate / 1000) params.startdate = Math.round(+ this.startDate / 1000)
params.enddate = Math.round(+ this.endDate / 1000)
} }
HTTP.get(url, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) this.taskService.getAll({}, params)
.then(response => { .then(r => {
// Filter all done tasks if (r.length > 0) {
if (response.data !== null) { for (const index in r) {
for (const index in response.data) { if (r[index].done !== true) {
if (response.data[index].done !== true) {
this.hasUndoneTasks = true this.hasUndoneTasks = true
} }
} }
response.data.sort(this.sortyByDeadline) r.sort(this.sortyByDeadline)
} }
this.$set(this, 'tasks', response.data) this.$set(this, 'tasks', r)
cancel()
}) })
.catch(e => { .catch(e => {
cancel() message.error(e, this)
this.handleError(e)
}) })
}, },
formatUnixDate(dateUnix) { formatUnixDate(dateUnix) {
@ -114,9 +97,6 @@
gotoList(lid) { gotoList(lid) {
router.push({name: 'showList', params: {id: lid}}) router.push({name: 'showList', params: {id: lid}})
}, },
handleError(e) {
message.error(e, this)
}
}, },
} }
</script> </script>

View File

@ -5,7 +5,7 @@ export default class TaskService extends AbstractService {
constructor() { constructor() {
super({ super({
create: '/lists/{listID}', create: '/lists/{listID}',
getAll: '/tasks/all/{sortBy}/{startDate}/{endDate}', getAll: '/tasks/all',
update: '/tasks/{id}', update: '/tasks/{id}',
delete: '/tasks/{id}', delete: '/tasks/{id}',
}); });