Skip to content

Commit

Permalink
Merge pull request #42103 from nextcloud/fix/stable28-reference-picker
Browse files Browse the repository at this point in the history
[stable28]  fix: Adjust reference picker code for the vue based FilePicker
  • Loading branch information
blizzz authored Dec 7, 2023
2 parents ceb3975 + 6ea6048 commit 4a77f28
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 82 deletions.
124 changes: 57 additions & 67 deletions apps/files/src/views/FileReferencePickerElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@
-->

<template>
<div ref="picker" class="reference-file-picker" />
<div :id="containerId">
<FilePicker v-bind="filepickerOptions" @close="onClose" />
</div>
</template>

<script>
import { FilePickerType } from '@nextcloud/dialogs'
<script lang="ts">
import type { Node as NcNode } from '@nextcloud/files'
import type { IFilePickerButton } from '@nextcloud/dialogs'

import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
export default {
import { defineComponent } from 'vue'

export default defineComponent({
name: 'FileReferencePickerElement',
components: {
FilePicker,
},
props: {
providerId: {
Expand All @@ -40,74 +49,55 @@ export default {
default: false,
},
},
mounted() {
this.openFilePicker()
window.addEventListener('click', this.onWindowClick)
},
beforeDestroy() {
window.removeEventListener('click', this.onWindowClick)
computed: {
containerId() {
return `filepicker-${Math.random().toString(36).slice(7)}`
},
filepickerOptions() {
return {
allowPickDirectory: false,
buttons: this.buttonFactory,
container: `#${this.containerId}`,
multiselect: false,
name: t('files', 'Select file or folder to link to'),
}
},
},
methods: {
onWindowClick(e) {
if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
this.$emit('cancel')
t,

buttonFactory(selected: NcNode[]): IFilePickerButton[] {
const buttons = [] as IFilePickerButton[]
if (selected.length === 0) {
buttons.push({
label: t('files', 'Choose file'),
type: 'tertiary' as never,
callback: this.onClose,
})
} else {
buttons.push({
label: t('files', 'Choose {file}', { file: selected[0].basename }),
type: 'primary',
callback: this.onClose,
})
}
return buttons
},
async openFilePicker() {
OC.dialogs.filepicker(
t('files', 'Select file or folder to link to'),
(file) => {
const client = OC.Files.getClient()
client.getFileInfo(file).then((_status, fileInfo) => {
this.submit(fileInfo.id)
})
},
false, // multiselect
[], // mime filter
false, // modal
FilePickerType.Choose, // type
'',
{
target: this.$refs.picker,
},
)

onClose(nodes?: NcNode[]) {
if (nodes === undefined || nodes.length === 0) {
this.$emit('cancel')
} else {
this.onSubmit(nodes[0])
}
},
submit(fileId) {
const fileLink = window.location.protocol + '//' + window.location.host
+ generateUrl('/f/{fileId}', { fileId })
this.$emit('submit', fileLink)

onSubmit(node: NcNode) {
const url = new URL(window.location.href)
url.pathname = generateUrl('/f/{fileId}', { fileId: node.fileid! })
url.search = ''
this.$emit('submit', url.href)
},
},
}
})
</script>

<style scoped lang="scss">
.reference-file-picker {
flex-grow: 1;
padding: 12px 16px 16px 16px;

&:deep(.oc-dialog) {
transform: none !important;
box-shadow: none !important;
flex-grow: 1 !important;
position: static !important;
width: 100% !important;
height: auto !important;
padding: 0 !important;
max-width: initial;

.oc-dialog-close {
display: none;
}

.oc-dialog-buttonrow.onebutton.aside {
position: absolute;
padding: 12px 32px;
}

.oc-dialog-content {
max-width: 100% !important;
}
}
}
</style>
4 changes: 2 additions & 2 deletions dist/core-unified-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unified-search.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-reference-files.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dist/files-reference-files.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@
* 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/>.
*/

/**
* @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
*
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @license AGPL-3.0-or-later
*
* 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/>.
*
*/
2 changes: 1 addition & 1 deletion dist/files-reference-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-personal-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-personal-settings.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-vue-settings-admin-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-admin-security.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/sharebymail-vue-settings-admin-sharebymail.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sharebymail-vue-settings-admin-sharebymail.js.map

Large diffs are not rendered by default.

0 comments on commit 4a77f28

Please sign in to comment.