VBV-224: Only show selected circles on cockpit page

This commit is contained in:
Daniel Egger 2022-12-19 18:12:34 +01:00
parent c8eb505cd2
commit 59787ade3b
2 changed files with 45 additions and 10 deletions

View File

@ -9,7 +9,7 @@ import colors from "@/colors.json";
import type { Circle } from "@/services/circle"; import type { Circle } from "@/services/circle";
import type { LearningPath } from "@/services/learningPath"; import type { LearningPath } from "@/services/learningPath";
import type { LearningSequence, Topic } from "@/types"; import type { LearningSequence, Topic } from "@/types";
import { computed, onMounted, reactive } from "vue"; import { computed, onMounted, reactive, watch } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
export type DiagramType = "horizontal" | "vertical" | "horizontalSmall"; export type DiagramType = "horizontal" | "vertical" | "horizontalSmall";
@ -19,15 +19,23 @@ export interface Props {
postfix?: string; postfix?: string;
profileUserId?: string; profileUserId?: string;
learningPath: LearningPath; learningPath: LearningPath;
// set to undefined (default) to show all circles
showCircleIds?: number[];
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
diagramType: "horizontal", diagramType: "horizontal",
postfix: "", postfix: "",
profileUserId: "", profileUserId: "",
showCircleIds: undefined,
}); });
log.debug("LearningPathDiagram created", props.postfix, props.profileUserId); log.debug(
"LearningPathDiagram created",
props.postfix,
props.profileUserId,
props.showCircleIds
);
const state = reactive({ width: 1640, height: 384 }); const state = reactive({ width: 1640, height: 384 });
@ -46,6 +54,15 @@ onMounted(async () => {
render(); render();
}); });
watch(
() => props.showCircleIds,
(newCircleIds, oldCircleIds) => {
log.debug("LearningPathDiagram showCircleIds changed", newCircleIds, oldCircleIds);
render();
},
{ deep: true }
);
function someFinished(circle: Circle, learningSequence: LearningSequence) { function someFinished(circle: Circle, learningSequence: LearningSequence) {
if (circle) { if (circle) {
return circle.someFinishedInLearningSequence(learningSequence.translation_key); return circle.someFinishedInLearningSequence(learningSequence.translation_key);
@ -82,6 +99,14 @@ interface InternalCircle {
pieData: CirclePie[]; pieData: CirclePie[];
} }
function isCircleVisible(circleId: number) {
if (props.showCircleIds) {
return props.showCircleIds.includes(circleId);
}
return true;
}
const circles = computed(() => { const circles = computed(() => {
if (props.learningPath) { if (props.learningPath) {
const internalCircles: InternalCircle[] = []; const internalCircles: InternalCircle[] = [];
@ -102,13 +127,15 @@ const circles = computed(() => {
pie.allFinished = allFinished(circle, thisLearningSequence); pie.allFinished = allFinished(circle, thisLearningSequence);
}); });
internalCircles.push({ if (isCircleVisible(circle.id)) {
pieData: pieData.reverse() as CirclePie[], internalCircles.push({
title: circle.title, pieData: pieData.reverse() as CirclePie[],
frontend_url: circle.frontend_url, title: circle.title,
id: circle.id, frontend_url: circle.frontend_url,
slug: _.kebabCase(circle.title), id: circle.id,
}); slug: _.kebabCase(circle.title),
});
}
}); });
return internalCircles; return internalCircles;
} }
@ -116,6 +143,7 @@ const circles = computed(() => {
}); });
function render() { function render() {
log.debug("LearningPathDiagram render");
// clean old svg // clean old svg
d3.select("#" + svgId.value) d3.select("#" + svgId.value)
.selectAll("*") .selectAll("*")
@ -166,7 +194,13 @@ function render() {
.data(circles.value) .data(circles.value)
.enter() .enter()
.append("g") .append("g")
.attr("class", "circle") .attr("class", (internalCircle) => {
let result = "circle";
if (!isCircleVisible(internalCircle.id)) {
result += " hidden";
}
return result;
})
.attr("data-cy", (d) => { .attr("data-cy", (d) => {
if (props.diagramType === "vertical") { if (props.diagramType === "vertical") {
return `circle-${d.slug}-vertical`; return `circle-${d.slug}-vertical`;

View File

@ -127,6 +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"
diagram-type="horizontalSmall" diagram-type="horizontalSmall"
></LearningPathDiagram> ></LearningPathDiagram>
</div> </div>