2018-01-09 16:52:26 +00:00
|
|
|
<template>
|
2019-01-21 14:08:22 +00:00
|
|
|
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
|
2019-04-03 15:29:03 +00:00
|
|
|
<div class="container">
|
|
|
|
<div class="navbar-brand">
|
|
|
|
<router-link class="navbar-item" :to="{ name: 'Home' }"><logo /></router-link>
|
2019-01-18 13:47:10 +00:00
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
<a
|
|
|
|
role="button"
|
|
|
|
class="navbar-burger burger"
|
|
|
|
aria-label="menu"
|
|
|
|
aria-expanded="false"
|
|
|
|
data-target="navbarBasicExample"
|
|
|
|
@click="showNavbar = !showNavbar" :class="{ 'is-active': showNavbar }"
|
|
|
|
>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
</a>
|
|
|
|
</div>
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
<div class="navbar-menu" :class="{ 'is-active': showNavbar }">
|
|
|
|
<div class="navbar-end">
|
|
|
|
<div class="navbar-item">
|
|
|
|
<search-field />
|
|
|
|
</div>
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
<div class="navbar-item has-dropdown is-hoverable" v-if="currentUser.isLoggedIn">
|
|
|
|
<a
|
|
|
|
class="navbar-link"
|
2019-09-11 07:59:01 +00:00
|
|
|
v-if="currentActor"
|
2019-06-17 15:15:27 +00:00
|
|
|
>
|
2019-09-11 07:59:01 +00:00
|
|
|
<figure class="image is-24x24" v-if="currentActor.avatar">
|
|
|
|
<img alt="avatarUrl" :src="currentActor.avatar.url">
|
2019-06-17 15:15:27 +00:00
|
|
|
</figure>
|
2019-09-11 07:59:01 +00:00
|
|
|
<span>{{ currentActor.preferredUsername }}</span>
|
2019-06-17 15:15:27 +00:00
|
|
|
</a>
|
|
|
|
|
2019-09-11 07:59:01 +00:00
|
|
|
<div class="navbar-dropdown is-boxed">
|
|
|
|
<div v-for="identity in identities" v-if="identities.length > 0">
|
|
|
|
<a class="navbar-item" @click="setIdentity(identity)" :class="{ 'is-active': identity.id === currentActor.id }">
|
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-24x24" v-if="identity.avatar">
|
|
|
|
<img class="is-rounded" :src="identity.avatar.url">
|
|
|
|
</figure>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="media-content">
|
|
|
|
<h3>{{ identity.displayName() }}</h3>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<hr class="navbar-divider">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<a class="navbar-item">
|
2019-09-12 09:34:01 +00:00
|
|
|
<router-link :to="{ name: 'UpdateIdentity' }">{{ $t('My account') }}</router-link>
|
2019-09-11 07:59:01 +00:00
|
|
|
</a>
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2019-09-11 07:59:01 +00:00
|
|
|
<a class="navbar-item">
|
2019-09-12 09:34:01 +00:00
|
|
|
<router-link :to="{ name: ActorRouteName.CREATE_GROUP }">{{ $t('Create group') }}</router-link>
|
2019-09-11 07:59:01 +00:00
|
|
|
</a>
|
2019-09-02 08:50:00 +00:00
|
|
|
|
2019-09-11 07:59:01 +00:00
|
|
|
<a class="navbar-item" v-if="currentUser.role === ICurrentUserRole.ADMINISTRATOR">
|
2019-09-12 09:34:01 +00:00
|
|
|
<router-link :to="{ name: AdminRouteName.DASHBOARD }">{{ $t('Administration') }}</router-link>
|
2019-09-11 07:59:01 +00:00
|
|
|
</a>
|
2019-09-09 07:31:08 +00:00
|
|
|
|
2019-09-12 09:34:01 +00:00
|
|
|
<a class="navbar-item" v-on:click="logout()">{{ $t('Log out') }}</a>
|
2019-04-03 15:29:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-01 09:49:54 +00:00
|
|
|
|
2019-06-17 15:15:27 +00:00
|
|
|
<div class="navbar-item" v-else>
|
|
|
|
<div class="buttons">
|
|
|
|
<router-link class="button is-primary" v-if="config && config.registrationsOpen" :to="{ name: 'Register' }">
|
2019-09-12 09:34:01 +00:00
|
|
|
<strong>{{ $t('Sign up') }}</strong>
|
2019-04-26 13:22:16 +00:00
|
|
|
</router-link>
|
|
|
|
|
2019-09-12 09:34:01 +00:00
|
|
|
<router-link class="button is-primary" :to="{ name: 'Login' }">{{ $t('Log in') }}</router-link>
|
2019-04-03 15:29:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-21 14:08:22 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2018-01-09 16:52:26 +00:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 14:41:34 +00:00
|
|
|
<script lang="ts">
|
2019-08-13 06:43:37 +00:00
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
|
|
|
import { CURRENT_USER_CLIENT } from '@/graphql/user';
|
2019-09-11 07:59:01 +00:00
|
|
|
import { changeIdentity, logout } from '@/utils/auth';
|
|
|
|
import { CURRENT_ACTOR_CLIENT, IDENTITIES, UPDATE_CURRENT_ACTOR_CLIENT } from '@/graphql/actor';
|
|
|
|
import { IPerson, Person } from '@/types/actor';
|
2019-08-13 06:43:37 +00:00
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-09-09 07:31:08 +00:00
|
|
|
import { ICurrentUser, ICurrentUserRole } from '@/types/current-user.model';
|
2019-08-13 06:43:37 +00:00
|
|
|
import Logo from '@/components/Logo.vue';
|
|
|
|
import SearchField from '@/components/SearchField.vue';
|
2019-09-02 08:50:00 +00:00
|
|
|
import { ActorRouteName } from '@/router/actor';
|
2019-09-09 07:31:08 +00:00
|
|
|
import { AdminRouteName } from '@/router/admin';
|
|
|
|
import { RouteName } from '@/router';
|
2019-08-12 14:04:16 +00:00
|
|
|
|
2019-08-13 06:43:37 +00:00
|
|
|
@Component({
|
2018-12-21 16:10:39 +00:00
|
|
|
apollo: {
|
2019-01-18 13:47:10 +00:00
|
|
|
currentUser: {
|
2019-03-22 09:57:14 +00:00
|
|
|
query: CURRENT_USER_CLIENT,
|
2019-01-21 14:08:22 +00:00
|
|
|
},
|
2019-09-11 07:59:01 +00:00
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
|
|
|
identities: {
|
|
|
|
query: IDENTITIES,
|
|
|
|
update: ({ identities }) => identities.map(identity => new Person(identity)),
|
|
|
|
},
|
2019-03-22 12:58:19 +00:00
|
|
|
config: {
|
|
|
|
query: CONFIG,
|
2019-03-21 19:23:42 +00:00
|
|
|
},
|
|
|
|
},
|
2019-04-03 15:29:03 +00:00
|
|
|
components: {
|
|
|
|
Logo,
|
|
|
|
SearchField,
|
|
|
|
},
|
2018-12-21 16:10:39 +00:00
|
|
|
})
|
|
|
|
export default class NavBar extends Vue {
|
|
|
|
notifications = [
|
2019-03-22 09:57:14 +00:00
|
|
|
{ header: 'Coucou' },
|
2019-08-13 06:43:37 +00:00
|
|
|
{ title: 'T\'as une notification', subtitle: 'Et elle est cool' },
|
2018-12-21 16:10:39 +00:00
|
|
|
];
|
2019-09-11 07:59:01 +00:00
|
|
|
currentActor!: IPerson;
|
2019-03-22 12:58:19 +00:00
|
|
|
config!: IConfig;
|
2019-04-01 09:49:54 +00:00
|
|
|
currentUser!: ICurrentUser;
|
2019-09-09 07:31:08 +00:00
|
|
|
ICurrentUserRole = ICurrentUserRole;
|
2019-09-11 07:59:01 +00:00
|
|
|
identities!: IPerson[];
|
2019-04-03 15:29:03 +00:00
|
|
|
showNavbar: boolean = false;
|
2018-12-21 14:41:34 +00:00
|
|
|
|
2019-09-02 08:50:00 +00:00
|
|
|
ActorRouteName = ActorRouteName;
|
2019-09-09 07:31:08 +00:00
|
|
|
AdminRouteName = AdminRouteName;
|
2019-09-02 08:50:00 +00:00
|
|
|
|
2019-09-11 07:59:01 +00:00
|
|
|
// @Watch('currentUser')
|
|
|
|
// async onCurrentUserChanged() {
|
|
|
|
// // Refresh logged person object
|
|
|
|
// if (this.currentUser.isLoggedIn) {
|
|
|
|
// const result = await this.$apollo.query({
|
|
|
|
// query: CURRENT_ACTOR_CLIENT,
|
|
|
|
// });
|
|
|
|
// console.log(result);
|
|
|
|
//
|
|
|
|
// this.loggedPerson = result.data.currentActor;
|
|
|
|
// } else {
|
|
|
|
// this.loggedPerson = null;
|
|
|
|
// }
|
|
|
|
// }
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
|
|
async logout() {
|
2019-08-12 14:04:16 +00:00
|
|
|
await logout(this.$apollo.provider.defaultClient);
|
2019-04-01 09:49:54 +00:00
|
|
|
|
2019-09-09 07:31:08 +00:00
|
|
|
if (this.$route.name === RouteName.HOME) return;
|
|
|
|
return this.$router.push({ name: RouteName.HOME });
|
2019-01-18 13:47:10 +00:00
|
|
|
}
|
2019-09-11 07:59:01 +00:00
|
|
|
|
|
|
|
async setIdentity(identity: IPerson) {
|
|
|
|
return await changeIdentity(this.$apollo.provider.defaultClient, identity);
|
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
}
|
2018-12-21 14:41:34 +00:00
|
|
|
</script>
|
2019-04-03 15:29:03 +00:00
|
|
|
<style lang="scss" scoped>
|
2019-08-13 06:43:37 +00:00
|
|
|
@import "../variables.scss";
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2019-08-13 06:43:37 +00:00
|
|
|
nav {
|
|
|
|
border-bottom: solid 1px #0a0a0a;
|
2019-04-24 15:36:25 +00:00
|
|
|
|
2019-08-13 06:43:37 +00:00
|
|
|
.navbar-item img {
|
|
|
|
max-height: 2.5em;
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
2019-08-13 06:43:37 +00:00
|
|
|
}
|
2019-04-03 15:29:03 +00:00
|
|
|
</style>
|