vbv/client/src/router/index.ts

494 lines
14 KiB
TypeScript

import LoginPage from "@/pages/LoginPage.vue";
import DashboardPage from "@/pages/dashboard/DashboardPage.vue";
import GuestStartPage from "@/pages/start/GuestStartPage.vue";
import UKStartPage from "@/pages/start/UKStartPage.vue";
import VVStartPage from "@/pages/start/VVStartPage.vue";
import {
handleAcceptLearningMentorInvitation,
handleCourseSessionAsQueryParam,
handleCurrentCourseSession,
redirectToLoginIfRequired,
updateLoggedIn,
} from "@/router/guards";
import { addToHistory, setLastNavigationWasPush } from "@/router/history";
import { onboardingRedirect } from "@/router/onboarding";
import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else {
return { top: 0 };
}
},
routes: [
{
path: "/start",
name: "start",
component: GuestStartPage,
meta: {
public: true,
},
},
{
path: "/start/vv",
component: VVStartPage,
name: "vvStart",
meta: {
public: true,
},
},
{
path: "/start/uk",
component: UKStartPage,
name: "ukStart",
meta: {
public: true,
},
},
{
path: "/login-local",
component: LoginPage,
meta: {
public: true,
},
},
{
path: "/",
name: "home",
component: DashboardPage,
},
{
path: "/dashboard/persons",
component: () => import("@/pages/dashboard/DashboardPersonsPage.vue"),
},
{
path: "/dashboard/persons-competence",
component: () => import("@/pages/dashboard/DashboardPersonsPage.vue"),
props: { mode: "competenceMetrics" },
},
{
path: "/dashboard/due-dates",
component: () => import("@/pages/dashboard/DashboardDueDatesPage.vue"),
},
{
path: "/dashboard/cost/:courseSessionId",
component: () => import("@/pages/dashboard/DashboardCostPage.vue"),
props: true,
},
{
path: "/course/:courseSlug/media",
props: true,
component: () => import("@/pages/mediaLibrary/MediaLibraryParentPage.vue"),
children: [
{
path: "",
component: () => import("@/pages/mediaLibrary/MediaLibraryIndexPage.vue"),
},
{
path: ":categorySlug",
props: true,
component: () => import("@/pages/mediaLibrary/MediaLibraryCategoryPage.vue"),
},
{
path: ":categorySlug/:contentSlug",
props: true,
component: () => import("@/pages/mediaLibrary/MediaLibraryContentPage.vue"),
},
],
},
{
path: "/course/:courseSlug/competence",
props: true,
component: () => import("@/pages/competence/CompetenceParentPage.vue"),
children: [
{
path: "",
props: true,
component: () => import("@/pages/competence/CompetenceIndexPage.vue"),
},
{
path: "certificates",
props: true,
component: () =>
import("@/pages/competence/CompetenceCertificateListPage.vue"),
},
{
path: "certificates/:certificateSlug",
props: true,
component: () =>
import("@/pages/competence/CompetenceCertificateDetailPage.vue"),
},
{
name: "selfEvaluationAndFeedback",
path: "self-evaluation-and-feedback",
props: true,
component: () =>
import("@/pages/competence/SelfEvaluationAndFeedbackPage.vue"),
},
{
path: "competences",
props: true,
component: () => import("@/pages/competence/ActionCompetenceListPage.vue"),
},
],
},
{
path: "/course/:courseSlug/learn",
component: () =>
import("../pages/learningPath/learningPathPage/LearningPathPage.vue"),
props: true,
},
{
path: "/course/:courseSlug/learn/:circleSlug",
component: () => import("../pages/learningPath/circlePage/CirclePage.vue"),
props: true,
},
{
path: "/course/:courseSlug/learn/:circleSlug/evaluate/:learningUnitSlug",
component: () =>
import("../pages/learningPath/selfEvaluationPage/SelfEvaluationPage.vue"),
props: true,
},
{
path: "/course/:courseSlug/learn/:circleSlug/:contentSlug",
component: () =>
import("../pages/learningPath/learningContentPage/LearningContentPage.vue"),
props: true,
},
{
path: "/lernbegleitung/:courseId/invitation/:invitationId",
component: () => import("@/pages/learningMentor/InvitationAcceptPage.vue"),
props: true,
beforeEnter: handleAcceptLearningMentorInvitation,
meta: {
// The login redirect is handled in the beforeEnter guard
public: true,
},
},
{
path: "/course/:courseSlug/profile/:userId",
component: () => import("@/pages/userProfile/UserProfilePage.vue"),
props: true,
children: [
{
path: "learning-path",
component: () => import("@/pages/userProfile/LearningPathProfilePage.vue"),
props: true,
name: "profileLearningPath",
meta: {
hideChrome: true,
showCloseButton: true,
},
},
{
path: "competence",
component: () => import("@/pages/userProfile/CompetenceProfilePage.vue"),
props: true,
name: "profileCompetence",
children: [
{
path: "",
name: "competenceMain",
component: () =>
import(
"@/components/selfEvaluationFeedback/SelfEvaluationAndFeedbackOverview.vue"
),
meta: {
hideChrome: true,
showCloseButton: true,
},
},
{
path: "evaluations",
name: "competenceEvaluations",
component: () =>
import(
"@/components/selfEvaluationFeedback/SelfEvaluationAndFeedbackList.vue"
),
},
{
path: "certificates/:certificateSlug",
name: "competenceCertificateDetail",
props: true,
component: () =>
import("@/pages/competence/CompetenceCertificateDetailPage.vue"),
},
{
path: "certificates",
name: "competenceCertificates",
component: () =>
import("@/pages/competence/CompetenceCertificateListPage.vue"),
},
],
},
],
},
{
path: "/course/:courseSlug/learning-mentor",
component: () => import("@/pages/learningMentor/mentor/MentorIndexPage.vue"),
props: true,
name: "learningMentor",
children: [
{
path: "",
component: () =>
import("@/pages/learningMentor/mentor/MentorParticipantsPage.vue"),
name: "mentorsAndParticipants",
},
{
path: "tasks",
component: () =>
import("@/pages/learningMentor/mentor/MentorOverviewPage.vue"),
name: "learningMentorOverview",
},
{
path: "self-evaluation-feedback/:learningUnitId",
component: () =>
import("@/pages/learningMentor/mentor/SelfEvaluationFeedbackPage.vue"),
name: "mentorSelfEvaluationFeedback",
props: true,
},
{
path: "details",
component: () =>
import("@/pages/learningMentor/mentor/MentorDetailParentPage.vue"),
children: [
{
path: "praxis-assignments/:praxisAssignmentId",
component: () =>
import("@/pages/learningMentor/mentor/MentorPraxisAssignmentPage.vue"),
name: "learningMentorPraxisAssignments",
props: true,
},
{
path: "self-evaluation-feedback-assignments/:learningUnitId",
component: () =>
import(
"@/pages/learningMentor/mentor/MentorSelfEvaluationFeedbackAssignmentPage.vue"
),
name: "learningMentorSelfEvaluationFeedbackAssignments",
props: true,
},
],
},
],
},
{
path: "/course/:courseSlug/assignment-evaluation/:assignmentId/:userId",
component: () =>
import("@/pages/assignmentEvaluation/AssignmentEvaluationPage.vue"),
props: true,
},
{
path: "/course/:courseSlug/cockpit",
name: "cockpit",
children: [
{
path: "",
component: () => import("@/pages/cockpit/cockpitPage/CockpitExpertPage.vue"),
props: true,
},
{
path: "profile/:userId/:circleSlug",
component: () => import("@/pages/cockpit/CockpitUserCirclePage.vue"),
props: true,
},
{
path: "feedback/:circleId",
component: () => import("@/pages/cockpit/FeedbackPage.vue"),
props: true,
},
{
path: "assignment/:assignmentId",
component: () =>
import("@/pages/cockpit/assignmentsPage/AssignmentsPage.vue"),
props: true,
},
{
path: "attendance",
component: () =>
import("@/pages/cockpit/attendanceCheckPage/AttendanceCheckPage.vue"),
props: true,
},
{
path: "documents",
component: () => import("@/pages/cockpit/documentPage/DocumentPage.vue"),
props: true,
},
],
},
{
path: "/statistic/:courseSlug",
props: true,
component: () => import("@/pages/dashboard/statistic/StatisticParentPage.vue"),
children: [
{
path: "attendance",
props: true,
component: () => import("@/pages/dashboard/statistic/AttendanceList.vue"),
},
{
path: "assignment",
props: true,
component: () => import("@/pages/dashboard/statistic/AssignmentList.vue"),
},
{
path: "competence",
props: true,
component: () => import("@/pages/dashboard/statistic/CompetenceList.vue"),
},
{
path: "feedback",
props: true,
component: () => import("@/pages/dashboard/statistic/FeedbackList.vue"),
},
{
path: "list",
props: true,
component: () => import("@/pages/dashboard/CourseListPage.vue"),
},
],
},
{
path: "/statistic/:agentRole/:courseSlug/assignment",
props: true,
component: () =>
import("@/pages/dashboard/agentAssignment/AgentAssignmentStatisticPage.vue"),
},
{
path: "/statistic/:agentRole/:courseSlug/assignment/:assignmentId",
props: true,
component: () =>
import("@/pages/dashboard/agentAssignment/AgentAssignmentDetailPage.vue"),
},
{
path: "/statistic/:agentRole/:courseSlug/competence-grade",
props: true,
component: () =>
import("@/pages/dashboard/agentAssignment/AgentCompetenceGradePage.vue"),
},
{
path: "/statistic/:agentRole/:courseSlug/competence-grade/:courseSessionId/:competenceCertificateId",
props: true,
component: () =>
import("@/pages/dashboard/agentAssignment/AgentCompetenceGradeDetailPage.vue"),
},
{
path: "/shop",
component: () => import("@/pages/ShopPage.vue"),
},
{
path: "/messages",
component: () => import("@/pages/MessagesPage.vue"),
},
{
path: "/profile",
component: () => import("@/pages/personalProfile/PersonalProfilePage.vue"),
name: "personalProfile",
},
{
path: "/settings",
component: () => import("@/pages/SettingsPage.vue"),
},
{
path: "/notifications",
component: () => import("@/pages/NotificationsPage.vue"),
},
{
path: "/onboarding/:courseType",
props: true,
component: () => import("@/pages/onboarding/WizardBase.vue"),
meta: {
public: true,
hideChrome: true,
},
beforeEnter: onboardingRedirect,
children: [
{
path: "account/create",
component: () => import("@/pages/onboarding/AccountSetup.vue"),
name: "accountCreate",
props: true,
},
{
path: "account/confirm",
component: () => import("@/pages/onboarding/AccountConfirm.vue"),
name: "accountConfirm",
},
{
path: "account/profile",
component: () => import("@/pages/onboarding/AccountProfile.vue"),
name: "accountProfile",
},
{
path: "account/complete",
component: () => import("@/pages/onboarding/uk/SetupComplete.vue"),
name: "setupComplete",
},
{
path: "account/course-profile",
component: () => import("@/pages/onboarding/vv/AccountCourseProfile.vue"),
name: "accountCourseProfile",
props: true,
},
{
path: "checkout/address",
component: () => import("@/pages/onboarding/vv/CheckoutAddress.vue"),
name: "checkoutAddress",
props: true,
},
{
path: "checkout/complete",
component: () => import("@/pages/onboarding/vv/CheckoutComplete.vue"),
name: "checkoutComplete",
},
],
},
{
path: "/styleguide",
component: () => import("../pages/StyleGuidePage.vue"),
meta: {
public: true,
},
},
{
path: "/:pathMatch(.*)*",
component: () => import("../pages/404Page.vue"),
},
],
});
router.beforeEach(updateLoggedIn);
router.beforeEach(redirectToLoginIfRequired);
// register after login hooks
router.beforeEach(async (to) => await handleCurrentCourseSession(to));
router.beforeEach(async (to) => await handleCourseSessionAsQueryParam(to));
// only unset the current course session in the after hook
router.afterEach(async (to) => await handleCurrentCourseSession(to, { unset: true }));
router.beforeEach(addToHistory);
// Wrap router.replace to track when it's called
const originalReplace = router.replace;
router.replace = function (to) {
setLastNavigationWasPush(false);
return originalReplace.call(this, to);
};
// Wrap router.push to track when it's called
const originalPush = router.push;
router.push = function (to) {
setLastNavigationWasPush(true);
return originalPush.call(this, to);
};
export default router;