Comments and bugfixes

pull/144/head
Henrique Dias 2017-07-08 12:32:25 +01:00
parent c206bea84a
commit 55c097b2aa
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
4 changed files with 44 additions and 30 deletions

View File

@ -7,6 +7,11 @@
<editor v-else-if="isEditor"></editor> <editor v-else-if="isEditor"></editor>
<listing :class="{ multiple }" v-else-if="isListing"></listing> <listing :class="{ multiple }" v-else-if="isListing"></listing>
<preview v-else-if="isPreview"></preview> <preview v-else-if="isPreview"></preview>
<div v-else>
<h2 class="message">
<span>Loading...</span>
</h2>
</div>
</template> </template>
<script> <script>
@ -16,19 +21,9 @@ import InternalError from './errors/500'
import Preview from './Preview' import Preview from './Preview'
import Listing from './Listing' import Listing from './Listing'
import Editor from './Editor' import Editor from './Editor'
import css from '@/utils/css'
import api from '@/utils/api' import api from '@/utils/api'
import { mapGetters, mapState, mapMutations } from 'vuex' import { mapGetters, mapState, mapMutations } 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 { export default {
name: 'files', name: 'files',
components: { components: {
@ -72,14 +67,18 @@ export default {
'$route': 'fetchData', '$route': 'fetchData',
'reload': function () { 'reload': function () {
this.$store.commit('setReload', false) this.$store.commit('setReload', false)
this.$store.commit('resetSelected')
this.$store.commit('multiple', false)
this.$store.commit('closeHovers')
this.fetchData() this.fetchData()
} }
}, },
mounted () { mounted () {
updateColumnSizes()
window.addEventListener('resize', updateColumnSizes)
window.addEventListener('keydown', this.keyEvent) window.addEventListener('keydown', this.keyEvent)
}, },
beforeDestroy () {
window.removeEventListener('keydown', this.keyEvent)
},
methods: { methods: {
...mapMutations([ 'setLoading' ]), ...mapMutations([ 'setLoading' ]),
fetchData () { fetchData () {
@ -117,18 +116,12 @@ export default {
if (event.keyCode === 27) { if (event.keyCode === 27) {
this.$store.commit('closeHovers') this.$store.commit('closeHovers')
if (this.req.kind !== 'listing') { // If we're on a listing, unselect all
return // files and folders.
} if (this.req.kind === 'listing') {
// If we're on a listing, unselect all files and folders.
let items = document.getElementsByClassName('item')
Array.from(items).forEach(link => {
link.setAttribute('aria-selected', false)
})
this.$store.commit('resetSelected') this.$store.commit('resetSelected')
} }
}
// Del! // Del!
if (event.keyCode === 46) { if (event.keyCode === 46) {

View File

@ -73,6 +73,7 @@
<script> <script>
import {mapState} from 'vuex' import {mapState} from 'vuex'
import Item from './ListingItem' import Item from './ListingItem'
import css from '@/utils/css'
import api from '@/utils/api' import api from '@/utils/api'
import buttons from '@/utils/buttons' import buttons from '@/utils/buttons'
@ -103,17 +104,38 @@ export default {
} }
}, },
mounted: function () { mounted: function () {
document.addEventListener('dragover', function (event) { // Check the columns size for the first time.
event.preventDefault() this.resizeEvent()
}, false)
document.addEventListener('drop', this.drop, false) // Add the needed event listeners to the window and document.
window.addEventListener('resize', this.resizeEvent)
document.addEventListener('dragover', this.preventDefault)
document.addEventListener('drop', this.drop)
},
beforeDestroy () {
// Remove event listeners before destroying this page.
window.removeEventListener('resize', this.resizeEvent)
document.removeEventListener('dragover', this.preventDefault)
document.removeEventListener('drop', this.drop)
}, },
methods: { methods: {
base64: function (name) { base64: function (name) {
return window.btoa(unescape(encodeURIComponent(name))) return window.btoa(unescape(encodeURIComponent(name)))
}, },
preventDefault (event) {
// Wrapper around prevent default.
event.preventDefault()
},
resizeEvent () {
// Update the columns size based on the window width.
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)`
},
dragEnter: function (event) { dragEnter: function (event) {
// When the user starts dragging an item, put every
// file on the listing with 50% opacity.
let items = document.getElementsByClassName('item') let items = document.getElementsByClassName('item')
Array.from(items).forEach(file => { Array.from(items).forEach(file => {

View File

@ -34,8 +34,7 @@
.action i { .action i {
padding: 0.4em; padding: 0.4em;
-webkit-transition: 0.2s ease-in-out all; transition: .1s ease-in-out all;
transition: 0.2s ease-in-out all;
border-radius: 50%; border-radius: 50%;
} }

View File

@ -13,7 +13,7 @@ function loading (button) {
el.classList.add('spin') el.classList.add('spin')
el.innerHTML = 'autorenew' el.innerHTML = 'autorenew'
el.style.opacity = 1 el.style.opacity = 1
}, 0) }, 100)
} }
function done (button, success = true) { function done (button, success = true) {
@ -30,7 +30,7 @@ function done (button, success = true) {
el.classList.remove('spin') el.classList.remove('spin')
el.innerHTML = el.dataset.icon el.innerHTML = el.dataset.icon
el.style.opacity = 1 el.style.opacity = 1
}, 0) }, 100)
} }
export default { export default {