blob: a2e638a224d771dfae5c567718693b43a36da4f3 [file] [log] [blame]
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +02001<script>
2import {mapGetters} from 'vuex';
3
Adrià Vilanova Martíneze877a002021-09-03 22:03:01 +02004import config from './config.js';
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +02005import GsiButton from './GsiButton.vue';
6
7export default {
8 data() {
9 return {
10 isDrawerOpen: false,
11 mainMenuOpen: false,
12 };
13 },
14 components: {
15 GsiButton,
16 },
17 computed: {
18 ...mapGetters([
19 'isSignedIn',
20 ]),
21 },
22 methods: {
23 onSignIn(response) {
24 this.$store.commit('setJwtToken', response.credential);
25 },
26 onSignOut() {
27 this.$store.commit('setJwtToken', null);
28 },
29 onSelectMainMenu(e) {
30 switch (e.item.getAttribute('data-entry')) {
31 case 'sign-out':
32 this.onSignOut();
33 break;
34
35 default:
36 console.error('Unknown menu entry.');
37 }
38 },
39 },
40 created() {
41 this.$store.dispatch('connectClient', config.grpcWebHost);
42 },
43};
44</script>
45
46<template>
47 <mcw-drawer
48 ref="drawer"
49 v-model="isDrawerOpen"
50 dismissible
51 class="primary-drawer">
52 <template #header>
53 <div class="mdc-drawer__header"></div>
54 </template>
55
56 <mcw-list-item icon="home" to="/" tabindex="0">Home</mcw-list-item>
57 <mcw-list-item icon="emergency" to="/kill-switches">Kill switches</mcw-list-item>
58 <template v-if="isSignedIn">
59 <mcw-list-item icon="person" to="/authorized-users">Authorized users</mcw-list-item>
60 </template>
61 </mcw-drawer>
62 <div ref="app-content" class="mdc-drawer-app-content">
63 <mcw-top-app-bar class="main-toolbar">
64 <div class="mdc-top-app-bar__row">
65 <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
66 <button @click="isDrawerOpen = !isDrawerOpen" class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button" aria-label="Open navigation menu">menu</button>
67 <span class="mdc-top-app-bar__title">{{ $route.meta.title }}</span>
68 </section>
69 <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
70 <template v-if="isSignedIn">
71 <mcw-menu-anchor>
72 <button @click="mainMenuOpen = true" class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Options">more_vert</button>
73 <mcw-menu v-model="mainMenuOpen" @select="onSelectMainMenu">
74 <mcw-list-item data-entry="sign-out">Sign out</mcw-list-item>
75 </mcw-menu>
76 </mcw-menu-anchor>
77 </template>
78 <template v-else>
79 <gsi-button @on-signin="onSignIn"></gsi-button>
80 </template>
81 </section>
82 </div>
83 </mcw-top-app-bar>
84 <main class="mdc-top-app-bar--fixed-adjust">
85 <router-view />
86 </main>
87 </div>
88</template>