2018-05-27 22:37:03 +00:00
|
|
|
<template>
|
2018-08-26 21:05:10 +00:00
|
|
|
<div class="content-box animate fadein">
|
2018-08-14 05:58:58 +00:00
|
|
|
<div class="filemanager-breadcrumbs">
|
|
|
|
/<span class="px-1">home</span><!--
|
|
|
|
-->/<router-link :to="{ name: 'server-files' }" class="px-1">container</router-link><!--
|
|
|
|
--><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 font-semibold">{{crumb.directoryName}}</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
2018-08-04 05:32:01 +00:00
|
|
|
<div v-if="loading">
|
|
|
|
<div class="spinner spinner-xl blue"></div>
|
|
|
|
</div>
|
2018-08-14 04:06:11 +00:00
|
|
|
<div v-else-if="!loading && errorMessage">
|
|
|
|
<div class="alert error" v-text="errorMessage"></div>
|
|
|
|
</div>
|
2018-08-04 05:32:01 +00:00
|
|
|
<div class="filemanager" 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>
|
2018-08-14 05:58:58 +00:00
|
|
|
<div v-if="!directories.length && !files.length">
|
|
|
|
<p class="text-grey text-sm text-center p-6 pb-4">This directory is empty.</p>
|
2018-08-04 05:32:01 +00:00
|
|
|
</div>
|
2018-08-14 05:58:58 +00:00
|
|
|
<div v-else>
|
2018-08-15 04:17:10 +00:00
|
|
|
<div v-for="directory in directories">
|
|
|
|
<file-manager-folder-row :directory="directory"/>
|
|
|
|
</div>
|
|
|
|
<div v-for="file in files">
|
|
|
|
<file-manager-file-row :file="file" :editable="editableFiles" />
|
2018-08-04 05:32:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-05-27 22:37:03 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-08-15 04:17:10 +00:00
|
|
|
import map from 'lodash/map';
|
2018-08-04 05:32:01 +00:00
|
|
|
import filter from 'lodash/filter';
|
2018-08-14 04:06:11 +00:00
|
|
|
import isObject from 'lodash/isObject';
|
2018-08-04 05:32:01 +00:00
|
|
|
import { mapState } from 'vuex';
|
2018-08-15 04:17:10 +00:00
|
|
|
import FileManagerFileRow from '../components/FileManagerFileRow';
|
|
|
|
import FileManagerFolderRow from '../components/FileManagerFolderRow';
|
2018-08-04 05:32:01 +00:00
|
|
|
|
2018-05-27 22:37:03 +00:00
|
|
|
export default {
|
2018-08-04 05:32:01 +00:00
|
|
|
name: 'file-manager-page',
|
2018-08-15 04:17:10 +00:00
|
|
|
components: {FileManagerFolderRow, FileManagerFileRow},
|
2018-08-04 05:32:01 +00:00
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState('server', ['server', 'credentials']),
|
2018-08-14 04:06:11 +00:00
|
|
|
...mapState('socket', ['connected']),
|
2018-08-14 05:58:58 +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-15 04:17:10 +00:00
|
|
|
return map(directories, function (value, key) {
|
2018-08-14 05:58:58 +00:00
|
|
|
if (key === directories.length - 1) {
|
|
|
|
return {directoryName: value};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
directoryName: value,
|
|
|
|
path: directories.slice(0, key + 1).join('/'),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2018-08-04 05:32:01 +00:00
|
|
|
},
|
|
|
|
|
2018-08-07 06:14:13 +00:00
|
|
|
watch: {
|
2018-08-14 05:58:58 +00:00
|
|
|
/**
|
|
|
|
* When the route changes reload the directory.
|
|
|
|
*/
|
|
|
|
'$route': function (to) {
|
|
|
|
this.currentDirectory = to.params.path || '/';
|
|
|
|
},
|
|
|
|
|
2018-08-14 04:06:11 +00:00
|
|
|
/**
|
|
|
|
* Watch the current directory setting and when it changes update the file listing.
|
|
|
|
*/
|
2018-08-07 06:14:13 +00:00
|
|
|
currentDirectory: function () {
|
|
|
|
this.listDirectory();
|
|
|
|
},
|
2018-08-14 04:06:11 +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 () {
|
|
|
|
if (this.connected) {
|
|
|
|
this.listDirectory();
|
|
|
|
}
|
|
|
|
}
|
2018-08-07 06:14:13 +00:00
|
|
|
},
|
|
|
|
|
2018-08-04 05:32:01 +00:00
|
|
|
data: function () {
|
|
|
|
return {
|
2018-08-14 05:58:58 +00:00
|
|
|
currentDirectory: this.$route.params.path || '/',
|
2018-08-04 05:32:01 +00:00
|
|
|
loading: true,
|
2018-08-14 04:06:11 +00:00
|
|
|
errorMessage: null,
|
2018-08-04 05:32:01 +00:00
|
|
|
|
2018-08-07 06:14:13 +00:00
|
|
|
directories: [],
|
|
|
|
editableFiles: [],
|
2018-08-04 05:32:01 +00:00
|
|
|
files: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted: function () {
|
|
|
|
this.listDirectory();
|
|
|
|
},
|
2018-05-27 22:37:03 +00:00
|
|
|
|
2018-08-04 05:32:01 +00:00
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* List the contents of a directory.
|
|
|
|
*/
|
|
|
|
listDirectory: function () {
|
2018-08-07 06:14:13 +00:00
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
window.axios.get(this.route('server.files', {
|
|
|
|
server: this.$route.params.id,
|
2018-08-14 05:58:58 +00:00
|
|
|
directory: encodeURI(this.currentDirectory.replace(/^\/|\/$/, '')),
|
2018-08-07 06:14:13 +00:00
|
|
|
}))
|
2018-08-04 05:32:01 +00:00
|
|
|
.then((response) => {
|
2018-08-07 06:14:13 +00:00
|
|
|
this.files = filter(response.data.contents, function (o) {
|
2018-08-04 05:32:01 +00:00
|
|
|
return o.file;
|
|
|
|
});
|
2018-05-27 22:37:03 +00:00
|
|
|
|
2018-08-07 06:14:13 +00:00
|
|
|
this.directories = filter(response.data.contents, function (o) {
|
2018-08-04 05:32:01 +00:00
|
|
|
return o.directory;
|
|
|
|
});
|
2018-08-07 06:14:13 +00:00
|
|
|
|
|
|
|
this.editableFiles = response.data.editable;
|
2018-08-14 04:06:11 +00:00
|
|
|
this.errorMessage = null;
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2018-08-14 05:58:58 +00:00
|
|
|
console.error({err});
|
|
|
|
if (err.response.status === 404) {
|
|
|
|
this.errorMessage = 'The directory you requested could not be located on the server.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-14 04:06:11 +00:00
|
|
|
if (err.response.data && isObject(err.response.data.errors)) {
|
|
|
|
err.response.data.errors.forEach(error => {
|
|
|
|
this.errorMessage = error.detail;
|
|
|
|
});
|
|
|
|
}
|
2018-08-04 05:32:01 +00:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|