25
25
</template >
26
26
27
27
<script setup>
28
- import { ref , watchEffect } from " vue"
28
+ import { computed , ref , watchEffect } from " vue"
29
29
import { useRoute , useRouter } from " vue-router"
30
30
import { useI18n } from " vue-i18n"
31
31
import Breadcrumb from " primevue/breadcrumb"
32
32
import { useCidReqStore } from " ../store/cidReq"
33
33
import { storeToRefs } from " pinia"
34
+ import { useStore } from " vuex"
34
35
35
36
const legacyItems = ref (window .breadcrumb )
36
37
@@ -41,6 +42,9 @@ const { t } = useI18n()
41
42
42
43
const { course , session } = storeToRefs (cidReqStore)
43
44
45
+ const store = useStore ()
46
+ const resourceNode = computed (() => store .getters [" resourcenode/getResourceNode" ])
47
+
44
48
const specialRouteNames = [
45
49
" MyCourses" ,
46
50
" MySessions" ,
@@ -62,6 +66,7 @@ watchEffect(() => {
62
66
63
67
itemList .value = []
64
68
69
+ // Admin routes
65
70
if (route .fullPath .startsWith (" /admin" )) {
66
71
const parts = route .path .split (" /" ).filter (Boolean )
67
72
parts .forEach ((part , index ) => {
@@ -77,24 +82,28 @@ watchEffect(() => {
77
82
})
78
83
}
79
84
85
+ // Pages
80
86
if (route .name && route .name .includes (" Page" )) {
81
87
itemList .value .push ({
82
88
label: t (" Pages" ),
83
89
to: " /resources/pages" ,
84
90
})
85
91
}
86
92
93
+ // Messages
87
94
if (route .name && route .name .includes (" Message" )) {
88
95
itemList .value .push ({
89
96
label: t (" Messages" ),
90
- // disabled: route.path === path || lastItem.path === route.path,
91
97
to: " /resources/messages" ,
92
98
})
93
99
}
94
100
101
+ // Home and special
95
102
if (specialRouteNames .includes (route .name )) {
96
103
return
97
104
}
105
+
106
+ // My Courses or My Sessions
98
107
if (course .value ) {
99
108
if (session .value ) {
100
109
itemList .value .push ({
@@ -109,6 +118,7 @@ watchEffect(() => {
109
118
}
110
119
}
111
120
121
+ // Legacy breadcrumbs
112
122
if (legacyItems .value .length > 0 ) {
113
123
const mainUrl = window .location .href
114
124
const mainPath = mainUrl .indexOf (" main/" )
@@ -140,5 +150,64 @@ watchEffect(() => {
140
150
})
141
151
}
142
152
}
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
+ }
143
212
})
144
213
< / script>
0 commit comments