2017-06-28 10:45:41 +00:00
|
|
|
<template>
|
2017-06-30 11:43:43 +00:00
|
|
|
<div id="app" :class="{ multiple: $store.state.multiple }">
|
2017-06-28 10:45:41 +00:00
|
|
|
<header>
|
2017-06-28 21:20:28 +00:00
|
|
|
<div>
|
2017-06-28 18:26:07 +00:00
|
|
|
<img src="./assets/logo.svg" alt="File Manager">
|
|
|
|
<search></search>
|
|
|
|
</div>
|
2017-06-28 21:20:28 +00:00
|
|
|
<div>
|
2017-06-29 10:34:47 +00:00
|
|
|
<rename-button v-show="showRenameButton()"></rename-button>
|
2017-06-29 13:16:08 +00:00
|
|
|
<move-button v-show="showMoveButton()"></move-button>
|
2017-06-29 10:34:47 +00:00
|
|
|
<delete-button v-show="showDeleteButton()"></delete-button>
|
2017-06-30 11:43:43 +00:00
|
|
|
<switch-button v-show="$store.state.req.kind !== 'editor'"></switch-button>
|
2017-06-29 08:11:46 +00:00
|
|
|
<download-button></download-button>
|
|
|
|
<upload-button v-show="showUpload()"></upload-button>
|
2017-06-28 18:26:07 +00:00
|
|
|
<info-button></info-button>
|
|
|
|
</div>
|
2017-06-28 10:45:41 +00:00
|
|
|
</header>
|
2017-06-29 20:46:08 +00:00
|
|
|
|
|
|
|
<nav>
|
2017-06-30 11:43:43 +00:00
|
|
|
<a class="action" :href="$store.state.baseURL + '/'">
|
2017-06-28 10:45:41 +00:00
|
|
|
<i class="material-icons">folder</i>
|
|
|
|
<span>My Files</span>
|
|
|
|
</a>
|
2017-06-30 11:43:43 +00:00
|
|
|
<div v-if="$store.state.user.allowNew">
|
2017-06-30 09:25:35 +00:00
|
|
|
<button @click="$store.commit('showNewDir', true)" aria-label="New directory" title="New directory" class="action">
|
2017-06-29 18:12:05 +00:00
|
|
|
<i class="material-icons">create_new_folder</i>
|
|
|
|
<span>New folder</span>
|
|
|
|
</button>
|
2017-06-30 09:25:35 +00:00
|
|
|
<button @click="$store.commit('showNewFile', true)" aria-label="New file" title="New file" class="action">
|
2017-06-29 18:12:05 +00:00
|
|
|
<i class="material-icons">note_add</i>
|
|
|
|
<span>New file</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<button class="action" id="logout" tabindex="0" role="button" aria-label="Log out">
|
2017-06-28 10:45:41 +00:00
|
|
|
<i class="material-icons" title="Logout">exit_to_app</i>
|
|
|
|
<span>Logout</span>
|
2017-06-29 18:12:05 +00:00
|
|
|
</button>
|
2017-06-28 10:45:41 +00:00
|
|
|
</nav>
|
2017-06-29 20:46:08 +00:00
|
|
|
|
2017-06-28 10:45:41 +00:00
|
|
|
<main>
|
2017-06-30 11:43:43 +00:00
|
|
|
<editor v-if="$store.state.req.kind === 'editor'"></editor>
|
|
|
|
<listing v-if="$store.state.req.kind === 'listing'"></listing>
|
|
|
|
<preview v-if="$store.state.req.kind === 'preview'"></preview>
|
2017-06-28 10:45:41 +00:00
|
|
|
</main>
|
2017-06-28 21:24:00 +00:00
|
|
|
|
2017-06-30 09:25:35 +00:00
|
|
|
<new-file-prompt v-if="$store.state.showNewFile" :class="{ active: $store.state.showNewFile }"></new-file-prompt>
|
|
|
|
<new-dir-prompt v-if="$store.state.showNewDir" :class="{ active: $store.state.showNewDir }"></new-dir-prompt>
|
|
|
|
<rename-prompt v-if="$store.state.showRename" :class="{ active: $store.state.showRename }"></rename-prompt>
|
|
|
|
<delete-prompt v-if="$store.state.showDelete" :class="{ active: $store.state.showDelete }"></delete-prompt>
|
|
|
|
<info-prompt v-if="$store.state.showInfo" :class="{ active: $store.state.showInfo }"></info-prompt>
|
|
|
|
<move-prompt v-if="$store.state.showMove" :class="{ active: $store.state.showMove }"></move-prompt>
|
|
|
|
<help v-show="$store.state.showHelp" :class="{ active: $store.state.showHelp }"></help>
|
|
|
|
<div v-show="$store.getters.showOverlay" @click="resetPrompts" class="overlay" :class="{ active: $store.getters.showOverlay }"></div>
|
2017-06-28 21:20:28 +00:00
|
|
|
|
|
|
|
<footer>Served with <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>.</footer>
|
2017-06-28 10:45:41 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Search from './components/Search'
|
2017-06-28 21:20:28 +00:00
|
|
|
import Help from './components/Help'
|
2017-06-29 20:46:08 +00:00
|
|
|
import Preview from './components/Preview'
|
2017-06-28 10:45:41 +00:00
|
|
|
import Listing from './components/Listing'
|
2017-06-29 20:46:08 +00:00
|
|
|
import Editor from './components/Editor'
|
2017-06-28 18:26:07 +00:00
|
|
|
import InfoButton from './components/InfoButton'
|
2017-06-28 21:20:28 +00:00
|
|
|
import InfoPrompt from './components/InfoPrompt'
|
2017-06-28 21:24:00 +00:00
|
|
|
import DeleteButton from './components/DeleteButton'
|
2017-06-29 10:34:47 +00:00
|
|
|
import DeletePrompt from './components/DeletePrompt'
|
2017-06-29 08:11:46 +00:00
|
|
|
import RenameButton from './components/RenameButton'
|
2017-06-29 10:34:47 +00:00
|
|
|
import RenamePrompt from './components/RenamePrompt'
|
2017-06-29 08:11:46 +00:00
|
|
|
import UploadButton from './components/UploadButton'
|
|
|
|
import DownloadButton from './components/DownloadButton'
|
|
|
|
import SwitchButton from './components/SwitchViewButton'
|
|
|
|
import MoveButton from './components/MoveButton'
|
2017-06-29 13:16:08 +00:00
|
|
|
import MovePrompt from './components/MovePrompt'
|
2017-06-29 17:55:16 +00:00
|
|
|
import NewFilePrompt from './components/NewFilePrompt'
|
|
|
|
import NewDirPrompt from './components/NewDirPrompt'
|
2017-06-28 15:05:30 +00:00
|
|
|
import css from './css.js'
|
|
|
|
|
|
|
|
function updateColumnSizes () {
|
|
|
|
let columns = Math.floor(document.querySelector('main').offsetWidth / 300)
|
|
|
|
let items = css(['#listing.mosaic .item', '.mosaic#listing .item'])
|
|
|
|
|
2017-06-29 17:55:16 +00:00
|
|
|
if (columns === 0) columns = 1
|
|
|
|
|
2017-06-28 15:05:30 +00:00
|
|
|
items.style.width = `calc(${100 / columns}% - 1em)`
|
|
|
|
}
|
2017-06-28 10:45:41 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'app',
|
2017-06-29 08:11:46 +00:00
|
|
|
components: {
|
|
|
|
Search,
|
|
|
|
Preview,
|
|
|
|
Listing,
|
2017-06-29 20:46:08 +00:00
|
|
|
Editor,
|
2017-06-29 08:11:46 +00:00
|
|
|
InfoButton,
|
|
|
|
InfoPrompt,
|
|
|
|
Help,
|
|
|
|
DeleteButton,
|
2017-06-29 10:34:47 +00:00
|
|
|
DeletePrompt,
|
2017-06-29 08:11:46 +00:00
|
|
|
RenameButton,
|
2017-06-29 10:34:47 +00:00
|
|
|
RenamePrompt,
|
2017-06-29 08:11:46 +00:00
|
|
|
DownloadButton,
|
|
|
|
UploadButton,
|
|
|
|
SwitchButton,
|
2017-06-29 13:16:08 +00:00
|
|
|
MoveButton,
|
2017-06-29 17:55:16 +00:00
|
|
|
MovePrompt,
|
|
|
|
NewFilePrompt,
|
|
|
|
NewDirPrompt
|
2017-06-29 08:11:46 +00:00
|
|
|
},
|
2017-06-28 15:05:30 +00:00
|
|
|
mounted: function () {
|
2017-06-30 09:25:35 +00:00
|
|
|
updateColumnSizes()
|
|
|
|
window.addEventListener('resize', updateColumnSizes)
|
|
|
|
window.history.replaceState({
|
|
|
|
url: window.location.pathname,
|
|
|
|
name: document.title
|
|
|
|
}, document.title, window.location.pathname)
|
|
|
|
|
2017-06-30 11:43:43 +00:00
|
|
|
window.addEventListener('popstate', (event) => {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
this.$store.commit('multiple', false)
|
|
|
|
this.$store.commit('resetSelected')
|
|
|
|
this.$store.commit('resetPrompts')
|
|
|
|
|
|
|
|
let request = new window.XMLHttpRequest()
|
|
|
|
request.open('GET', event.state.url, true)
|
|
|
|
request.setRequestHeader('Accept', 'application/json')
|
|
|
|
|
|
|
|
request.onload = () => {
|
|
|
|
if (request.status === 200) {
|
|
|
|
let req = JSON.parse(request.responseText)
|
|
|
|
this.$store.commit('updateRequest', req)
|
|
|
|
document.title = event.state.name
|
|
|
|
} else {
|
|
|
|
console.log(request.responseText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request.onerror = (error) => { console.log(error) }
|
|
|
|
request.send()
|
|
|
|
})
|
|
|
|
|
2017-06-30 09:25:35 +00:00
|
|
|
window.addEventListener('keydown', (event) => {
|
|
|
|
// Esc!
|
|
|
|
if (event.keyCode === 27) {
|
|
|
|
this.$store.commit('resetPrompts')
|
|
|
|
|
|
|
|
// Unselect all files and folders.
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.$store.state.req.kind === 'listing') {
|
2017-06-30 09:25:35 +00:00
|
|
|
let items = document.getElementsByClassName('item')
|
|
|
|
Array.from(items).forEach(link => {
|
|
|
|
link.setAttribute('aria-selected', false)
|
|
|
|
})
|
|
|
|
|
2017-06-30 11:43:43 +00:00
|
|
|
this.$store.selected = []
|
2017-06-30 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Del!
|
|
|
|
if (event.keyCode === 46) {
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.showDeleteButton()) {
|
|
|
|
this.$store.commit('showDelete', true)
|
2017-06-30 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// F1!
|
|
|
|
if (event.keyCode === 112) {
|
|
|
|
event.preventDefault()
|
2017-06-30 11:43:43 +00:00
|
|
|
this.$store.commit('showHelp', true)
|
2017-06-30 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// F2!
|
|
|
|
if (event.keyCode === 113) {
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.showRenameButton()) {
|
|
|
|
this.$store.commit('showRename', true)
|
2017-06-30 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CTRL + S
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
switch (String.fromCharCode(event.which).toLowerCase()) {
|
|
|
|
case 's':
|
|
|
|
event.preventDefault()
|
|
|
|
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.$store.state.req.kind !== 'editor') {
|
2017-06-30 09:25:35 +00:00
|
|
|
window.location = '?download=true'
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: save file on editor!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let loading = document.getElementById('loading')
|
|
|
|
loading.classList.add('done')
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
loading.parentNode.removeChild(loading)
|
|
|
|
}, 1000)
|
2017-06-28 10:45:41 +00:00
|
|
|
},
|
2017-06-28 21:20:28 +00:00
|
|
|
methods: {
|
2017-06-29 08:11:46 +00:00
|
|
|
showUpload: function () {
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.$store.state.req.kind === 'editor') return false
|
|
|
|
return this.$store.state.user.allowNew
|
|
|
|
},
|
|
|
|
showDeleteButton: function () {
|
|
|
|
if (this.$store.state.req.kind === 'listing') {
|
|
|
|
if (this.$store.getters.selectedCount === 0) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$store.state.user.allowEdit
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$store.state.user.allowEdit
|
|
|
|
},
|
|
|
|
showRenameButton: function () {
|
|
|
|
if (this.$store.state.req.kind === 'listing') {
|
|
|
|
if (this.$store.getters.selectedCount === 1) {
|
|
|
|
return this.$store.state.user.allowEdit
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$store.state.user.allowEdit
|
2017-06-29 09:17:35 +00:00
|
|
|
},
|
2017-06-29 13:16:08 +00:00
|
|
|
showMoveButton: function () {
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.$store.state.req.kind !== 'listing') {
|
2017-06-29 13:16:08 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-06-30 11:43:43 +00:00
|
|
|
if (this.$store.getters.selectedCount > 0) {
|
|
|
|
return this.$store.state.user.allowEdit
|
2017-06-29 13:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2017-06-29 10:34:47 +00:00
|
|
|
},
|
2017-06-30 09:25:35 +00:00
|
|
|
resetPrompts: function () {
|
|
|
|
this.$store.commit('resetPrompts')
|
|
|
|
}
|
2017-06-28 10:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
@import './css/styles.css';
|
|
|
|
</style>
|