filebrowser/frontend/src/components/prompts/FileList.vue

145 lines
3.4 KiB
Vue
Raw Normal View History

2018-02-01 12:17:04 +00:00
<template>
<div>
2024-02-10 00:13:02 +00:00
<div class="searchContext">Path: {{ nav }}</div>
2018-02-01 12:17:04 +00:00
<ul class="file-list">
2021-03-21 11:51:58 +00:00
<li
@click="itemClick"
2018-02-01 12:17:04 +00:00
@touchstart="touchstart"
@dblclick="next"
role="button"
tabindex="0"
:aria-label="item.name"
:aria-selected="selected == item.url"
2021-03-21 11:51:58 +00:00
:key="item.name"
v-for="item in items"
:data-url="item.url"
>
{{ item.name }}
</li>
2018-02-01 12:17:04 +00:00
</ul>
</div>
</template>
<script>
2024-07-30 17:45:27 +00:00
import { state, mutations } from "@/store";
2021-03-21 11:51:58 +00:00
import url from "@/utils/url";
import { files } from "@/api";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "file-list",
2018-02-01 12:17:04 +00:00
data: function () {
return {
items: [],
touches: {
2021-03-21 11:51:58 +00:00
id: "",
count: 0,
2018-02-01 12:17:04 +00:00
},
selected: null,
2021-03-21 11:51:58 +00:00
current: window.location.pathname,
};
2018-02-01 12:17:04 +00:00
},
computed: {
2021-03-21 11:51:58 +00:00
nav() {
return decodeURIComponent(this.current);
},
2018-02-01 12:17:04 +00:00
},
2021-03-21 11:51:58 +00:00
mounted() {
2024-07-30 17:45:27 +00:00
this.fillOptions(state.req);
2018-02-01 12:17:04 +00:00
},
methods: {
2021-03-21 11:51:58 +00:00
fillOptions(req) {
2018-02-01 12:17:04 +00:00
// Sets the current path and resets
// the current items.
2021-03-21 11:51:58 +00:00
this.current = req.url;
this.items = [];
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
this.$emit("update:selected", this.current);
2018-02-01 12:17:04 +00:00
// If the path isn't the root path,
// show a button to navigate to the previous
// directory.
2021-03-21 11:51:58 +00:00
if (req.url !== "/files/") {
2018-02-01 12:17:04 +00:00
this.items.push({
2021-03-21 11:51:58 +00:00
name: "..",
url: url.removeLastDir(req.url) + "/",
});
2018-02-01 12:17:04 +00:00
}
// If this folder is empty, finish here.
2021-03-21 11:51:58 +00:00
if (req.items === null) return;
2018-02-01 12:17:04 +00:00
// Otherwise we add every directory to the
// move options.
for (let item of req.items) {
2021-03-21 11:51:58 +00:00
if (!item.isDir) continue;
2018-02-01 12:17:04 +00:00
this.items.push({
name: item.name,
2021-03-21 11:51:58 +00:00
url: item.url,
});
2018-02-01 12:17:04 +00:00
}
},
next: function (event) {
// Retrieves the URL of the directory the user
// just clicked in and fill the options with its
// content.
2021-03-21 11:51:58 +00:00
let uri = event.currentTarget.dataset.url;
2018-02-01 12:17:04 +00:00
2024-09-16 21:01:16 +00:00
files.fetch(uri).then(this.fillOptions);
2018-02-01 12:17:04 +00:00
},
2021-03-21 11:51:58 +00:00
touchstart(event) {
let url = event.currentTarget.dataset.url;
2018-02-01 12:17:04 +00:00
// In 300 milliseconds, we shall reset the count.
setTimeout(() => {
2021-03-21 11:51:58 +00:00
this.touches.count = 0;
}, 300);
2018-02-01 12:17:04 +00:00
// If the element the user is touching
// is different from the last one he touched,
// reset the count.
if (this.touches.id !== url) {
2021-03-21 11:51:58 +00:00
this.touches.id = url;
this.touches.count = 1;
return;
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
this.touches.count++;
2018-02-01 12:17:04 +00:00
// If there is more than one touch already,
// open the next screen.
if (this.touches.count > 1) {
2021-03-21 11:51:58 +00:00
this.next(event);
2018-02-01 12:17:04 +00:00
}
},
itemClick: function (event) {
2024-07-30 17:45:27 +00:00
if (state.user.singleClick) this.next(event);
2021-03-21 11:51:58 +00:00
else this.select(event);
},
2018-02-01 12:17:04 +00:00
select: function (event) {
// If the element is already selected, unselect it.
if (this.selected === event.currentTarget.dataset.url) {
2021-03-21 11:51:58 +00:00
this.selected = null;
this.$emit("update:selected", this.current);
return;
2018-02-01 12:17:04 +00:00
}
// Otherwise select the element.
2021-03-21 11:51:58 +00:00
this.selected = event.currentTarget.dataset.url;
this.$emit("update:selected", this.selected);
},
2024-02-10 00:13:02 +00:00
createDir: async function () {
2024-07-30 17:45:27 +00:00
mutations.showHover({
name: "newDir",
2024-02-10 00:13:02 +00:00
action: null,
confirm: null,
props: {
redirect: false,
2024-07-30 17:45:27 +00:00
base: this.current === state.route.path ? null : this.current,
2024-02-10 00:13:02 +00:00
},
});
},
2021-03-21 11:51:58 +00:00
},
};
2018-02-01 12:17:04 +00:00
</script>