Handle unshare in frontend

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2021-01-04 15:29:53 +01:00
parent 199cccf86b
commit 019444f9fc
4 changed files with 34 additions and 15 deletions

View File

@@ -37,7 +37,7 @@
@change="handleUploadFile"> @change="handleUploadFile">
<ul class="attachment-list"> <ul class="attachment-list">
<li v-for="attachment in uploadQueue" :key="attachment.name" class="attachment"> <li v-for="attachment in uploadQueue" :key="attachment.name" class="attachment">
<a class="fileicon" :style="mimetypeForAttachment('none')" /> <a class="fileicon" :style="mimetypeForAttachment()" />
<div class="details"> <div class="details">
<a> <a>
<div class="filename"> <div class="filename">
@@ -72,7 +72,7 @@
<ActionLink v-if="attachment.extendedData.fileid" icon="icon-folder" :href="internalLink(attachment)"> <ActionLink v-if="attachment.extendedData.fileid" icon="icon-folder" :href="internalLink(attachment)">
{{ t('deck', 'Show in files') }} {{ t('deck', 'Show in files') }}
</ActionLink> </ActionLink>
<ActionButton v-if="attachment.extendedData.fileid" icon="icon-delete"> <ActionButton v-if="attachment.extendedData.fileid" icon="icon-delete" @click="unshareAttachment(attachment)">
{{ t('deck', 'Unshare file') }} {{ t('deck', 'Unshare file') }}
</ActionButton> </ActionButton>
@@ -143,10 +143,13 @@ export default {
}, },
computed: { computed: {
attachments() { attachments() {
return [...this.$store.getters.attachmentsByCard(this.cardId)].sort((a, b) => b.id - a.id) return [...this.$store.getters.attachmentsByCard(this.cardId)].filter(attachment => attachment.deletedAt >= 0).sort((a, b) => b.id - a.id)
}, },
mimetypeForAttachment() { mimetypeForAttachment() {
return (attachment) => { return (attachment) => {
if (!attachment) {
return {}
}
const url = attachment.extendedData.hasPreview ? this.attachmentPreview(attachment) : OC.MimeType.getIconUrl(attachment.extendedData.mimetype) const url = attachment.extendedData.hasPreview ? this.attachmentPreview(attachment) : OC.MimeType.getIconUrl(attachment.extendedData.mimetype)
const styles = { const styles = {
'background-image': `url("${url}")`, 'background-image': `url("${url}")`,
@@ -217,6 +220,9 @@ export default {
}) })
}) })
}, },
unshareAttachment(attachment) {
this.$store.dispatch('unshareAttachment', attachment)
},
clickAddNewAttachmment() { clickAddNewAttachmment() {
this.$refs.localAttachments.click() this.$refs.localAttachments.click()
}, },

View File

@@ -78,7 +78,7 @@ export default {
bodyFormData.append('file', this.file) bodyFormData.append('file', this.file)
this.$store.dispatch('updateAttachment', { this.$store.dispatch('updateAttachment', {
cardId: this.cardId, cardId: this.cardId,
attachmentId: this.overwriteAttachment.id, attachment: this.overwriteAttachment,
formData: bodyFormData, formData: bodyFormData,
}) })

View File

@@ -47,10 +47,10 @@ export class AttachmentApi {
return response.data return response.data
} }
async updateAttachment({ cardId, attachmentId, formData }) { async updateAttachment({ cardId, attachment, formData }) {
const response = await axios({ const response = await axios({
method: 'POST', method: 'POST',
url: this.url(`/cards/${cardId}/attachment/${attachmentId}`), url: this.url(`/cards/${cardId}/attachment/${attachment.type}:${attachment.id}`),
data: formData, data: formData,
}) })
return response.data return response.data
@@ -59,14 +59,14 @@ export class AttachmentApi {
async deleteAttachment(attachment) { async deleteAttachment(attachment) {
await axios({ await axios({
method: 'DELETE', method: 'DELETE',
url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.id}`), url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.type}:${attachment.id}`),
}) })
} }
async restoreAttachment(attachment) { async restoreAttachment(attachment) {
const response = await axios({ const response = await axios({
method: 'GET', method: 'GET',
url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.id}/restore`), url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.type}:${attachment.id}/restore`),
}) })
return response.data return response.data
} }
@@ -74,7 +74,7 @@ export class AttachmentApi {
async displayAttachment(attachment) { async displayAttachment(attachment) {
const response = await axios({ const response = await axios({
method: 'GET', method: 'GET',
url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.id}`), url: this.url(`/cards/${attachment.cardId}/attachment/${attachment.type}:${attachment.id}`),
}) })
return response.data return response.data
} }

View File

@@ -52,21 +52,28 @@ export default {
}, },
updateAttachment(state, { cardId, attachment }) { updateAttachment(state, { cardId, attachment }) {
const existingIndex = state.attachments[attachment.cardId].findIndex(a => a.id === attachment.id) const existingIndex = state.attachments[attachment.cardId].findIndex(a => a.id === attachment.id && a.type === attachment.type)
if (existingIndex !== -1) { if (existingIndex !== -1) {
Vue.set(state.attachments[cardId], existingIndex, attachment) 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 && a.type === deletedAttachment.type)
if (existingIndex !== -1) {
state.attachments[deletedAttachment.cardId][existingIndex].deletedAt = Date.now() / 1000 | 0
}
},
unshareAttachment(state, deletedAttachment) {
const existingIndex = state.attachments[deletedAttachment.cardId].findIndex(a => a.id === deletedAttachment.id && a.type === deletedAttachment.type)
if (existingIndex !== -1) { if (existingIndex !== -1) {
state.attachments[deletedAttachment.cardId][existingIndex].deletedAt = -1 state.attachments[deletedAttachment.cardId][existingIndex].deletedAt = -1
} }
}, },
restoreAttachment(state, restoredAttachment) { restoreAttachment(state, restoredAttachment) {
const existingIndex = state.attachments[restoredAttachment.cardId].findIndex(a => a.id === restoredAttachment.id) const existingIndex = state.attachments[restoredAttachment.cardId].findIndex(a => a.id === restoredAttachment.id && a.type === restoredAttachment.type)
if (existingIndex !== -1) { if (existingIndex !== -1) {
state.attachments[restoredAttachment.cardId][existingIndex].deletedAt = 0 state.attachments[restoredAttachment.cardId][existingIndex].deletedAt = 0
} }
@@ -85,9 +92,9 @@ export default {
commit('cardIncreaseAttachmentCount', cardId) commit('cardIncreaseAttachmentCount', cardId)
}, },
async updateAttachment({ commit }, { cardId, attachmentId, formData }) { async updateAttachment({ commit }, { cardId, attachment, formData }) {
const attachment = await apiClient.updateAttachment({ cardId, attachmentId, formData }) const result = await apiClient.updateAttachment({ cardId, attachment, formData })
commit('updateAttachment', { cardId, attachment }) commit('updateAttachment', { cardId, attachment: result })
}, },
async deleteAttachment({ commit }, attachment) { async deleteAttachment({ commit }, attachment) {
@@ -96,6 +103,12 @@ export default {
commit('cardDecreaseAttachmentCount', attachment.cardId) commit('cardDecreaseAttachmentCount', attachment.cardId)
}, },
async unshareAttachment({ commit }, attachment) {
await apiClient.deleteAttachment(attachment)
commit('unshareAttachment', attachment)
commit('cardDecreaseAttachmentCount', attachment.cardId)
},
async restoreAttachment({ commit }, attachment) { async restoreAttachment({ commit }, attachment) {
const restoredAttachment = await apiClient.restoreAttachment(attachment) const restoredAttachment = await apiClient.restoreAttachment(attachment)
commit('restoreAttachment', restoredAttachment) commit('restoreAttachment', restoredAttachment)