Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: Use filepicker Vue component #9302

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
multiple
style="display: none;"
@change="onLocalAttachmentSelected">
<FilePicker v-if="isAttachementPickerOpen"
:title="t('mail','Choose a file to add as attachment')"
:buttons="attachementPickerButtons"
:filter-fn="filterAttachements"
@close="()=>isAttachementPickerOpen = false" />
<FilePicker v-if="isLinkPickerOpen"
:title="t('mail','Choose a file to share as a link')"
:multiselect="false"
:buttons="linkPickerButtons"
:filter-fn="filterAttachements"
@close="()=>isLinkPickerOpen = false" />
</div>
</template>

Expand All @@ -60,7 +71,8 @@
import { getRequestToken } from '@nextcloud/auth'
import { formatFileSize } from '@nextcloud/files'
import prop from 'lodash/fp/prop.js'
import { getFilePickerBuilder, showWarning } from '@nextcloud/dialogs'
import { showWarning } from '@nextcloud/dialogs'
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import sumBy from 'lodash/fp/sumBy.js'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'

Expand All @@ -87,6 +99,7 @@
export default {
name: 'ComposerAttachments',
components: {
FilePicker,
ComposerAttachment,
ChevronDown,
ChevronUp,
Expand All @@ -113,6 +126,23 @@
attachments: [],
isToggle: false,
hasNextLine: false,
isAttachementPickerOpen: false,
isLinkPickerOpen: false,
attachementPickerButtons: [
{
label: t('mail', 'Choose'),
callback: this.onAddCloudAttachment,
type: 'primary',
},
],
linkPickerButtons: [
{
label: t('mail', 'Choose'),
callback: this.onAddCloudAttachmentLink,
type: 'primary',
},
],

}
},
computed: {
Expand Down Expand Up @@ -163,8 +193,8 @@
},
created() {
this.bus.on('on-add-local-attachment', this.onAddLocalAttachment)
this.bus.on('on-add-cloud-attachment', this.onAddCloudAttachment)
this.bus.on('on-add-cloud-attachment-link', this.onAddCloudAttachmentLink)
this.bus.on('on-add-cloud-attachment', this.openAttachementPicker)
this.bus.on('on-add-cloud-attachment-link', this.OpenctLinkPicker)
this.bus.on('on-add-message-as-attachment', this.onAddMessageAsAttachment)
this.value.map(attachment => {
this.attachments.push({
Expand All @@ -180,6 +210,17 @@
})
},
methods: {
filterAttachements(node) {
const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
const downloadPermissions = downloadShareAttribute !== undefined ? downloadShareAttribute.enabled : true
return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
},
openAttachementPicker() {
this.isAttachementPickerOpen = true
},
OpenctLinkPicker() {
this.isLinkPickerOpen = true
},
onAddLocalAttachment() {
this.$refs.localAttachments.click()
},
Expand All @@ -199,7 +240,7 @@
onLocalAttachmentSelected(e) {
this.uploading = true
// BUG - if choose again - progress lost/ move to complete()
Vue.set(this, 'uploads', {})

Check warning on line 243 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Caution: `Vue` also has a named export `set`. Check if you meant to write `import {set} from 'vue'` instead

const toUpload = sumBy(prop('size'), Object.values(e.target.files))
const newTotal = toUpload + this.totalSizeOfUpload()
Expand Down Expand Up @@ -244,7 +285,7 @@
}
this.attachments.push(attachment)

Vue.set(this.uploads, file.name, {

Check warning on line 288 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Caution: `Vue` also has a named export `set`. Check if you meant to write `import {set} from 'vue'` instead
total: file.size,
uploaded: 0,
})
Expand Down Expand Up @@ -285,11 +326,10 @@

return done
},
async onAddCloudAttachment() {
const picker = getFilePickerBuilder(t('mail', 'Choose a file to add as attachment')).setMultiSelect(true).build()

async onAddCloudAttachment(nodes) {
try {
const paths = await picker.pick(t('mail', 'Choose a file to add as attachment'))
const paths = nodes.map(node => node.path)
this.cloudAttachement = false
// maybe fiiled front with placeholder loader...?
const filesFromCloud = await Promise.all(paths.map(getFileData))

Expand Down Expand Up @@ -332,12 +372,10 @@
logger.error('could not choose a file as attachment', { error })
}
},
async onAddCloudAttachmentLink() {
const picker = getFilePickerBuilder(t('mail', 'Choose a file to share as a link')).build()

async onAddCloudAttachmentLink(nodes) {
try {
const path = await picker.pick(t('mail', 'Choose a file to share as a link'))
const url = await shareFile(path, getRequestToken())
this.cloudAttachementLink = false
const url = await shareFile(nodes[0].path, getRequestToken())

this.appendToBodyAtCursor(`<a href="${url}">${url}</a>`)
} catch (error) {
Expand Down
Loading