frontend/src/components/Home.vue

94 lines
2.6 KiB
Vue
Raw Normal View History

2018-09-06 17:46:38 +00:00
<template>
2018-09-09 14:22:02 +00:00
<div class="content has-text-centered">
<h2>Hi {{user.infos.username}}!</h2>
<p>Click on a list or namespace on the left to get started.</p>
2018-11-06 14:54:25 +00:00
<p v-if="loading">Loading tasks...</p>
<h3 v-if="tasks && tasks.length > 0">Current tasks</h3>
2018-12-25 15:03:51 +00:00
<div class="tasks" v-if="tasks && tasks.length > 0">
2018-11-06 14:54:25 +00:00
<div @click="gotoList(l.listID)" class="task" v-for="l in tasks" v-bind:key="l.id" v-if="!l.done">
<label v-bind:for="l.id">
2018-11-25 22:20:35 +00:00
<div class="fancycheckbox">
2018-12-25 15:03:51 +00:00
<input type="checkbox" v-bind:id="l.id" v-bind:checked="l.done" style="display: none;" disabled>
2018-11-25 22:20:35 +00:00
<label v-bind:for="l.id" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg>
</label>
</div>
<span class="tasktext">
{{l.text}}
<i v-if="l.dueDate > 0"> - Due on {{formatUnixDate(l.dueDate)}}</i>
</span>
2018-11-06 14:54:25 +00:00
</label>
</div>
</div>
2018-09-06 17:46:38 +00:00
</div>
</template>
<script>
import auth from '../auth'
import router from '../router'
2018-11-06 14:54:25 +00:00
import {HTTP} from '../http-common'
import message from '../message'
2018-09-06 17:46:38 +00:00
export default {
name: "Home",
2018-09-09 14:22:02 +00:00
data() {
2018-09-06 17:46:38 +00:00
return {
2018-11-06 14:54:25 +00:00
user: auth.user,
loading: false,
tasks: []
2018-09-06 17:46:38 +00:00
}
2018-09-09 14:22:02 +00:00
},
2018-09-06 17:46:38 +00:00
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
2018-11-01 21:34:29 +00:00
if (!auth.user.authenticated) {
2018-09-06 17:46:38 +00:00
router.push({name: 'login'})
}
},
2018-11-06 14:54:25 +00:00
created() {
if (auth.user.authenticated) {
this.loadPendingTasks()
}
2018-11-06 14:54:25 +00:00
},
2018-09-06 18:01:03 +00:00
methods: {
2018-09-09 14:22:02 +00:00
logout() {
2018-09-06 18:01:03 +00:00
auth.logout()
2018-11-06 14:54:25 +00:00
},
loadPendingTasks() {
2018-11-27 10:23:50 +00:00
const cancel = message.setLoading(this)
2018-12-02 18:33:17 +00:00
HTTP.get(`tasks/all`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
2018-11-06 14:54:25 +00:00
.then(response => {
this.tasks = response.data
this.tasks.sort(this.sortyByDeadline)
2018-11-27 10:23:50 +00:00
cancel()
2018-11-06 14:54:25 +00:00
this.loading = false
})
.catch(e => {
2018-11-27 10:23:50 +00:00
cancel()
this.loading = false
2018-11-06 14:54:25 +00:00
this.handleError(e)
})
},
formatUnixDate(dateUnix) {
return (new Date(dateUnix * 1000)).toLocaleString()
},
sortyByDeadline(a, b) {
return ((a.dueDate > b.dueDate) ? -1 : ((a.dueDate < b.dueDate) ? 1 : 0));
},
gotoList(lid) {
router.push({name: 'showList', params: {id: lid}})
},
handleError(e) {
message.error(e, this)
}
2018-09-06 18:01:03 +00:00
},
2018-09-06 17:46:38 +00:00
}
</script>
<style scoped>
2018-11-06 14:54:25 +00:00
h3{
text-align: left;
}
2018-09-06 17:46:38 +00:00
</style>