2018-02-01 12:17:04 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2021-03-03 12:25:59 +00:00
|
|
|
<breadcrumbs base="/files" />
|
2022-05-04 12:11:36 +00:00
|
|
|
<errors v-if="error" :errorCode="error.status" />
|
2024-07-30 17:45:27 +00:00
|
|
|
<component v-else-if="currentViewLoaded" :is="currentView"></component>
|
2018-02-01 12:17:04 +00:00
|
|
|
<div v-else>
|
2021-04-16 12:47:50 +00:00
|
|
|
<h2 class="message delayed">
|
|
|
|
<div class="spinner">
|
|
|
|
<div class="bounce1"></div>
|
|
|
|
<div class="bounce2"></div>
|
|
|
|
<div class="bounce3"></div>
|
|
|
|
</div>
|
2021-03-21 11:51:58 +00:00
|
|
|
<span>{{ $t("files.loading") }}</span>
|
2018-02-01 12:17:04 +00:00
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2024-08-03 15:34:12 +00:00
|
|
|
|
2018-02-01 12:17:04 +00:00
|
|
|
<script>
|
2021-03-21 11:51:58 +00:00
|
|
|
import { files as api } from "@/api";
|
2021-02-25 18:37:07 +00:00
|
|
|
|
2024-07-30 17:45:27 +00:00
|
|
|
import Breadcrumbs from "@/components/Breadcrumbs.vue";
|
|
|
|
import Errors from "@/views/Errors.vue";
|
2023-12-01 23:47:00 +00:00
|
|
|
import Preview from "@/views/files/Preview.vue";
|
2024-02-10 00:13:02 +00:00
|
|
|
import ListingView from "@/views/files/ListingView.vue";
|
2023-12-01 23:47:00 +00:00
|
|
|
import Editor from "@/views/files/Editor.vue";
|
2024-07-30 17:45:27 +00:00
|
|
|
import { state, mutations, getters } from "@/store";
|
|
|
|
import { pathsMatch } from "@/utils/url";
|
2019-01-05 16:12:09 +00:00
|
|
|
|
2018-02-01 12:17:04 +00:00
|
|
|
export default {
|
2021-03-21 11:51:58 +00:00
|
|
|
name: "files",
|
2018-02-01 12:17:04 +00:00
|
|
|
components: {
|
2021-03-03 12:25:59 +00:00
|
|
|
Breadcrumbs,
|
2021-02-25 18:37:07 +00:00
|
|
|
Errors,
|
2018-02-01 12:17:04 +00:00
|
|
|
Preview,
|
2024-02-10 00:13:02 +00:00
|
|
|
ListingView,
|
2023-12-01 23:47:00 +00:00
|
|
|
Editor,
|
2021-02-25 18:37:07 +00:00
|
|
|
},
|
2024-07-30 17:45:27 +00:00
|
|
|
data() {
|
2021-02-25 18:37:07 +00:00
|
|
|
return {
|
|
|
|
error: null,
|
2021-03-21 11:51:58 +00:00
|
|
|
width: window.innerWidth,
|
|
|
|
};
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2021-03-21 11:51:58 +00:00
|
|
|
currentView() {
|
2024-07-30 17:45:27 +00:00
|
|
|
return getters.currentView();
|
|
|
|
},
|
|
|
|
currentViewLoaded() {
|
|
|
|
return getters.currentView() !== null;
|
|
|
|
},
|
|
|
|
reload() {
|
2024-08-03 15:34:12 +00:00
|
|
|
return state.reload;
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
},
|
2021-03-21 11:51:58 +00:00
|
|
|
created() {
|
|
|
|
this.fetchData();
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2021-03-21 11:51:58 +00:00
|
|
|
$route: "fetchData",
|
2024-07-30 17:45:27 +00:00
|
|
|
reload(value) {
|
2024-08-03 15:34:12 +00:00
|
|
|
if (value) {
|
2021-03-21 11:51:58 +00:00
|
|
|
this.fetchData();
|
2021-01-11 23:00:40 +00:00
|
|
|
}
|
2021-03-21 11:51:58 +00:00
|
|
|
},
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
2021-03-21 11:51:58 +00:00
|
|
|
mounted() {
|
|
|
|
window.addEventListener("keydown", this.keyEvent);
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
2023-09-25 01:03:09 +00:00
|
|
|
beforeUnmount() {
|
2021-03-21 11:51:58 +00:00
|
|
|
window.removeEventListener("keydown", this.keyEvent);
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
2023-09-25 01:03:09 +00:00
|
|
|
unmounted() {
|
2024-07-30 17:45:27 +00:00
|
|
|
if (state.showShell) {
|
|
|
|
mutations.toggleShell(); // Use mutation
|
2021-02-25 18:37:07 +00:00
|
|
|
}
|
2024-07-30 17:45:27 +00:00
|
|
|
mutations.replaceRequest({}); // Use mutation
|
2023-09-04 02:21:25 +00:00
|
|
|
},
|
2018-02-01 12:17:04 +00:00
|
|
|
methods: {
|
2021-03-21 11:51:58 +00:00
|
|
|
async fetchData() {
|
2024-08-03 15:34:12 +00:00
|
|
|
// Set loading to true and reset the error.
|
|
|
|
mutations.setLoading(true);
|
|
|
|
this.error = null;
|
|
|
|
|
2024-07-30 17:45:27 +00:00
|
|
|
// Reset view information using mutations
|
|
|
|
mutations.setReload(false);
|
|
|
|
mutations.resetSelected();
|
|
|
|
mutations.setMultiple(false);
|
|
|
|
mutations.closeHovers();
|
2018-02-01 12:17:04 +00:00
|
|
|
|
2024-07-30 17:45:27 +00:00
|
|
|
let url = state.route.path;
|
2021-03-21 11:51:58 +00:00
|
|
|
if (url === "") url = "/";
|
|
|
|
if (url[0] !== "/") url = "/" + url;
|
2024-07-30 17:45:27 +00:00
|
|
|
let data = {};
|
2019-01-05 16:12:09 +00:00
|
|
|
try {
|
2024-07-30 17:45:27 +00:00
|
|
|
// Fetch initial data
|
2024-02-10 00:13:02 +00:00
|
|
|
let res = await api.fetch(url);
|
2024-07-30 17:45:27 +00:00
|
|
|
// If not a directory, fetch content
|
2024-02-10 00:13:02 +00:00
|
|
|
if (!res.isDir) {
|
2024-07-30 17:45:27 +00:00
|
|
|
res = await api.fetch(url, true);
|
2024-02-10 00:13:02 +00:00
|
|
|
}
|
2024-07-30 17:45:27 +00:00
|
|
|
data = res;
|
|
|
|
// Verify if the fetched path matches the current route
|
|
|
|
if (pathsMatch(res.path, `/${state.route.params.path}`)) {
|
|
|
|
document.title = `${res.name} - ${document.title}`;
|
2019-01-05 16:12:09 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2021-03-21 11:51:58 +00:00
|
|
|
this.error = e;
|
2024-08-03 15:34:12 +00:00
|
|
|
} finally {
|
|
|
|
mutations.setLoading(false);
|
|
|
|
mutations.replaceRequest(data);
|
2019-01-05 16:12:09 +00:00
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
2021-03-21 11:51:58 +00:00
|
|
|
keyEvent(event) {
|
2018-02-01 12:17:04 +00:00
|
|
|
// F1!
|
|
|
|
if (event.keyCode === 112) {
|
2021-03-21 11:51:58 +00:00
|
|
|
event.preventDefault();
|
2024-07-30 17:45:27 +00:00
|
|
|
mutations.showHover("help"); // Use mutation
|
2018-02-01 12:17:04 +00:00
|
|
|
}
|
2021-03-21 11:51:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2018-02-01 12:17:04 +00:00
|
|
|
</script>
|