Merge pull request #1610 from nextcloud/enh/attachment-dad-cards

new mixin and component
This commit is contained in:
Julius Härtl
2020-03-29 11:50:35 +02:00
committed by GitHub
6 changed files with 374 additions and 207 deletions

10
package-lock.json generated
View File

@@ -12604,7 +12604,7 @@
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true, "dev": true,
"requires": { "requires": {
@@ -13212,7 +13212,7 @@
}, },
"os-homedir": { "os-homedir": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
"dev": true "dev": true
}, },
@@ -13229,7 +13229,7 @@
}, },
"os-tmpdir": { "os-tmpdir": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
"dev": true "dev": true
}, },
@@ -13409,7 +13409,7 @@
}, },
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
}, },
"path-key": { "path-key": {
@@ -16325,7 +16325,7 @@
}, },
"string_decoder": { "string_decoder": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": { "requires": {
"safe-buffer": "~5.1.0" "safe-buffer": "~5.1.0"

View File

@@ -0,0 +1,217 @@
<!--
- @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
-
- @author Jakob Röhrl <jakob.roehrl@web.de>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div class="attachments-drag-zone"
@dragover.prevent="!isDraggingOver && (isDraggingOver = true)"
@dragleave.prevent="isDraggingOver && (isDraggingOver = false)"
@drop.prevent="handleDropFiles">
<slot />
<transition name="fade" mode="out-in">
<div
v-show="isDraggingOver"
class="dragover">
<div class="drop-hint">
<div
class="drop-hint__icon"
:class="{
'icon-upload' : !isReadOnly,
'icon-error' : isReadOnly}" />
<h2
class="drop-hint__text">
{{ dropHintText }}
</h2>
</div>
</div>
</transition>
<Modal v-if="modalShow" :title="t('deck', 'File already exists')" @close="modalShow=false">
<div class="modal__content">
<h2>{{ t('deck', 'File already exists') }}</h2>
<p>
{{ t('deck', 'A file with the name {filename} already exists.', {filename: file.name}) }}
</p>
<p>
{{ t('deck', 'Do you want to overwrite it?') }}
</p>
<button class="primary" @click="overrideAttachment">
{{ t('deck', 'Overwrite file') }}
</button>
<button @click="modalShow=false">
{{ t('deck', 'Keep existing file') }}
</button>
</div>
</Modal>
</div>
</template>
<script>
import { Modal } from '@nextcloud/vue'
import attachmentUpload from '../mixins/attachmentUpload'
import { loadState } from '@nextcloud/initial-state'
const maxUploadSizeState = loadState('deck', 'maxUploadSize')
export default {
name: 'AttachmentDragAndDrop',
components: { Modal },
mixins: [ attachmentUpload ],
props: {
cardId: {
type: Number,
default: null,
},
},
data() {
return {
modalShow: false,
file: '',
overwriteAttachment: null,
isDraggingOver: false,
maxUploadSize: maxUploadSizeState,
}
},
computed: {
isReadOnly() {
return !this.$store.getters.canEdit
},
dropHintText() {
if (this.isReadOnly) {
return t('deck', 'This board is read only')
} else {
return t('deck', 'Drop your files to upload')
}
},
},
methods: {
dragEnter() {
},
dragLeave() {
},
handleDropFiles(event) {
this.isDraggingOver = false
if (this.isReadOnly) {
return
}
this.onLocalAttachmentSelected(event.dataTransfer.files[0])
event.dataTransfer.value = ''
},
},
}
</script>
<style scoped lang="scss">
.attachments-drag-zone {
flex-grow: 1;
position: relative;
}
.dragover {
position: absolute;
background: var(--color-primary-light);
z-index: 11;
display: flex;
border-radius: var(--border-radius);
opacity: .9;
margin: auto;
.drop-hint {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
&__icon {
background-size: 32px;
background-position: center center;
height: 48px;
margin-bottom: 16px;
}
&__text {
line-height: 125%;
text-align: center;
}
}
}
.drop-upload--sidebar .dragover {
top: 20%;
left: 10%;
width: 80%;
height: 60%;
box-shadow: 0px 0px 36px var(--color-box-shadow);
}
.drop-upload--card .dragover {
border: 0;
width: 100%;
height: 100%;
top: 0;
left: 0;
h2 {
font-size: 13px;
margin: 0;
}
.drop-hint__icon {
margin: 0;
background-size: 16px;
height: 16px;
}
}
.fade {
&-enter {
opacity: 0;
}
&-enter-to {
opacity: .9;
}
&-leave {
opacity: .9;
}
&-leave-to {
opacity: 0;
}
&-enter-active,
&-leave-active {
transition: opacity 150ms ease-in-out;
}
}
.modal__content {
width: 25vw;
min-width: 250px;
height: 120px;
text-align: center;
margin: 20px 20px 60px 20px;
}
.modal__content button {
float: right;
margin: 40px 3px 3px 0;
}
</style>

View File

@@ -21,10 +21,7 @@
--> -->
<template> <template>
<div class="attachments-drag-zone" <AttachmentDragAndDrop :card-id="card.id" class="drop-upload--sidebar">
@dragover.prevent="!isDraggingOver && (isDraggingOver = true)"
@dragleave.prevent="isDraggingOver && (isDraggingOver = false)"
@drop.prevent="handleDropFiles">
<button class="icon-upload" @click="clickAddNewAttachmment()"> <button class="icon-upload" @click="clickAddNewAttachmment()">
{{ t('settings', 'Upload attachment') }} {{ t('settings', 'Upload attachment') }}
</button> </button>
@@ -38,7 +35,7 @@
:key="attachment.id" :key="attachment.id"
class="attachment" class="attachment"
style="display: flex;"> style="display: flex;">
<a class="fileicon" :style="mimetypeForAttachment(attachment)" :href="attachmentUrl(attachment)" /> <a class="fileicon" :style="mimetypeForAttachment(attachment.extendedData.mimetype)" :href="attachmentUrl(attachment)" />
<div class="details"> <div class="details">
<a :href="attachmentUrl(attachment)" target="_blank"> <a :href="attachmentUrl(attachment)" target="_blank">
<div class="filename"> <div class="filename">
@@ -61,52 +58,17 @@
</li> </li>
</ul> </ul>
</div> </div>
</AttachmentDragAndDrop>
<transition name="fade" mode="out-in">
<div
v-show="isDraggingOver"
class="dragover">
<div class="drop-hint">
<div
class="drop-hint__icon"
:class="{
'icon-upload' : !isReadOnly,
'icon-error' : isReadOnly}" />
<h2
class="drop-hint__text">
{{ dropHintText }}
</h2>
</div>
</div>
</transition>
<Modal v-if="modalShow" :title="t('deck', 'File already exists')" @close="modalShow=false">
<div class="modal__content">
<h2>{{ t('deck', 'File already exists') }}</h2>
<p>
{{ t('deck', 'A file with the name {filename} already exists.', {filename: file.name}) }}
</p>
<p>
{{ t('deck', 'Do you want to overwrite it?') }}
</p>
<button class="primary" @click="overrideAttachment">
{{ t('deck', 'Overwrite file') }}
</button>
<button @click="modalShow=false">
{{ t('deck', 'Keep existing file') }}
</button>
</div>
</Modal>
</div>
</template> </template>
<script> <script>
import { Actions, ActionButton, Modal } from '@nextcloud/vue' import { Actions, ActionButton } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import { formatFileSize } from '@nextcloud/files' import { formatFileSize } from '@nextcloud/files'
import relativeDate from '../../mixins/relativeDate' import relativeDate from '../../mixins/relativeDate'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import AttachmentDragAndDrop from '../AttachmentDragAndDrop'
import attachmentUpload from '../../mixins/attachmentUpload'
const maxUploadSizeState = loadState('deck', 'maxUploadSize') const maxUploadSizeState = loadState('deck', 'maxUploadSize')
export default { export default {
@@ -114,9 +76,9 @@ export default {
components: { components: {
Actions, Actions,
ActionButton, ActionButton,
Modal, AttachmentDragAndDrop,
}, },
mixins: [ relativeDate ], mixins: [ relativeDate, attachmentUpload ],
props: { props: {
card: { card: {
type: Object, type: Object,
@@ -153,8 +115,8 @@ export default {
return (filesize) => formatFileSize(filesize) return (filesize) => formatFileSize(filesize)
}, },
mimetypeForAttachment() { mimetypeForAttachment() {
return (attachment) => { return (mimetype) => {
const url = OC.MimeType.getIconUrl(attachment.extendedData.mimetype) const url = OC.MimeType.getIconUrl(mimetype)
const styles = { const styles = {
'background-image': `url("${url}")`, 'background-image': `url("${url}")`,
} }
@@ -164,6 +126,9 @@ export default {
attachmentUrl() { attachmentUrl() {
return (attachment) => OC.generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`) return (attachment) => OC.generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`)
}, },
cardId() {
return this.card.id
},
}, },
created: function() { created: function() {
this.$store.dispatch('fetchAttachments', this.card.id) this.$store.dispatch('fetchAttachments', this.card.id)
@@ -190,102 +155,18 @@ export default {
clickAddNewAttachmment() { clickAddNewAttachmment() {
this.$refs.localAttachments.click() this.$refs.localAttachments.click()
}, },
async onLocalAttachmentSelected(file) {
if (this.maxUploadSize > 0 && file.size > this.maxUploadSize) {
showError(
t('deck', `Failed to upload {name}`, { name: file.name }) + ' - '
+ t('deck', 'Maximum file size of {size} exceeded', { size: formatFileSize(this.maxUploadSize) })
)
event.target.value = ''
return
}
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.card.id)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', file)
try {
await this.$store.dispatch('createAttachment', { cardId: this.card.id, 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)
}
}
},
deleteAttachment(attachment) { deleteAttachment(attachment) {
this.$store.dispatch('deleteAttachment', attachment) this.$store.dispatch('deleteAttachment', attachment)
}, },
restoreAttachment(attachment) { restoreAttachment(attachment) {
this.$store.dispatch('restoreAttachment', attachment) this.$store.dispatch('restoreAttachment', attachment)
}, },
overrideAttachment() {
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.card.id)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', this.file)
this.$store.dispatch('updateAttachment', {
cardId: this.card.id,
attachmentId: this.overwriteAttachment.id,
formData: bodyFormData,
})
this.modalShow = false
},
}, },
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.attachments-drag-zone {
flex-grow: 1;
}
.dragover {
position: absolute;
top: 20%;
left: 10%;
width: 80%;
height: 60%;
background: var(--color-primary-light);
z-index: 11;
display: flex;
box-shadow: 0px 0px 36px var(--color-box-shadow);
border-radius: var(--border-radius);
opacity: .9;
}
.drop-hint {
margin: auto;
&__icon {
background-size: 48px;
height: 48px;
margin-bottom: 16px;
}
}
.fade {
&-enter {
opacity: 0;
}
&-enter-to {
opacity: .9;
}
&-leave {
opacity: .9;
}
&-leave-to {
opacity: 0;
}
&-enter-active,
&-leave-active {
transition: opacity 150ms ease-in-out;
}
}
.icon-upload { .icon-upload {
padding-left: 35px; padding-left: 35px;
background-position: 10px center; background-position: 10px center;

View File

@@ -25,75 +25,77 @@
--> -->
<template> <template>
<div :class="{'compact': compactMode, 'current-card': currentCard, 'has-labels': card.labels && card.labels.length > 0, 'is-editing': editing}" <AttachmentDragAndDrop :card-id="id" class="drop-upload--card">
tag="div" <div :class="{'compact': compactMode, 'current-card': currentCard, 'has-labels': card.labels && card.labels.length > 0, 'is-editing': editing}"
class="card" tag="div"
@click="openCard"> class="card"
<div class="card-upper"> @click="openCard">
<h3 v-if="showArchived || !canEdit"> <div class="card-upper">
{{ card.title }} <h3 v-if="showArchived || !canEdit">
</h3> {{ card.title }}
<h3 v-else-if="!editing"> </h3>
<span @click.stop="startEditing(card)">{{ card.title }}</span> <h3 v-else-if="!editing">
</h3> <span @click.stop="startEditing(card)">{{ card.title }}</span>
</h3>
<form v-if="editing" <form v-if="editing"
v-click-outside="cancelEdit" v-click-outside="cancelEdit"
class="dragDisabled" class="dragDisabled"
@keyup.esc="cancelEdit" @keyup.esc="cancelEdit"
@submit.prevent="finishedEdit(card)"> @submit.prevent="finishedEdit(card)">
<input v-model="copiedCard.title" type="text" autofocus> <input v-model="copiedCard.title" type="text" autofocus>
<input type="button" class="icon-confirm" @click="finishedEdit(card)"> <input type="button" class="icon-confirm" @click="finishedEdit(card)">
</form> </form>
<Actions v-if="canEdit && !editing" @click.stop.prevent> <Actions v-if="canEdit && !editing" @click.stop.prevent>
<ActionButton v-if="showArchived === false" icon="icon-user" @click="assignCardToMe()"> <ActionButton v-if="showArchived === false" icon="icon-user" @click="assignCardToMe()">
{{ t('deck', 'Assign to me') }} {{ t('deck', 'Assign to me') }}
</ActionButton> </ActionButton>
<ActionButton icon="icon-archive" @click="archiveUnarchiveCard()"> <ActionButton icon="icon-archive" @click="archiveUnarchiveCard()">
{{ t('deck', (showArchived ? 'Unarchive card' : 'Archive card')) }} {{ t('deck', (showArchived ? 'Unarchive card' : 'Archive card')) }}
</ActionButton> </ActionButton>
<ActionButton v-if="showArchived === false" icon="icon-delete" @click="deleteCard()"> <ActionButton v-if="showArchived === false" icon="icon-delete" @click="deleteCard()">
{{ t('deck', 'Delete card') }} {{ t('deck', 'Delete card') }}
</ActionButton> </ActionButton>
<ActionButton icon="icon-external" @click.stop="modalShow=true"> <ActionButton icon="icon-external" @click.stop="modalShow=true">
{{ t('deck', 'Move card') }}
</ActionButton>
<ActionButton icon="icon-settings-dark" @click="openCard">
{{ t('deck', 'Card details') }}
</ActionButton>
</Actions>
<Modal v-if="modalShow" title="Move card to another board" @close="modalShow=false">
<div class="modal__content">
<Multiselect v-model="selectedBoard"
:placeholder="t('deck', 'Select a board')"
:options="boards"
label="title"
@select="loadStacksFromBoard" />
<Multiselect v-model="selectedStack"
:placeholder="t('deck', 'Select a stack')"
:options="stacksFromBoard"
label="title" />
<button :disabled="!isBoardAndStackChoosen" class="primary" @click="moveCard">
{{ t('deck', 'Move card') }} {{ t('deck', 'Move card') }}
</button> </ActionButton>
<button @click="modalShow=false"> <ActionButton icon="icon-settings-dark" @click="openCard">
{{ t('deck', 'Cancel') }} {{ t('deck', 'Card details') }}
</button> </ActionButton>
</div> </Actions>
</Modal>
<Modal v-if="modalShow" title="Move card to another board" @close="modalShow=false">
<div class="modal__content">
<Multiselect v-model="selectedBoard"
:placeholder="t('deck', 'Select a board')"
:options="boards"
label="title"
@select="loadStacksFromBoard" />
<Multiselect v-model="selectedStack"
:placeholder="t('deck', 'Select a stack')"
:options="stacksFromBoard"
label="title" />
<button :disabled="!isBoardAndStackChoosen" class="primary" @click="moveCard">
{{ t('deck', 'Move card') }}
</button>
<button @click="modalShow=false">
{{ t('deck', 'Cancel') }}
</button>
</div>
</Modal>
</div>
<ul v-if="card.labels && card.labels.length > 0" class="labels" @click="openCard">
<li v-for="label in card.labels" :key="label.id" :style="labelStyle(label)">
<span>{{ label.title }}</span>
</li>
</ul>
<div v-show="!compactMode" class="card-controls compact-item" @click="openCard">
<CardBadges :id="id" />
</div>
</div> </div>
<ul v-if="card.labels && card.labels.length > 0" class="labels" @click="openCard"> </AttachmentDragAndDrop>
<li v-for="label in card.labels" :key="label.id" :style="labelStyle(label)">
<span>{{ label.title }}</span>
</li>
</ul>
<div v-show="!compactMode" class="card-controls compact-item" @click="openCard">
<CardBadges :id="id" />
</div>
</div>
</template> </template>
<script> <script>
@@ -105,10 +107,11 @@ import axios from '@nextcloud/axios'
import CardBadges from './CardBadges' import CardBadges from './CardBadges'
import Color from '../../mixins/color' import Color from '../../mixins/color'
import labelStyle from '../../mixins/labelStyle' import labelStyle from '../../mixins/labelStyle'
import AttachmentDragAndDrop from '../AttachmentDragAndDrop'
export default { export default {
name: 'CardItem', name: 'CardItem',
components: { Modal, CardBadges, Actions, ActionButton, Multiselect }, components: { Modal, CardBadges, Actions, ActionButton, Multiselect, AttachmentDragAndDrop },
directives: { directives: {
ClickOutside, ClickOutside,
}, },

View File

@@ -0,0 +1,68 @@
/*
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { showError } from '@nextcloud/dialogs'
import { formatFileSize } from '@nextcloud/files'
export default {
methods: {
async onLocalAttachmentSelected(file) {
if (this.maxUploadSize > 0 && file.size > this.maxUploadSize) {
showError(
t('deck', `Failed to upload {name}`, { name: file.name }) + ' - '
+ t('deck', 'Maximum file size of {size} exceeded', { size: formatFileSize(this.maxUploadSize) })
)
event.target.value = ''
return
}
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)
}
}
},
overrideAttachment() {
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.cardId)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', this.file)
this.$store.dispatch('updateAttachment', {
cardId: this.cardId,
attachmentId: this.overwriteAttachment.id,
formData: bodyFormData,
})
this.modalShow = false
},
},
}

View File

@@ -143,15 +143,13 @@ export default {
cardIncreaseAttachmentCount(state, cardId) { cardIncreaseAttachmentCount(state, cardId) {
const existingIndex = state.cards.findIndex(_card => _card.id === cardId) const existingIndex = state.cards.findIndex(_card => _card.id === cardId)
if (existingIndex !== -1) { if (existingIndex !== -1) {
const existingCard = state.cards.find(_card => _card.id === cardId) Vue.set(state.cards[existingIndex], 'attachmentCount', state.cards[existingIndex].attachmentCount + 1)
Vue.set(state.cards, existingCard.attachmentCount, existingCard.attachmentCount++)
} }
}, },
cardDecreaseAttachmentCount(state, cardId) { cardDecreaseAttachmentCount(state, cardId) {
const existingIndex = state.cards.findIndex(_card => _card.id === cardId) const existingIndex = state.cards.findIndex(_card => _card.id === cardId)
if (existingIndex !== -1) { if (existingIndex !== -1) {
const existingCard = state.cards.find(_card => _card.id === cardId) Vue.set(state.cards[existingIndex], 'attachmentCount', state.cards[existingIndex].attachmentCount - 1)
Vue.set(state.cards, existingCard.attachmentCount, existingCard.attachmentCount--)
} }
}, },
}, },