Browse Source

Merge pull request #42104 from nextcloud/fix/reference-picker

fix: Adjust reference picker code for the vue based FilePicker
pull/42111/head
Arthur Schiwon 2 years ago
committed by GitHub
parent
commit
445a09cfe2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 124
      apps/files/src/views/FileReferencePickerElement.vue
  2. 4
      dist/core-unified-search.js
  3. 2
      dist/core-unified-search.js.map
  4. 4
      dist/files-reference-files.js
  5. 22
      dist/files-reference-files.js.LICENSE.txt
  6. 2
      dist/files-reference-files.js.map
  7. 4
      dist/settings-vue-settings-admin-delegation.js
  8. 2
      dist/settings-vue-settings-admin-delegation.js.map
  9. 4
      dist/settings-vue-settings-admin-security.js
  10. 2
      dist/settings-vue-settings-admin-security.js.map

124
apps/files/src/views/FileReferencePickerElement.vue

@ -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: {
@ -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
dist/core-unified-search.js
File diff suppressed because it is too large
View File

2
dist/core-unified-search.js.map
File diff suppressed because it is too large
View File

4
dist/files-reference-files.js
File diff suppressed because it is too large
View File

22
dist/files-reference-files.js.LICENSE.txt

@ -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
dist/files-reference-files.js.map
File diff suppressed because it is too large
View File

4
dist/settings-vue-settings-admin-delegation.js
File diff suppressed because it is too large
View File

2
dist/settings-vue-settings-admin-delegation.js.map
File diff suppressed because it is too large
View File

4
dist/settings-vue-settings-admin-security.js
File diff suppressed because it is too large
View File

2
dist/settings-vue-settings-admin-security.js.map
File diff suppressed because it is too large
View File

Loading…
Cancel
Save