2017-07-03 09:40:24 +00:00
|
|
|
<template>
|
|
|
|
<div :class="{ multiple }">
|
|
|
|
<header>
|
|
|
|
<div>
|
|
|
|
<img src="../assets/logo.svg" alt="File Manager">
|
|
|
|
<search></search>
|
|
|
|
</div>
|
|
|
|
<div>
|
2017-07-03 14:19:17 +00:00
|
|
|
<rename-button v-show="!loading && showRenameButton()"></rename-button>
|
|
|
|
<move-button v-show="!loading && showMoveButton()"></move-button>
|
|
|
|
<delete-button v-show="!loading && showDeleteButton()"></delete-button>
|
|
|
|
<switch-button v-show="!loading && req.kind !== 'editor'"></switch-button>
|
2017-07-03 09:40:24 +00:00
|
|
|
<download-button></download-button>
|
2017-07-03 14:19:17 +00:00
|
|
|
<upload-button v-show="!loading && showUpload()"></upload-button>
|
2017-07-03 09:40:24 +00:00
|
|
|
<info-button></info-button>
|
|
|
|
|
2017-07-03 14:19:17 +00:00
|
|
|
<button v-show="isListing" @click="$store.commit('multiple', true)" aria-label="Select multiple" class="action">
|
2017-07-03 09:40:24 +00:00
|
|
|
<i class="material-icons">check_circle</i>
|
|
|
|
<span>Select</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<nav>
|
2017-07-03 14:19:17 +00:00
|
|
|
<router-link class="action" to="/files/">
|
2017-07-03 09:40:24 +00:00
|
|
|
<i class="material-icons">folder</i>
|
|
|
|
<span>My Files</span>
|
2017-07-03 14:19:17 +00:00
|
|
|
</router-link>
|
2017-07-03 09:40:24 +00:00
|
|
|
|
|
|
|
<div v-if="user.allowNew">
|
|
|
|
<button @click="$store.commit('showNewDir', true)" aria-label="New directory" title="New directory" class="action">
|
|
|
|
<i class="material-icons">create_new_folder</i>
|
|
|
|
<span>New folder</span>
|
|
|
|
</button>
|
|
|
|
<button @click="$store.commit('showNewFile', true)" aria-label="New file" title="New file" class="action">
|
|
|
|
<i class="material-icons">note_add</i>
|
|
|
|
<span>New file</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-for="plugin in plugins">
|
|
|
|
<button v-for="action in plugin.sidebar" @click="action.click" :aria-label="action.name" :title="action.name" class="action">
|
|
|
|
<i class="material-icons">{{ action.icon }}</i>
|
|
|
|
<span>{{ action.name }}</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2017-07-03 14:19:17 +00:00
|
|
|
<button @click="logout" class="action" id="logout" aria-label="Log out">
|
2017-07-03 09:40:24 +00:00
|
|
|
<i class="material-icons" title="Logout">exit_to_app</i>
|
|
|
|
<span>Logout</span>
|
|
|
|
</button>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
<main>
|
2017-07-03 14:19:17 +00:00
|
|
|
<editor v-if="isEditor"></editor>
|
|
|
|
<listing v-if="isListing"></listing>
|
|
|
|
<preview v-if="isPreview"></preview>
|
2017-07-03 09:40:24 +00:00
|
|
|
</main>
|
|
|
|
|
|
|
|
<download-prompt v-if="showDownload" :class="{ active: showDownload }"></download-prompt>
|
|
|
|
<new-file-prompt v-if="showNewFile" :class="{ active: showNewFile }"></new-file-prompt>
|
|
|
|
<new-dir-prompt v-if="showNewDir" :class="{ active: showNewDir }"></new-dir-prompt>
|
|
|
|
<rename-prompt v-if="showRename" :class="{ active: showRename }"></rename-prompt>
|
|
|
|
<delete-prompt v-if="showDelete" :class="{ active: showDelete }"></delete-prompt>
|
|
|
|
<info-prompt v-if="showInfo" :class="{ active: showInfo }"></info-prompt>
|
|
|
|
<move-prompt v-if="showMove" :class="{ active: showMove }"></move-prompt>
|
|
|
|
<help v-show="showHelp" :class="{ active: showHelp }"></help>
|
2017-07-03 14:19:17 +00:00
|
|
|
<div v-show="showOverlay" @click="resetPrompts" class="overlay" :class="{ active: showOverlay }"></div>
|
2017-07-03 09:40:24 +00:00
|
|
|
|
|
|
|
<footer>Served with <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>.</footer>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Search from './Search'
|
|
|
|
import Help from './Help'
|
|
|
|
import Preview from './Preview'
|
|
|
|
import Listing from './Listing'
|
|
|
|
import Editor from './Editor'
|
2017-07-03 10:20:36 +00:00
|
|
|
import InfoButton from './buttons/InfoButton'
|
|
|
|
import InfoPrompt from './prompts/InfoPrompt'
|
|
|
|
import DeleteButton from './buttons/DeleteButton'
|
|
|
|
import DeletePrompt from './prompts/DeletePrompt'
|
|
|
|
import RenameButton from './buttons/RenameButton'
|
|
|
|
import RenamePrompt from './prompts/RenamePrompt'
|
|
|
|
import UploadButton from './buttons/UploadButton'
|
|
|
|
import DownloadButton from './buttons/DownloadButton'
|
|
|
|
import DownloadPrompt from './prompts/DownloadPrompt'
|
|
|
|
import SwitchButton from './buttons/SwitchViewButton'
|
|
|
|
import MoveButton from './buttons/MoveButton'
|
|
|
|
import MovePrompt from './prompts/MovePrompt'
|
|
|
|
import NewFilePrompt from './prompts/NewFilePrompt'
|
|
|
|
import NewDirPrompt from './prompts/NewDirPrompt'
|
2017-07-03 09:40:24 +00:00
|
|
|
import css from '@/utils/css'
|
|
|
|
import auth from '@/utils/auth'
|
2017-07-03 10:04:14 +00:00
|
|
|
import api from '@/utils/api'
|
2017-07-03 09:40:24 +00:00
|
|
|
import {mapGetters, mapState} from 'vuex'
|
|
|
|
|
|
|
|
function updateColumnSizes () {
|
|
|
|
let columns = Math.floor(document.querySelector('main').offsetWidth / 300)
|
|
|
|
let items = css(['#listing.mosaic .item', '.mosaic#listing .item'])
|
|
|
|
|
|
|
|
if (columns === 0) columns = 1
|
|
|
|
|
|
|
|
items.style.width = `calc(${100 / columns}% - 1em)`
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'main',
|
|
|
|
components: {
|
|
|
|
Search,
|
|
|
|
Preview,
|
|
|
|
Listing,
|
|
|
|
Editor,
|
|
|
|
InfoButton,
|
|
|
|
InfoPrompt,
|
|
|
|
Help,
|
|
|
|
DeleteButton,
|
|
|
|
DeletePrompt,
|
|
|
|
RenameButton,
|
|
|
|
RenamePrompt,
|
|
|
|
DownloadButton,
|
|
|
|
DownloadPrompt,
|
|
|
|
UploadButton,
|
|
|
|
SwitchButton,
|
|
|
|
MoveButton,
|
|
|
|
MovePrompt,
|
|
|
|
NewFilePrompt,
|
|
|
|
NewDirPrompt
|
|
|
|
},
|
|
|
|
computed: {
|
2017-07-03 14:19:17 +00:00
|
|
|
...mapGetters([
|
|
|
|
'selectedCount',
|
|
|
|
'showOverlay'
|
|
|
|
]),
|
2017-07-03 09:40:24 +00:00
|
|
|
...mapState([
|
|
|
|
'req',
|
|
|
|
'user',
|
|
|
|
'baseURL',
|
|
|
|
'multiple',
|
|
|
|
'showInfo',
|
|
|
|
'showHelp',
|
|
|
|
'showDelete',
|
|
|
|
'showRename',
|
|
|
|
'showMove',
|
|
|
|
'showNewFile',
|
|
|
|
'showNewDir',
|
|
|
|
'showDownload'
|
2017-07-03 14:19:17 +00:00
|
|
|
]),
|
|
|
|
isListing () {
|
|
|
|
return this.req.kind === 'listing' && !this.loading
|
|
|
|
},
|
|
|
|
isPreview () {
|
|
|
|
return this.req.kind === 'preview' && !this.loading
|
|
|
|
},
|
|
|
|
isEditor () {
|
|
|
|
return this.req.kind === 'editor' && !this.loading
|
|
|
|
}
|
2017-07-03 09:40:24 +00:00
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
2017-07-03 14:19:17 +00:00
|
|
|
plugins: [],
|
|
|
|
loading: true
|
2017-07-03 09:40:24 +00:00
|
|
|
}
|
|
|
|
},
|
2017-07-03 14:19:17 +00:00
|
|
|
created () {
|
|
|
|
this.fetchData()
|
2017-07-03 10:04:14 +00:00
|
|
|
},
|
2017-07-03 14:19:17 +00:00
|
|
|
watch: {
|
|
|
|
'$route': 'fetchData'
|
2017-07-03 10:04:14 +00:00
|
|
|
},
|
|
|
|
mounted () {
|
2017-07-03 09:40:24 +00:00
|
|
|
updateColumnSizes()
|
|
|
|
window.addEventListener('resize', updateColumnSizes)
|
|
|
|
|
|
|
|
if (window.plugins !== undefined || window.plugins !== null) {
|
|
|
|
this.plugins = window.plugins
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('keydown', (event) => {
|
|
|
|
// Esc!
|
|
|
|
if (event.keyCode === 27) {
|
|
|
|
this.$store.commit('resetPrompts')
|
|
|
|
|
|
|
|
// Unselect all files and folders.
|
|
|
|
if (this.req.kind === 'listing') {
|
|
|
|
let items = document.getElementsByClassName('item')
|
|
|
|
Array.from(items).forEach(link => {
|
|
|
|
link.setAttribute('aria-selected', false)
|
|
|
|
})
|
|
|
|
|
|
|
|
this.$store.commit('resetSelected')
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Del!
|
|
|
|
if (event.keyCode === 46) {
|
|
|
|
if (this.showDeleteButton()) {
|
|
|
|
this.$store.commit('showDelete', true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// F1!
|
|
|
|
if (event.keyCode === 112) {
|
|
|
|
event.preventDefault()
|
|
|
|
this.$store.commit('showHelp', true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// F2!
|
|
|
|
if (event.keyCode === 113) {
|
|
|
|
if (this.showRenameButton()) {
|
|
|
|
this.$store.commit('showRename', true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CTRL + S
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
switch (String.fromCharCode(event.which).toLowerCase()) {
|
|
|
|
case 's':
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
if (this.req.kind !== 'editor') {
|
|
|
|
window.location = '?download=true'
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: save file on editor!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
2017-07-03 14:19:17 +00:00
|
|
|
fetchData () {
|
|
|
|
this.loading = true
|
|
|
|
// Reset selected items and multiple selection.
|
|
|
|
this.$store.commit('resetSelected')
|
|
|
|
this.$store.commit('multiple', false)
|
|
|
|
|
|
|
|
let url = this.$route.path
|
|
|
|
if (url === '') url = '/'
|
|
|
|
if (url[0] !== '/') url = '/' + url
|
|
|
|
|
|
|
|
console.log('Going to ' + url)
|
|
|
|
|
|
|
|
api.fetch(url)
|
|
|
|
.then((trueURL) => {
|
|
|
|
if (!url.endsWith('/') && trueURL.endsWith('/')) {
|
|
|
|
window.history.replaceState(window.history.state, document.title, window.location.pathname + '/')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = false
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
// TODO: 404, 403 and 500!
|
|
|
|
console.log(error)
|
|
|
|
|
|
|
|
this.loading = false
|
|
|
|
})
|
|
|
|
},
|
2017-07-03 09:40:24 +00:00
|
|
|
showUpload: function () {
|
|
|
|
if (this.req.kind === 'editor') return false
|
|
|
|
return this.user.allowNew
|
|
|
|
},
|
|
|
|
showDeleteButton: function () {
|
|
|
|
if (this.req.kind === 'listing') {
|
|
|
|
if (this.selectedCount === 0) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.user.allowEdit
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.user.allowEdit
|
|
|
|
},
|
|
|
|
showRenameButton: function () {
|
|
|
|
if (this.req.kind === 'listing') {
|
|
|
|
if (this.selectedCount === 1) {
|
|
|
|
return this.user.allowEdit
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.user.allowEdit
|
|
|
|
},
|
|
|
|
showMoveButton: function () {
|
|
|
|
if (this.req.kind !== 'listing') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selectedCount > 0) {
|
|
|
|
return this.user.allowEdit
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
resetPrompts: function () {
|
|
|
|
this.$store.commit('resetPrompts')
|
|
|
|
},
|
|
|
|
logout: auth.logout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|