2018-02-01 12:17:04 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2021-02-25 18:37:07 +00:00
|
|
|
<header-bar showMenu showLogo>
|
|
|
|
<search /> <title />
|
|
|
|
<action class="search-button" icon="search" :label="$t('buttons.search')" @action="openSearch()" />
|
|
|
|
|
|
|
|
<template #actions v-if="!error">
|
|
|
|
<template v-if="!isMobile">
|
|
|
|
<share-button v-if="headerButtons.share" />
|
|
|
|
<rename-button v-if="headerButtons.rename" />
|
|
|
|
<copy-button v-if="headerButtons.copy" />
|
|
|
|
<move-button v-if="headerButtons.move" />
|
|
|
|
<delete-button v-if="headerButtons.delete" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<shell-button v-if="headerButtons.shell" />
|
|
|
|
<switch-button />
|
|
|
|
<download-button v-if="headerButtons.download" />
|
|
|
|
<upload-button v-if="headerButtons.upload" />
|
|
|
|
<info-button />
|
|
|
|
<action icon="check_circle" :label="$t('buttons.selectMultiple')" @action="toggleMultipleSelection" />
|
|
|
|
</template>
|
|
|
|
</header-bar>
|
|
|
|
|
|
|
|
<div id="file-selection" v-if="isMobile">
|
|
|
|
<span v-if="selectedCount > 0">{{ selectedCount }} selected</span>
|
|
|
|
<share-button v-if="headerButtons.share" />
|
|
|
|
<rename-button v-if="headerButtons.rename" />
|
|
|
|
<copy-button v-if="headerButtons.copy" />
|
|
|
|
<move-button v-if="headerButtons.move" />
|
|
|
|
<delete-button v-if="headerButtons.delete" />
|
|
|
|
</div>
|
|
|
|
|
2020-07-04 03:11:51 +00:00
|
|
|
<div id="breadcrumbs" v-if="isListing || error">
|
2018-02-01 12:17:04 +00:00
|
|
|
<router-link to="/files/" :aria-label="$t('files.home')" :title="$t('files.home')">
|
|
|
|
<i class="material-icons">home</i>
|
|
|
|
</router-link>
|
|
|
|
|
2018-06-27 07:48:16 +00:00
|
|
|
<span v-for="(link, index) in breadcrumbs" :key="index">
|
2018-02-01 12:17:04 +00:00
|
|
|
<span class="chevron"><i class="material-icons">keyboard_arrow_right</i></span>
|
|
|
|
<router-link :to="link.url">{{ link.name }}</router-link>
|
|
|
|
</span>
|
|
|
|
</div>
|
2020-07-14 01:18:53 +00:00
|
|
|
|
2021-02-25 18:37:07 +00:00
|
|
|
<errors v-if="error" :errorCode="errorCode" />
|
2020-07-14 01:18:53 +00:00
|
|
|
<preview v-else-if="isPreview"></preview>
|
2018-02-01 12:17:04 +00:00
|
|
|
<editor v-else-if="isEditor"></editor>
|
|
|
|
<listing :class="{ multiple }" v-else-if="isListing"></listing>
|
|
|
|
<div v-else>
|
|
|
|
<h2 class="message">
|
|
|
|
<span>{{ $t('files.loading') }}</span>
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-01-05 16:12:09 +00:00
|
|
|
import { files as api } from '@/api'
|
2018-02-01 12:17:04 +00:00
|
|
|
import { mapGetters, mapState, mapMutations } from 'vuex'
|
2021-02-25 18:37:07 +00:00
|
|
|
import { enableExec } from '@/utils/constants'
|
|
|
|
|
|
|
|
import HeaderBar from '@/components/header/HeaderBar'
|
|
|
|
import Action from '@/components/header/Action'
|
|
|
|
import Search from '@/components/Search'
|
|
|
|
import InfoButton from '@/components/buttons/Info'
|
|
|
|
import DeleteButton from '@/components/buttons/Delete'
|
|
|
|
import RenameButton from '@/components/buttons/Rename'
|
|
|
|
import UploadButton from '@/components/buttons/Upload'
|
|
|
|
import DownloadButton from '@/components/buttons/Download'
|
|
|
|
import SwitchButton from '@/components/buttons/SwitchView'
|
|
|
|
import MoveButton from '@/components/buttons/Move'
|
|
|
|
import CopyButton from '@/components/buttons/Copy'
|
|
|
|
import ShareButton from '@/components/buttons/Share'
|
|
|
|
import ShellButton from '@/components/buttons/Shell'
|
|
|
|
|
|
|
|
import Errors from '@/views/Errors'
|
|
|
|
import Preview from '@/components/files/Preview'
|
|
|
|
import Listing from '@/components/files/Listing'
|
2018-02-01 12:17:04 +00:00
|
|
|
|
2019-01-05 16:12:09 +00:00
|
|
|
function clean (path) {
|
|
|
|
return path.endsWith('/') ? path.slice(0, -1) : path
|
|
|
|
}
|
|
|
|
|
2018-02-01 12:17:04 +00:00
|
|
|
export default {
|
|
|
|
name: 'files',
|
|
|
|
components: {
|
2021-02-25 18:37:07 +00:00
|
|
|
HeaderBar,
|
|
|
|
Action,
|
|
|
|
Search,
|
|
|
|
InfoButton,
|
|
|
|
DeleteButton,
|
|
|
|
ShareButton,
|
|
|
|
RenameButton,
|
|
|
|
DownloadButton,
|
|
|
|
CopyButton,
|
|
|
|
UploadButton,
|
|
|
|
SwitchButton,
|
|
|
|
MoveButton,
|
|
|
|
ShellButton,
|
|
|
|
Errors,
|
2018-02-01 12:17:04 +00:00
|
|
|
Preview,
|
|
|
|
Listing,
|
2021-02-25 18:37:07 +00:00
|
|
|
Editor: () => import('@/components/files/Editor'),
|
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
error: null,
|
|
|
|
width: window.innerWidth
|
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters([
|
2019-01-05 16:12:09 +00:00
|
|
|
'selectedCount',
|
|
|
|
'isListing',
|
|
|
|
'isEditor',
|
|
|
|
'isFiles'
|
2018-02-01 12:17:04 +00:00
|
|
|
]),
|
|
|
|
...mapState([
|
|
|
|
'req',
|
|
|
|
'user',
|
|
|
|
'reload',
|
|
|
|
'multiple',
|
2020-07-04 14:19:03 +00:00
|
|
|
'loading',
|
|
|
|
'show'
|
2018-02-01 12:17:04 +00:00
|
|
|
]),
|
|
|
|
isPreview () {
|
2020-07-14 01:18:53 +00:00
|
|
|
return !this.loading && !this.isListing && !this.isEditor || this.loading && this.$store.state.previewMode
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
breadcrumbs () {
|
|
|
|
let parts = this.$route.path.split('/')
|
|
|
|
|
|
|
|
if (parts[0] === '') {
|
|
|
|
parts.shift()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[parts.length - 1] === '') {
|
|
|
|
parts.pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
let breadcrumbs = []
|
|
|
|
|
|
|
|
for (let i = 0; i < parts.length; i++) {
|
|
|
|
if (i === 0) {
|
|
|
|
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: '/' + parts[i] + '/' })
|
|
|
|
} else {
|
|
|
|
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: breadcrumbs[i - 1].url + parts[i] + '/' })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
breadcrumbs.shift()
|
|
|
|
|
|
|
|
if (breadcrumbs.length > 3) {
|
|
|
|
while (breadcrumbs.length !== 4) {
|
|
|
|
breadcrumbs.shift()
|
|
|
|
}
|
|
|
|
|
|
|
|
breadcrumbs[0].name = '...'
|
|
|
|
}
|
|
|
|
|
|
|
|
return breadcrumbs
|
2021-02-25 18:37:07 +00:00
|
|
|
},
|
|
|
|
headerButtons() {
|
|
|
|
return {
|
|
|
|
upload: this.user.perm.create,
|
|
|
|
download: this.user.perm.download,
|
|
|
|
shell: this.user.perm.execute && enableExec,
|
|
|
|
delete: this.selectedCount > 0 && this.user.perm.delete,
|
|
|
|
rename: this.selectedCount === 1 && this.user.perm.rename,
|
|
|
|
share: this.selectedCount === 1 && this.user.perm.share,
|
|
|
|
move: this.selectedCount === 1 && this.user.perm.rename,
|
|
|
|
copy: this.selectedCount === 1 && this.user.perm.create,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
errorCode() {
|
|
|
|
return (this.error.message === '404' || this.error.message === '403') ? parseInt(this.error.message) : 500
|
|
|
|
},
|
|
|
|
isMobile () {
|
|
|
|
return this.width <= 736
|
|
|
|
},
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.fetchData()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$route': 'fetchData',
|
2021-01-11 23:00:40 +00:00
|
|
|
'reload': function (value) {
|
|
|
|
if (value === true) {
|
|
|
|
this.fetchData()
|
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
window.addEventListener('keydown', this.keyEvent)
|
|
|
|
window.addEventListener('scroll', this.scroll)
|
2021-02-25 18:37:07 +00:00
|
|
|
window.addEventListener('resize', this.windowsResize)
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
window.removeEventListener('keydown', this.keyEvent)
|
|
|
|
window.removeEventListener('scroll', this.scroll)
|
2021-02-25 18:37:07 +00:00
|
|
|
window.removeEventListener('resize', this.windowsResize)
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
destroyed () {
|
2021-02-25 18:37:07 +00:00
|
|
|
if (this.$store.state.showShell) {
|
|
|
|
this.$store.commit('toggleShell')
|
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
this.$store.commit('updateRequest', {})
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapMutations([ 'setLoading' ]),
|
2019-01-05 16:12:09 +00:00
|
|
|
async fetchData () {
|
2018-02-01 12:17:04 +00:00
|
|
|
// Reset view information.
|
|
|
|
this.$store.commit('setReload', false)
|
|
|
|
this.$store.commit('resetSelected')
|
|
|
|
this.$store.commit('multiple', false)
|
|
|
|
this.$store.commit('closeHovers')
|
|
|
|
|
|
|
|
// Set loading to true and reset the error.
|
|
|
|
this.setLoading(true)
|
|
|
|
this.error = null
|
|
|
|
|
|
|
|
let url = this.$route.path
|
|
|
|
if (url === '') url = '/'
|
|
|
|
if (url[0] !== '/') url = '/' + url
|
|
|
|
|
2019-01-05 16:12:09 +00:00
|
|
|
try {
|
|
|
|
const res = await api.fetch(url)
|
2018-02-01 12:17:04 +00:00
|
|
|
|
2019-01-05 16:12:09 +00:00
|
|
|
if (clean(res.path) !== clean(`/${this.$route.params.pathMatch}`)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$store.commit('updateRequest', res)
|
|
|
|
document.title = res.name
|
|
|
|
} catch (e) {
|
|
|
|
this.error = e
|
|
|
|
} finally {
|
|
|
|
this.setLoading(false)
|
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
},
|
|
|
|
keyEvent (event) {
|
2020-07-04 14:19:03 +00:00
|
|
|
if (this.show !== null) {
|
|
|
|
// Esc!
|
|
|
|
if (event.keyCode === 27) {
|
|
|
|
this.$store.commit('closeHovers')
|
|
|
|
}
|
2018-02-01 12:17:04 +00:00
|
|
|
|
2020-07-04 14:19:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Esc!
|
2021-02-25 18:37:07 +00:00
|
|
|
if (event.keyCode === 27) {
|
2018-02-01 12:17:04 +00:00
|
|
|
// If we're on a listing, unselect all
|
|
|
|
// files and folders.
|
2019-01-05 16:12:09 +00:00
|
|
|
if (this.isListing) {
|
2018-02-01 12:17:04 +00:00
|
|
|
this.$store.commit('resetSelected')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Del!
|
|
|
|
if (event.keyCode === 46) {
|
2019-01-05 16:12:09 +00:00
|
|
|
if (this.isEditor ||
|
|
|
|
!this.isFiles ||
|
2018-02-01 12:17:04 +00:00
|
|
|
this.loading ||
|
2019-01-05 16:12:09 +00:00
|
|
|
!this.user.perm.delete ||
|
2019-10-24 11:10:34 +00:00
|
|
|
(this.isListing && this.selectedCount === 0) ||
|
|
|
|
this.$store.state.show != null) return
|
2018-02-01 12:17:04 +00:00
|
|
|
|
|
|
|
this.$store.commit('showHover', 'delete')
|
|
|
|
}
|
|
|
|
|
|
|
|
// F1!
|
|
|
|
if (event.keyCode === 112) {
|
|
|
|
event.preventDefault()
|
|
|
|
this.$store.commit('showHover', 'help')
|
|
|
|
}
|
|
|
|
|
|
|
|
// F2!
|
|
|
|
if (event.keyCode === 113) {
|
2019-01-05 16:12:09 +00:00
|
|
|
if (this.isEditor ||
|
|
|
|
!this.isFiles ||
|
2018-02-01 12:17:04 +00:00
|
|
|
this.loading ||
|
2019-01-05 16:12:09 +00:00
|
|
|
!this.user.perm.rename ||
|
|
|
|
(this.isListing && this.selectedCount === 0) ||
|
|
|
|
(this.isListing && this.selectedCount > 1)) return
|
2018-02-01 12:17:04 +00:00
|
|
|
|
|
|
|
this.$store.commit('showHover', 'rename')
|
|
|
|
}
|
|
|
|
|
|
|
|
// CTRL + S
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
2019-01-05 16:12:09 +00:00
|
|
|
if (this.isEditor) return
|
|
|
|
|
2018-02-01 12:17:04 +00:00
|
|
|
if (String.fromCharCode(event.which).toLowerCase() === 's') {
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
if (this.req.kind !== 'editor') {
|
|
|
|
document.getElementById('download-button').click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-01-05 16:12:09 +00:00
|
|
|
scroll () {
|
2018-02-01 12:17:04 +00:00
|
|
|
if (this.req.kind !== 'listing' || this.$store.state.user.viewMode === 'mosaic') return
|
|
|
|
|
|
|
|
let top = 112 - window.scrollY
|
|
|
|
|
|
|
|
if (top < 64) {
|
|
|
|
top = 64
|
|
|
|
}
|
|
|
|
|
|
|
|
document.querySelector('#listing.list .item.header').style.top = top + 'px'
|
|
|
|
},
|
|
|
|
openSearch () {
|
|
|
|
this.$store.commit('showHover', 'search')
|
2021-02-25 18:37:07 +00:00
|
|
|
},
|
|
|
|
toggleMultipleSelection () {
|
|
|
|
this.$store.commit('multiple', !this.multiple)
|
|
|
|
this.$store.commit('closeHovers')
|
|
|
|
},
|
|
|
|
windowsResize () {
|
|
|
|
this.width = window.innerWidth
|
2018-02-01 12:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|