Skip to content

Commit 2efc080

Browse files
Merge pull request #6303 from christianbeeznest/ofaj-20950
Course: Fix breadcrumb in Vue tools, show tool name and folder hierarchy - refs BT#20950
2 parents 79a2d48 + 7dd0003 commit 2efc080

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

assets/vue/components/Breadcrumb.vue

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
</template>
2626

2727
<script setup>
28-
import { ref, watchEffect } from "vue"
28+
import { computed, ref, watchEffect } from "vue"
2929
import { useRoute, useRouter } from "vue-router"
3030
import { useI18n } from "vue-i18n"
3131
import Breadcrumb from "primevue/breadcrumb"
3232
import { useCidReqStore } from "../store/cidReq"
3333
import { storeToRefs } from "pinia"
34+
import { useStore } from "vuex"
3435
3536
const legacyItems = ref(window.breadcrumb)
3637
@@ -41,6 +42,9 @@ const { t } = useI18n()
4142
4243
const { course, session } = storeToRefs(cidReqStore)
4344
45+
const store = useStore()
46+
const resourceNode = computed(() => store.getters["resourcenode/getResourceNode"])
47+
4448
const specialRouteNames = [
4549
"MyCourses",
4650
"MySessions",
@@ -62,6 +66,7 @@ watchEffect(() => {
6266
6367
itemList.value = []
6468
69+
// Admin routes
6570
if (route.fullPath.startsWith("/admin")) {
6671
const parts = route.path.split("/").filter(Boolean)
6772
parts.forEach((part, index) => {
@@ -77,24 +82,28 @@ watchEffect(() => {
7782
})
7883
}
7984
85+
// Pages
8086
if (route.name && route.name.includes("Page")) {
8187
itemList.value.push({
8288
label: t("Pages"),
8389
to: "/resources/pages",
8490
})
8591
}
8692
93+
// Messages
8794
if (route.name && route.name.includes("Message")) {
8895
itemList.value.push({
8996
label: t("Messages"),
90-
//disabled: route.path === path || lastItem.path === route.path,
9197
to: "/resources/messages",
9298
})
9399
}
94100
101+
// Home and special
95102
if (specialRouteNames.includes(route.name)) {
96103
return
97104
}
105+
106+
// My Courses or My Sessions
98107
if (course.value) {
99108
if (session.value) {
100109
itemList.value.push({
@@ -109,6 +118,7 @@ watchEffect(() => {
109118
}
110119
}
111120
121+
// Legacy breadcrumbs
112122
if (legacyItems.value.length > 0) {
113123
const mainUrl = window.location.href
114124
const mainPath = mainUrl.indexOf("main/")
@@ -140,5 +150,64 @@ watchEffect(() => {
140150
})
141151
}
142152
}
153+
154+
const mainToolName = route.matched?.[0]?.name
155+
if (mainToolName && mainToolName !== "documents") {
156+
const formatToolName = (name) => {
157+
return name
158+
.replace(/([a-z])([A-Z])/g, "$1 $2")
159+
.replace(/_/g, " ")
160+
.replace(/\b\w/g, (c) => c.toUpperCase())
161+
}
162+
163+
itemList.value.push({
164+
label: formatToolName(mainToolName),
165+
route: { name: mainToolName, params: route.params, query: route.query },
166+
})
167+
}
168+
if (mainToolName === "documents" && resourceNode.value) {
169+
const folderTrail = []
170+
171+
let current = resourceNode.value
172+
while (current?.parent && current.parent.title !== "courses") {
173+
folderTrail.unshift({
174+
label: current.title,
175+
nodeId: current.id,
176+
})
177+
current = current.parent
178+
}
179+
180+
if (folderTrail.length === 0) {
181+
itemList.value.push({
182+
label: t("Documents"),
183+
route: {
184+
name: "DocumentsList",
185+
params: route.params,
186+
query: route.query,
187+
},
188+
})
189+
} else {
190+
const first = folderTrail.shift()
191+
itemList.value.push({
192+
label: t("Documents"),
193+
route: {
194+
name: "DocumentsList",
195+
params: { node: first.nodeId },
196+
query: route.query,
197+
},
198+
})
199+
200+
folderTrail.forEach((folder) => {
201+
itemList.value.push({
202+
label: folder.label,
203+
route: {
204+
name: "DocumentsList",
205+
params: { node: folder.nodeId },
206+
query: route.query,
207+
},
208+
})
209+
})
210+
}
211+
}
143212
})
144213
</script>

public/main/course_description/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
}
3333

3434
// interbreadcrumb
35-
$interbreadcrumb[] = ['url' => 'index.php?'.api_get_cidreq(), 'name' => get_lang('Description')];
3635
if (1 == $description_type) {
3736
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Description')];
3837
}

public/main/course_progress/index.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ function update_done_thematic_advance(selected_value) {
179179
$action = 'thematic_details';
180180
}
181181

182-
$interbreadcrumb[] = [
183-
'url' => $currentUrl,
184-
'name' => get_lang('Thematic control'),
185-
];
186-
187182
$actionLeft = '';
188183
// instance thematic object for using like library here
189184
$thematicManager = new Thematic();

0 commit comments

Comments
 (0)