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">
|
|
|
|
<div class="navbar-item logo">
|
|
|
|
<img src="logo-full.svg"/>
|
2018-09-09 17:23:06 +02:00
|
|
|
</div>
|
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">
|
|
|
|
<div class="buttons">
|
|
|
|
<a class="button is-success">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="plus"/>
|
|
|
|
</span>
|
|
|
|
New Namespace
|
|
|
|
</a>
|
|
|
|
</div>
|
2018-09-07 08:42:17 +02:00
|
|
|
<aside class="menu">
|
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">
|
2018-09-07 22:44:07 +02:00
|
|
|
<p class="menu-label" :key="n.id">
|
2018-09-07 08:42:17 +02:00
|
|
|
{{n.name}}
|
|
|
|
</p>
|
2018-09-09 21:28:07 +02:00
|
|
|
<router-link :to="{ name: 'newList', params: { id: n.id} }" class="button is-success" :key="n.id + 'newList'">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="list-ol"/>
|
|
|
|
</span>
|
|
|
|
New List
|
|
|
|
</router-link>
|
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" />
|
2018-09-06 19:46:09 +02:00
|
|
|
</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
|
|
|
|
2018-09-06 19:46:09 +02:00
|
|
|
export default {
|
2018-09-07 08:42:17 +02:00
|
|
|
name: 'app',
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
user: auth.user,
|
|
|
|
loading: false,
|
|
|
|
namespaces: [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2018-09-08 21:24:10 +02:00
|
|
|
if (this.user.authenticated) {
|
|
|
|
this.loadNamespaces()
|
|
|
|
}
|
2018-09-07 08:42:17 +02:00
|
|
|
},
|
2018-09-09 16:17:56 +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 => {
|
|
|
|
|
2018-09-07 22:44:07 +02:00
|
|
|
let nps = response.data
|
2018-09-07 08:42:17 +02:00
|
|
|
|
2018-09-07 22:44:07 +02:00
|
|
|
// Loop through the namespaces and get their lists
|
|
|
|
for (const n in nps) {
|
2018-09-07 08:42:17 +02:00
|
|
|
|
2018-09-07 22:44:07 +02:00
|
|
|
this.namespaces.push(nps[n])
|
2018-09-07 08:42:17 +02:00
|
|
|
|
2018-09-07 22:44:07 +02:00
|
|
|
HTTP.get(`namespaces/` + nps[n].id + `/lists`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
2018-09-07 08:42:17 +02:00
|
|
|
.then(response => {
|
2018-09-07 22:44:07 +02:00
|
|
|
// This adds a new element "list" to our object which contains all lists
|
|
|
|
this.$set(this.namespaces[n], 'lists', response.data)
|
2018-09-07 08:42:17 +02:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2018-09-08 21:43:16 +02:00
|
|
|
this.handleError(e)
|
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
|
|
|
})
|
|
|
|
},
|
2018-09-09 16:17:56 +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-09-06 19:46:09 +02:00
|
|
|
}
|
2018-08-28 22:50:22 +02:00
|
|
|
</script>
|
|
|
|
|
2018-09-09 17:33:36 +02:00
|
|
|
<style lang="scss">
|
2018-09-09 17:23:06 +02:00
|
|
|
/* Logout-icon */
|
|
|
|
.logout-icon {
|
|
|
|
padding-right: 2em !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Navbar */
|
|
|
|
.navbar{
|
|
|
|
background: none !important;
|
2018-09-09 17:33:24 +02:00
|
|
|
padding-top: 0.5rem;
|
2018-09-09 17:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.logo {
|
|
|
|
|
|
|
|
padding-left: 2rem !important;
|
|
|
|
|
|
|
|
img {
|
|
|
|
max-height: 3rem !important;
|
|
|
|
margin-right: 1rem;
|
|
|
|
}
|
|
|
|
}
|
2018-09-09 19:09:46 +02:00
|
|
|
|
|
|
|
/* Buttons icons */
|
2018-09-09 19:41:43 +02:00
|
|
|
.button .icon.is-small {
|
2018-09-09 19:09:46 +02:00
|
|
|
margin-right: 0.05rem !important;
|
|
|
|
}
|
2018-09-09 19:41:43 +02:00
|
|
|
|
|
|
|
/* List active link */
|
|
|
|
.menu-list a.router-link-active{
|
|
|
|
background: darken(#fff, 5%);
|
|
|
|
}
|
2018-08-28 22:50:22 +02:00
|
|
|
</style>
|