|
1 | 1 |
|
2 | 2 | <script> |
3 | 3 | import { mapActions, mapGetters } from 'vuex' |
4 | | - import { version } from '../../config' |
5 | 4 | import CcSpinner from '../general/spinner' |
| 5 | + import { version } from '../../config' |
6 | 6 |
|
7 | 7 | export default { |
8 | 8 | components: { |
9 | 9 | CcSpinner, |
10 | 10 | }, |
11 | 11 | computed: { |
| 12 | + /** |
| 13 | + * See src/app/auth/vuex/getters.js |
| 14 | + */ |
12 | 15 | ...mapGetters(['currentUser', 'isLogged']), |
13 | 16 | version() { |
14 | 17 | return version |
15 | 18 | }, |
16 | 19 | }, |
17 | 20 | watch: { |
18 | | - isLogged(value) { |
| 21 | + isLogged(value) { // isLogged changes when the token changes |
19 | 22 | if (value === false) { |
20 | 23 | this.$router.push({ name: 'auth.singin' }) |
21 | 24 | } |
22 | 25 | }, |
23 | 26 | }, |
24 | 27 | methods: { |
| 28 | + /** |
| 29 | + * Makes logout() action available withint this component |
| 30 | + * See /src/app/auth/vuex/actions.js |
| 31 | + */ |
25 | 32 | ...mapActions(['logout']), |
| 33 | + /* eslint-disable no-undef */ |
| 34 | + navigate(name) { |
| 35 | + switch (name) { |
| 36 | + case 'codecasts': |
| 37 | + window.location = 'https://codecasts.com.br/' |
| 38 | + break; |
| 39 | + case 'logout': |
| 40 | + this.logout() |
| 41 | + break; |
| 42 | + default: |
| 43 | + this.$router.push({ name }) |
| 44 | + break; |
| 45 | + } |
| 46 | + }, |
26 | 47 | }, |
27 | 48 | } |
28 | 49 | </script> |
29 | 50 |
|
30 | 51 | <template> |
31 | 52 | <div> |
32 | | - <nav class="navbar navbar-default"> |
33 | | - <div class="container-fluid"> |
34 | | - <div class="navbar-header spacer"> |
35 | | - <a class="navbar-brand" href="http://www.codecasts.com.br/"> |
36 | | - Codecasts.com.br |
37 | | - </a><br> |
38 | | - <small class="version">version {{ version }}</small> |
39 | | - </div> |
40 | | - <div class="collapse navbar-collapse"> |
41 | | - <ul class="nav navbar-nav"> |
42 | | - <router-link tag="li" :to="{ name: 'dashboard.index' }" exact> |
43 | | - <a>Dashboard</a> |
44 | | - </router-link> |
45 | | - <router-link tag="li" :to="{ name: 'categories.index', query: { page: 1 } }"> |
46 | | - <a>Categories</a> |
47 | | - </router-link> |
48 | | - <router-link tag="li" :to="{ name: 'products.index', query: { page: 1 } }"> |
49 | | - <a>Products</a> |
50 | | - </router-link> |
51 | | - </ul> |
52 | | - <div class="nav navbar-form navbar-right"> |
53 | | - <cc-spinner></cc-spinner> |
54 | | - <span class="username">{{ currentUser.name }}</span> |
55 | | - <button class="btn btn-default btn-sm" @click="logout">Logout</button> |
56 | | - </div> |
57 | | - </div> |
58 | | - </div> |
59 | | - </nav> |
| 53 | + <cc-spinner></cc-spinner> |
| 54 | + <el-menu theme="dark" default-active="1" class="cc-navigation" |
| 55 | + mode="horizontal" @select="navigate"> |
| 56 | + <el-menu-item index="codecasts" class="brand">Codecasts.com.br</el-menu-item> |
| 57 | + <el-menu-item index="dashboard.index">Dashboard</el-menu-item> |
| 58 | + <el-submenu index="menu-modules"> |
| 59 | + <template slot="title">Modules</template> |
| 60 | + <el-menu-item index="categories.index">Categories</el-menu-item> |
| 61 | + <el-menu-item index="products.index">Products</el-menu-item> |
| 62 | + </el-submenu> |
| 63 | + <el-submenu index="menu-user" class="logout-button"> |
| 64 | + <template slot="title">{{ currentUser.name }}</template> |
| 65 | + <el-menu-item index="logout">Logout</el-menu-item> |
| 66 | + </el-submenu> |
| 67 | + </el-menu> |
| 68 | + <small class="version">version {{ version }}</small> |
60 | 69 | </div> |
61 | 70 | </template> |
62 | 71 |
|
63 | 72 | <style scoped> |
64 | | - .spacer { |
65 | | - margin-left: 120px; |
| 73 | + .cc-navigation { |
| 74 | + padding-left: 115px; |
| 75 | + padding-right: 30px; |
| 76 | + } |
| 77 | + .brand { |
| 78 | + font-size: 1.2em; |
66 | 79 | } |
67 | | - .username { |
68 | | - padding: 6px 20px; |
69 | | - border-radius: 20px; |
70 | | - background-color: #ddd; |
71 | | - display: inline-block; |
| 80 | + .logout-button { |
| 81 | + float: right; |
72 | 82 | } |
73 | 83 | .version { |
74 | 84 | position: absolute; |
75 | 85 | right: 15px; |
76 | | - top: 58px; |
| 86 | + top: 65px; |
77 | 87 | } |
78 | 88 | </style> |
0 commit comments