refactor: editor-file.vue -> upload, move, delete
This commit is contained in:
parent
fe76708124
commit
c38ba72b5b
@ -38,6 +38,7 @@ import join from 'lodash/join'
|
|||||||
import kebabCase from 'lodash/kebabCase'
|
import kebabCase from 'lodash/kebabCase'
|
||||||
import last from 'lodash/last'
|
import last from 'lodash/last'
|
||||||
import map from 'lodash/map'
|
import map from 'lodash/map'
|
||||||
|
import nth from 'lodash/nth'
|
||||||
import pullAt from 'lodash/pullAt'
|
import pullAt from 'lodash/pullAt'
|
||||||
import reject from 'lodash/reject'
|
import reject from 'lodash/reject'
|
||||||
import slice from 'lodash/slice'
|
import slice from 'lodash/slice'
|
||||||
@ -101,6 +102,7 @@ const _ = {
|
|||||||
kebabCase,
|
kebabCase,
|
||||||
last,
|
last,
|
||||||
map,
|
map,
|
||||||
|
nth,
|
||||||
pullAt,
|
pullAt,
|
||||||
reject,
|
reject,
|
||||||
slice,
|
slice,
|
||||||
|
@ -8,29 +8,29 @@
|
|||||||
.modal-content.is-expanded(v-show='isShown')
|
.modal-content.is-expanded(v-show='isShown')
|
||||||
header.is-green
|
header.is-green
|
||||||
span {{ $t('editor.filetitle') }}
|
span {{ $t('editor.filetitle') }}
|
||||||
p.modal-notify(v-bind:class='{ "is-active": isLoading }')
|
p.modal-notify(:class='{ "is-active": isLoading }')
|
||||||
span {{ isLoadingText }}
|
span {{ isLoadingText }}
|
||||||
i
|
i
|
||||||
.modal-toolbar.is-green
|
.modal-toolbar.is-green
|
||||||
a.button(v-on:click='newFolder')
|
a.button(@click='newFolder')
|
||||||
i.icon-folder2
|
i.icon-folder2
|
||||||
span {{ $t('editor.newfolder') }}
|
span {{ $t('editor.newfolder') }}
|
||||||
a.button#btn-editor-file-upload
|
a.button#btn-editor-file-upload
|
||||||
i.icon-cloud-upload
|
i.icon-cloud-upload
|
||||||
span {{ $t('editor.fileupload') }}
|
span {{ $t('editor.fileupload') }}
|
||||||
label
|
label
|
||||||
input(type='file', multiple)
|
input(type='file', multiple, :disabled='isLoading', ref='editorFileUploadInput')
|
||||||
section.is-gapless
|
section.is-gapless
|
||||||
.columns.is-stretched
|
.columns.is-stretched
|
||||||
.column.is-one-quarter.modal-sidebar.is-green(style={'max-width':'350px'})
|
.column.is-one-quarter.modal-sidebar.is-green(style={'max-width':'350px'})
|
||||||
.model-sidebar-header {{ $t('editor.folders') }}
|
.model-sidebar-header {{ $t('editor.folders') }}
|
||||||
ul.model-sidebar-list
|
ul.model-sidebar-list
|
||||||
li(v-for='fld in folders')
|
li(v-for='fld in folders')
|
||||||
a(v-on:click='selectFolder(fld)', v-bind:class='{ "is-active": currentFolder === fld }')
|
a(@click='selectFolder(fld)', :class='{ "is-active": currentFolder === fld }')
|
||||||
i.icon-folder2
|
i.icon-folder2
|
||||||
span / {{ fld }}
|
span / {{ fld }}
|
||||||
.column.editor-modal-file-choices
|
.column.editor-modal-file-choices
|
||||||
figure(v-for='fl in files', v-bind:class='{ "is-active": currentFile === fl._id }', v-on:click='selectFile(fl._id)', v-bind:data-uid='fl._id')
|
figure(v-for='fl in files', :class='{ "is-active": currentFile === fl._id }', @click='selectFile(fl._id)', :data-uid='fl._id')
|
||||||
i(class='icon-file')
|
i(class='icon-file')
|
||||||
span: strong {{ fl.filename }}
|
span: strong {{ fl.filename }}
|
||||||
span {{ fl.mime }}
|
span {{ fl.mime }}
|
||||||
@ -39,49 +39,56 @@
|
|||||||
i.icon-marquee-minus
|
i.icon-marquee-minus
|
||||||
| {{ $t('editor.filefolderempty') }}
|
| {{ $t('editor.filefolderempty') }}
|
||||||
footer
|
footer
|
||||||
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('editor.discard') }}
|
a.button.is-grey.is-outlined(@click='cancel') {{ $t('editor.discard') }}
|
||||||
a.button.is-green(v-on:click='insertFileLink') {{ $t('editor.fileinsert') }}
|
a.button.is-green(@click='insertFileLink') {{ $t('editor.fileinsert') }}
|
||||||
|
|
||||||
|
transition(:duration="400")
|
||||||
.modal.is-superimposed(v-show='newFolderShow')
|
.modal.is-superimposed(v-show='newFolderShow')
|
||||||
transition(name='modal-background')
|
transition(name='modal-background')
|
||||||
.modal-background
|
.modal-background(v-show='newFolderShow')
|
||||||
.modal-container(v-show='newFolderShow')
|
.modal-container
|
||||||
transition(name='modal-content')
|
transition(name='modal-content')
|
||||||
.modal-content(v-show='newFolderShow')
|
.modal-content(v-show='newFolderShow')
|
||||||
header.is-light-blue {{ $t('modal.newfoldertitle') }}
|
header.is-light-blue {{ $t('modal.newfoldertitle') }}
|
||||||
section
|
section
|
||||||
label.label {{ $t('modal.newfoldername') }}
|
label.label {{ $t('modal.newfoldername') }}
|
||||||
p.control.is-fullwidth
|
p.control.is-fullwidth
|
||||||
input.input(type='text', v-bind:placeholder='$t("modal.newfoldernameplaceholder")', v-model='newFolderName', ref='editorFileNewFolderInput', v-on:keyup.enter='newFolderCreate', v-on:keyup.esc='newFolderDiscard')
|
input.input(type='text', :placeholder='$t("modal.newfoldernameplaceholder")', v-model='newFolderName', ref='editorFileNewFolderInput', @keyup.enter='newFolderCreate', @keyup.esc='newFolderDiscard')
|
||||||
span.help.is-danger(v-show='newFolderError') {{ $t('modal.newfolderinvalid') }}
|
span.help.is-danger(v-show='newFolderError') {{ $t('modal.newfolderinvalid') }}
|
||||||
footer
|
footer
|
||||||
a.button.is-grey.is-outlined(v-on:click='newFolderDiscard') {{ $t('modal.discard') }}
|
a.button.is-grey.is-outlined(@click='newFolderDiscard') {{ $t('modal.discard') }}
|
||||||
a.button.is-light-blue(v-on:click='newFolderCreate') {{ $t('modal.create') }}
|
a.button.is-light-blue(@click='newFolderCreate') {{ $t('modal.create') }}
|
||||||
|
|
||||||
|
transition(:duration="400")
|
||||||
.modal.is-superimposed(v-show='renameFileShow')
|
.modal.is-superimposed(v-show='renameFileShow')
|
||||||
.modal-background
|
transition(name='modal-background')
|
||||||
|
.modal-background(v-show='renameFileShow')
|
||||||
.modal-container
|
.modal-container
|
||||||
.modal-content
|
transition(name='modal-content')
|
||||||
|
.modal-content(v-show='renameFileShow')
|
||||||
header.is-indigo {{ $t('modal.renamefiletitle') }}
|
header.is-indigo {{ $t('modal.renamefiletitle') }}
|
||||||
section
|
section
|
||||||
label.label {{ $t('modal.renamefilename') }}
|
label.label {{ $t('modal.renamefilename') }}
|
||||||
p.control.is-fullwidth
|
p.control.is-fullwidth
|
||||||
input.input#txt-editor-file-rename(type='text', v-bind:placeholder='$t("modal.renamefilenameplaceholder")', v-model='renameFileFilename', ref='editorFileRenameInput', v-on:keyup.enter='renameFileGo', v-on:keyup.esc='renameFileDiscard')
|
input.input#txt-editor-file-rename(type='text', :placeholder='$t("modal.renamefilenameplaceholder")', v-model='renameFileFilename', ref='editorFileRenameInput', @keyup.enter='renameFileGo', @keyup.esc='renameFileDiscard')
|
||||||
span.help.is-danger.is-hidden {{ $t('modal.renamefileinvalid') }}
|
span.help.is-danger.is-hidden {{ $t('modal.renamefileinvalid') }}
|
||||||
footer
|
footer
|
||||||
a.button.is-grey.is-outlined(v-on:click='renameFileDiscard') {{ $t('modal.discard') }}
|
a.button.is-grey.is-outlined(@click='renameFileDiscard') {{ $t('modal.discard') }}
|
||||||
a.button.is-light-blue(v-on:click='renameFileGo') {{ $t('modal.renamefile') }}
|
a.button.is-light-blue(@click='renameFileGo') {{ $t('modal.renamefile') }}
|
||||||
|
|
||||||
|
transition(:duration="400")
|
||||||
.modal.is-superimposed(v-show='deleteFileShow')
|
.modal.is-superimposed(v-show='deleteFileShow')
|
||||||
.modal-background
|
transition(name='modal-background')
|
||||||
|
.modal-background(v-show='deleteFileShow')
|
||||||
.modal-container
|
.modal-container
|
||||||
.modal-content
|
transition(name='modal-content')
|
||||||
|
.modal-content(v-show='deleteFileShow')
|
||||||
header.is-red {{ $t('modal.deletefiletitle') }}
|
header.is-red {{ $t('modal.deletefiletitle') }}
|
||||||
section
|
section
|
||||||
span {{ $t('modal.deletefilewarn') }} #[strong {{deleteFileFilename}}]?
|
span {{ $t('modal.deletefilewarn') }} #[strong {{deleteFileFilename}}]?
|
||||||
footer
|
footer
|
||||||
a.button.is-grey.is-outlined(v-on:click='deleteFileWarn(false)') {{ $t('modal.discard') }}
|
a.button.is-grey.is-outlined(@click='deleteFileWarn(false)') {{ $t('modal.discard') }}
|
||||||
a.button.is-red(v-on:click='deleteFileGo') {{ $t('modal.delete') }}
|
a.button.is-red(@click='deleteFileGo') {{ $t('modal.delete') }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -115,9 +122,11 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init () {
|
init () {
|
||||||
|
$(this.$refs.editorFileUploadInput).on('change', this.upload)
|
||||||
this.refreshFolders()
|
this.refreshFolders()
|
||||||
},
|
},
|
||||||
cancel () {
|
cancel () {
|
||||||
|
$(this.$refs.editorFileUploadInput).off('change', this.upload)
|
||||||
this.$store.dispatch('editorFile/close')
|
this.$store.dispatch('editorFile/close')
|
||||||
},
|
},
|
||||||
filesize (rawSize) {
|
filesize (rawSize) {
|
||||||
@ -240,6 +249,11 @@
|
|||||||
socket.emit('uploadsMoveFile', { uid, folder: fld }, (data) => {
|
socket.emit('uploadsMoveFile', { uid, folder: fld }, (data) => {
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
self.loadFiles()
|
self.loadFiles()
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'blue',
|
||||||
|
icon: 'arrow-right2',
|
||||||
|
msg: self.$t('editor.filemovesuccess')
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
self.$store.dispatch('alert', {
|
self.$store.dispatch('alert', {
|
||||||
@ -271,6 +285,11 @@
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
socket.emit('uploadsDeleteFile', { uid: this.deleteFileId }, (data) => {
|
socket.emit('uploadsDeleteFile', { uid: this.deleteFileId }, (data) => {
|
||||||
self.loadFiles()
|
self.loadFiles()
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'blue',
|
||||||
|
icon: 'trash2',
|
||||||
|
msg: self.$t('editor.filedeletesuccess')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -404,6 +423,79 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
upload() {
|
||||||
|
let self = this
|
||||||
|
let curFileAmount = this.files.length
|
||||||
|
|
||||||
|
$(this.$refs.editorFileUploadInput).simpleUpload('/uploads/file', {
|
||||||
|
|
||||||
|
name: 'binfile',
|
||||||
|
data: {
|
||||||
|
folder: self.currentFolder
|
||||||
|
},
|
||||||
|
limit: 20,
|
||||||
|
expect: 'json',
|
||||||
|
maxFileSize: 0,
|
||||||
|
|
||||||
|
init: (totalUploads) => {
|
||||||
|
self.uploadSucceeded = false
|
||||||
|
self.isLoadingText = 'Preparing to upload...'
|
||||||
|
self.isLoading = true
|
||||||
|
},
|
||||||
|
|
||||||
|
progress: (progress) => {
|
||||||
|
self.isLoadingText = 'Uploading...' + Math.round(progress) + '%'
|
||||||
|
},
|
||||||
|
|
||||||
|
success: (data) => {
|
||||||
|
if (data.ok) {
|
||||||
|
let failedUpls = self._.filter(data.results, ['ok', false])
|
||||||
|
if (failedUpls.length) {
|
||||||
|
self._.forEach(failedUpls, (u) => {
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'red',
|
||||||
|
icon: 'square-cross',
|
||||||
|
msg: self.$t('editor.fileuploaderror', { err: u.msg })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if (failedUpls.length < data.results.length) {
|
||||||
|
self.uploadSucceeded = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.uploadSucceeded = true
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'blue',
|
||||||
|
icon: 'cloud-upload',
|
||||||
|
msg: self.$t('editor.fileuploadsuccess')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'red',
|
||||||
|
icon: 'square-cross',
|
||||||
|
msg: self.$t('editor.fileuploaderror', { err: data.msg })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
error: (error) => {
|
||||||
|
self.$store.dispatch('alert', {
|
||||||
|
style: 'red',
|
||||||
|
icon: 'square-cross',
|
||||||
|
msg: self.$t('editor.fileuploaderror', { err: error.message })
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
finish: () => {
|
||||||
|
if (self.uploadSucceeded) {
|
||||||
|
self.waitChangeComplete(curFileAmount, true)
|
||||||
|
} else {
|
||||||
|
self.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"filedeleteaction": "Delete",
|
"filedeleteaction": "Delete",
|
||||||
"filedeleteloading": "Deleting file...",
|
"filedeleteloading": "Deleting file...",
|
||||||
"filedeletedefault": "this file",
|
"filedeletedefault": "this file",
|
||||||
|
"filedeletesuccess": "File deleted successfully.",
|
||||||
"fileerror": "Unable to fetch updated listing.",
|
"fileerror": "Unable to fetch updated listing.",
|
||||||
"filefolderempty": "This folder is empty.",
|
"filefolderempty": "This folder is empty.",
|
||||||
"fileinsert": "Insert Link to File",
|
"fileinsert": "Insert Link to File",
|
||||||
@ -17,11 +18,14 @@
|
|||||||
"filemoveaction": "Move to...",
|
"filemoveaction": "Move to...",
|
||||||
"filemoveerror": "Move error: {{err}}",
|
"filemoveerror": "Move error: {{err}}",
|
||||||
"filemoveloading": "Moving file...",
|
"filemoveloading": "Moving file...",
|
||||||
|
"filemovesuccess": "File moved successfully.",
|
||||||
"fileprocessing": "Processing...",
|
"fileprocessing": "Processing...",
|
||||||
"filerenameaction": "Rename",
|
"filerenameaction": "Rename",
|
||||||
"filesuccess": "File link has been inserted.",
|
"filesuccess": "File link has been inserted.",
|
||||||
"filetitle": "Insert File",
|
"filetitle": "Insert File",
|
||||||
"fileupload": "Upload File",
|
"fileupload": "Upload File",
|
||||||
|
"fileuploaderror": "Upload Error: {{err}}",
|
||||||
|
"fileuploadsuccess": "File(s) uploaded successfully.",
|
||||||
"folders": "Folders",
|
"folders": "Folders",
|
||||||
"foldersloading": "Fetching folders list...",
|
"foldersloading": "Fetching folders list...",
|
||||||
"newfolder": "New Folder",
|
"newfolder": "New Folder",
|
||||||
|
Loading…
Reference in New Issue
Block a user