Adrià Vilanova MartÃnez | f7ee658 | 2021-09-02 21:53:28 +0200 | [diff] [blame^] | 1 | <script> |
| 2 | import {mapGetters} from 'vuex'; |
| 3 | |
| 4 | import config from './config.json5'; |
| 5 | import GsiButton from './GsiButton.vue'; |
| 6 | |
| 7 | export 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> |