useCompetenceStore is not needed anymore

This commit is contained in:
Daniel Egger 2023-10-13 17:26:04 +02:00
parent 20ccf7d38b
commit e5cc0aa80e
9 changed files with 33 additions and 205 deletions

View File

@ -433,6 +433,7 @@ export type LearningContentEdoniqTestObjectType = CoursePageInterface & Learning
course?: Maybe<CourseObjectType>;
description: Scalars['String']['output'];
frontend_url: Scalars['String']['output'];
has_extended_time_test: Scalars['Boolean']['output'];
id: Scalars['ID']['output'];
live: Scalars['Boolean']['output'];
minutes?: Maybe<Scalars['Int']['output']>;

View File

@ -463,6 +463,7 @@ type LearningContentEdoniqTestObjectType implements CoursePageInterface & Learni
can_user_self_toggle_course_completion: Boolean!
circle: CircleLightObjectType
competence_certificate: CompetenceCertificateObjectType
has_extended_time_test: Boolean!
}
type CourseSessionUserObjectsType {

View File

@ -1,8 +1,8 @@
<script setup lang="ts">
import { useCompetenceStore } from "@/stores/competence";
import * as log from "loglevel";
import { computed } from "vue";
import _ from "lodash";
import { useLearningPathWithCompletion } from "@/composables";
const props = defineProps<{
courseSlug: string;
@ -10,28 +10,30 @@ const props = defineProps<{
log.debug("PerformanceCriteriaPage created", props);
const competenceStore = useCompetenceStore();
const courseCompletionData = useLearningPathWithCompletion(props.courseSlug);
const uniqueLearningUnits = computed(() => {
// FIXME: this complex calculation can go away,
// once the criteria are in its own learning content
// get the learningUnits sorted by circle order in the course
const circles = competenceStore.circles.map((c, index) => {
const circles = (courseCompletionData.circles.value ?? []).map((c, index) => {
return { ...c, sortKey: index };
});
return _.orderBy(
_.uniqBy(
competenceStore.flatPerformanceCriteria().map((pc) => {
return {
luId: pc.learning_unit.id,
luTitle: pc.learning_unit.title,
luSlug: pc.learning_unit.slug,
circleId: pc.circle.id,
circleTitle: pc.circle.title,
url: pc.learning_unit.evaluate_url,
sortKey: circles.find((c) => c.id === pc.circle.id)?.sortKey,
};
}),
(courseCompletionData.flatPerformanceCriteria.value ?? [])
.filter((pc) => Boolean(pc.learning_unit))
.map((pc) => {
return {
luId: pc.learning_unit?.id,
luTitle: pc.learning_unit?.title,
luSlug: pc.learning_unit?.slug,
circleId: pc.circle.id,
circleTitle: pc.circle.title,
url: pc.learning_unit?.evaluate_url,
sortKey: circles.find((c) => c.id === pc.circle.id)?.sortKey,
};
}),
"luId"
),
"sortKey"
@ -40,9 +42,9 @@ const uniqueLearningUnits = computed(() => {
const criteriaByLearningUnit = computed(() => {
return uniqueLearningUnits.value.map((lu) => {
const criteria = competenceStore
.flatPerformanceCriteria()
.filter((pc) => pc.learning_unit.id === lu.luId);
const criteria = (courseCompletionData.flatPerformanceCriteria.value ?? []).filter(
(pc) => pc.learning_unit?.id === lu.luId
);
return {
...lu,
countSuccess: criteria.filter((c) => c.completion_status === "SUCCESS").length,
@ -98,7 +100,7 @@ const criteriaByLearningUnit = computed(() => {
<div>
<router-link
:to="selfEvaluation.url"
:to="selfEvaluation.url ?? '/'"
class="link"
:data-cy="`${selfEvaluation.luSlug}-open`"
>

View File

@ -34,7 +34,7 @@ const queryResult = useQuery({
query: ASSIGNMENT_COMPLETION_QUERY,
variables: {
courseSessionId: courseSession.value.id,
assignmentId: props.learningContent.content_assignment_id,
assignmentId: props.learningContent.content_assignment.id,
learningContentId: props.learningContent.id,
},
pause: true,
@ -95,7 +95,7 @@ watchEffect(() => {
onMounted(async () => {
log.debug(
"AssignmentView mounted",
props.learningContent.content_assignment_id,
props.learningContent.content_assignment.id,
props.learningContent
);

View File

@ -9,7 +9,7 @@ const props = defineProps<{
<template>
<AssignmentView
:assignment-id="props.content.content_assignment_id"
:assignment-id="props.content.content_assignment.id"
:learning-content="props.content"
/>
</template>

View File

@ -30,7 +30,7 @@ const queryResult = useQuery({
query: ASSIGNMENT_COMPLETION_QUERY,
variables: {
courseSessionId: courseSession.value.id,
assignmentId: props.content.content_assignment_id,
assignmentId: props.content.content_assignment.id,
learningContentId: props.content.id,
},
});

View File

@ -1,179 +0,0 @@
import { useCurrentCourseSession } from "@/composables";
import { itGetCached } from "@/fetchHelpers";
import { useCompletionStore } from "@/stores/completion";
import { useUserStore } from "@/stores/user";
import type {
CircleLight,
CompetencePage,
CompetenceProfilePage,
PerformanceCriteria,
} from "@/types";
import _ from "lodash";
import cloneDeep from "lodash/cloneDeep";
import groupBy from "lodash/groupBy";
import orderBy from "lodash/orderBy";
import { defineStore } from "pinia";
export type CompetenceStoreState = {
competenceProfilePages: Map<string, CompetenceProfilePage>;
circles: CircleLight[];
};
export const useCompetenceStore = defineStore({
id: "competence",
state: () => {
return {
competenceProfilePages: new Map<string, CompetenceProfilePage>(),
circles: [],
} as CompetenceStoreState;
},
getters: {},
actions: {
calcStatusCount(criteria: PerformanceCriteria[]) {
if (criteria) {
const grouped = groupBy(criteria, "completion_status");
return {
UNKNOWN: grouped?.UNKNOWN?.length || 0,
SUCCESS: grouped?.SUCCESS?.length || 0,
FAIL: grouped?.FAIL?.length || 0,
};
}
return {
UNKNOWN: 0,
SUCCESS: 0,
FAIL: 0,
};
},
criteriaByCompetence(competence: CompetencePage) {
return competence.children;
},
competenceProfilePage(userId: string | undefined = undefined) {
if (!userId) {
const userStore = useUserStore();
userId = userStore.id;
}
return this.competenceProfilePages.get(userId);
},
flatPerformanceCriteria(
userId: string | undefined = undefined,
circleId: string | undefined = undefined
) {
if (!userId) {
const userStore = useUserStore();
userId = userStore.id;
}
if (this.competenceProfilePages.get(userId)) {
const competenceProfilePage = this.competenceProfilePages.get(userId);
if (competenceProfilePage) {
let criteria = orderBy(
competenceProfilePage.children.flatMap((competence) => {
return competence.children;
}),
["competence_id"],
["asc"]
);
if (circleId) {
criteria = criteria.filter((c) => circleId === c.circle.id);
}
return criteria;
}
}
return [];
},
competences(userId: string | undefined = undefined) {
if (!userId) {
const userStore = useUserStore();
userId = userStore.id;
}
if (this.competenceProfilePages.get(userId)) {
const competenceProfilePage = this.competenceProfilePages.get(userId);
if (competenceProfilePage?.children.length) {
return _.orderBy(
competenceProfilePage.children.filter((competence) => {
const criteria = competence.children;
return criteria.length > 0;
}),
["competence_id"],
["asc"]
);
}
}
return [];
},
async loadCompetenceProfilePage(
slug: string,
userId: string | undefined = undefined,
reload = false
) {
if (!userId) {
const userStore = useUserStore();
userId = userStore.id;
}
if (this.competenceProfilePages.has(userId) && !reload) {
const competenceProfilePage = this.competenceProfilePages.get(userId);
await this.parseCompletionData(userId);
return competenceProfilePage;
}
const competenceProfilePage = await itGetCached(`/api/course/page/${slug}/`, {
reload: reload,
});
if (!competenceProfilePage) {
throw `No competenceProfilePageData found with: ${slug}`;
}
this.competenceProfilePages.set(userId, cloneDeep(competenceProfilePage));
this.circles = competenceProfilePage.circles;
await this.parseCompletionData(userId);
return this.competenceProfilePages.get(userId);
},
async parseCompletionData(userId: string) {
const competenceProfilePage = this.competenceProfilePages.get(userId);
if (competenceProfilePage) {
const completionStore = useCompletionStore();
const courseSession = useCurrentCourseSession();
if (courseSession) {
const completionData = await completionStore.loadCourseSessionCompletionData(
courseSession.value.id,
userId
);
if (completionData) {
competenceProfilePage.children.forEach((competence) => {
competence.children.forEach((performanceCriteria) => {
const completion = completionData.find(
(c) => c.page_id === performanceCriteria.id
);
if (completion) {
performanceCriteria.completion_status = completion.completion_status;
performanceCriteria.completion_status_updated_at =
completion.updated_at;
} else {
performanceCriteria.completion_status = "UNKNOWN";
performanceCriteria.completion_status_updated_at = "";
}
});
});
this.competenceProfilePages.set(userId, competenceProfilePage);
}
}
}
},
},
});

View File

@ -59,7 +59,7 @@ class ActionCompetenceObjectType(DjangoObjectType):
class Meta:
model = ActionCompetence
interfaces = (CoursePageInterface,)
fields = ["competence_id", "children"]
fields = ["competence_id"]
def resolve_performance_criteria(self, info):
return self.get_children().specific()

View File

@ -136,6 +136,7 @@ class LearningContentEdoniqTestObjectType(DjangoObjectType):
competence_certificate = graphene.Field(
"vbv_lernwelt.competence.graphql.types.CompetenceCertificateObjectType",
)
has_extended_time_test = graphene.Boolean(required=True)
class Meta:
model = LearningContentEdoniqTest
@ -145,9 +146,11 @@ class LearningContentEdoniqTestObjectType(DjangoObjectType):
)
fields = ["content_assignment", "checkbox_text", "has_extended_time_test"]
@staticmethod
def resolve_competence_certificate(root: LearningContentEdoniqTest, info):
return root.content_assignment.competence_certificate
def resolve_competence_certificate(self: LearningContentEdoniqTest, info):
return self.content_assignment.competence_certificate
def resolve_has_extended_time_test(self: LearningContentEdoniqTest, info):
return self.has_extended_time_test
class LearningContentRichTextObjectType(DjangoObjectType):