Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<template>
<div class="position-sticky pt-3 page">
<h6>
<span
class="
sidebar-heading
d-flex
justify-content-between
align-items-center
px-3
mt-4
mb-1
text-muted
"
>
<template v-if="isAuthenticated">
Angemeldet als {{ username }}
</template>
<template v-else> Nicht eingeloggt </template>
</span>
</h6>
<ul v-if="isAuthenticated" class="nav flex-column">
<template v-for="(e, idx) in items" :key="idx">
<h6
v-if="e.type === 'heading'"
class="
sidebar-heading
d-flex
justify-content-between
align-items-center
px-3
mt-4
mb-1
text-muted
"
>
{{ e.text }}
</h6>
<li v-if="e.type === 'link' && 'href' in e" class="nav-item">
<a class="nav-link" aria-current="page" :href="e.href">
<i v-if="e.icon" class="bi feather" :class="'bi-' + e.icon"></i>
<i v-else class="bi bi-file-earmark feather"></i>
{{ e.text }}
</a>
</li>
<li v-if="e.type === 'link' && 'name' in e" class="nav-item">
<router-link
class="nav-link"
:to="{ name: e.name }"
active-class="active"
>
<i v-if="e.icon" class="bi feather" :class="'bi-' + e.icon"></i>
<i v-else class="bi bi-file-earmark feather"></i>
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{{ e.text }}
</router-link>
</li>
</template>
</ul>
</div>
</template>
<script>
/**
* Sidebar for DashboardLayout. Uses vue-keycloak to determine if the user is authenticated.
* Possible navigation entries are specified via the `items`-property.
*
* Usage: specify an array of navigation items.
*
* Possible items:
* Headers: {text: "something", type: "heading"}
* href links: {text: "somthing", type: "link", href:"/somewhere", icon:"plus"}
* router links: {text: "somthing", type: "link", name:"route-name", icon:"plus"}
*
* Icons are optional and are taken from bootstrap-icons. You only need to specify the
* name, not the full class. E.g. for `<i class="bi bi-ui-checks-grid"></i>` you only need
* to use `ui-checks-grid`.
*/
import { useKeycloak } from "@baloise/vue-keycloak";
export default {
props: {
items: {
type: Array,
default: () => [],
},
noKeycloak: { type: Boolean, default: false },
},
setup(props) {
if (props.noKeycloak) {
const isAuthenticated = false;
return { isAuthenticated };
} else {
const { isAuthenticated, username } = useKeycloak();
return {
isAuthenticated,
username,
};
}
},
};
</script>