filebrowser/frontend/src/components/Breadcrumbs.vue

89 lines
1.9 KiB
Vue
Raw Normal View History

2021-03-03 12:25:59 +00:00
<template>
<div class="breadcrumbs">
2021-03-21 11:51:58 +00:00
<component
:is="element"
:to="base || ''"
:aria-label="$t('files.home')"
:title="$t('files.home')"
>
2021-03-03 12:25:59 +00:00
<i class="material-icons">home</i>
</component>
<span v-for="(link, index) in items" :key="index">
2024-02-10 00:13:02 +00:00
<span class="chevron"><i class="material-icons">keyboard_arrow_right</i></span>
2021-03-03 12:25:59 +00:00
<component :is="element" :to="link.url">{{ link.name }}</component>
</span>
2024-02-10 00:13:02 +00:00
<action style="display: contents" v-if="showShare" icon="share" show="share" />
2021-03-03 12:25:59 +00:00
</div>
</template>
<script>
2024-02-10 00:13:02 +00:00
import { mapState } from "vuex";
import Action from "@/components/header/Action";
2021-03-03 12:25:59 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "breadcrumbs",
2024-02-10 00:13:02 +00:00
components: {
Action,
},
2021-03-21 11:51:58 +00:00
props: ["base", "noLink"],
2021-03-03 12:25:59 +00:00
computed: {
2024-02-10 00:13:02 +00:00
...mapState(["req", "user"]),
2021-03-21 11:51:58 +00:00
items() {
2024-02-10 00:13:02 +00:00
2021-03-21 11:51:58 +00:00
const relativePath = this.$route.path.replace(this.base, "");
let parts = relativePath.split("/");
2021-03-03 12:25:59 +00:00
2021-03-21 11:51:58 +00:00
if (parts[0] === "") {
parts.shift();
2021-03-03 12:25:59 +00:00
}
2021-03-21 11:51:58 +00:00
if (parts[parts.length - 1] === "") {
parts.pop();
2021-03-03 12:25:59 +00:00
}
2021-03-21 11:51:58 +00:00
let breadcrumbs = [];
2021-03-03 12:25:59 +00:00
for (let i = 0; i < parts.length; i++) {
if (i === 0) {
2021-03-21 11:51:58 +00:00
breadcrumbs.push({
name: decodeURIComponent(parts[i]),
url: this.base + "/" + parts[i] + "/",
});
} else {
breadcrumbs.push({
name: decodeURIComponent(parts[i]),
url: breadcrumbs[i - 1].url + parts[i] + "/",
});
2021-03-03 12:25:59 +00:00
}
}
if (breadcrumbs.length > 3) {
while (breadcrumbs.length !== 4) {
2021-03-21 11:51:58 +00:00
breadcrumbs.shift();
2021-03-03 12:25:59 +00:00
}
2021-03-21 11:51:58 +00:00
breadcrumbs[0].name = "...";
2021-03-03 12:25:59 +00:00
}
2021-03-21 11:51:58 +00:00
return breadcrumbs;
2021-03-03 12:25:59 +00:00
},
2021-03-21 11:51:58 +00:00
element() {
2021-03-03 12:25:59 +00:00
if (this.noLink !== undefined) {
2021-03-21 11:51:58 +00:00
return "span";
2021-03-03 12:25:59 +00:00
}
2021-03-21 11:51:58 +00:00
return "router-link";
},
2024-02-10 00:13:02 +00:00
showShare() {
if (this.$route.path.startsWith("/share")) {
return;
}
return this.user.perm.share;
},
2021-03-21 11:51:58 +00:00
},
};
2021-03-03 12:25:59 +00:00
</script>
2021-03-21 11:51:58 +00:00
<style></style>