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

File widget for references #33755

Merged
merged 3 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php',
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php',
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Listener\RenderReferenceEventListener;
use OCA\Files\Notification\Notifier;
use OCA\Files\Search\FilesSearchProvider;
use OCA\Files\Service\TagService;
Expand All @@ -53,6 +54,7 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\IConfig;
use OCP\IL10N;
Expand Down Expand Up @@ -118,6 +120,7 @@ public function register(IRegistrationContext $context): void {

$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
$context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);

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

Expand Down
39 changes: 39 additions & 0 deletions apps/files/lib/Listener/RenderReferenceEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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/>.
*/

namespace OCA\Files\Listener;

use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class RenderReferenceEventListener implements IEventListener {
public function handle(Event $event): void {
if (!$event instanceof RenderReferenceEvent) {
return;
}

\OCP\Util::addScript('files', 'reference-files');
}
}
58 changes: 58 additions & 0 deletions apps/files/src/reference-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @copyright Copyright (c) 2022 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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 Vue from 'vue'
import { translate as t } from '@nextcloud/l10n'

import { registerWidget, registerCustomPickerElement, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Components/NcRichText.js'

import FileWidget from './views/ReferenceFileWidget.vue'
import FileReferencePickerElement from './views/FileReferencePickerElement.vue'

Vue.mixin({
methods: {
t,
},
})

registerWidget('file', (el, { richObjectType, richObject, accessible }) => {
const Widget = Vue.extend(FileWidget)
new Widget({
propsData: {
richObjectType,
richObject,
accessible,
},
}).$mount(el)
})

registerCustomPickerElement('files', (el, { providerId, accessible }) => {
const Element = Vue.extend(FileReferencePickerElement)
const vueElement = new Element({
propsData: {
providerId,
accessible,
},
}).$mount(el)
return new NcCustomPickerRenderResult(vueElement.$el, vueElement)
}, (el, renderResult) => {
renderResult.object.$destroy()
})
113 changes: 113 additions & 0 deletions apps/files/src/views/FileReferencePickerElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--
- @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
-
- @author Julius Härtl <[email protected]>
-
- @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 ref="picker" class="reference-file-picker" />
</template>

<script>
import { FilePickerType } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
export default {
name: 'FileReferencePickerElement',
components: {
},
props: {
providerId: {
type: String,
required: true,
},
accessible: {
type: Boolean,
default: false,
},
},
mounted() {
this.openFilePicker()
window.addEventListener('click', this.onWindowClick)
},
beforeDestroy() {
window.removeEventListener('click', this.onWindowClick)
},
methods: {
onWindowClick(e) {
if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
this.$emit('cancel')
}
},
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,
},
)
},
submit(fileId) {
const fileLink = window.location.protocol + '//' + window.location.host
+ generateUrl('/f/{fileId}', { fileId })
this.$emit('submit', fileLink)
},
},
}
</script>

<style scoped lang="scss">
.reference-file-picker {
flex-grow: 1;
margin-top: 44px;

&: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>
Loading