filebrowser/frontend/src/components/Breadcrumbs.vue

119 lines
2.8 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" />
2024-09-16 21:01:16 +00:00
<div v-if="isCardView">
2024-08-24 22:02:33 +00:00
Size:
<input
v-model="gallerySize"
type="range"
2024-10-07 22:44:53 +00:00
id="gallery-size"
name="gallery-size"
2024-08-24 22:02:33 +00:00
:value="gallerySize"
min="0"
max="10"
2024-10-07 22:44:53 +00:00
@input="updateGallerySize"
@change="commitGallerySize"
2024-08-24 22:02:33 +00:00
/>
</div>
2021-03-03 12:25:59 +00:00
</div>
</template>
<script>
2024-10-07 22:44:53 +00:00
import { state, mutations, getters } from "@/store";
2024-11-21 00:15:30 +00:00
import { removePrefix } from "@/utils/url.js";
2024-09-16 21:01:16 +00:00
import Action from "@/components/Action.vue";
2024-02-10 00:13:02 +00:00
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,
},
2024-08-24 22:02:33 +00:00
data() {
return {
gallerySize: state.user.gallerySize,
};
},
2021-03-21 11:51:58 +00:00
props: ["base", "noLink"],
2021-03-03 12:25:59 +00:00
computed: {
2024-09-16 21:01:16 +00:00
isCardView() {
return getters.isCardView();
2024-08-24 22:02:33 +00:00
},
2021-03-21 11:51:58 +00:00
items() {
2024-11-21 00:15:30 +00:00
let relativePath = removePrefix(state.route.path, "files");
if (getters.currentView() == "share") {
// Split the path, filter out any empty elements, then join again with slashes
relativePath = removePrefix(state.route.path, "share");
}
2021-03-21 11:51:58 +00:00
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() {
2024-11-21 00:15:30 +00:00
return (
state.user?.perm && state.user?.perm.share && state.user.username != "publicUser"
);
2024-10-07 22:44:53 +00:00
},
},
methods: {
updateGallerySize(event) {
this.gallerySize = parseInt(event.target.value, 10);
},
commitGallerySize() {
mutations.setGallerySize(this.gallerySize);
2024-07-30 17:45:27 +00:00
},
},
2021-03-21 11:51:58 +00:00
};
2021-03-03 12:25:59 +00:00
</script>