2018-01-09 17:52:26 +01:00
|
|
|
<template>
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-navbar
|
2021-10-10 16:24:12 +02:00
|
|
|
id="navbar"
|
2020-11-30 10:24:11 +01:00
|
|
|
type="is-secondary"
|
|
|
|
wrapper-class="container"
|
|
|
|
:active.sync="mobileNavbarActive"
|
|
|
|
>
|
2019-09-20 18:22:25 +02:00
|
|
|
<template slot="brand">
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-navbar-item
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.HOME }"
|
|
|
|
:aria-label="$t('Home')"
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
<logo />
|
|
|
|
</b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
<template slot="start">
|
2020-08-12 17:55:38 +02:00
|
|
|
<b-navbar-item tag="router-link" :to="{ name: RouteName.SEARCH }">{{
|
2020-02-18 08:57:00 +01:00
|
|
|
$t("Explore")
|
|
|
|
}}</b-navbar-item>
|
2021-05-18 11:01:30 +02:00
|
|
|
<b-navbar-item
|
|
|
|
v-if="currentActor.id && currentUser.isLoggedIn"
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.MY_EVENTS }"
|
|
|
|
>{{ $t("My events") }}</b-navbar-item
|
|
|
|
>
|
2020-06-08 16:47:57 +02:00
|
|
|
<b-navbar-item
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.MY_GROUPS }"
|
2021-05-18 11:01:30 +02:00
|
|
|
v-if="
|
|
|
|
config &&
|
|
|
|
config.features.groups &&
|
|
|
|
currentActor.id &&
|
|
|
|
currentUser.isLoggedIn
|
|
|
|
"
|
2020-06-08 16:47:57 +02:00
|
|
|
>{{ $t("My groups") }}</b-navbar-item
|
|
|
|
>
|
2021-05-18 11:01:30 +02:00
|
|
|
<b-navbar-item
|
|
|
|
tag="span"
|
|
|
|
v-if="
|
|
|
|
config &&
|
|
|
|
config.features.eventCreation &&
|
|
|
|
currentActor.id &&
|
|
|
|
currentUser.isLoggedIn
|
|
|
|
"
|
|
|
|
>
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-button
|
2021-10-06 18:00:50 +02:00
|
|
|
v-if="!hideCreateEventsButton"
|
2020-11-30 10:24:11 +01:00
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.CREATE_EVENT }"
|
|
|
|
type="is-primary"
|
|
|
|
>{{ $t("Create") }}</b-button
|
|
|
|
>
|
2019-10-03 11:37:34 +02:00
|
|
|
</b-navbar-item>
|
2021-05-17 18:55:09 +02:00
|
|
|
<b-navbar-item
|
2021-05-18 16:33:32 +02:00
|
|
|
v-if="config && config.features.koenaConnect"
|
2021-05-17 18:55:09 +02:00
|
|
|
class="koena"
|
|
|
|
tag="a"
|
|
|
|
href="https://mediation.koena.net/framasoft/mobilizon/"
|
|
|
|
target="_blank"
|
2021-11-02 19:47:54 +01:00
|
|
|
rel="noopener external"
|
2021-10-10 16:24:12 +02:00
|
|
|
hreflang="fr"
|
2021-05-17 18:55:09 +02:00
|
|
|
>
|
|
|
|
<img
|
|
|
|
src="/img/koena-a11y.svg"
|
|
|
|
width="150"
|
|
|
|
alt="Contact accessibilité"
|
|
|
|
/>
|
|
|
|
</b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
<template slot="end">
|
|
|
|
<b-navbar-item tag="div">
|
2020-08-18 15:26:11 +02:00
|
|
|
<search-field @navbar-search="mobileNavbarActive = false" />
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
|
2021-06-11 18:31:13 +02:00
|
|
|
<b-navbar-dropdown
|
|
|
|
v-if="currentActor.id && currentUser.isLoggedIn"
|
|
|
|
right
|
|
|
|
collapsible
|
2021-10-10 16:24:12 +02:00
|
|
|
ref="user-dropdown"
|
|
|
|
tabindex="0"
|
|
|
|
tag="span"
|
|
|
|
@keyup.enter="toggleMenu"
|
2021-06-11 18:31:13 +02:00
|
|
|
>
|
2021-11-09 08:52:43 +01:00
|
|
|
<template slot="label" v-if="currentActor">
|
2021-06-11 18:31:13 +02:00
|
|
|
<div class="identity-wrapper">
|
|
|
|
<div>
|
|
|
|
<figure class="image is-32x32" v-if="currentActor.avatar">
|
|
|
|
<img
|
|
|
|
class="is-rounded"
|
|
|
|
alt="avatarUrl"
|
|
|
|
:src="currentActor.avatar.url"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
<b-icon v-else icon="account-circle" />
|
|
|
|
</div>
|
|
|
|
<div class="media-content is-hidden-desktop">
|
|
|
|
<span>{{ displayName(currentActor) }}</span>
|
|
|
|
<span class="has-text-grey-dark" v-if="currentActor.name"
|
|
|
|
>@{{ currentActor.preferredUsername }}</span
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
<!-- No identities dropdown if no identities -->
|
|
|
|
<span v-if="identities.length <= 1" />
|
|
|
|
<b-navbar-item
|
|
|
|
tag="span"
|
|
|
|
v-for="identity in identities"
|
|
|
|
v-else
|
|
|
|
:active="identity.id === currentActor.id"
|
|
|
|
:key="identity.id"
|
2021-10-10 16:24:12 +02:00
|
|
|
tabindex="0"
|
|
|
|
@click="setIdentity(identity)"
|
|
|
|
@keyup.enter="setIdentity(identity)"
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
2021-10-10 16:24:12 +02:00
|
|
|
<span>
|
2019-09-20 18:22:25 +02:00
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-32x32" v-if="identity.avatar">
|
2021-06-15 17:25:33 +02:00
|
|
|
<img
|
|
|
|
class="is-rounded"
|
|
|
|
loading="lazy"
|
|
|
|
:src="identity.avatar.url"
|
|
|
|
alt
|
|
|
|
/>
|
2019-06-17 17:15:27 +02:00
|
|
|
</figure>
|
2020-03-05 19:32:34 +01:00
|
|
|
<b-icon v-else size="is-medium" icon="account-circle" />
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
<div class="media-content">
|
2021-06-11 18:31:13 +02:00
|
|
|
<span>{{ displayName(identity) }}</span>
|
|
|
|
<span class="has-text-grey-dark" v-if="identity.name"
|
2020-02-18 08:57:00 +01:00
|
|
|
>@{{ identity.preferredUsername }}</span
|
|
|
|
>
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
2019-09-20 18:22:25 +02:00
|
|
|
</span>
|
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
<hr class="navbar-divider" role="presentation" />
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-navbar-item
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.UPDATE_IDENTITY }"
|
|
|
|
>{{ $t("My account") }}</b-navbar-item
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-navbar-item
|
|
|
|
v-if="currentUser.role === ICurrentUserRole.ADMINISTRATOR"
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.ADMIN_DASHBOARD }"
|
|
|
|
>{{ $t("Administration") }}</b-navbar-item
|
|
|
|
>
|
2019-09-20 18:22:25 +02:00
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
<b-navbar-item
|
|
|
|
tag="span"
|
|
|
|
tabindex="0"
|
|
|
|
@click="logout"
|
|
|
|
@keyup.enter="logout"
|
|
|
|
>
|
|
|
|
<span>{{ $t("Log out") }}</span>
|
2020-02-18 08:57:00 +01:00
|
|
|
</b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-dropdown>
|
|
|
|
|
|
|
|
<b-navbar-item v-else tag="div">
|
|
|
|
<div class="buttons">
|
2020-02-18 08:57:00 +01:00
|
|
|
<router-link
|
|
|
|
class="button is-primary"
|
|
|
|
v-if="config && config.registrationsOpen"
|
|
|
|
:to="{ name: RouteName.REGISTER }"
|
|
|
|
>
|
|
|
|
<strong>{{ $t("Sign up") }}</strong>
|
2019-09-20 18:22:25 +02:00
|
|
|
</router-link>
|
|
|
|
|
2020-11-30 10:24:11 +01:00
|
|
|
<router-link
|
|
|
|
class="button is-light"
|
|
|
|
:to="{ name: RouteName.LOGIN }"
|
|
|
|
>{{ $t("Log in") }}</router-link
|
|
|
|
>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
</template>
|
|
|
|
</b-navbar>
|
2018-01-09 17:52:26 +01:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 15:41:34 +01:00
|
|
|
<script lang="ts">
|
2021-10-10 16:25:50 +02:00
|
|
|
import { Component, Ref, Vue, Watch } from "vue-property-decorator";
|
2020-02-18 08:57:00 +01:00
|
|
|
import Logo from "@/components/Logo.vue";
|
|
|
|
import { GraphQLError } from "graphql";
|
2020-10-28 18:58:43 +01:00
|
|
|
import { loadLanguageAsync } from "@/utils/i18n";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ICurrentUserRole } from "@/types/enums";
|
2020-10-28 18:58:43 +01:00
|
|
|
import { CURRENT_USER_CLIENT, USER_SETTINGS } from "../graphql/user";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { changeIdentity, logout } from "../utils/auth";
|
2020-11-30 10:24:11 +01:00
|
|
|
import {
|
|
|
|
CURRENT_ACTOR_CLIENT,
|
|
|
|
IDENTITIES,
|
|
|
|
UPDATE_DEFAULT_ACTOR,
|
|
|
|
} from "../graphql/actor";
|
2021-06-11 18:31:13 +02:00
|
|
|
import { displayName, IPerson, Person } from "../types/actor";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { CONFIG } from "../graphql/config";
|
|
|
|
import { IConfig } from "../types/config.model";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ICurrentUser, IUser } from "../types/current-user.model";
|
2020-02-18 08:57:00 +01:00
|
|
|
import SearchField from "./SearchField.vue";
|
|
|
|
import RouteName from "../router/name";
|
2019-08-12 16:04:16 +02:00
|
|
|
|
2019-08-13 08:43:37 +02:00
|
|
|
@Component({
|
2018-12-21 17:10:39 +01:00
|
|
|
apollo: {
|
2021-10-29 10:54:35 +02:00
|
|
|
currentUser: CURRENT_USER_CLIENT,
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
2019-09-11 09:59:01 +02:00
|
|
|
identities: {
|
|
|
|
query: IDENTITIES,
|
2020-02-18 08:57:00 +01:00
|
|
|
update: ({ identities }) =>
|
2020-11-30 10:24:11 +01:00
|
|
|
identities
|
|
|
|
? identities.map((identity: IPerson) => new Person(identity))
|
|
|
|
: [],
|
2019-10-07 13:47:46 +02:00
|
|
|
skip() {
|
|
|
|
return this.currentUser.isLoggedIn === false;
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
error({ graphQLErrors }) {
|
|
|
|
this.handleErrors(graphQLErrors);
|
|
|
|
},
|
2019-09-11 09:59:01 +02:00
|
|
|
},
|
2020-08-05 14:39:17 +02:00
|
|
|
config: CONFIG,
|
2020-10-28 18:58:43 +01:00
|
|
|
loggedUser: {
|
|
|
|
query: USER_SETTINGS,
|
|
|
|
skip() {
|
2021-08-13 16:56:51 +02:00
|
|
|
return !this.currentUser || this.currentUser.isLoggedIn === false;
|
2020-10-28 18:58:43 +01:00
|
|
|
},
|
|
|
|
},
|
2019-03-21 20:23:42 +01:00
|
|
|
},
|
2019-04-03 17:29:03 +02:00
|
|
|
components: {
|
|
|
|
Logo,
|
|
|
|
SearchField,
|
|
|
|
},
|
2018-12-21 17:10:39 +01:00
|
|
|
})
|
|
|
|
export default class NavBar extends Vue {
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor!: IPerson;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-03-22 13:58:19 +01:00
|
|
|
config!: IConfig;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
currentUser!: ICurrentUser;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-10-28 18:58:43 +01:00
|
|
|
loggedUser!: IUser;
|
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
ICurrentUserRole = ICurrentUserRole;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
identities: IPerson[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-10-03 11:37:34 +02:00
|
|
|
RouteName = RouteName;
|
2018-12-21 15:41:34 +01:00
|
|
|
|
2020-08-31 12:40:30 +02:00
|
|
|
mobileNavbarActive = false;
|
2020-08-18 15:26:11 +02:00
|
|
|
|
2021-06-11 18:31:13 +02:00
|
|
|
displayName = displayName;
|
|
|
|
|
2021-10-10 16:25:50 +02:00
|
|
|
@Ref("user-dropdown") userDropDown!: any;
|
|
|
|
|
|
|
|
toggleMenu(): void {
|
|
|
|
console.debug("called toggleMenu");
|
|
|
|
this.userDropDown.showMenu();
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("currentActor")
|
2020-09-22 10:37:16 +02:00
|
|
|
async initializeListOfIdentities(): Promise<void> {
|
2019-10-07 13:47:46 +02:00
|
|
|
if (!this.currentUser.isLoggedIn) return;
|
2019-09-18 17:32:37 +02:00
|
|
|
const { data } = await this.$apollo.query<{ identities: IPerson[] }>({
|
|
|
|
query: IDENTITIES,
|
|
|
|
});
|
|
|
|
if (data) {
|
2021-05-12 18:10:07 +02:00
|
|
|
this.identities = data.identities.map(
|
|
|
|
(identity: IPerson) => new Person(identity)
|
|
|
|
);
|
2019-10-04 18:28:25 +02:00
|
|
|
|
|
|
|
// If we don't have any identities, the user has validated their account,
|
|
|
|
// is logging for the first time but didn't create an identity somehow
|
|
|
|
if (this.identities.length === 0) {
|
2021-11-29 09:50:26 +01:00
|
|
|
console.debug(
|
|
|
|
"We have no identities listed for current user",
|
|
|
|
this.identities
|
|
|
|
);
|
|
|
|
console.debug("Pushing route to REGISTER_PROFILE");
|
2021-08-09 19:29:15 +02:00
|
|
|
try {
|
|
|
|
await this.$router.push({
|
|
|
|
name: RouteName.REGISTER_PROFILE,
|
|
|
|
params: {
|
|
|
|
email: this.currentUser.email,
|
|
|
|
userAlreadyActivated: "true",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2019-10-04 18:28:25 +02:00
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 18:58:43 +01:00
|
|
|
@Watch("loggedUser")
|
|
|
|
setSavedLanguage(): void {
|
|
|
|
if (this.loggedUser?.locale) {
|
2021-08-09 19:29:15 +02:00
|
|
|
console.debug("Setting locale from navbar");
|
2020-10-28 18:58:43 +01:00
|
|
|
loadLanguageAsync(this.loggedUser.locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 10:37:16 +02:00
|
|
|
async handleErrors(errors: GraphQLError[]): Promise<void> {
|
2020-02-18 08:57:00 +01:00
|
|
|
if (
|
|
|
|
errors.length > 0 &&
|
2020-11-30 10:24:11 +01:00
|
|
|
errors[0].message ===
|
|
|
|
"You need to be logged-in to view your list of identities"
|
2020-02-18 08:57:00 +01:00
|
|
|
) {
|
2019-10-08 18:13:06 +02:00
|
|
|
await this.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 10:37:16 +02:00
|
|
|
async logout(): Promise<void> {
|
2019-08-12 16:04:16 +02:00
|
|
|
await logout(this.$apollo.provider.defaultClient);
|
2019-09-23 11:30:23 +02:00
|
|
|
this.$buefy.notification.open({
|
2020-02-18 08:57:00 +01:00
|
|
|
message: this.$t("You have been disconnected") as string,
|
|
|
|
type: "is-success",
|
|
|
|
position: "is-bottom-right",
|
2019-09-23 11:30:23 +02:00
|
|
|
duration: 5000,
|
|
|
|
});
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
if (this.$route.name === RouteName.HOME) return;
|
2019-09-23 11:30:23 +02:00
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
2019-01-18 14:47:10 +01:00
|
|
|
}
|
2019-09-11 09:59:01 +02:00
|
|
|
|
2020-09-22 10:37:16 +02:00
|
|
|
async setIdentity(identity: IPerson): Promise<void> {
|
2020-02-18 08:57:00 +01:00
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_DEFAULT_ACTOR,
|
|
|
|
variables: {
|
|
|
|
preferredUsername: identity.preferredUsername,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return changeIdentity(this.$apollo.provider.defaultClient, identity);
|
2019-09-11 09:59:01 +02:00
|
|
|
}
|
2021-10-06 18:00:50 +02:00
|
|
|
|
|
|
|
get hideCreateEventsButton(): boolean {
|
|
|
|
return !!this.config?.restrictions?.onlyGroupsCanCreateEvents;
|
|
|
|
}
|
2018-12-21 17:10:39 +01:00
|
|
|
}
|
2018-12-21 15:41:34 +01:00
|
|
|
</script>
|
2019-04-03 17:29:03 +02:00
|
|
|
<style lang="scss" scoped>
|
2021-11-04 18:14:36 +01:00
|
|
|
@use "@/styles/_mixins" as *;
|
2019-08-13 08:43:37 +02:00
|
|
|
nav {
|
2020-06-15 18:12:49 +02:00
|
|
|
.navbar-item {
|
2020-06-17 15:54:24 +02:00
|
|
|
a.button {
|
2020-06-16 16:15:38 +02:00
|
|
|
font-weight: bold;
|
2020-06-15 18:12:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
height: 1.75rem;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
.navbar-dropdown .navbar-item {
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
span {
|
2021-06-11 18:31:13 +02:00
|
|
|
display: flex;
|
2019-09-20 18:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
background: $secondary;
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
span.icon.is-medium {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
img {
|
|
|
|
max-height: 2.5em;
|
|
|
|
}
|
|
|
|
}
|
2019-04-24 17:36:25 +02:00
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
.navbar-item.has-dropdown a.navbar-link figure {
|
2021-11-04 18:14:36 +01:00
|
|
|
@include margin-right(0.75rem);
|
2019-10-12 19:23:32 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
2019-10-11 15:07:34 +02:00
|
|
|
|
|
|
|
a.navbar-item:focus-within {
|
|
|
|
background-color: inherit;
|
|
|
|
}
|
2021-05-17 18:55:09 +02:00
|
|
|
|
|
|
|
.koena {
|
|
|
|
padding-top: 0;
|
|
|
|
padding-bottom: 0;
|
|
|
|
& > img {
|
|
|
|
max-height: 4rem;
|
|
|
|
padding-top: 0.2rem;
|
|
|
|
}
|
|
|
|
}
|
2021-06-11 18:31:13 +02:00
|
|
|
|
|
|
|
.identity-wrapper {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.media-content span {
|
|
|
|
display: flex;
|
|
|
|
color: $violet-2;
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 08:43:37 +02:00
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
</style>
|