2018-08-28 22:50:22 +02:00
|
|
|
<template>
|
2018-09-07 08:42:17 +02:00
|
|
|
<div id="app" class="container">
|
|
|
|
<div class="column is-centered" v-if="user.authenticated">
|
|
|
|
<button v-on:click="logout()" class="button is-right">Logout</button>
|
|
|
|
</div>
|
|
|
|
<div class="column is-centered">
|
|
|
|
<div class="box" v-if="user.authenticated">
|
|
|
|
<div class="container">
|
|
|
|
<div class="columns">
|
|
|
|
<div class="column is-3">
|
|
|
|
<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-07 22:44:07 +02:00
|
|
|
<ul class="menu-list" :key="n.id + 'child'">
|
|
|
|
<li v-for="l in n.lists" :key="l.id">
|
|
|
|
<a>{{l.title}}</a>
|
|
|
|
</li>
|
2018-09-07 08:42:17 +02:00
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
<div class="column is-9">
|
2018-09-07 22:44:07 +02:00
|
|
|
<button class="button is-success" v-on:click="loadNamespaces()">Load Namespaces</button>
|
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
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
logout() {
|
|
|
|
auth.logout()
|
|
|
|
},
|
|
|
|
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-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>
|
|
|
|
|
|
|
|
<style>
|
2018-09-06 20:15:49 +02:00
|
|
|
body {
|
|
|
|
background: #f5f5f5;
|
|
|
|
min-height: 100vh;
|
2018-09-06 19:46:09 +02:00
|
|
|
}
|
2018-08-28 22:50:22 +02:00
|
|
|
</style>
|