frontend/src/App.vue

155 lines
4.9 KiB
Vue
Raw Normal View History

2018-08-28 20:50:22 +00:00
<template>
2018-09-07 06:42:17 +00:00
<div id="app" class="container">
2018-09-09 15:33:24 +00:00
<nav class="navbar" role="navigation" aria-label="main navigation" v-if="user.authenticated">
2018-09-09 17:54:28 +00:00
<div class="navbar-brand">
2018-10-03 17:06:50 +00:00
<router-link :to="{name: 'home'}" class="navbar-item logo">
2018-09-11 05:02:32 +00:00
<img src="images/logo-full.svg"/>
2018-10-03 17:06:50 +00:00
</router-link>
2018-09-09 17:54:28 +00:00
</div>
<div class="navbar-menu">
2018-09-09 15:33:24 +00: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 15:23:06 +00:00
</span>
2018-09-09 15:33:24 +00: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 15:23:06 +00:00
</div>
</nav>
2018-09-07 06:42:17 +00:00
<div class="column is-centered">
2018-09-09 19:00:27 +00:00
<div v-if="user.authenticated">
<div class="box">
2018-09-07 06:42:17 +00:00
<div class="columns">
2018-09-09 17:09:46 +00: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 20:44:07 +00:00
<p class="menu-label" v-if="loading">Loading...</p>
2018-09-07 06:42:17 +00:00
<template v-for="n in namespaces">
<div :key="n.id">
2018-09-17 05:36:25 +00:00
<router-link :to="{name: 'editNamespace', params: {id: n.id} }" class="nsettings">
<span class="icon">
<icon icon="cog"/>
</span>
2018-09-11 17:46:14 +00:00
</router-link>
2018-09-17 05:36:25 +00: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 20:44:07 +00:00
<ul class="menu-list" :key="n.id + 'child'">
<li v-for="l in n.lists" :key="l.id">
2018-09-08 21:33:09 +00:00
<router-link :to="{ name: 'showList', params: { id: l.id} }">{{l.title}}</router-link>
2018-09-07 20:44:07 +00:00
</li>
2018-09-07 06:42:17 +00:00
</ul>
</template>
</aside>
</div>
2018-09-09 19:00:27 +00:00
<div class="column is-9">
2018-09-07 06:42:17 +00:00
<router-view/>
</div>
</div>
</div>
</div>
<div v-else>
2018-11-01 21:34:29 +00:00
<div class="container has-text-centered">
<div class="column is-4 is-offset-4">
<img src="images/logo-full.svg"/>
<router-view/>
</div>
</div>
2018-09-07 06:42:17 +00:00
</div>
</div>
2018-09-08 19:43:16 +00:00
<notifications position="bottom left" />
</div>
2018-08-28 20:50:22 +00:00
</template>
<script>
2018-09-07 06:42:17 +00:00
import auth from './auth'
import {HTTP} from './http-common'
2018-09-08 19:43:16 +00:00
import message from './message'
2018-11-01 21:34:29 +00:00
import router from './router'
2018-09-07 06:42:17 +00:00
export default {
2018-09-07 06:42:17 +00:00
name: 'app',
data() {
return {
user: auth.user,
loading: false,
namespaces: [],
}
},
2018-11-01 21:34:29 +00:00
beforeMount() {
// Password reset
if(this.$route.query.userPasswordReset !== undefined) {
localStorage.removeItem('passwordResetToken') // Delete an eventually preexisting old token
localStorage.setItem('passwordResetToken', this.$route.query.userPasswordReset)
router.push({name: 'passwordReset'})
}
// Email verification
if(this.$route.query.userEmailConfirm !== undefined) {
localStorage.removeItem('emailConfirmToken') // Delete an eventually preexisting old token
localStorage.setItem('emailConfirmToken', this.$route.query.userEmailConfirm)
router.push({name: 'login'})
}
2018-11-01 21:34:29 +00:00
},
2018-09-07 06:42:17 +00:00
created() {
if (this.user.authenticated) {
this.loadNamespaces()
}
2018-09-07 06:42:17 +00:00
},
watch: {
// call the method again if the route changes
'$route': 'loadNamespacesIfNeeded'
},
2018-09-07 06:42:17 +00:00
methods: {
logout() {
auth.logout()
},
2018-09-09 15:23:06 +00:00
gravatar() {
return 'https://www.gravatar.com/avatar/' + this.user.infos.avatar + '?s=50'
},
2018-09-07 06:42:17 +00: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 06:42:17 +00:00
this.loading = false
})
.catch(e => {
2018-09-08 19:43:16 +00:00
this.handleError(e)
2018-09-07 06:42:17 +00:00
})
},
loadNamespacesIfNeeded(e){
if (this.user.authenticated && e.name === 'home') {
this.loadNamespaces()
}
},
2018-09-08 19:43:16 +00:00
handleError(e) {
this.loading = false
message.error(e, this)
}
2018-09-07 06:42:17 +00:00
},
}
2018-08-28 20:50:22 +00:00
</script>