From 46a2f6a3ba868c6a27eac8149c467a6b38067b90 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 18 Apr 2024 16:15:30 +0200 Subject: [PATCH] Add filters to dashboard person table --- .../pages/dashboard/DashboardPersonsPage.vue | 142 ++++++++++++++++-- 1 file changed, 131 insertions(+), 11 deletions(-) diff --git a/client/src/pages/dashboard/DashboardPersonsPage.vue b/client/src/pages/dashboard/DashboardPersonsPage.vue index b4a96cc3..ac944f5a 100644 --- a/client/src/pages/dashboard/DashboardPersonsPage.vue +++ b/client/src/pages/dashboard/DashboardPersonsPage.vue @@ -2,10 +2,117 @@ import LoadingSpinner from "@/components/ui/LoadingSpinner.vue"; import log from "loglevel"; import { useDashboardPersons } from "@/composables"; +import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue"; +import { computed, ref, watch } from "vue"; +import { useTranslation } from "i18next-vue"; +import _ from "lodash"; +import type { DashboardPersonCourseSessionType } from "@/services/dashboard"; log.debug("DashboardPersonsPage created"); +const UNFILTERED = 0; + +type MenuItem = { + id: number; + name: string; +}; + +const { t } = useTranslation(); + const { loading: loadingPersons, dashboardPersons } = useDashboardPersons(); + +const courses = computed(() => { + return [ + { + id: UNFILTERED, + name: t("a.Alle Lehrgänge"), + }, + ..._(dashboardPersons.value) + .flatMap((person) => person.course_sessions) + .map((cs) => { + return { name: cs.course_title, id: cs.course_id }; + }) + .uniqBy("id") + .orderBy("name") + .value(), + ]; +}); + +const selectedCourse = ref(courses.value[0]); + +const courseSessions = computed(() => { + let sessions = _(dashboardPersons.value) + .flatMap((person) => person.course_sessions) + .map((cs) => { + return Object.assign({}, cs, { name: cs.session_title, id: cs.id }); + }) + .uniqBy("id") + .orderBy("name") + .value(); + + // filter by selected course + if (selectedCourse.value.id !== UNFILTERED) { + sessions = sessions.filter((cs) => cs.course_id === selectedCourse.value.id); + } + + return [ + { + id: UNFILTERED, + name: t("a.AlleDurchführungen"), + }, + ...sessions, + ]; +}); + +watch(selectedCourse, () => { + selectedSession.value = courseSessions.value[0]; +}); + +const selectedSession = ref(courseSessions.value[0]); + +const filteredPersons = computed(() => { + return _.orderBy( + dashboardPersons.value + .filter((person) => { + if (selectedCourse.value.id === UNFILTERED) { + return true; + } + return person.course_sessions.some( + (cs) => cs.course_id === selectedCourse.value.id + ); + }) + .filter((person) => { + if (selectedSession.value.id === UNFILTERED) { + return true; + } + return person.course_sessions.some((cs) => cs.id === selectedSession.value.id); + }), + ["last_name", "first_name"] + ); +}); + +const filtersVisible = computed(() => { + return courses.value.length > 2 || courseSessions.value.length > 2; +}); + +function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessionType) { + if (personCourseSession.is_uk) { + if (personCourseSession.user_role === "EXPERT") { + return t("a.Trainer"); + } + if (personCourseSession.user_role === "LEARNING_MENTOR") { + return t("a.Praxisbildner"); + } + } + + if (personCourseSession.is_vv) { + if (personCourseSession.user_role === "LEARNING_MENTOR") { + return t("a.Lernbegleitung"); + } + } + + return ""; +}