96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import { useCourseData, useCourseSessionDetailQuery } from "@/composables";
|
|
import type { CourseSessionAttendanceCourseObjectType } from "@/gql/graphql";
|
|
import { useUserStore } from "@/stores/user";
|
|
import type { CircleLight, CourseSessionUser, ExpertSessionUser } from "@/types";
|
|
import log from "loglevel";
|
|
import { defineStore } from "pinia";
|
|
import { computed, ref } from "vue";
|
|
|
|
type CircleExpertCockpit = CircleLight & {
|
|
name: string;
|
|
};
|
|
|
|
async function courseCircles(
|
|
courseSlug: string,
|
|
currentCourseSessionUser: CourseSessionUser | undefined
|
|
) {
|
|
if (currentCourseSessionUser && currentCourseSessionUser.role === "EXPERT") {
|
|
const expert = currentCourseSessionUser as ExpertSessionUser;
|
|
return expert.circles.map((c) => {
|
|
return { ...c, name: c.title };
|
|
});
|
|
}
|
|
|
|
const userStore = useUserStore();
|
|
// Return all circles from learning path for admin users
|
|
if (userStore.is_superuser) {
|
|
const lpQueryResult = useCourseData(courseSlug);
|
|
await lpQueryResult.resultPromise;
|
|
|
|
return (lpQueryResult.circles.value ?? []).map((c) => {
|
|
return {
|
|
id: c.id,
|
|
slug: c.slug,
|
|
title: c.title,
|
|
name: c.title,
|
|
} as const;
|
|
});
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
export type ExpertCockpitStoreState = {
|
|
courseSessionMembers: CourseSessionUser[] | undefined;
|
|
circles: CircleExpertCockpit[] | undefined;
|
|
currentCircle: CircleExpertCockpit | undefined;
|
|
};
|
|
|
|
export const useExpertCockpitStore = defineStore("expertCockpit", () => {
|
|
const courseSessionMembers = ref<CourseSessionUser[] | undefined>(undefined);
|
|
const circles = ref<CircleExpertCockpit[] | undefined>([]);
|
|
const currentCircle = ref<CircleExpertCockpit | undefined>(undefined);
|
|
const courseSessionDetailResult = useCourseSessionDetailQuery();
|
|
|
|
const attendanceCourses = computed(() => {
|
|
return (
|
|
courseSessionDetailResult.courseSessionDetail.value?.attendance_courses ?? []
|
|
);
|
|
});
|
|
|
|
const currentCourse = computed(() => {
|
|
return attendanceCourses.value.find(
|
|
(i) => i.learning_content.circle?.id == currentCircle.value?.id
|
|
);
|
|
});
|
|
|
|
const loadCircles = async (
|
|
courseSlug: string,
|
|
currentCourseSessionUser: CourseSessionUser | undefined
|
|
) => {
|
|
log.debug("loadCircles called", courseSlug);
|
|
|
|
circles.value = await courseCircles(courseSlug, currentCourseSessionUser);
|
|
|
|
if (circles.value?.length) {
|
|
await setCurrentCourseCircle(circles.value[0].slug);
|
|
}
|
|
};
|
|
|
|
const setCurrentCourseCircle = async (circleSlug: string) => {
|
|
currentCircle.value = circles.value?.find((c) => c.slug === circleSlug);
|
|
};
|
|
const setCurrentCourseCircleFromEvent = async (event: CircleLight) => {
|
|
await setCurrentCourseCircle(event.slug);
|
|
};
|
|
|
|
return {
|
|
courseSessionMembers,
|
|
circles,
|
|
currentCircle,
|
|
loadCircles,
|
|
currentCourse,
|
|
setCurrentCourseCircleFromEvent,
|
|
};
|
|
});
|