VBV-213: Filter criteria by selected circle

This commit is contained in:
Daniel Egger 2022-12-21 10:38:27 +01:00
parent 59787ade3b
commit 59f717fa39
5 changed files with 37 additions and 24 deletions

View File

@ -20,21 +20,21 @@ export interface Props {
profileUserId?: string; profileUserId?: string;
learningPath: LearningPath; learningPath: LearningPath;
// set to undefined (default) to show all circles // set to undefined (default) to show all circles
showCircleIds?: number[]; showCircleTranslationKeys: string[];
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
diagramType: "horizontal", diagramType: "horizontal",
postfix: "", postfix: "",
profileUserId: "", profileUserId: "",
showCircleIds: undefined, showCircleTranslationKeys: undefined,
}); });
log.debug( log.debug(
"LearningPathDiagram created", "LearningPathDiagram created",
props.postfix, props.postfix,
props.profileUserId, props.profileUserId,
props.showCircleIds props.showCircleTranslationKeys
); );
const state = reactive({ width: 1640, height: 384 }); const state = reactive({ width: 1640, height: 384 });
@ -55,7 +55,7 @@ onMounted(async () => {
}); });
watch( watch(
() => props.showCircleIds, () => props.showCircleTranslationKeys,
(newCircleIds, oldCircleIds) => { (newCircleIds, oldCircleIds) => {
log.debug("LearningPathDiagram showCircleIds changed", newCircleIds, oldCircleIds); log.debug("LearningPathDiagram showCircleIds changed", newCircleIds, oldCircleIds);
render(); render();
@ -93,15 +93,16 @@ interface CirclePie extends d3.PieArcDatum<number> {
interface InternalCircle { interface InternalCircle {
id: number; id: number;
translation_key: string;
title: string; title: string;
frontend_url: string; frontend_url: string;
slug: string; slug: string;
pieData: CirclePie[]; pieData: CirclePie[];
} }
function isCircleVisible(circleId: number) { function isCircleVisible(circleTranslationKey: string) {
if (props.showCircleIds) { if (props.showCircleTranslationKeys) {
return props.showCircleIds.includes(circleId); return props.showCircleTranslationKeys.includes(circleTranslationKey);
} }
return true; return true;
@ -127,12 +128,13 @@ const circles = computed(() => {
pie.allFinished = allFinished(circle, thisLearningSequence); pie.allFinished = allFinished(circle, thisLearningSequence);
}); });
if (isCircleVisible(circle.id)) { if (isCircleVisible(circle.translation_key)) {
internalCircles.push({ internalCircles.push({
pieData: pieData.reverse() as CirclePie[], pieData: pieData.reverse() as CirclePie[],
title: circle.title, title: circle.title,
frontend_url: circle.frontend_url, frontend_url: circle.frontend_url,
id: circle.id, id: circle.id,
translation_key: circle.translation_key,
slug: _.kebabCase(circle.title), slug: _.kebabCase(circle.title),
}); });
} }
@ -196,7 +198,7 @@ function render() {
.append("g") .append("g")
.attr("class", (internalCircle) => { .attr("class", (internalCircle) => {
let result = "circle"; let result = "circle";
if (!isCircleVisible(internalCircle.id)) { if (!isCircleVisible(internalCircle.translation_key)) {
result += " hidden"; result += " hidden";
} }
return result; return result;

View File

@ -21,7 +21,7 @@ const learningPathStore = useLearningPathStore();
function userCountStatus(userId: number) { function userCountStatus(userId: number) {
return competenceStore.calcStatusCount( return competenceStore.calcStatusCount(
competenceStore.flatPerformanceCriteria(userId) competenceStore.flatPerformanceCriteria(userId, cockpitStore.selectedCircles)
); );
} }
@ -33,8 +33,8 @@ const data = {
}, },
}; };
function setActiveClasses(id: number) { function setActiveClasses(translationKey: string) {
return cockpitStore.selectedCircles.indexOf(id) > -1 return cockpitStore.selectedCircles.indexOf(translationKey) > -1
? ["bg-blue-900", "text-white"] ? ["bg-blue-900", "text-white"]
: ["text-bg-900"]; : ["text-bg-900"];
} }
@ -48,13 +48,13 @@ function setActiveClasses(id: number) {
<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 cockpitStore.circles"
:key="circle.id" :key="circle.translation_key"
class="mr-4 last:mr-0" class="mr-4 last:mr-0"
> >
<button <button
class="border-2 border-blue-900 rounded-full px-4 mr-4 last:mr-0" class="border-2 border-blue-900 rounded-full px-4 mr-4 last:mr-0"
:class="setActiveClasses(circle.id)" :class="setActiveClasses(circle.translation_key)"
@click="cockpitStore.toggleCourseSelection(circle.id)" @click="cockpitStore.toggleCourseSelection(circle.translation_key)"
> >
{{ circle.title }} {{ circle.title }}
</button> </button>
@ -127,7 +127,7 @@ function setActiveClasses(id: number) {
" "
:postfix="`cockpit-${csu.user_id}`" :postfix="`cockpit-${csu.user_id}`"
:profile-user-id="`${csu.user_id}`" :profile-user-id="`${csu.user_id}`"
:show-circle-ids="cockpitStore.selectedCircles" :show-circle-translation-keys="cockpitStore.selectedCircles"
diagram-type="horizontalSmall" diagram-type="horizontalSmall"
></LearningPathDiagram> ></LearningPathDiagram>
</div> </div>

View File

@ -7,7 +7,7 @@ import { defineStore } from "pinia";
export type CockpitStoreState = { export type CockpitStoreState = {
courseSessionUsers: CourseSessionUser[] | undefined; courseSessionUsers: CourseSessionUser[] | undefined;
cockpitSessionUser: ExpertSessionUser | undefined; cockpitSessionUser: ExpertSessionUser | undefined;
selectedCircles: number[]; selectedCircles: string[];
}; };
export const useCockpitStore = defineStore({ export const useCockpitStore = defineStore({
@ -23,7 +23,7 @@ export const useCockpitStore = defineStore({
circles: (state) => state.cockpitSessionUser?.circles, circles: (state) => state.cockpitSessionUser?.circles,
selectedCirclesTitles: (state) => selectedCirclesTitles: (state) =>
state.cockpitSessionUser?.circles state.cockpitSessionUser?.circles
.filter((circle) => state.selectedCircles.indexOf(circle.id) > -1) .filter((circle) => state.selectedCircles.indexOf(circle.translation_key) > -1)
.map((circle) => circle.title), .map((circle) => circle.title),
}, },
actions: { actions: {
@ -37,7 +37,7 @@ export const useCockpitStore = defineStore({
this.cockpitSessionUser = data.cockpit_user; this.cockpitSessionUser = data.cockpit_user;
if (this.cockpitSessionUser && this.cockpitSessionUser.circles?.length > 0) { if (this.cockpitSessionUser && this.cockpitSessionUser.circles?.length > 0) {
this.selectedCircles = [this.cockpitSessionUser.circles[0].id]; this.selectedCircles = [this.cockpitSessionUser.circles[0].translation_key];
} }
if (!this.courseSessionUsers) { if (!this.courseSessionUsers) {
@ -45,14 +45,14 @@ export const useCockpitStore = defineStore({
} }
return this.courseSessionUsers; return this.courseSessionUsers;
}, },
toggleCourseSelection(id: number) { toggleCourseSelection(translationKey: string) {
if (this.selectedCircles.indexOf(id) < 0) { if (this.selectedCircles.indexOf(translationKey) < 0) {
this.selectedCircles.push(id); this.selectedCircles.push(translationKey);
} else { } else {
if (this.selectedCircles.length === 1) { if (this.selectedCircles.length === 1) {
return; return;
} }
const index = this.selectedCircles.indexOf(id); const index = this.selectedCircles.indexOf(translationKey);
this.selectedCircles.splice(index, 1); this.selectedCircles.splice(index, 1);
} }
}, },

View File

@ -61,7 +61,10 @@ export const useCompetenceStore = defineStore({
return this.competenceProfilePages.get(userId); return this.competenceProfilePages.get(userId);
}, },
flatPerformanceCriteria(userId: number | undefined = undefined) { flatPerformanceCriteria(
userId: number | undefined = undefined,
circleTranslationKeys: string[] | undefined = undefined
) {
if (!userId) { if (!userId) {
const userStore = useUserStore(); const userStore = useUserStore();
userId = userStore.id; userId = userStore.id;
@ -84,6 +87,12 @@ export const useCompetenceStore = defineStore({
); );
} }
if (circleTranslationKeys) {
criteria = criteria.filter((c) =>
circleTranslationKeys.includes(c.circle.translation_key)
);
}
return criteria; return criteria;
} }
} }

View File

@ -346,5 +346,7 @@ export interface ExpertSessionUser extends CourseSessionUser {
circles: { circles: {
id: number; id: number;
title: string; title: string;
slug: string;
translation_key: string;
}[]; }[];
} }