vikunja-frontend/src/components/lists/ShowList.vue

77 lines
2.4 KiB
Vue
Raw Normal View History

2018-09-08 23:33:23 +02:00
<template>
<div class="loader-container" :class="{ 'is-loading': listService.loading}">
2018-09-08 23:33:23 +02:00
<div class="content">
<router-link :to="{ name: 'editList', params: { id: list.id } }" class="icon settings is-medium">
<icon icon="cog" size="2x"/>
</router-link>
2018-09-08 23:33:23 +02:00
<h1>{{ list.title }}</h1>
2019-04-29 23:41:39 +02:00
<div class="switch-view">
<router-link :to="{ name: 'showList', params: { id: list.id } }" :class="{'is-active': $route.params.type !== 'gantt'}">List</router-link>
<router-link :to="{ name: 'showListWithType', params: { id: list.id, type: 'gantt' } }" :class="{'is-active': $route.params.type === 'gantt'}">Gantt</router-link>
</div>
2018-09-08 23:33:23 +02:00
</div>
2019-04-29 23:41:39 +02:00
<gantt :list="list" v-if="$route.params.type === 'gantt'"/>
<show-list-task :the-list="list" v-else/>
2018-09-08 23:33:23 +02:00
</div>
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
2019-04-29 23:41:39 +02:00
import ShowListTask from '../tasks/ShowListTasks'
import Gantt from '../tasks/Gantt'
import ListModel from '../../models/list'
2019-04-29 23:41:39 +02:00
import ListService from '../../services/list'
2019-09-09 20:36:30 +02:00
import authType from '../../models/authTypes'
export default {
data() {
return {
listID: this.$route.params.id,
listService: ListService,
2019-04-29 23:41:39 +02:00
list: ListModel,
}
},
components: {
2019-04-29 23:41:39 +02:00
Gantt,
ShowListTask,
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
2019-09-09 20:36:30 +02:00
if (!auth.user.authenticated && auth.user.infos.type !== authType.LINK_SHARE) {
router.push({name: 'home'})
}
2019-04-29 23:41:39 +02:00
// If the type is invalid, redirect the user
2019-09-09 20:36:30 +02:00
if (auth.user.authenticated && auth.user.infos.type !== authType.LINK_SHARE && this.$route.params.type !== 'gantt' && this.$route.params.type !== '') {
2019-04-29 23:41:39 +02:00
router.push({name: 'showList', params: { id: this.$route.params.id }})
}
},
created() {
this.listService = new ListService()
2019-04-29 23:41:39 +02:00
this.list = new ListModel()
this.loadList()
},
watch: {
// call again the method if the route changes
2019-12-03 19:09:12 +01:00
'$route.path': 'loadList'
},
methods: {
loadList() {
// We create an extra list object instead of creating it in this.list because that would trigger a ui update which would result in bad ux.
let list = new ListModel({id: this.$route.params.id})
this.listService.get(list)
.then(r => {
this.$set(this, 'list', r)
})
.catch(e => {
message.error(e, this)
})
},
}
}
2018-11-06 15:54:25 +01:00
</script>