2019-02-10 05:14:58 +00:00
|
|
|
<template>
|
|
|
|
<div class="animated-fade-in">
|
|
|
|
<div class="filemanager-breadcrumbs">
|
|
|
|
/<span class="px-1">home</span><!--
|
2019-02-10 05:15:45 +00:00
|
|
|
-->/
|
|
|
|
<router-link :to="{ name: 'server-files' }" class="px-1">container</router-link><!--
|
2019-02-10 05:14:58 +00:00
|
|
|
--><span v-for="crumb in breadcrumbs" class="inline-block">
|
|
|
|
<span v-if="crumb.path">
|
|
|
|
/<router-link :to="{ name: 'server-files', params: { path: crumb.path } }" class="px-1">{{crumb.directoryName}}</router-link>
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
/<span class="px-1 text-neutral-600 font-medium">{{crumb.directoryName}}</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="content-box">
|
|
|
|
<div v-if="loading">
|
|
|
|
<div class="spinner spinner-xl blue"></div>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="!loading && errorMessage">
|
|
|
|
<div class="alert error" v-text="errorMessage"></div>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="!directories.length && !files.length">
|
|
|
|
<p class="text-neutral-500 text-sm text-center p-6 pb-4">This directory is empty.</p>
|
|
|
|
</div>
|
|
|
|
<div class="filemanager animated-fade-in" v-else>
|
|
|
|
<div class="header">
|
|
|
|
<div class="flex-none w-8"></div>
|
|
|
|
<div class="flex-1">Name</div>
|
|
|
|
<div class="flex-1 text-right">Size</div>
|
|
|
|
<div class="flex-1 text-right">Modified</div>
|
|
|
|
<div class="flex-none w-1/6">Actions</div>
|
|
|
|
</div>
|
2019-03-10 22:44:49 +00:00
|
|
|
<div v-for="file in Array.concat(directories, files)">
|
|
|
|
<FileRow
|
|
|
|
:key="file.directory ? `dir-${file.name}` : file.name"
|
|
|
|
:file="file"
|
|
|
|
:editable="editableFiles"
|
|
|
|
v-on:deleted="fileRowDeleted(file, file.directory)"
|
2019-03-11 01:42:53 +00:00
|
|
|
v-on:list="listDirectory"
|
2019-03-10 22:44:49 +00:00
|
|
|
/>
|
2019-02-10 05:14:58 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex mt-6" v-if="!loading && !errorMessage">
|
|
|
|
<div class="flex-1"></div>
|
|
|
|
<div class="mr-4">
|
2019-02-17 01:54:15 +00:00
|
|
|
<a href="#" class="block btn btn-secondary btn-sm" v-on:click.prevent="openNewFolderModal">New Folder</a>
|
2019-02-10 05:14:58 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<a href="#" class="block btn btn-primary btn-sm">New File</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-03-10 21:28:24 +00:00
|
|
|
<CreateFolderModal v-on:created="directoryCreated"/>
|
2019-02-10 05:14:58 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-02-10 05:15:45 +00:00
|
|
|
import Vue from 'vue';
|
2019-03-10 21:28:24 +00:00
|
|
|
import { join } from 'path';
|
2019-02-10 05:15:45 +00:00
|
|
|
import {map} from 'lodash';
|
|
|
|
import getDirectoryContents from "@/api/server/getDirectoryContents";
|
|
|
|
import FileRow from "@/components/server/components/filemanager/FileRow.vue";
|
2019-02-17 01:54:15 +00:00
|
|
|
import CreateFolderModal from '../components/filemanager/modals/CreateFolderModal.vue';
|
2019-02-19 05:23:42 +00:00
|
|
|
import DeleteFileModal from '../components/filemanager/modals/DeleteFileModal.vue';
|
2019-02-19 04:41:58 +00:00
|
|
|
import {DirectoryContentObject} from "@/api/server/types";
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
type DataStructure = {
|
|
|
|
loading: boolean,
|
|
|
|
errorMessage: string | null,
|
|
|
|
currentDirectory: string,
|
2019-02-19 04:41:58 +00:00
|
|
|
files: Array<DirectoryContentObject>,
|
|
|
|
directories: Array<DirectoryContentObject>,
|
2019-02-10 05:15:45 +00:00
|
|
|
editableFiles: Array<string>,
|
|
|
|
}
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
export default Vue.extend({
|
|
|
|
name: 'FileManager',
|
2019-03-10 22:44:49 +00:00
|
|
|
components: {CreateFolderModal, DeleteFileModal, FileRow},
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-03-10 22:44:49 +00:00
|
|
|
computed: {
|
2019-02-10 05:15:45 +00:00
|
|
|
/**
|
|
|
|
* Configure the breadcrumbs that display on the filemanager based on the directory that the
|
|
|
|
* user is currently in.
|
|
|
|
*/
|
|
|
|
breadcrumbs: function () {
|
|
|
|
const directories = this.currentDirectory.replace(/^\/|\/$/, '').split('/');
|
|
|
|
if (directories.length < 1 || !directories[0]) {
|
|
|
|
return [];
|
2018-08-14 05:58:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
return map(directories, function (value: string, key: number) {
|
|
|
|
if (key === directories.length - 1) {
|
|
|
|
return {directoryName: value};
|
|
|
|
}
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
return {
|
|
|
|
directoryName: value,
|
|
|
|
path: directories.slice(0, key + 1).join('/'),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2018-08-04 05:32:01 +00:00
|
|
|
},
|
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
watch: {
|
|
|
|
/**
|
|
|
|
* When the route changes reload the directory.
|
|
|
|
*/
|
|
|
|
'$route': function (to) {
|
|
|
|
this.currentDirectory = to.params.path || '/';
|
|
|
|
},
|
2018-08-14 05:58:58 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
/**
|
|
|
|
* Watch the current directory setting and when it changes update the file listing.
|
|
|
|
*/
|
|
|
|
currentDirectory: function () {
|
2018-08-07 06:14:13 +00:00
|
|
|
this.listDirectory();
|
2019-02-10 05:15:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When we reconnect to the Daemon make sure we grab a listing of all of the files
|
|
|
|
* so that the error message disappears and we then load in a fresh listing.
|
|
|
|
*/
|
|
|
|
connected: function () {
|
|
|
|
// @ts-ignore
|
|
|
|
if (this.connected) {
|
|
|
|
this.listDirectory();
|
|
|
|
}
|
|
|
|
},
|
2018-08-07 06:14:13 +00:00
|
|
|
},
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
data: function (): DataStructure {
|
|
|
|
return {
|
|
|
|
currentDirectory: this.$route.params.path || '/',
|
|
|
|
loading: true,
|
|
|
|
errorMessage: null,
|
|
|
|
directories: [],
|
|
|
|
editableFiles: [],
|
|
|
|
files: [],
|
|
|
|
};
|
|
|
|
},
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
mounted: function () {
|
|
|
|
this.listDirectory();
|
|
|
|
},
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* List the contents of a directory.
|
|
|
|
*/
|
|
|
|
listDirectory: function () {
|
|
|
|
this.loading = true;
|
2018-09-23 23:06:23 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
const directory = encodeURI(this.currentDirectory.replace(/^\/|\/$/, ''));
|
2019-02-17 21:29:11 +00:00
|
|
|
this.$store.dispatch('server/updateCurrentDirectory', `/${directory}`);
|
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
getDirectoryContents(this.$route.params.id, directory)
|
|
|
|
.then((response) => {
|
|
|
|
this.files = response.files;
|
|
|
|
this.directories = response.directories;
|
|
|
|
this.editableFiles = response.editable;
|
|
|
|
this.errorMessage = null;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
if (typeof err === 'string') {
|
|
|
|
this.errorMessage = err;
|
|
|
|
return;
|
|
|
|
}
|
2018-08-07 06:14:13 +00:00
|
|
|
|
2019-02-10 05:15:45 +00:00
|
|
|
console.error('An error was encountered while processing this request.', {err});
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
},
|
2019-02-17 01:54:15 +00:00
|
|
|
|
|
|
|
openNewFolderModal: function () {
|
|
|
|
window.events.$emit('server:files:open-directory-modal');
|
2019-03-10 21:14:47 +00:00
|
|
|
},
|
|
|
|
|
2019-03-10 22:44:49 +00:00
|
|
|
fileRowDeleted: function (file: DirectoryContentObject, directory: boolean) {
|
|
|
|
if (directory) {
|
|
|
|
this.directories = this.directories.filter(data => data !== file);
|
|
|
|
} else {
|
|
|
|
this.files = this.files.filter(data => data !== file);
|
|
|
|
}
|
2019-03-10 21:50:44 +00:00
|
|
|
},
|
|
|
|
|
2019-03-10 21:28:24 +00:00
|
|
|
directoryCreated: function (directory: string) {
|
|
|
|
this.$router.push({ name: 'server-files', params: { path: join(this.currentDirectory, directory) }});
|
|
|
|
},
|
2018-08-04 05:32:01 +00:00
|
|
|
},
|
2019-02-10 05:15:45 +00:00
|
|
|
});
|
2019-02-10 05:14:58 +00:00
|
|
|
</script>
|