api resource refactoring part 2

This commit is contained in:
Peter Papp
2021-08-27 10:05:20 +02:00
parent e0e060e5a1
commit 174f2a2c1f
7 changed files with 61 additions and 24 deletions

View File

@@ -174,15 +174,13 @@
},
dragFinish(data, event) {
if (event.dataTransfer.items.length == 0) {
if (event.dataTransfer.items.length === 0) {
// Prevent to drop on file or image
if (data.data.type !== 'folder' || this.draggingId === data) return
//Prevent move selected folder to folder if in beteewn selected folders
if (this.clipboard.find(item => item === data && this.clipboard.length > 1)) return
// Move folder to new parent
//Move item if is not included in selected items
if (!this.clipboard.includes(this.draggingId)) {
this.$store.dispatch('moveItem', {to_item: data, noSelectedItem: this.draggingId})

View File

@@ -1,9 +1,9 @@
<template>
<div v-if="canBePreview" class="preview">
<img v-if="clipboard[0].type == 'image' && clipboard[0].thumbnail" :src="clipboard[0].thumbnail" :alt="clipboard[0].name" />
<audio v-else-if="clipboard[0].type == 'audio'" :src="clipboard[0].file_url" controlsList="nodownload" controls></audio>
<video v-else-if="clipboard[0].type == 'video'" controlsList="nodownload" disablePictureInPicture playsinline controls>
<source :src="clipboard[0].file_url" type="video/mp4">
<img v-if="singleFile.data.type === 'image' && singleFile.data.attributes.thumbnail" :src="singleFile.data.attributes.thumbnail" :alt="singleFile.data.attributes.name" />
<audio v-else-if="singleFile.data.type === 'audio'" :src="singleFile.data.attributes.file_url" controlsList="nodownload" controls></audio>
<video v-else-if="singleFile.data.type === 'video'" controlsList="nodownload" disablePictureInPicture playsinline controls>
<source :src="singleFile.data.attributes.file_url" type="video/mp4">
</video>
</div>
</template>
@@ -15,11 +15,16 @@
export default {
name: 'FilePreview',
computed: {
...mapGetters(['clipboard']),
...mapGetters([
'clipboard'
]),
singleFile() {
return this.clipboard[0]
},
canBePreview() {
return this.clipboard[0] && ! includes([
return this.singleFile && ! includes([
'folder', 'file'
], this.clipboard[0].type)
], this.singleFile.data.type)
}
},
}

View File

@@ -96,7 +96,7 @@ const FunctionHelpers = {
// Push items to file queue
[...files].map(item => {
this.$store.commit('ADD_FILES_TO_QUEUE', {
folder_id: store.getters.currentFolder.data.id ? store.getters.currentFolder.data.id : '',
folder_id: store.getters.currentFolder ? store.getters.currentFolder.data.id : '',
file: item,
})
});

View File

@@ -58,9 +58,16 @@ const actions = {
? `/api/editor/move/${router.currentRoute.params.token}`
: '/api/move'
let moveToId = undefined
if (to_item.data)
moveToId = to_item.data.id
else if (to_item.id)
moveToId = to_item.id
axios
.post(route, {
to_id: to_item.id ? to_item.id : null,
to_id: moveToId,
items: itemsToMove
})
.then(() => {
@@ -170,7 +177,7 @@ const actions = {
resolve(response)
// Proceed if was returned database record
if (response.data.id) {
if (response.data.data.id) {
commit('PROCESSING_FILE', false)
@@ -178,18 +185,18 @@ const actions = {
commit('SHIFT_FROM_FILE_QUEUE')
// Check if user is in uploading folder, if yes, than show new file
if (response.data.folder_id === getters.currentFolder.data.id) {
if ((! getters.currentFolder && !response.data.data.attributes.folder_id) || response.data.data.attributes.folder_id === getters.currentFolder.data.id) {
// Add uploaded item into view
commit('ADD_NEW_ITEMS', response.data)
// Reset file progress
commit('UPLOADING_FILE_PROGRESS', 0)
// Increase count in files in queue uploaded for 1
commit('INCREASE_FILES_IN_QUEUE_UPLOADED')
}
// Reset file progress
commit('UPLOADING_FILE_PROGRESS', 0)
// Increase count in files in queue uploaded for 1
commit('INCREASE_FILES_IN_QUEUE_UPLOADED')
// Start uploading next file if file queue is not empty
if (getters.fileQueue.length) {
Vue.prototype.$handleUploading(getters.fileQueue[0])
@@ -218,6 +225,9 @@ const actions = {
}
}
console.log(error.response);
console.log(error.response.status);
events.$emit('alert:open', {
emoji: '😬😬😬',
title: messages[error.response.status]['title'],