Display chosen profile on user profile page
This commit is contained in:
parent
d22a7c296f
commit
59c695b838
|
|
@ -267,7 +267,8 @@ type CourseObjectType {
|
|||
learning_path: LearningPathObjectType!
|
||||
action_competences: [ActionCompetenceObjectType!]!
|
||||
profiles: [String]
|
||||
course_session_users: [CourseSessionUserType]!
|
||||
course_session_users(id: String): [CourseSessionUserType]!
|
||||
chosen_profile(user: String!): String
|
||||
}
|
||||
|
||||
type ActionCompetenceObjectType implements CoursePageInterface {
|
||||
|
|
|
|||
|
|
@ -264,14 +264,14 @@ export const COURSE_SESSION_DETAIL_QUERY = graphql(`
|
|||
`);
|
||||
|
||||
export const COURSE_QUERY = graphql(`
|
||||
query courseQuery($slug: String!) {
|
||||
query courseQuery($slug: String!, $user: String) {
|
||||
course(slug: $slug) {
|
||||
id
|
||||
title
|
||||
slug
|
||||
category_name
|
||||
profiles
|
||||
course_session_users {
|
||||
course_session_users(id: $user) {
|
||||
id
|
||||
__typename
|
||||
chosen_profile
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import { useCourseDataWithCompletion } from "@/composables";
|
|||
import UserProfileContent from "@/components/userProfile/UserProfileContent.vue";
|
||||
import LearningPathCircle from "@/pages/learningPath/learningPathPage/LearningPathCircle.vue";
|
||||
import LearningSequence from "@/pages/learningPath/circlePage/LearningSequence.vue";
|
||||
import { ref, watch } from "vue";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import type { CircleType } from "@/types";
|
||||
import { COURSE_QUERY } from "@/graphql/queries";
|
||||
import { useQuery } from "@urql/vue";
|
||||
|
||||
const props = defineProps<{
|
||||
userId: string;
|
||||
|
|
@ -20,6 +22,23 @@ function selectCircle(circle: CircleType) {
|
|||
selectedCircle.value = circle;
|
||||
}
|
||||
|
||||
const courseReactiveResult = useQuery({
|
||||
query: COURSE_QUERY,
|
||||
variables: { slug: props.courseSlug, user: props.userId },
|
||||
});
|
||||
|
||||
const courseReactive = computed(() => courseReactiveResult.data.value?.course);
|
||||
const courseSessionUsers = computed(() => {
|
||||
return courseReactive.value?.course_session_users;
|
||||
});
|
||||
|
||||
const chosenProfile = computed(() => {
|
||||
if (courseSessionUsers.value && courseSessionUsers.value.length > 0) {
|
||||
return courseSessionUsers.value[0]?.chosen_profile;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
watch(lpQueryResult.learningPath, () => {
|
||||
if (lpQueryResult.learningPath?.value?.topics?.length) {
|
||||
selectCircle(lpQueryResult.learningPath.value.topics[0].circles[0]);
|
||||
|
|
@ -30,6 +49,13 @@ watch(lpQueryResult.learningPath, () => {
|
|||
<template>
|
||||
<UserProfileContent>
|
||||
<template #side>
|
||||
<div v-if="chosenProfile">
|
||||
<h3 class="mb-4 text-base font-bold">
|
||||
Zulassungsprofil:
|
||||
<br />
|
||||
{{ $t(`profile.${chosenProfile}`) }}
|
||||
</h3>
|
||||
</div>
|
||||
<div
|
||||
v-for="topic in lpQueryResult.learningPath?.value?.topics ?? []"
|
||||
:key="topic.id"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from graphql import GraphQLError
|
|||
from rest_framework.exceptions import PermissionDenied
|
||||
|
||||
from vbv_lernwelt.competence.graphql.types import ActionCompetenceObjectType
|
||||
from vbv_lernwelt.core.models import User
|
||||
from vbv_lernwelt.course.models import (
|
||||
CircleDocument,
|
||||
Course,
|
||||
|
|
@ -108,7 +109,9 @@ class CourseObjectType(DjangoObjectType):
|
|||
configuration = graphene.Field(CourseConfigurationObjectType, required=True)
|
||||
profiles = graphene.List(graphene.String)
|
||||
course_session_users = graphene.List(
|
||||
"vbv_lernwelt.course.graphql.types.CourseSessionUserType", required=True
|
||||
"vbv_lernwelt.course.graphql.types.CourseSessionUserType",
|
||||
required=True,
|
||||
id=graphene.String(),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
|
@ -134,7 +137,11 @@ class CourseObjectType(DjangoObjectType):
|
|||
return CourseProfile.objects.all().values_list("code", flat=True)
|
||||
|
||||
@staticmethod
|
||||
def resolve_course_session_users(root: Course, info, **kwargs):
|
||||
def resolve_course_session_users(root: Course, info, id=None, **kwargs):
|
||||
# todo: restrict users that can be queried
|
||||
if id is not None:
|
||||
user = User.objects.get(id=id)
|
||||
else:
|
||||
user = info.context.user
|
||||
users = CourseSessionUser.objects.filter(user=user, course_session__course=root)
|
||||
return users
|
||||
|
|
|
|||
Loading…
Reference in New Issue