useCompetenceStore is not needed anymore
This commit is contained in:
parent
20ccf7d38b
commit
e5cc0aa80e
|
|
@ -433,6 +433,7 @@ export type LearningContentEdoniqTestObjectType = CoursePageInterface & Learning
|
||||||
course?: Maybe<CourseObjectType>;
|
course?: Maybe<CourseObjectType>;
|
||||||
description: Scalars['String']['output'];
|
description: Scalars['String']['output'];
|
||||||
frontend_url: Scalars['String']['output'];
|
frontend_url: Scalars['String']['output'];
|
||||||
|
has_extended_time_test: Scalars['Boolean']['output'];
|
||||||
id: Scalars['ID']['output'];
|
id: Scalars['ID']['output'];
|
||||||
live: Scalars['Boolean']['output'];
|
live: Scalars['Boolean']['output'];
|
||||||
minutes?: Maybe<Scalars['Int']['output']>;
|
minutes?: Maybe<Scalars['Int']['output']>;
|
||||||
|
|
|
||||||
|
|
@ -463,6 +463,7 @@ type LearningContentEdoniqTestObjectType implements CoursePageInterface & Learni
|
||||||
can_user_self_toggle_course_completion: Boolean!
|
can_user_self_toggle_course_completion: Boolean!
|
||||||
circle: CircleLightObjectType
|
circle: CircleLightObjectType
|
||||||
competence_certificate: CompetenceCertificateObjectType
|
competence_certificate: CompetenceCertificateObjectType
|
||||||
|
has_extended_time_test: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
type CourseSessionUserObjectsType {
|
type CourseSessionUserObjectsType {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useCompetenceStore } from "@/stores/competence";
|
|
||||||
import * as log from "loglevel";
|
import * as log from "loglevel";
|
||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { useLearningPathWithCompletion } from "@/composables";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
courseSlug: string;
|
courseSlug: string;
|
||||||
|
|
@ -10,28 +10,30 @@ const props = defineProps<{
|
||||||
|
|
||||||
log.debug("PerformanceCriteriaPage created", props);
|
log.debug("PerformanceCriteriaPage created", props);
|
||||||
|
|
||||||
const competenceStore = useCompetenceStore();
|
const courseCompletionData = useLearningPathWithCompletion(props.courseSlug);
|
||||||
|
|
||||||
const uniqueLearningUnits = computed(() => {
|
const uniqueLearningUnits = computed(() => {
|
||||||
// FIXME: this complex calculation can go away,
|
// FIXME: this complex calculation can go away,
|
||||||
// once the criteria are in its own learning content
|
// once the criteria are in its own learning content
|
||||||
// get the learningUnits sorted by circle order in the course
|
// 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 { ...c, sortKey: index };
|
||||||
});
|
});
|
||||||
return _.orderBy(
|
return _.orderBy(
|
||||||
_.uniqBy(
|
_.uniqBy(
|
||||||
competenceStore.flatPerformanceCriteria().map((pc) => {
|
(courseCompletionData.flatPerformanceCriteria.value ?? [])
|
||||||
return {
|
.filter((pc) => Boolean(pc.learning_unit))
|
||||||
luId: pc.learning_unit.id,
|
.map((pc) => {
|
||||||
luTitle: pc.learning_unit.title,
|
return {
|
||||||
luSlug: pc.learning_unit.slug,
|
luId: pc.learning_unit?.id,
|
||||||
circleId: pc.circle.id,
|
luTitle: pc.learning_unit?.title,
|
||||||
circleTitle: pc.circle.title,
|
luSlug: pc.learning_unit?.slug,
|
||||||
url: pc.learning_unit.evaluate_url,
|
circleId: pc.circle.id,
|
||||||
sortKey: circles.find((c) => c.id === pc.circle.id)?.sortKey,
|
circleTitle: pc.circle.title,
|
||||||
};
|
url: pc.learning_unit?.evaluate_url,
|
||||||
}),
|
sortKey: circles.find((c) => c.id === pc.circle.id)?.sortKey,
|
||||||
|
};
|
||||||
|
}),
|
||||||
"luId"
|
"luId"
|
||||||
),
|
),
|
||||||
"sortKey"
|
"sortKey"
|
||||||
|
|
@ -40,9 +42,9 @@ const uniqueLearningUnits = computed(() => {
|
||||||
|
|
||||||
const criteriaByLearningUnit = computed(() => {
|
const criteriaByLearningUnit = computed(() => {
|
||||||
return uniqueLearningUnits.value.map((lu) => {
|
return uniqueLearningUnits.value.map((lu) => {
|
||||||
const criteria = competenceStore
|
const criteria = (courseCompletionData.flatPerformanceCriteria.value ?? []).filter(
|
||||||
.flatPerformanceCriteria()
|
(pc) => pc.learning_unit?.id === lu.luId
|
||||||
.filter((pc) => pc.learning_unit.id === lu.luId);
|
);
|
||||||
return {
|
return {
|
||||||
...lu,
|
...lu,
|
||||||
countSuccess: criteria.filter((c) => c.completion_status === "SUCCESS").length,
|
countSuccess: criteria.filter((c) => c.completion_status === "SUCCESS").length,
|
||||||
|
|
@ -98,7 +100,7 @@ const criteriaByLearningUnit = computed(() => {
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<router-link
|
<router-link
|
||||||
:to="selfEvaluation.url"
|
:to="selfEvaluation.url ?? '/'"
|
||||||
class="link"
|
class="link"
|
||||||
:data-cy="`${selfEvaluation.luSlug}-open`"
|
:data-cy="`${selfEvaluation.luSlug}-open`"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ const queryResult = useQuery({
|
||||||
query: ASSIGNMENT_COMPLETION_QUERY,
|
query: ASSIGNMENT_COMPLETION_QUERY,
|
||||||
variables: {
|
variables: {
|
||||||
courseSessionId: courseSession.value.id,
|
courseSessionId: courseSession.value.id,
|
||||||
assignmentId: props.learningContent.content_assignment_id,
|
assignmentId: props.learningContent.content_assignment.id,
|
||||||
learningContentId: props.learningContent.id,
|
learningContentId: props.learningContent.id,
|
||||||
},
|
},
|
||||||
pause: true,
|
pause: true,
|
||||||
|
|
@ -95,7 +95,7 @@ watchEffect(() => {
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
log.debug(
|
log.debug(
|
||||||
"AssignmentView mounted",
|
"AssignmentView mounted",
|
||||||
props.learningContent.content_assignment_id,
|
props.learningContent.content_assignment.id,
|
||||||
props.learningContent
|
props.learningContent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ const props = defineProps<{
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AssignmentView
|
<AssignmentView
|
||||||
:assignment-id="props.content.content_assignment_id"
|
:assignment-id="props.content.content_assignment.id"
|
||||||
:learning-content="props.content"
|
:learning-content="props.content"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ const queryResult = useQuery({
|
||||||
query: ASSIGNMENT_COMPLETION_QUERY,
|
query: ASSIGNMENT_COMPLETION_QUERY,
|
||||||
variables: {
|
variables: {
|
||||||
courseSessionId: courseSession.value.id,
|
courseSessionId: courseSession.value.id,
|
||||||
assignmentId: props.content.content_assignment_id,
|
assignmentId: props.content.content_assignment.id,
|
||||||
learningContentId: props.content.id,
|
learningContentId: props.content.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
@ -59,7 +59,7 @@ class ActionCompetenceObjectType(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ActionCompetence
|
model = ActionCompetence
|
||||||
interfaces = (CoursePageInterface,)
|
interfaces = (CoursePageInterface,)
|
||||||
fields = ["competence_id", "children"]
|
fields = ["competence_id"]
|
||||||
|
|
||||||
def resolve_performance_criteria(self, info):
|
def resolve_performance_criteria(self, info):
|
||||||
return self.get_children().specific()
|
return self.get_children().specific()
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ class LearningContentEdoniqTestObjectType(DjangoObjectType):
|
||||||
competence_certificate = graphene.Field(
|
competence_certificate = graphene.Field(
|
||||||
"vbv_lernwelt.competence.graphql.types.CompetenceCertificateObjectType",
|
"vbv_lernwelt.competence.graphql.types.CompetenceCertificateObjectType",
|
||||||
)
|
)
|
||||||
|
has_extended_time_test = graphene.Boolean(required=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LearningContentEdoniqTest
|
model = LearningContentEdoniqTest
|
||||||
|
|
@ -145,9 +146,11 @@ class LearningContentEdoniqTestObjectType(DjangoObjectType):
|
||||||
)
|
)
|
||||||
fields = ["content_assignment", "checkbox_text", "has_extended_time_test"]
|
fields = ["content_assignment", "checkbox_text", "has_extended_time_test"]
|
||||||
|
|
||||||
@staticmethod
|
def resolve_competence_certificate(self: LearningContentEdoniqTest, info):
|
||||||
def resolve_competence_certificate(root: LearningContentEdoniqTest, info):
|
return self.content_assignment.competence_certificate
|
||||||
return root.content_assignment.competence_certificate
|
|
||||||
|
def resolve_has_extended_time_test(self: LearningContentEdoniqTest, info):
|
||||||
|
return self.has_extended_time_test
|
||||||
|
|
||||||
|
|
||||||
class LearningContentRichTextObjectType(DjangoObjectType):
|
class LearningContentRichTextObjectType(DjangoObjectType):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue