Skip to content

Commit c76be65

Browse files
authored
Merge pull request #33755 from nextcloud/enh/reference-file
File widget for references
2 parents b6d8fc9 + 38e4f8a commit c76be65

20 files changed

Lines changed: 471 additions & 19 deletions

apps/files/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
5151
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
5252
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
53+
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
5354
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
5455
'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php',
5556
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ComposerStaticInitFiles
6565
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
6666
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
6767
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
68+
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
6869
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
6970
'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php',
7071
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',

apps/files/lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCA\Files\Event\LoadSidebar;
4545
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
4646
use OCA\Files\Listener\LoadSidebarListener;
47+
use OCA\Files\Listener\RenderReferenceEventListener;
4748
use OCA\Files\Notification\Notifier;
4849
use OCA\Files\Search\FilesSearchProvider;
4950
use OCA\Files\Service\TagService;
@@ -53,6 +54,7 @@
5354
use OCP\AppFramework\Bootstrap\IBootContext;
5455
use OCP\AppFramework\Bootstrap\IBootstrap;
5556
use OCP\AppFramework\Bootstrap\IRegistrationContext;
57+
use OCP\Collaboration\Reference\RenderReferenceEvent;
5658
use OCP\Collaboration\Resources\IProviderManager;
5759
use OCP\IConfig;
5860
use OCP\IL10N;
@@ -118,6 +120,7 @@ public function register(IRegistrationContext $context): void {
118120

119121
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
120122
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
123+
$context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
121124

122125
$context->registerSearchProvider(FilesSearchProvider::class);
123126

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @author Julius Härtl <jus@bitgrid.net>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
namespace OCA\Files\Listener;
26+
27+
use OCP\Collaboration\Reference\RenderReferenceEvent;
28+
use OCP\EventDispatcher\Event;
29+
use OCP\EventDispatcher\IEventListener;
30+
31+
class RenderReferenceEventListener implements IEventListener {
32+
public function handle(Event $event): void {
33+
if (!$event instanceof RenderReferenceEvent) {
34+
return;
35+
}
36+
37+
\OCP\Util::addScript('files', 'reference-files');
38+
}
39+
}

apps/files/src/reference-files.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
3+
*
4+
* @author Julius Härtl <jus@bitgrid.net>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
import Vue from 'vue'
23+
import { translate as t } from '@nextcloud/l10n'
24+
25+
import { registerWidget, registerCustomPickerElement, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Components/NcRichText.js'
26+
27+
import FileWidget from './views/ReferenceFileWidget.vue'
28+
import FileReferencePickerElement from './views/FileReferencePickerElement.vue'
29+
30+
Vue.mixin({
31+
methods: {
32+
t,
33+
},
34+
})
35+
36+
registerWidget('file', (el, { richObjectType, richObject, accessible }) => {
37+
const Widget = Vue.extend(FileWidget)
38+
new Widget({
39+
propsData: {
40+
richObjectType,
41+
richObject,
42+
accessible,
43+
},
44+
}).$mount(el)
45+
})
46+
47+
registerCustomPickerElement('files', (el, { providerId, accessible }) => {
48+
const Element = Vue.extend(FileReferencePickerElement)
49+
const vueElement = new Element({
50+
propsData: {
51+
providerId,
52+
accessible,
53+
},
54+
}).$mount(el)
55+
return new NcCustomPickerRenderResult(vueElement.$el, vueElement)
56+
}, (el, renderResult) => {
57+
renderResult.object.$destroy()
58+
})
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--
2+
- @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
3+
-
4+
- @author Julius Härtl <jus@bitgrid.net>
5+
-
6+
- @license GNU AGPL version 3 or any later version
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-->
21+
22+
<template>
23+
<div ref="picker" class="reference-file-picker" />
24+
</template>
25+
26+
<script>
27+
import { FilePickerType } from '@nextcloud/dialogs'
28+
import { generateUrl } from '@nextcloud/router'
29+
export default {
30+
name: 'FileReferencePickerElement',
31+
components: {
32+
},
33+
props: {
34+
providerId: {
35+
type: String,
36+
required: true,
37+
},
38+
accessible: {
39+
type: Boolean,
40+
default: false,
41+
},
42+
},
43+
mounted() {
44+
this.openFilePicker()
45+
window.addEventListener('click', this.onWindowClick)
46+
},
47+
beforeDestroy() {
48+
window.removeEventListener('click', this.onWindowClick)
49+
},
50+
methods: {
51+
onWindowClick(e) {
52+
if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
53+
this.$emit('cancel')
54+
}
55+
},
56+
async openFilePicker() {
57+
OC.dialogs.filepicker(
58+
t('files', 'Select file or folder to link to'),
59+
(file) => {
60+
const client = OC.Files.getClient()
61+
client.getFileInfo(file).then((_status, fileInfo) => {
62+
this.submit(fileInfo.id)
63+
})
64+
},
65+
false, // multiselect
66+
[], // mime filter
67+
false, // modal
68+
FilePickerType.Choose, // type
69+
'',
70+
{
71+
target: this.$refs.picker,
72+
},
73+
)
74+
},
75+
submit(fileId) {
76+
const fileLink = window.location.protocol + '//' + window.location.host
77+
+ generateUrl('/f/{fileId}', { fileId })
78+
this.$emit('submit', fileLink)
79+
},
80+
},
81+
}
82+
</script>
83+
84+
<style scoped lang="scss">
85+
.reference-file-picker {
86+
flex-grow: 1;
87+
margin-top: 44px;
88+
89+
&:deep(.oc-dialog) {
90+
transform: none !important;
91+
box-shadow: none !important;
92+
flex-grow: 1 !important;
93+
position: static !important;
94+
width: 100% !important;
95+
height: auto !important;
96+
padding: 0 !important;
97+
max-width: initial;
98+
99+
.oc-dialog-close {
100+
display: none;
101+
}
102+
103+
.oc-dialog-buttonrow.onebutton.aside {
104+
position: absolute;
105+
padding: 12px 32px;
106+
}
107+
108+
.oc-dialog-content {
109+
max-width: 100% !important;
110+
}
111+
}
112+
}
113+
</style>

0 commit comments

Comments
 (0)