From 4672698895ed7d4d8d803f9e3733ccdc7c75fae4 Mon Sep 17 00:00:00 2001 From: Livio Bieri Date: Thu, 28 Sep 2023 17:08:22 +0200 Subject: [PATCH] wip: appointment filtering poc --- .../components/header/MainNavigationBar.vue | 20 ++- client/src/pages/AppointmentsPage.vue | 118 ++++++++++++++++++ client/src/router/index.ts | 4 + client/src/utils/route.ts | 14 ++- 4 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 client/src/pages/AppointmentsPage.vue diff --git a/client/src/components/header/MainNavigationBar.vue b/client/src/components/header/MainNavigationBar.vue index 09de45af..75792952 100644 --- a/client/src/components/header/MainNavigationBar.vue +++ b/client/src/components/header/MainNavigationBar.vue @@ -23,8 +23,14 @@ const breakpoints = useBreakpoints(breakpointsTailwind); const userStore = useUserStore(); const courseSessionsStore = useCourseSessionsStore(); const notificationsStore = useNotificationsStore(); -const { inCockpit, inCompetenceProfile, inCourse, inLearningPath, inMediaLibrary } = - useRouteLookups(); +const { + inCockpit, + inCompetenceProfile, + inCourse, + inLearningPath, + inMediaLibrary, + inDueDates, +} = useRouteLookups(); const { t } = useTranslation(); const state = reactive({ @@ -159,6 +165,16 @@ onMounted(() => {
+ + + + +import { computed, ref, watch } from "vue"; +import { useCourseSessionsStore } from "@/stores/courseSessions"; +import { useLearningPathStore } from "@/stores/learningPath"; +import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue"; + +const UNFILTERED = Number.MAX_SAFE_INTEGER; + +const courseSessionsStore = useCourseSessionsStore(); +const learningPathStore = useLearningPathStore(); + +function getCourseSession(id: number) { + return courseSessionsStore.allCourseSessions.find((cs) => cs.id === id); +} + +const allItem = { + id: UNFILTERED, + name: "Alle", +}; + +const circles = ref([{ ...allItem }]); + +const courseSessions = [ + { ...allItem }, + ...courseSessionsStore.allCourseSessions.map((courseSession) => ({ + id: courseSession.id, + name: courseSession.title, + })), +]; + +const selectedSession = ref(courseSessions[0]); +const selectedCircle = ref(circles.value[0]); + +watch(selectedSession, async () => { + const cs = getCourseSession(selectedSession.value.id); + + if (selectedSession.value.id === UNFILTERED || !cs) { + circles.value = [{ ...allItem }]; + selectedCircle.value = circles.value[0]; + return; + } + + const data = await learningPathStore.loadLearningPath( + cs.course.slug + "-lp", + undefined, + false, + false + ); + + circles.value = + data?.circles.map((circle) => ({ + id: circle.id, + name: circle.title, + })) || []; + + circles.value = [{ ...allItem }, ...circles.value]; + selectedCircle.value = circles.value[0]; +}); + +const appointments = computed(() => { + console.log("recomputing appointments"); + console.log("current session", selectedSession.value.name); + console.log("current circle", selectedCircle.value.name); + const filtered = courseSessionsStore + .allDueDates() + .filter( + (appointment) => + // first filter by course session + selectedSession.value.id === UNFILTERED || + appointment.course_session === selectedSession.value.id + ) + .filter( + (appointment) => + // then filter by circle + selectedCircle.value.id === UNFILTERED || + appointment.circle?.id === selectedCircle.value.id + ); + console.table(filtered); + return filtered; +}); + + + + + diff --git a/client/src/router/index.ts b/client/src/router/index.ts index dac7036f..80aa4add 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -183,6 +183,10 @@ const router = createRouter({ path: "/notifications", component: () => import("@/pages/NotificationsPage.vue"), }, + { + path: "/appointments", + component: () => import("@/pages/AppointmentsPage.vue"), + }, { path: "/styleguide", component: () => import("../pages/StyleGuidePage.vue"), diff --git a/client/src/utils/route.ts b/client/src/utils/route.ts index 71f147a2..11a566a4 100644 --- a/client/src/utils/route.ts +++ b/client/src/utils/route.ts @@ -27,5 +27,17 @@ export function useRouteLookups() { return regex.test(route.path); } - return { inMediaLibrary, inCockpit, inLearningPath, inCompetenceProfile, inCourse }; + function inDueDates() { + const regex = new RegExp("/[^/]+/duedates"); + return regex.test(route.path); + } + + return { + inMediaLibrary, + inCockpit, + inLearningPath, + inCompetenceProfile, + inCourse, + inDueDates, + }; }