diff --git a/src/vue/components/course-modules/CourseModule.vue b/src/vue/components/course-modules/CourseModule.vue
index e035c5df..cbd17c59 100644
--- a/src/vue/components/course-modules/CourseModule.vue
+++ b/src/vue/components/course-modules/CourseModule.vue
@@ -29,14 +29,15 @@
:aria-hidden="collapsed || isLeaf"
:role="collapsed || isLeaf ? 'presentation' : 'group'"
>
-
@@ -28,6 +29,8 @@
import { defineProps, ref } from 'vue';
import Icon from '../icon/Icon.vue';
import CourseModule from './CourseModule.vue';
+import { extractLabelForSelectedLanguage } from '../../utils/lang-utils';
+
const props = defineProps({
nodes: Array,
@@ -35,27 +38,27 @@ const props = defineProps({
const treestructure = props.nodes; // Assign nodes prop to treestructure
-const selectedNode = ref(null);
+const selectedNode = ref(-1);
-const toggleActiveModule = ({module, isOpen}) => {
- if (selectedNode.value === module) {
+const toggleActiveModule = ({moduleId, isOpen}) => {
+ if (selectedNode.value === moduleId) {
if (isOpen) {
- selectedNode.value = module;
+ selectedNode.value = moduleId;
} else {
- selectedNode.value = null;
+ selectedNode.value = -1;
}
} else {
if (isOpen) {
- selectedNode.value = module;
+ selectedNode.value = moduleId;
} else {
- selectedNode.value = null;
+ selectedNode.value = -1;
}
}
};
-const isActiveModule = (nodeLabel) => {
- return nodeLabel === selectedNode.value;
+const isActiveModule = (nodeId) => {
+ return nodeId === selectedNode.value;
};
diff --git a/src/vue/components/course-modules/lang-utils.js b/src/vue/components/course-modules/lang-utils.js
deleted file mode 100644
index e1dc311b..00000000
--- a/src/vue/components/course-modules/lang-utils.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Cleans a string to extract content based on a specified language code.
- * @param {string} label - The input string containing language-specific content.
- * @param {string} param - The language code ('nb' or 'nn') to match.
- * @returns {string} The extracted content based on the specified language code.
- */
-function extractLabelForSelectedLanguage(label, param) {
- // Define a regular expression pattern to match the desired language code and text.
- const pattern = new RegExp(`${param}: (.+?)(?:\\||$)`);
-
- // Execute the regular expression to find the matching content.
- const match = pattern.exec(label);
-
- // Check if a match was found.
- if (match) {
- // Extract and return the matched text.
- return match[1];
- }
-
- // Return the label, if it is not multilang.
- return label;
-}
diff --git a/src/vue/components/course-modules/test-data.js b/src/vue/components/course-modules/test-data.js
index 32e15c04..7626795c 100644
--- a/src/vue/components/course-modules/test-data.js
+++ b/src/vue/components/course-modules/test-data.js
@@ -375,3 +375,31 @@ export const tree_data_3_levels = [
],
},
];
+
+export function addPropertiesToTreeData(data) {
+ data.forEach((module, moduleIndex) => {
+ const moduleId = `${moduleIndex + 1}`;
+ const moduleUrl = module.label.replace(/ /g, "-");
+ module.id = moduleId;
+
+ if (module.nodes && module.nodes.length > 0) {
+ module.nodes.forEach((node, nodeIndex) => {
+ const nodeId = `${moduleId}-${nodeIndex + 1}`;
+ const nodeUrl = `${moduleUrl}/${node.label.replace(/ /g, "-")}`;
+ node.id = nodeId;
+
+ if (node.nodes && node.nodes.length > 0) {
+ // Add properties to third-level nodes
+ node.nodes.forEach((subNode, subNodeIndex) => {
+ const subNodeId = `${nodeId}-${subNodeIndex + 1}`;
+ const subNodeUrl = `${nodeUrl}/${subNode.label.replace(/ /g, "-")}`;
+ subNode.id = subNodeId;
+ subNode.url = subNodeUrl;
+ });
+ }
+ });
+ }
+ });
+ console.log('Hello the data looks like that:', data)
+ return data;
+}
diff --git a/src/vue/components/tree-view/TreeView.vue b/src/vue/components/tree-view/TreeView.vue
index 06d2d8fd..77f23a35 100644
--- a/src/vue/components/tree-view/TreeView.vue
+++ b/src/vue/components/tree-view/TreeView.vue
@@ -22,10 +22,11 @@
- -
+
-
import { ref, computed, defineProps, defineEmits } from 'vue';
import Icon from '../icon/Icon.vue';
+import { extractLabelForSelectedLanguage } from '../../utils/lang-utils';
const props = defineProps({
type: String,
label: String,
url: String,
+ id: Number,
nodes: Array,
isCompleted: Boolean,
isActive: Boolean,
@@ -59,23 +62,23 @@ const isLeaf = computed(() => props.nodes.length === 0);
const toggleCollapse = () => {
if (!isLeaf.value) {
collapsed.value = !collapsed.value;
- emits('toggleActiveModule', { module: props.label, isOpen: !collapsed.value });
+ emits('toggleActiveModule', { moduleId: props.id, isOpen: !collapsed.value });
}
if (isLeaf.value) {
window.location.href = url;
}
};
-const toggleActiveModule = ({module, isOpen}) => {
- if (selectedNode.value === module) {
+const toggleActiveModule = ({moduleId, isOpen}) => {
+ if (selectedNode.value === moduleId) {
if (isOpen) {
- selectedNode.value = module;
+ selectedNode.value = moduleId;
} else {
selectedNode.value = null;
}
} else {
if (isOpen) {
- selectedNode.value = module;
+ selectedNode.value = moduleId;
} else {
selectedNode.value = null;
}
diff --git a/src/vue/utils/lang-utils.js b/src/vue/utils/lang-utils.js
new file mode 100644
index 00000000..84176307
--- /dev/null
+++ b/src/vue/utils/lang-utils.js
@@ -0,0 +1,34 @@
+/**
+ * Cleans a string to extract content based on a specified language code.
+ * @param {string} label - The input string containing language-specific content.
+ * @param {string} param - The language code ('nb' or 'nn') to match.
+ * @returns {string} The extracted content based on the specified language code, the first alternative, or the label as is.
+ */
+export function extractLabelForSelectedLanguage(label, param) {
+ // Check if the label contains language codes or separators.
+ if (/\w\w:/.test(label)) {
+ // Define a regular expression pattern to match the desired language code and text.
+ const pattern = new RegExp(`${param}: (.+?)(?:\\||$)`);
+
+ // Execute the regular expression to find the matching content.
+ const match = pattern.exec(label);
+
+ // Check if a match was found.
+ if (match) {
+ // Extract and return the matched text.
+ return match[1];
+ }
+
+ // Check if there are alternative languages.
+ const alternatives = label.split("|");
+ if (alternatives.length > 1) {
+ // Return the content of the first alternative.
+ const firstAlternative = alternatives[0].trim();
+ // Remove any leading language code if present.
+ return firstAlternative.replace(/^\w\w:/, "").trim();
+ }
+ }
+
+ // If there's no language codes or matches, return the label as is.
+ return label;
+}