Add dynamic "Lernpfad" and "KompetenzNavi" urls
This commit is contained in:
parent
089d81bd03
commit
5aaa9da8dc
|
|
@ -6,7 +6,7 @@ import IconSettings from "@/components/icons/IconSettings.vue";
|
|||
import MobileMenu from "@/components/MobileMenu.vue";
|
||||
import ItDropdown from "@/components/ui/ItDropdown.vue";
|
||||
import { useAppStore } from "@/stores/app";
|
||||
import { useLearningPathStore } from "@/stores/learningPath";
|
||||
import { useCourseSessionsStore } from "@/stores/courseSessions";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import type { DropdownListItem } from "@/types";
|
||||
import type { Component } from "vue";
|
||||
|
|
@ -26,8 +26,9 @@ const route = useRoute();
|
|||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const appStore = useAppStore();
|
||||
const courseSessionsStore = useCourseSessionsStore();
|
||||
|
||||
const { t } = useI18n();
|
||||
const learningPathStore = useLearningPathStore();
|
||||
const state = reactive({ showMenu: false });
|
||||
|
||||
function toggleNav() {
|
||||
|
|
@ -35,6 +36,7 @@ function toggleNav() {
|
|||
}
|
||||
|
||||
function isInRoutePath(checkPaths: string[]) {
|
||||
log.debug("isInRoutePath", checkPaths, route.path);
|
||||
return checkPaths.some((path) => route.path.startsWith(path));
|
||||
}
|
||||
|
||||
|
|
@ -42,20 +44,6 @@ function inCourse() {
|
|||
return isInRoutePath(["/learn", "/competence"]);
|
||||
}
|
||||
|
||||
function getLearningPathStringProp(prop: "title" | "slug"): string {
|
||||
return inCourse() && learningPathStore.learningPath
|
||||
? learningPathStore.learningPath[prop]
|
||||
: "";
|
||||
}
|
||||
|
||||
function learningPathName(): string {
|
||||
return getLearningPathStringProp("title");
|
||||
}
|
||||
|
||||
function learninPathSlug(): string {
|
||||
return getLearningPathStringProp("slug");
|
||||
}
|
||||
|
||||
function handleDropdownSelect(data: DropdownData) {
|
||||
switch (data.action) {
|
||||
case "settings":
|
||||
|
|
@ -75,6 +63,7 @@ function logout() {
|
|||
|
||||
onMounted(() => {
|
||||
log.debug("MainNavigationBar mounted");
|
||||
courseSessionsStore.loadCourseSessionsData();
|
||||
});
|
||||
|
||||
const profileDropdownData: DropdownListItem[] = [
|
||||
|
|
@ -100,8 +89,7 @@ const profileDropdownData: DropdownListItem[] = [
|
|||
<Teleport to="body">
|
||||
<MobileMenu
|
||||
:show="state.showMenu"
|
||||
:learning-path-slug="learninPathSlug()"
|
||||
:learning-path-name="learningPathName()"
|
||||
:course-session="courseSessionsStore.courseSessionForRoute"
|
||||
@closemodal="state.showMenu = false"
|
||||
/>
|
||||
</Teleport>
|
||||
|
|
@ -156,8 +144,8 @@ const profileDropdownData: DropdownListItem[] = [
|
|||
class="flex-auto mt-8 lg:flex lg:space-y-0 lg:flex-row lg:items-center lg:space-x-10 lg:mt-0"
|
||||
>
|
||||
<router-link
|
||||
v-if="inCourse()"
|
||||
to="/learn/versicherungsvermittlerin-lp"
|
||||
v-if="inCourse() && courseSessionsStore.courseSessionForRoute"
|
||||
:to="courseSessionsStore.courseSessionForRoute.learning_path_url"
|
||||
class="nav-item"
|
||||
:class="{ 'nav-item--active': isInRoutePath(['/learn']) }"
|
||||
>
|
||||
|
|
@ -165,8 +153,8 @@ const profileDropdownData: DropdownListItem[] = [
|
|||
</router-link>
|
||||
|
||||
<router-link
|
||||
v-if="inCourse()"
|
||||
to="/competence/versicherungsvermittlerin-competence"
|
||||
v-if="inCourse() && courseSessionsStore.courseSessionForRoute"
|
||||
:to="courseSessionsStore.courseSessionForRoute.competence_url"
|
||||
class="nav-item"
|
||||
:class="{ 'nav-item--active': isInRoutePath(['/competence']) }"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import IconLogout from "@/components/icons/IconLogout.vue";
|
|||
import IconSettings from "@/components/icons/IconSettings.vue";
|
||||
import ItFullScreenModal from "@/components/ui/ItFullScreenModal.vue";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import type { CourseSession } from "@/types";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
const router = useRouter();
|
||||
|
|
@ -10,15 +11,16 @@ const userStore = useUserStore();
|
|||
|
||||
const props = defineProps<{
|
||||
show: boolean;
|
||||
learningPathName: string;
|
||||
learningPathSlug: string;
|
||||
courseSession: CourseSession | undefined;
|
||||
}>();
|
||||
|
||||
const emits = defineEmits(["closemodal"]);
|
||||
|
||||
const clickLink = (to: string) => {
|
||||
router.push(to);
|
||||
emits("closemodal");
|
||||
const clickLink = (to: string | undefined) => {
|
||||
if (to) {
|
||||
router.push(to);
|
||||
emits("closemodal");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
@ -48,18 +50,16 @@ const clickLink = (to: string) => {
|
|||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div v-if="true" class="mt-6 pb-6 border-b">
|
||||
<h4 class="text-gray-900 text-sm">Kurs: Versicherungsvermittler/in</h4>
|
||||
<div v-if="courseSession" class="mt-6 pb-6 border-b">
|
||||
<h4 class="text-gray-900 text-sm">{{ courseSession.course.title }}</h4>
|
||||
<ul class="mt-6">
|
||||
<li>
|
||||
<button @click="clickLink(`/learn/versicherungsvermittlerin-lp`)">
|
||||
<button @click="clickLink(courseSession?.learning_path_url)">
|
||||
{{ $t("general.learningPath") }}
|
||||
</button>
|
||||
</li>
|
||||
<li class="mt-6">
|
||||
<button
|
||||
@click="clickLink(`/competence/versicherungsvermittlerin-competence`)"
|
||||
>
|
||||
<button @click="clickLink(courseSession?.competence_url)">
|
||||
KompetenzNavi
|
||||
</button>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -18,12 +18,7 @@ function employer() {
|
|||
|
||||
onMounted(async () => {
|
||||
log.debug("CockpitView mounted");
|
||||
|
||||
try {
|
||||
await courseSessionsStore.loadCourseSessionsData();
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
await courseSessionsStore.loadCourseSessionsData();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,40 @@ import { itGetCached } from "@/fetchHelpers";
|
|||
import type { CourseSession } from "@/types";
|
||||
import log from "loglevel";
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
export const useCourseSessionsStore = defineStore("courseSessions", () => {
|
||||
const courseSessions = ref<CourseSession[] | undefined>(undefined);
|
||||
export type CourseSessionsStoreState = {
|
||||
courseSessions: CourseSession[] | undefined;
|
||||
};
|
||||
|
||||
async function loadCourseSessionsData(reload = false) {
|
||||
log.debug("loadCourseSessionsData called");
|
||||
courseSessions.value = await itGetCached(`/api/course/sessions/`, {
|
||||
reload: reload,
|
||||
});
|
||||
if (!courseSessions.value) {
|
||||
throw `No courseSessionData found for user`;
|
||||
}
|
||||
return courseSessions.value;
|
||||
}
|
||||
|
||||
return { courseSessions, loadCourseSessionsData };
|
||||
export const useCourseSessionsStore = defineStore({
|
||||
id: "courseSessions",
|
||||
state: () => {
|
||||
return {
|
||||
courseSessions: undefined,
|
||||
} as CourseSessionsStoreState;
|
||||
},
|
||||
getters: {
|
||||
courseSessionForRoute: (state) => {
|
||||
const route = useRoute();
|
||||
return state.courseSessions?.find((cs) => {
|
||||
return (
|
||||
route.path.startsWith(cs.learning_path_url) ||
|
||||
route.path.startsWith(cs.competence_url)
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async loadCourseSessionsData(reload = false) {
|
||||
log.debug("loadCourseSessionsData called");
|
||||
this.courseSessions = await itGetCached(`/api/course/sessions/`, {
|
||||
reload: reload,
|
||||
});
|
||||
if (!this.courseSessions) {
|
||||
throw `No courseSessionData found for user`;
|
||||
}
|
||||
return this.courseSessions;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue