2525</template >
2626
2727<script setup>
28- import { ref , watchEffect } from " vue"
28+ import { computed , ref , watchEffect } from " vue"
2929import { useRoute , useRouter } from " vue-router"
3030import { useI18n } from " vue-i18n"
3131import Breadcrumb from " primevue/breadcrumb"
3232import { useCidReqStore } from " ../store/cidReq"
3333import { storeToRefs } from " pinia"
34+ import { useStore } from " vuex"
3435
3536const legacyItems = ref (window .breadcrumb )
3637
@@ -41,6 +42,9 @@ const { t } = useI18n()
4142
4243const { course , session } = storeToRefs (cidReqStore)
4344
45+ const store = useStore ()
46+ const resourceNode = computed (() => store .getters [" resourcenode/getResourceNode" ])
47+
4448const 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>
0 commit comments