flaschengeist-frontend/src/components/navigation/EssentialLink.vue

84 lines
1.9 KiB
Vue
Raw Normal View History

2020-10-02 07:13:14 +00:00
<template>
<q-item
clickable
tag="a"
target="self"
:to="{ name: link }"
v-if="hasPermissions"
>
<q-item-section v-if="icon" avatar>
<q-icon :name="icon" />
2020-10-02 07:13:14 +00:00
</q-item-section>
<q-item-section>
<q-item-label>{{ realTitle }}</q-item-label>
<!--<q-item-label caption>
{{ caption }}
</q-item-label>-->
2020-10-02 07:13:14 +00:00
</q-item-section>
</q-item>
</template>
<script lang="ts">
import { computed, defineComponent } from '@vue/composition-api';
import { Store } from 'vuex';
import { StateInterface } from 'src/store';
2020-10-02 07:13:14 +00:00
export default defineComponent({
name: 'EssentialLink',
props: {
title: {
type: String,
required: true
2020-10-02 07:13:14 +00:00
},
caption: {
type: String,
default: ''
2020-10-02 07:13:14 +00:00
},
link: {
type: String,
default: 'home'
2020-10-02 07:13:14 +00:00
},
icon: {
type: String,
default: ''
2020-10-31 18:33:05 +00:00
},
permissions: {
default: undefined
}
2020-10-09 16:04:32 +00:00
},
setup(props, { root }) {
2020-10-28 23:12:46 +00:00
let title = computed<string>(() => {
if (props.title.includes('loadFromStore')) {
const startIndex = props.title.indexOf('(') + 1;
const endIndex = props.title.indexOf(')');
const substring = props.title
.substring(startIndex, endIndex)
.replace(/"/g, '');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2020-10-28 23:12:46 +00:00
return <string>root.$store.getters[substring];
}
return props.title;
});
2020-10-31 18:33:05 +00:00
const hasPermissions = computed(() => {
let permissions = props.permissions;
2020-10-31 18:33:05 +00:00
if (permissions) {
return (<string[]>permissions).every(permission => {
return (<{ 'user/permissions': string[] }>(
(<Store<StateInterface>>root.$store).getters
))['user/permissions'].includes(permission);
});
2020-10-31 18:33:05 +00:00
}
return true;
});
2020-10-31 18:33:05 +00:00
return { realTitle: title, hasPermissions };
}
2020-10-02 07:13:14 +00:00
});
</script>