Access courseSession by `useCurrentCourseSession`

This commit is contained in:
Daniel Egger 2023-05-16 14:32:05 +02:00
parent 44131f1d8b
commit 2f9fbed8f5
12 changed files with 52 additions and 78 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import { useCockpitStore } from "@/stores/cockpit";
import { useCompetenceStore } from "@/stores/competence";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useLearningPathStore } from "@/stores/learningPath";
import { useUserStore } from "@/stores/user";
import * as log from "loglevel";
@ -16,25 +16,22 @@ const props = defineProps<{
const cockpitStore = useCockpitStore();
const competenceStore = useCompetenceStore();
const learningPathStore = useLearningPathStore();
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
onMounted(async () => {
log.debug("CockpitParentPage mounted", props.courseSlug);
try {
const currentCourseSession = courseSessionsStore.currentCourseSession;
if (currentCourseSession?.id) {
await cockpitStore.loadCourseSessionUsers(currentCourseSession.id);
cockpitStore.courseSessionUsers?.forEach((csu) => {
competenceStore.loadCompetenceProfilePage(
props.courseSlug + "-competence",
csu.user_id
);
await cockpitStore.loadCourseSessionUsers(courseSession.id);
cockpitStore.courseSessionUsers?.forEach((csu) => {
competenceStore.loadCompetenceProfilePage(
props.courseSlug + "-competence",
csu.user_id
);
learningPathStore.loadLearningPath(props.courseSlug + "-lp", csu.user_id);
});
learningPathStore.loadLearningPath(props.courseSlug + "-lp", useUserStore().id);
}
learningPathStore.loadLearningPath(props.courseSlug + "-lp", csu.user_id);
});
learningPathStore.loadLearningPath(props.courseSlug + "-lp", useUserStore().id);
} catch (error) {
log.error(error);
}

View File

@ -59,8 +59,8 @@ import HorizontalBarChart from "@/components/ui/HorizontalBarChart.vue";
import OpenFeedback from "@/components/ui/OpenFeedback.vue";
import RatingScale from "@/components/ui/RatingScale.vue";
import VerticalBarChart from "@/components/ui/VerticalBarChart.vue";
import { useCurrentCourseSession } from "@/composables";
import { itGet } from "@/fetchHelpers";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import * as log from "loglevel";
import { onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
@ -79,7 +79,7 @@ const props = defineProps<{
log.debug("FeedbackPage created", props.circleId);
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const { t } = useI18n();
const orderedQuestions = [
@ -144,7 +144,7 @@ const feedbackData = reactive<FeedbackData>({ amount: 0, questions: {} });
onMounted(async () => {
log.debug("FeedbackPage mounted");
const data = await itGet(
`/api/core/feedback/${courseSessionsStore.currentCourseSession?.course.id}/${props.circleId}`
`/api/core/feedback/${courseSession.course.id}/${props.circleId}`
);
Object.assign(feedbackData, data);
});

View File

@ -1,8 +1,8 @@
<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import { ASSIGNMENT_COMPLETION_QUERY } from "@/graphql/queries";
import EvaluationContainer from "@/pages/cockpit/assignmentEvaluationPage/EvaluationContainer.vue";
import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import type {
Assignment,
AssignmentCompletion,
@ -32,14 +32,14 @@ const state: StateInterface = reactive({
assignmentUser: undefined,
});
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const router = useRouter();
// noinspection TypeScriptValidateTypes TODO: because of IntelliJ
const queryResult = useQuery({
query: ASSIGNMENT_COMPLETION_QUERY,
variables: {
courseSessionId: courseSessionsStore.currentCourseSession!.id.toString(),
courseSessionId: courseSession.id.toString(),
assignmentId: props.assignmentId,
assignmentUserId: props.userId,
},
@ -48,11 +48,9 @@ const queryResult = useQuery({
onMounted(async () => {
log.debug("AssignmentView mounted", props.assignmentId, props.userId);
if (courseSessionsStore.currentCourseSession) {
state.assignmentUser = courseSessionsStore.currentCourseSession.users.find(
(user) => user.user_id === Number(props.userId)
);
}
state.assignmentUser = courseSession.users.find(
(user) => user.user_id === Number(props.userId)
);
});
function close() {

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import type { Assignment, AssignmentCompletion, CourseSessionUser } from "@/types";
import { useMutation } from "@urql/vue";
import dayjs, { Dayjs } from "dayjs";
@ -17,7 +17,7 @@ const emit = defineEmits(["startEvaluation"]);
log.debug("EvaluationIntro setup");
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const upsertAssignmentCompletionMutation = useMutation(
UPSERT_ASSIGNMENT_COMPLETION_MUTATION
@ -29,7 +29,7 @@ async function startEvaluation() {
// noinspection TypeScriptValidateTypes
upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignment.id.toString(),
courseSessionId: (courseSessionsStore?.currentCourseSession?.id ?? 0).toString(),
courseSessionId: courseSession.id.toString(),
assignmentUserId: props.assignmentUser.user_id.toString(),
completionStatus: "EVALUATION_IN_PROGRESS",
completionDataString: JSON.stringify({}),

View File

@ -1,12 +1,12 @@
<script setup lang="ts">
import ItSuccessAlert from "@/components/ui/ItSuccessAlert.vue";
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import {
maxAssignmentPoints,
pointsToGrade,
userAssignmentPoints,
} from "@/services/assignmentService";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import type {
Assignment,
AssignmentCompletion,
@ -34,7 +34,7 @@ const state = reactive({
log.debug("EvaluationSummary setup");
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const upsertAssignmentCompletionMutation = useMutation(
UPSERT_ASSIGNMENT_COMPLETION_MUTATION
@ -44,7 +44,7 @@ async function submitEvaluation() {
// noinspection TypeScriptValidateTypes
upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignment.id.toString(),
courseSessionId: (courseSessionsStore?.currentCourseSession?.id ?? 0).toString(),
courseSessionId: courseSession.id.toString(),
assignmentUserId: props.assignmentUser.user_id.toString(),
completionStatus: "EVALUATION_SUBMITTED",
completionDataString: JSON.stringify({}),
@ -87,7 +87,7 @@ const grade = computed(() => {
const evaluationUser = computed(() => {
if (props.assignmentCompletion.evaluation_user) {
return (courseSessionsStore.currentCourseSession?.users ?? []).find(
return (courseSession.users ?? []).find(
(user) => user.user_id === Number(props.assignmentCompletion.evaluation_user)
) as CourseSessionUser;
}

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import ItTextarea from "@/components/ui/ItTextarea.vue";
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import type {
Assignment,
AssignmentCompletion,
@ -24,7 +24,7 @@ const props = defineProps<{
log.debug("EvaluationTask setup", props.taskIndex);
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const task = computed(() => props.assignment.evaluation_tasks[props.taskIndex]);
@ -68,7 +68,7 @@ async function evaluateAssignmentCompletion(completionData: AssignmentCompletion
// noinspection TypeScriptValidateTypes
upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignment.id.toString(),
courseSessionId: (courseSessionsStore?.currentCourseSession?.id ?? 0).toString(),
courseSessionId: courseSession.id.toString(),
assignmentUserId: props.assignmentUser.user_id.toString(),
completionStatus: "EVALUATION_IN_PROGRESS",
completionDataString: JSON.stringify(completionData),

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import AssignmentDetails from "@/pages/cockpit/assignmentsPage/AssignmentDetails.vue";
import { calcAssignmentLearningContents } from "@/services/assignmentService";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useLearningPathStore } from "@/stores/learningPath";
import { useUserStore } from "@/stores/user";
import * as log from "loglevel";
@ -14,31 +14,23 @@ const props = defineProps<{
log.debug("AssignmentsPage created", props.courseSlug);
const learningPathStore = useLearningPathStore();
const courseSessionsStore = useCourseSessionsStore();
const userStore = useUserStore();
const courseSession = useCurrentCourseSession();
onMounted(async () => {
log.debug("AssignmentsPage mounted");
});
const assignments = computed(() => {
// TODO: filter by selected circle
if (!courseSessionsStore.currentCourseSession) {
return [];
}
return calcAssignmentLearningContents(
learningPathStore.learningPathForUser(
courseSessionsStore.currentCourseSession.course.slug,
userStore.id
)
learningPathStore.learningPathForUser(courseSession.course.slug, userStore.id)
);
});
</script>
<template>
<div class="bg-gray-200">
<div v-if="courseSessionsStore.currentCourseSession" class="container-large">
<div class="container-large">
<nav class="py-4 pb-4">
<router-link
class="btn-text inline-flex items-center pl-0"
@ -58,7 +50,7 @@ const assignments = computed(() => {
<div v-for="assignment in assignments" :key="assignment.id">
<div class="bg-white p-6">
<AssignmentDetails
:course-session="courseSessionsStore.currentCourseSession"
:course-session="courseSession"
:assignment="assignment"
/>
</div>

View File

@ -5,10 +5,10 @@ import ItPersonRow from "@/components/ui/ItPersonRow.vue";
import ItProgress from "@/components/ui/ItProgress.vue";
import type { LearningPath } from "@/services/learningPath";
import { useCurrentCourseSession } from "@/composables";
import AssignmentsTile from "@/pages/cockpit/cockpitPage/AssignmentsTile.vue";
import { useCockpitStore } from "@/stores/cockpit";
import { useCompetenceStore } from "@/stores/competence";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useLearningPathStore } from "@/stores/learningPath";
import { useUserStore } from "@/stores/user";
import groupBy from "lodash/groupBy";
@ -25,7 +25,7 @@ const userStore = useUserStore();
const cockpitStore = useCockpitStore();
const competenceStore = useCompetenceStore();
const learningPathStore = useLearningPathStore();
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
function userCountStatusForCircle(userId: number, translationKey: string) {
const criteria = competenceStore.flatPerformanceCriteria(
@ -102,10 +102,7 @@ function setActiveClasses(translationKey: string) {
</div>
<!-- Status -->
<div class="mb-4 grid grid-rows-2 gap-4 lg:grid-cols-2 lg:grid-rows-none">
<AssignmentsTile
v-if="courseSessionsStore.currentCourseSession"
:course-session="courseSessionsStore.currentCourseSession"
/>
<AssignmentsTile :course-session="courseSession" />
<div class="bg-white px-6 py-5">
<h3 class="heading-3 mb-4 flex items-center gap-2">
<it-icon-test-large class="h-16 w-16"></it-icon-test-large>
@ -124,8 +121,8 @@ function setActiveClasses(translationKey: string) {
learningPathStore.learningPathForUser(props.courseSlug, userStore.id)
?.circles || []
"
:course-id="courseSessionsStore.currentCourseSession?.course.id || 0"
:url="courseSessionsStore.currentCourseSession?.course_url || ''"
:course-id="courseSession.course.id"
:url="courseSession.course_url || ''"
></FeedbackSummary>
<div>
<!-- progress -->

View File

@ -2,6 +2,7 @@
import ItButton from "@/components/ui/ItButton.vue";
import ItCheckbox from "@/components/ui/ItCheckbox.vue";
import ItSuccessAlert from "@/components/ui/ItSuccessAlert.vue";
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions";
@ -24,6 +25,7 @@ const emit = defineEmits<{
}>();
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const { t } = useI18n();
const state = reactive({
@ -57,16 +59,10 @@ const onEditTask = (task: AssignmentTask) => {
const onSubmit = async () => {
try {
const courseSessionId = courseSessionsStore.currentCourseSession?.id;
if (!courseSessionId) {
log.error("Invalid courseSessionId");
return;
}
// noinspection TypeScriptValidateTypes
upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignment.id.toString(),
courseSessionId: courseSessionId.toString(),
courseSessionId: courseSession.id.toString(),
completionDataString: JSON.stringify({}),
completionStatus: "SUBMITTED",
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

View File

@ -1,8 +1,8 @@
<script setup lang="ts">
import ItCheckbox from "@/components/ui/ItCheckbox.vue";
import ItTextarea from "@/components/ui/ItTextarea.vue";
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import type {
AssignmentCompletion,
AssignmentCompletionData,
@ -23,7 +23,7 @@ const props = defineProps<{
const checkboxState = reactive({} as Record<string, boolean>);
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const upsertAssignmentCompletionMutation = useMutation(
UPSERT_ASSIGNMENT_COMPLETION_MUTATION
@ -31,16 +31,10 @@ const upsertAssignmentCompletionMutation = useMutation(
async function upsertAssignmentCompletion(completion_data: AssignmentCompletionData) {
try {
const courseSessionId = courseSessionsStore.currentCourseSession?.id;
if (!courseSessionId) {
console.error("Invalid courseSessionId");
return;
}
// noinspection TypeScriptValidateTypes
await upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignmentId.toString(),
courseSessionId: courseSessionId.toString(),
courseSessionId: courseSession.id.toString(),
completionDataString: JSON.stringify(completion_data),
completionStatus: "IN_PROGRESS",
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

View File

@ -1,4 +1,5 @@
<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import { ASSIGNMENT_COMPLETION_QUERY } from "@/graphql/queries";
import EvaluationSummary from "@/pages/cockpit/assignmentEvaluationPage/EvaluationSummary.vue";
@ -6,7 +7,6 @@ import AssignmentIntroductionView from "@/pages/learningPath/learningContentPage
import AssignmentSubmissionView from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionView.vue";
import AssignmentTaskView from "@/pages/learningPath/learningContentPage/assignment/AssignmentTaskView.vue";
import LearningContentMultiLayout from "@/pages/learningPath/learningContentPage/layouts/LearningContentMultiLayout.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useUserStore } from "@/stores/user";
import type {
Assignment,
@ -24,7 +24,7 @@ import { computed, onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const courseSessionsStore = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const userStore = useUserStore();
interface State {
@ -43,7 +43,7 @@ const props = defineProps<{
const queryResult = useQuery({
query: ASSIGNMENT_COMPLETION_QUERY,
variables: {
courseSessionId: courseSessionsStore.currentCourseSession!.id.toString(),
courseSessionId: courseSession.id.toString(),
assignmentId: props.learningContent.content_assignment_id.toString(),
},
pause: true,

View File

@ -3,10 +3,10 @@ import { useCircleStore } from "@/stores/circle";
import type { LearningUnit } from "@/types";
import * as log from "loglevel";
import { useCurrentCourseSession } from "@/composables";
import { COMPLETION_FAILURE, COMPLETION_SUCCESS } from "@/constants";
import LearningContentContainer from "@/pages/learningPath/learningContentPage/LearningContentContainer.vue";
import LearningContentMultiLayout from "@/pages/learningPath/learningContentPage/layouts/LearningContentMultiLayout.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import eventBus from "@/utils/eventBus";
import { useRouteQuery } from "@vueuse/router";
import { computed, onUnmounted } from "vue";
@ -14,7 +14,7 @@ import { computed, onUnmounted } from "vue";
log.debug("LearningContent.vue setup");
const circleStore = useCircleStore();
const courseSession = useCourseSessionsStore();
const courseSession = useCurrentCourseSession();
const questionIndex = useRouteQuery("step", "0", { transform: Number, mode: "push" });
@ -124,7 +124,7 @@ onUnmounted(() => {
<div class="mt-6 lg:mt-12">
{{ $t("selfEvaluation.progressText") }}
<router-link
:to="courseSession.currentCourseSession?.competence_url || '/'"
:to="courseSession.competence_url"
class="text-primary-500 underline"
>
{{ $t("selfEvaluation.progressLink") }}