Refactor cockpit circle handling
This commit is contained in:
parent
1b87aa5bac
commit
9fc834e99e
|
|
@ -7,7 +7,9 @@ import type { LearningPath } from "@/services/learningPath";
|
||||||
import { useCockpitStore } from "@/stores/cockpit";
|
import { useCockpitStore } from "@/stores/cockpit";
|
||||||
import { useCompetenceStore } from "@/stores/competence";
|
import { useCompetenceStore } from "@/stores/competence";
|
||||||
import { useLearningPathStore } from "@/stores/learningPath";
|
import { useLearningPathStore } from "@/stores/learningPath";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
import { computed } from "vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
courseSlug: string;
|
courseSlug: string;
|
||||||
|
|
@ -15,6 +17,7 @@ const props = defineProps<{
|
||||||
|
|
||||||
log.debug("CockpitIndexPage created", props.courseSlug);
|
log.debug("CockpitIndexPage created", props.courseSlug);
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
const cockpitStore = useCockpitStore();
|
const cockpitStore = useCockpitStore();
|
||||||
const competenceStore = useCompetenceStore();
|
const competenceStore = useCompetenceStore();
|
||||||
const learningPathStore = useLearningPathStore();
|
const learningPathStore = useLearningPathStore();
|
||||||
|
|
@ -25,6 +28,33 @@ function userCountStatus(userId: number) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const circles = computed(() => {
|
||||||
|
const learningPathCircles = learningPathStore
|
||||||
|
.learningPathForUser(props.courseSlug, userStore.id)
|
||||||
|
?.circles.map((c) => {
|
||||||
|
return {
|
||||||
|
id: c.id,
|
||||||
|
title: c.title,
|
||||||
|
slug: c.slug,
|
||||||
|
translation_key: c.translation_key,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (cockpitStore.cockpitSessionUser?.circles?.length) {
|
||||||
|
return cockpitStore.cockpitSessionUser.circles;
|
||||||
|
} else if (learningPathCircles) {
|
||||||
|
return learningPathCircles;
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedCirclesTitles = computed(() => {
|
||||||
|
return circles.value
|
||||||
|
.filter((c) => cockpitStore.selectedCircles.includes(c.translation_key))
|
||||||
|
.map((c) => c.title);
|
||||||
|
});
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
transferProgress: {
|
transferProgress: {
|
||||||
fail: 0,
|
fail: 0,
|
||||||
|
|
@ -47,7 +77,7 @@ function setActiveClasses(translationKey: string) {
|
||||||
<h1 class="heading-3">{{ $t("general.circles") }}:</h1>
|
<h1 class="heading-3">{{ $t("general.circles") }}:</h1>
|
||||||
<ul class="flex flex-row leading-7 text-base font-bold ml-4">
|
<ul class="flex flex-row leading-7 text-base font-bold ml-4">
|
||||||
<li
|
<li
|
||||||
v-for="circle in cockpitStore.circles"
|
v-for="circle in circles"
|
||||||
:key="circle.translation_key"
|
:key="circle.translation_key"
|
||||||
class="mr-4 last:mr-0"
|
class="mr-4 last:mr-0"
|
||||||
>
|
>
|
||||||
|
|
@ -132,10 +162,7 @@ function setActiveClasses(translationKey: string) {
|
||||||
></LearningPathDiagram>
|
></LearningPathDiagram>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span
|
<span v-for="title in selectedCirclesTitles" :key="title">
|
||||||
v-for="title in cockpitStore.selectedCirclesTitles"
|
|
||||||
:key="title"
|
|
||||||
>
|
|
||||||
{{ title }}
|
{{ title }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import { useCockpitStore } from "@/stores/cockpit";
|
import { useCockpitStore } from "@/stores/cockpit";
|
||||||
import { useCompetenceStore } from "@/stores/competence";
|
import { useCompetenceStore } from "@/stores/competence";
|
||||||
import { useLearningPathStore } from "@/stores/learningPath";
|
import { useLearningPathStore } from "@/stores/learningPath";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
import * as log from "loglevel";
|
import * as log from "loglevel";
|
||||||
import { onMounted } from "vue";
|
import { onMounted } from "vue";
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
learningPathStore.loadLearningPath(props.courseSlug + "-lp", csu.user_id);
|
learningPathStore.loadLearningPath(props.courseSlug + "-lp", csu.user_id);
|
||||||
});
|
});
|
||||||
|
learningPathStore.loadLearningPath(props.courseSlug + "-lp", useUserStore().id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(error);
|
log.error(error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,6 @@ export const useCockpitStore = defineStore({
|
||||||
selectedCircles: [],
|
selectedCircles: [],
|
||||||
} as CockpitStoreState;
|
} as CockpitStoreState;
|
||||||
},
|
},
|
||||||
getters: {
|
|
||||||
circles: (state) => state.cockpitSessionUser?.circles,
|
|
||||||
selectedCirclesTitles: (state) =>
|
|
||||||
state.cockpitSessionUser?.circles
|
|
||||||
.filter((circle) => state.selectedCircles.indexOf(circle.translation_key) > -1)
|
|
||||||
.map((circle) => circle.title),
|
|
||||||
},
|
|
||||||
actions: {
|
actions: {
|
||||||
async loadCourseSessionUsers(courseSlug: string, reload = false) {
|
async loadCourseSessionUsers(courseSlug: string, reload = false) {
|
||||||
log.debug("loadCockpitData called");
|
log.debug("loadCockpitData called");
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@ from django.urls import include, path, re_path
|
||||||
from django.views import defaults as default_views
|
from django.views import defaults as default_views
|
||||||
from grapple import urls as grapple_urls
|
from grapple import urls as grapple_urls
|
||||||
from ratelimit.exceptions import Ratelimited
|
from ratelimit.exceptions import Ratelimited
|
||||||
from wagtail import urls as wagtail_urls
|
|
||||||
from wagtail.admin import urls as wagtailadmin_urls
|
|
||||||
from wagtail.documents import urls as wagtaildocs_urls
|
|
||||||
|
|
||||||
from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
|
from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
|
||||||
from vbv_lernwelt.core.views import (
|
from vbv_lernwelt.core.views import (
|
||||||
|
|
@ -36,6 +33,9 @@ from vbv_lernwelt.course.views import (
|
||||||
request_course_completion_for_user,
|
request_course_completion_for_user,
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.feedback.views import get_name
|
from vbv_lernwelt.feedback.views import get_name
|
||||||
|
from wagtail import urls as wagtail_urls
|
||||||
|
from wagtail.admin import urls as wagtailadmin_urls
|
||||||
|
from wagtail.documents import urls as wagtaildocs_urls
|
||||||
|
|
||||||
|
|
||||||
def raise_example_error(request):
|
def raise_example_error(request):
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ from vbv_lernwelt.course.models import (
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.course.permissions import (
|
from vbv_lernwelt.course.permissions import (
|
||||||
course_sessions_for_user_qs,
|
course_sessions_for_user_qs,
|
||||||
has_course_access_by_page_request,
|
|
||||||
has_course_access,
|
has_course_access,
|
||||||
|
has_course_access_by_page_request,
|
||||||
is_course_expert,
|
is_course_expert,
|
||||||
is_circle_expert,
|
is_circle_expert,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue