Fix updating attachments and computed properties
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
committed by
Jakob Röhrl
parent
10a12a7291
commit
98b733338b
6
package-lock.json
generated
6
package-lock.json
generated
@@ -5648,7 +5648,8 @@
|
|||||||
},
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": ""
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -16683,7 +16684,8 @@
|
|||||||
},
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": ""
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<button class="icon-upload" @click="clickAddNewAttachmment()">
|
<button class="icon-upload" @click="clickAddNewAttachmment()">
|
||||||
{{ t('deck', 'Upload attachment') }}
|
{{ t('settings', 'Upload attachment') }}
|
||||||
</button>
|
</button>
|
||||||
<input ref="localAttachments"
|
<input ref="localAttachments"
|
||||||
type="file"
|
type="file"
|
||||||
@@ -59,22 +59,20 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Modal v-if="modalShow" title="File already exists" @close="modalShow=false">
|
<Modal v-if="modalShow" :title="t('deck', 'File already exists')" @close="modalShow=false">
|
||||||
<div class="modal__content">
|
<div class="modal__content">
|
||||||
<h2>{{ t('deck', 'File already exists') }}</h2>
|
<h2>{{ t('deck', 'File already exists') }}</h2>
|
||||||
<p>
|
<p>
|
||||||
{{ t('deck', 'A file with the name') }}
|
{{ t('deck', 'A file with the name {filename} already exists.', {filename: file.name}) }}
|
||||||
{{ file.name }}
|
|
||||||
{{ t('deck', 'already exists.') }}
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
{{ t('deck', 'Do you want to overwrite it?') }}
|
{{ t('deck', 'Do you want to overwrite it?') }}
|
||||||
</p>
|
</p>
|
||||||
<button class="primary" @click="overrideAttachment">
|
<button class="primary" @click="overrideAttachment">
|
||||||
{{ t('deck', 'Yes') }}
|
{{ t('deck', 'Overwrite file') }}
|
||||||
</button>
|
</button>
|
||||||
<button @click="modalShow=false">
|
<button @click="modalShow=false">
|
||||||
{{ t('deck', 'No') }}
|
{{ t('deck', 'Keep existing file') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -115,7 +113,24 @@ export default {
|
|||||||
formattedFileSize() {
|
formattedFileSize() {
|
||||||
return (filesize) => formatFileSize(filesize)
|
return (filesize) => formatFileSize(filesize)
|
||||||
},
|
},
|
||||||
|
mimetypeForAttachment() {
|
||||||
|
return (attachment) => {
|
||||||
|
const url = OC.MimeType.getIconUrl(attachment.extendedData.mimetype)
|
||||||
|
const styles = {
|
||||||
|
'background-image': `url("${url}")`,
|
||||||
|
}
|
||||||
|
return styles
|
||||||
|
}
|
||||||
|
},
|
||||||
|
attachmentUrl() {
|
||||||
|
return (attachment) => OC.generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
'card': {
|
||||||
|
handler() {
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created: function() {
|
created: function() {
|
||||||
this.$store.dispatch('fetchAttachments', this.card.id)
|
this.$store.dispatch('fetchAttachments', this.card.id)
|
||||||
@@ -124,22 +139,23 @@ export default {
|
|||||||
clickAddNewAttachmment() {
|
clickAddNewAttachmment() {
|
||||||
this.$refs.localAttachments.click()
|
this.$refs.localAttachments.click()
|
||||||
},
|
},
|
||||||
async onLocalAttachmentSelected(e) {
|
async onLocalAttachmentSelected(event) {
|
||||||
const bodyFormData = new FormData()
|
const bodyFormData = new FormData()
|
||||||
bodyFormData.append('cardId', this.card.id)
|
bodyFormData.append('cardId', this.card.id)
|
||||||
bodyFormData.append('type', 'deck_file')
|
bodyFormData.append('type', 'deck_file')
|
||||||
bodyFormData.append('file', e.target.files[0])
|
bodyFormData.append('file', event.target.files[0])
|
||||||
this.file = e.target.files[0]
|
this.file = event.target.files[0]
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
|
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
if (e.response.data.status === 409) {
|
if (err.response.data.status === 409) {
|
||||||
this.overwriteAttachment = e.response.data.data
|
this.overwriteAttachment = err.response.data.data
|
||||||
this.modalShow = true
|
this.modalShow = true
|
||||||
} else {
|
} else {
|
||||||
showError(e.response.data.message)
|
showError(err.response.data.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
event.target.value = ''
|
||||||
},
|
},
|
||||||
deleteAttachment(attachment) {
|
deleteAttachment(attachment) {
|
||||||
this.$store.dispatch('deleteAttachment', attachment)
|
this.$store.dispatch('deleteAttachment', attachment)
|
||||||
@@ -147,16 +163,6 @@ export default {
|
|||||||
restoreAttachment(attachment) {
|
restoreAttachment(attachment) {
|
||||||
this.$store.dispatch('restoreAttachment', attachment)
|
this.$store.dispatch('restoreAttachment', attachment)
|
||||||
},
|
},
|
||||||
mimetypeForAttachment(attachment) {
|
|
||||||
const url = OC.MimeType.getIconUrl(attachment.extendedData.mimetype)
|
|
||||||
const styles = {
|
|
||||||
'background-image': `url("${url}")`,
|
|
||||||
}
|
|
||||||
return styles
|
|
||||||
},
|
|
||||||
attachmentUrl(attachment) {
|
|
||||||
return OC.generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`)
|
|
||||||
},
|
|
||||||
overrideAttachment() {
|
overrideAttachment() {
|
||||||
const bodyFormData = new FormData()
|
const bodyFormData = new FormData()
|
||||||
bodyFormData.append('cardId', this.card.id)
|
bodyFormData.append('cardId', this.card.id)
|
||||||
@@ -175,6 +181,11 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
.icon-upload {
|
||||||
|
padding-left: 20px;
|
||||||
|
background-position: left center;
|
||||||
|
}
|
||||||
|
|
||||||
.modal__content {
|
.modal__content {
|
||||||
width: 25vw;
|
width: 25vw;
|
||||||
min-width: 250px;
|
min-width: 250px;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default {
|
|||||||
mutations: {
|
mutations: {
|
||||||
createAttachment(state, { cardId, attachment }) {
|
createAttachment(state, { cardId, attachment }) {
|
||||||
if (typeof state.attachments[cardId] === 'undefined') {
|
if (typeof state.attachments[cardId] === 'undefined') {
|
||||||
Vue.set(state.attachments, cardId, attachment)
|
Vue.set(state.attachments, cardId, [attachment])
|
||||||
} else {
|
} else {
|
||||||
state.attachments[cardId].push(attachment)
|
state.attachments[cardId].push(attachment)
|
||||||
}
|
}
|
||||||
@@ -56,13 +56,15 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateAttachment(state, { cardId, attachment }) {
|
updateAttachment(state, { cardId, attachment }) {
|
||||||
Vue.set(state.attachments, cardId, attachment)
|
const existingIndex = state.attachments[attachment.cardId].findIndex(a => a.id === attachment.id)
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
Vue.set(state.attachments[cardId], existingIndex, attachment)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteAttachment(state, deletedAttachment) {
|
deleteAttachment(state, deletedAttachment) {
|
||||||
const existingIndex = state.attachments[deletedAttachment.cardId].findIndex(a => a.id === deletedAttachment.id)
|
const existingIndex = state.attachments[deletedAttachment.cardId].findIndex(a => a.id === deletedAttachment.id)
|
||||||
if (existingIndex !== -1) {
|
if (existingIndex !== -1) {
|
||||||
// state.attachments[deletedAttachment.cardId].splice(existingIndex, 1)
|
|
||||||
state.attachments[deletedAttachment.cardId][existingIndex].deletedAt = -1
|
state.attachments[deletedAttachment.cardId][existingIndex].deletedAt = -1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user