Refactor cockpit circle handling

This commit is contained in:
Daniel Egger 2023-01-09 18:48:29 +01:00
parent 1b87aa5bac
commit 9fc834e99e
5 changed files with 38 additions and 16 deletions

View File

@ -7,7 +7,9 @@ import type { LearningPath } from "@/services/learningPath";
import { useCockpitStore } from "@/stores/cockpit";
import { useCompetenceStore } from "@/stores/competence";
import { useLearningPathStore } from "@/stores/learningPath";
import { useUserStore } from "@/stores/user";
import log from "loglevel";
import { computed } from "vue";
const props = defineProps<{
courseSlug: string;
@ -15,6 +17,7 @@ const props = defineProps<{
log.debug("CockpitIndexPage created", props.courseSlug);
const userStore = useUserStore();
const cockpitStore = useCockpitStore();
const competenceStore = useCompetenceStore();
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 = {
transferProgress: {
fail: 0,
@ -47,7 +77,7 @@ function setActiveClasses(translationKey: string) {
<h1 class="heading-3">{{ $t("general.circles") }}:</h1>
<ul class="flex flex-row leading-7 text-base font-bold ml-4">
<li
v-for="circle in cockpitStore.circles"
v-for="circle in circles"
:key="circle.translation_key"
class="mr-4 last:mr-0"
>
@ -132,10 +162,7 @@ function setActiveClasses(translationKey: string) {
></LearningPathDiagram>
</div>
<div>
<span
v-for="title in cockpitStore.selectedCirclesTitles"
:key="title"
>
<span v-for="title in selectedCirclesTitles" :key="title">
{{ title }}
</span>
</div>

View File

@ -2,6 +2,7 @@
import { useCockpitStore } from "@/stores/cockpit";
import { useCompetenceStore } from "@/stores/competence";
import { useLearningPathStore } from "@/stores/learningPath";
import { useUserStore } from "@/stores/user";
import * as log from "loglevel";
import { onMounted } from "vue";
@ -28,6 +29,7 @@ onMounted(async () => {
learningPathStore.loadLearningPath(props.courseSlug + "-lp", csu.user_id);
});
learningPathStore.loadLearningPath(props.courseSlug + "-lp", useUserStore().id);
} catch (error) {
log.error(error);
}

View File

@ -20,13 +20,6 @@ export const useCockpitStore = defineStore({
selectedCircles: [],
} 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: {
async loadCourseSessionUsers(courseSlug: string, reload = false) {
log.debug("loadCockpitData called");

View File

@ -7,9 +7,6 @@ from django.urls import include, path, re_path
from django.views import defaults as default_views
from grapple import urls as grapple_urls
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.views import (
@ -36,6 +33,9 @@ from vbv_lernwelt.course.views import (
request_course_completion_for_user,
)
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):

View File

@ -13,8 +13,8 @@ from vbv_lernwelt.course.models import (
)
from vbv_lernwelt.course.permissions import (
course_sessions_for_user_qs,
has_course_access_by_page_request,
has_course_access,
has_course_access_by_page_request,
is_course_expert,
is_circle_expert,
)