0
0
Fork 0
This commit is contained in:
Joan Sanchez 2022-11-29 07:10:04 +01:00
parent 8e04a7559d
commit 3fa5eb1726
4 changed files with 41 additions and 16 deletions

View File

@ -3,7 +3,7 @@
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"esbenp.prettier-vscode", "esbenp.prettier-vscode",
"editorconfig.editorconfig", "editorconfig.editorconfig",
"johnsoncodehk.volar", "Vue.volar",
"wayou.vscode-todo-highlight" "wayou.vscode-todo-highlight"
], ],
"unwantedRecommendations": [ "unwantedRecommendations": [

View File

@ -1,18 +1,19 @@
<script setup> <script setup>
import { onMounted } from 'vue'; // import { onMounted } from 'vue';
// import { useI18n } from 'vue-i18n'; // import { useI18n } from 'vue-i18n';
import { useNavigation } from 'src/stores/useNavigation'; // import { useNavigation } from 'src/stores/useNavigationStoreStore';
// const { t } = useI18n(); // const { t } = useI18n();
const navigation = useNavigation(); // const navigation = useNavigation();
onMounted(() => { // onMounted(() => {
navigation.fetchPinned(); // navigation.fetchPinned();
}); // });
</script> </script>
<template> <template>
{{ navigation.pinned }} Test
<!-- {{ navigation.pinned }} -->
<!-- <q-menu--> <!-- <q-menu-->
<!-- anchor="bottom left"--> <!-- anchor="bottom left"-->
<!-- class="row q-pa-md q-col-gutter-lg"--> <!-- class="row q-pa-md q-col-gutter-lg"-->

View File

@ -4,14 +4,15 @@ import { useI18n } from 'vue-i18n';
import { useRole } from 'src/composables/useRole'; import { useRole } from 'src/composables/useRole';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useNavigation } from 'src/composables/useNavigation'; import { useNavigationStore } from 'src/stores/useNavigationStore';
import routes from 'src/router/modules'; import routes from 'src/router/modules';
import axios from 'axios';
const { t } = useI18n(); const { t } = useI18n();
const role = useRole(); const role = useRole();
const route = useRoute(); const route = useRoute();
const quasar = useQuasar(); const quasar = useQuasar();
const navigation = useNavigation(); const navigation = useNavigationStore();
const props = defineProps({ const props = defineProps({
source: { source: {
@ -76,6 +77,11 @@ if (props.source === 'main') {
const moduleDef = routes.find((route) => toLowerCamel(route.name) === module); const moduleDef = routes.find((route) => toLowerCamel(route.name) === module);
const item = addMenuItem(module, moduleDef, items.value); const item = addMenuItem(module, moduleDef, items.value);
const pinned = navigation.pinned.value;
if (pinned.contains(module)) {
item.isPinned = true
}
item.children = []; item.children = [];
item.module = module; item.module = module;
@ -92,8 +98,13 @@ if (props.source === 'card') {
addChildren(currentModule, moduleDef, items.value); addChildren(currentModule, moduleDef, items.value);
} }
async function togglePinnedModule(module, event) { async function togglePinned(moduleName, event) {
await navigation.toggleFavorite(module, event); if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
await axios.post('StarredModules/toggleStarredModule', { moduleName });
navigation.togglePinned(moduleName);
quasar.notify({ quasar.notify({
message: t('globals.dataSaved'), message: t('globals.dataSaved'),
@ -185,7 +196,7 @@ function isOpen(name) {
<q-item-section>{{ t(item.title) }}</q-item-section> <q-item-section>{{ t(item.title) }}</q-item-section>
<q-item-section side> <q-item-section side>
<q-btn <q-btn
@click="togglePinnedModule(item.module, $event)" @click="togglePinned(item.module, $event)"
icon="vn:pin" icon="vn:pin"
size="xs" size="xs"
flat flat

View File

@ -1,11 +1,13 @@
import { ref } from 'vue'; import { onMounted, ref } from 'vue';
import axios from 'axios'; import axios from 'axios';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
export const useNavigation = defineStore('navigation', () => { export const useNavigationStore = defineStore('navigationStore', () => {
const modules = ['customer', 'claim', 'ticket']; const modules = ['customer', 'claim', 'ticket'];
const pinned = ref([]); const pinned = ref([]);
onMounted(() => fetchPinned())
async function fetchPinned() { async function fetchPinned() {
const response = await axios.get('StarredModules/getStarredModules'); const response = await axios.get('StarredModules/getStarredModules');
// const filteredModules = modules.value.filter((module) => { // const filteredModules = modules.value.filter((module) => {
@ -15,9 +17,20 @@ export const useNavigation = defineStore('navigation', () => {
return (pinned.value = response.data); return (pinned.value = response.data);
} }
function togglePinned(module) {
if (pinned.value.includes(module)) {
const index = pinned.value.indexOf(module);
pinned.value.splice(index, 1);
return;
}
pinned.value.push(module);
}
return { return {
modules, modules,
pinned, pinned,
fetchPinned, togglePinned,
}; };
}); });