vikunja-frontend/src/App.vue

135 lines
4 KiB
Vue
Raw Normal View History

2018-08-28 22:50:22 +02:00
<template>
2018-09-07 08:42:17 +02:00
<div id="app" class="container">
2018-09-09 17:33:24 +02:00
<nav class="navbar" role="navigation" aria-label="main navigation" v-if="user.authenticated">
2018-09-09 19:54:28 +02:00
<div class="navbar-brand">
2018-10-03 19:06:50 +02:00
<router-link :to="{name: 'home'}" class="navbar-item logo">
2018-09-11 07:02:32 +02:00
<img src="images/logo-full.svg"/>
2018-10-03 19:06:50 +02:00
</router-link>
2018-09-09 19:54:28 +02:00
</div>
<div class="navbar-menu">
2018-09-09 17:33:24 +02:00
<div class="navbar-end">
<span class="navbar-item">{{user.infos.username}}</span>
<span class="navbar-item image">
<img :src="gravatar()" class="is-rounded" alt=""/>
2018-09-09 17:23:06 +02:00
</span>
2018-09-09 17:33:24 +02:00
<a v-on:click="logout()" class="navbar-item is-right logout-icon">
<span class="icon is-medium">
<icon icon="sign-out-alt" size="2x"/>
</span>
</a>
</div>
2018-09-09 17:23:06 +02:00
</div>
</nav>
2018-09-07 08:42:17 +02:00
<div class="column is-centered">
2018-09-09 21:00:27 +02:00
<div v-if="user.authenticated">
<div class="box">
2018-09-07 08:42:17 +02:00
<div class="columns">
2018-09-09 19:09:46 +02:00
<div class="column is-3">
<router-link :to="{name: 'listTeams'}" class="button is-primary is-fullwidth button-bottom">
<span class="icon is-small">
<icon icon="users"/>
</span>
Teams
</router-link>
<router-link :to="{name: 'newNamespace'}" class="button is-success is-fullwidth button-bottom">
<span class="icon is-small">
<icon icon="layer-group"/>
</span>
New Namespace
</router-link>
<aside class="menu namespaces-lists">
2018-09-07 22:44:07 +02:00
<p class="menu-label" v-if="loading">Loading...</p>
2018-09-07 08:42:17 +02:00
<template v-for="n in namespaces">
<div :key="n.id">
2018-09-17 07:36:25 +02:00
<router-link :to="{name: 'editNamespace', params: {id: n.id} }" class="nsettings">
<span class="icon">
<icon icon="cog"/>
</span>
2018-09-11 19:46:14 +02:00
</router-link>
2018-09-17 07:36:25 +02:00
<router-link :to="{ name: 'newList', params: { id: n.id} }" class="is-success nsettings" :key="n.id + 'newList'">
<span class="icon">
<icon icon="plus"/>
</span>
</router-link>
<div class="menu-label">
{{n.name}}
</div>
</div>
2018-09-07 22:44:07 +02:00
<ul class="menu-list" :key="n.id + 'child'">
<li v-for="l in n.lists" :key="l.id">
2018-09-08 23:33:09 +02:00
<router-link :to="{ name: 'showList', params: { id: l.id} }">{{l.title}}</router-link>
2018-09-07 22:44:07 +02:00
</li>
2018-09-07 08:42:17 +02:00
</ul>
</template>
</aside>
</div>
2018-09-09 21:00:27 +02:00
<div class="column is-9">
2018-09-07 08:42:17 +02:00
<router-view/>
</div>
</div>
</div>
</div>
<div v-else>
<router-view/>
</div>
</div>
2018-09-08 21:43:16 +02:00
<notifications position="bottom left" />
</div>
2018-08-28 22:50:22 +02:00
</template>
<script>
2018-09-07 08:42:17 +02:00
import auth from './auth'
import {HTTP} from './http-common'
2018-09-08 21:43:16 +02:00
import message from './message'
2018-09-07 08:42:17 +02:00
export default {
2018-09-07 08:42:17 +02:00
name: 'app',
data() {
return {
user: auth.user,
loading: false,
namespaces: [],
}
},
created() {
if (this.user.authenticated) {
this.loadNamespaces()
}
2018-09-07 08:42:17 +02:00
},
watch: {
// call the method again if the route changes
'$route': 'loadNamespacesIfNeeded'
},
2018-09-07 08:42:17 +02:00
methods: {
logout() {
auth.logout()
},
2018-09-09 17:23:06 +02:00
gravatar() {
return 'https://www.gravatar.com/avatar/' + this.user.infos.avatar + '?s=50'
},
2018-09-07 08:42:17 +02:00
loadNamespaces() {
this.loading = true
this.namespaces = []
HTTP.get(`namespaces`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.$set(this, 'namespaces', response.data)
2018-09-07 08:42:17 +02:00
this.loading = false
})
.catch(e => {
2018-09-08 21:43:16 +02:00
this.handleError(e)
2018-09-07 08:42:17 +02:00
})
},
loadNamespacesIfNeeded(e){
if (this.user.authenticated && e.name === 'home') {
this.loadNamespaces()
}
},
2018-09-08 21:43:16 +02:00
handleError(e) {
this.loading = false
message.error(e, this)
}
2018-09-07 08:42:17 +02:00
},
}
2018-08-28 22:50:22 +02:00
</script>