vikunja-frontend/src/App.vue
2018-09-11 07:02:32 +02:00

177 lines
4.8 KiB
Vue

<template>
<div id="app" class="container">
<nav class="navbar" role="navigation" aria-label="main navigation" v-if="user.authenticated">
<div class="navbar-brand">
<div class="navbar-item logo">
<img src="images/logo-full.svg"/>
</div>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<span class="navbar-item">{{user.infos.username}}</span>
<span class="navbar-item image">
<img :src="gravatar()" class="is-rounded" alt=""/>
</span>
<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>
</div>
</nav>
<div class="column is-centered">
<div v-if="user.authenticated">
<div class="box">
<div class="columns">
<div class="column is-3">
<a class="button is-success is-fullwidth button-bottom">
<span class="icon is-small">
<icon icon="plus"/>
</span>
New Namespace
</a>
<aside class="menu">
<p class="menu-label" v-if="loading">Loading...</p>
<template v-for="n in namespaces">
<p class="menu-label" :key="n.id">
{{n.name}}
</p>
<router-link :to="{ name: 'newList', params: { id: n.id} }" class="button is-success is-fullwidth button-bottom" :key="n.id + 'newList'">
<span class="icon is-small">
<icon icon="list-ol"/>
</span>
New List
</router-link>
<ul class="menu-list" :key="n.id + 'child'">
<li v-for="l in n.lists" :key="l.id">
<router-link :to="{ name: 'showList', params: { id: l.id} }">{{l.title}}</router-link>
</li>
</ul>
</template>
</aside>
</div>
<div class="column is-9">
<router-view/>
</div>
</div>
</div>
</div>
<div v-else>
<router-view/>
</div>
</div>
<notifications position="bottom left" />
</div>
</template>
<script>
import auth from './auth'
import {HTTP} from './http-common'
import message from './message'
export default {
name: 'app',
data() {
return {
user: auth.user,
loading: false,
namespaces: [],
}
},
created() {
if (this.user.authenticated) {
this.loadNamespaces()
}
},
watch: {
// call the method again if the route changes
'$route': 'loadNamespacesIfNeeded'
},
methods: {
logout() {
auth.logout()
},
gravatar() {
return 'https://www.gravatar.com/avatar/' + this.user.infos.avatar + '?s=50'
},
loadNamespaces() {
this.loading = true
this.namespaces = []
HTTP.get(`namespaces`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
let nps = response.data
// Loop through the namespaces and get their lists
for (const n in nps) {
this.namespaces.push(nps[n])
HTTP.get(`namespaces/` + nps[n].id + `/lists`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
// This adds a new element "list" to our object which contains all lists
this.$set(this.namespaces[n], 'lists', response.data)
})
.catch(e => {
this.handleError(e)
})
}
this.loading = false
})
.catch(e => {
this.handleError(e)
})
},
loadNamespacesIfNeeded(e){
if (this.user.authenticated && e.name === 'home') {
this.loadNamespaces()
}
},
handleError(e) {
this.loading = false
message.error(e, this)
}
},
}
</script>
<style lang="scss">
/* Logout-icon */
.logout-icon {
padding-right: 2em !important;
}
/* Navbar */
.navbar{
background: none !important;
padding-top: 0.5rem;
}
.logo {
padding-left: 2rem !important;
img {
max-height: 3rem !important;
margin-right: 1rem;
}
}
/* Buttons icons */
.button .icon.is-small {
margin-right: 0.05rem !important;
}
/* List active link */
.menu-list a.router-link-active{
background: darken(#fff, 5%);
}
/* menu buttons */
.button-bottom {
margin-bottom: 1rem;
}
</style>