Merge pull request #1652 from nextcloud/enh/attachmentProgressIndicator

Progress indicator for attachment uploads
This commit is contained in:
Julius Härtl 2020-04-07 12:07:16 +02:00 коммит произвёл GitHub
Родитель da3cc5b589 396a5c395f
Коммит 08284caedd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 80 добавлений и 39 удалений

25
package-lock.json сгенерированный
Просмотреть файл

@ -7049,6 +7049,11 @@
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs="
},
"eventemitter3": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.0.tgz",
"integrity": "sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg=="
},
"events": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.1.0.tgz",
@ -12778,8 +12783,7 @@
"p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=",
"dev": true
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
},
"p-is-promise": {
"version": "2.1.0",
@ -12805,6 +12809,23 @@
"p-limit": "^1.1.0"
}
},
"p-queue": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.3.0.tgz",
"integrity": "sha512-fg5dJlFpd5+3CgG3/0ogpVZUeJbjiyXFg0nu53hrOYsybqSiDyxyOpad0Rm6tAiGjgztAwkyvhlYHC53OiAJOA==",
"requires": {
"eventemitter3": "^4.0.0",
"p-timeout": "^3.1.0"
}
},
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
},
"p-try": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",

Просмотреть файл

@ -41,6 +41,7 @@
"blueimp-md5": "^2.13.0",
"dompurify": "^2.0.8",
"nextcloud-vue-collections": "^0.7.2",
"p-queue": "^6.3.0",
"url-search-params-polyfill": "^8.0.0",
"vue": "^2.6.11",
"vue-at": "^2.5.0-beta.2",

Просмотреть файл

@ -102,18 +102,15 @@ export default {
},
},
methods: {
dragEnter() {
},
dragLeave() {
},
handleDropFiles(event) {
this.isDraggingOver = false
if (this.isReadOnly) {
return
}
this.onLocalAttachmentSelected(event.dataTransfer.files[0])
const files = event.dataTransfer.files
for (const file of files) {
this.onLocalAttachmentSelected(file)
}
event.dataTransfer.value = ''
},
},

Просмотреть файл

@ -28,13 +28,24 @@
<input ref="localAttachments"
type="file"
style="display: none;"
multiple
@change="handleUploadFile">
<div class="attachment-list">
<ul>
<li v-for="attachment in uploadQueue" :key="attachment.name" class="attachment">
<a class="fileicon" :style="mimetypeForAttachment('none')" />
<div class="details">
<a>
<div class="filename">
<span class="basename">{{ attachment.name }}</span>
</div>
<progress :value="attachment.progress" max="100" />
</a>
</div>
</li>
<li v-for="attachment in attachments"
:key="attachment.id"
class="attachment"
style="display: flex;">
class="attachment">
<a class="fileicon" :style="mimetypeForAttachment(attachment.extendedData.mimetype)" :href="attachmentUrl(attachment)" />
<div class="details">
<a :href="attachmentUrl(attachment)" target="_blank">
@ -109,7 +120,7 @@ export default {
}
},
attachments() {
return this.$store.getters.attachmentsByCard(this.card.id)
return [...this.$store.getters.attachmentsByCard(this.card.id)].sort((a, b) => b.id - a.id)
},
formattedFileSize() {
return (filesize) => formatFileSize(filesize)
@ -134,22 +145,11 @@ export default {
this.$store.dispatch('fetchAttachments', this.card.id)
},
methods: {
dragEnter() {
},
dragLeave() {
},
handleDropFiles(event) {
this.isDraggingOver = false
if (this.isReadOnly) {
return
}
this.onLocalAttachmentSelected(event.dataTransfer.files[0])
event.dataTransfer.value = ''
},
handleUploadFile(event) {
this.onLocalAttachmentSelected(event.target.files[0])
const files = event.target.files ?? []
for (const file of files) {
this.onLocalAttachmentSelected(file)
}
event.target.value = ''
},
clickAddNewAttachmment() {
@ -214,6 +214,7 @@ export default {
li.attachment {
display: flex;
padding: 3px;
min-height: 44px;
&.deleted {
opacity: .5;

Просмотреть файл

@ -21,8 +21,16 @@
*/
import { showError } from '@nextcloud/dialogs'
import { formatFileSize } from '@nextcloud/files'
import PQueue from 'p-queue'
const queue = new PQueue({ concurrency: 2 })
export default {
data() {
return {
uploadQueue: {},
}
},
methods: {
async onLocalAttachmentSelected(file) {
if (this.maxUploadSize > 0 && file.size > this.maxUploadSize) {
@ -34,20 +42,32 @@ export default {
return
}
this.$set(this.uploadQueue, file.name, { name: file.name, progress: 0 })
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.cardId)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', file)
try {
await this.$store.dispatch('createAttachment', { cardId: this.cardId, formData: bodyFormData })
} catch (err) {
if (err.response.data.status === 409) {
this.overwriteAttachment = err.response.data.data
this.modalShow = true
} else {
showError(err.response.data.message)
await queue.add(async() => {
try {
await this.$store.dispatch('createAttachment', { cardId: this.cardId,
formData: bodyFormData,
onUploadProgress: (e) => {
const percentCompleted = Math.round((e.loaded * 100) / e.total)
console.debug(percentCompleted)
this.$set(this.uploadQueue[file.name], 'progress', percentCompleted)
},
})
} catch (err) {
if (err.response.data.status === 409) {
this.overwriteAttachment = err.response.data.data
this.modalShow = true
} else {
showError(err.response.data.message)
}
}
}
this.$delete(this.uploadQueue, file.name)
})
},
overrideAttachment() {

Просмотреть файл

@ -37,11 +37,12 @@ export class AttachmentApi {
return response.data
}
async createAttachment({ cardId, formData }) {
async createAttachment({ cardId, formData, onUploadProgress }) {
const response = await axios({
method: 'POST',
url: this.url(`/cards/${cardId}/attachment`),
data: formData,
onUploadProgress,
})
return response.data
}

Просмотреть файл

@ -83,8 +83,8 @@ export default {
commit('createAttachments', { cardId, attachments })
},
async createAttachment({ commit }, { cardId, formData }) {
const attachment = await apiClient.createAttachment({ cardId, formData })
async createAttachment({ commit }, { cardId, formData, onUploadProgress }) {
const attachment = await apiClient.createAttachment({ cardId, formData, onUploadProgress })
commit('createAttachment', { cardId, attachment })
commit('cardIncreaseAttachmentCount', cardId)
},