Skip to content

Commit 6a6cf3a

Browse files
committed
Implement file reference wiget
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 1ab6698 commit 6a6cf3a

19 files changed

+503
-4
lines changed

apps/files/composer/composer/autoload_classmap.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
4848
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
4949
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
50+
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
5051
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
5152
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
5253
'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php',

apps/files/composer/composer/autoload_static.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ComposerStaticInitFiles
6262
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
6363
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
6464
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
65+
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
6566
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
6667
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
6768
'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php',

apps/files/lib/AppInfo/Application.php

+3
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;
@@ -52,6 +53,7 @@
5253
use OCP\AppFramework\Bootstrap\IBootContext;
5354
use OCP\AppFramework\Bootstrap\IBootstrap;
5455
use OCP\AppFramework\Bootstrap\IRegistrationContext;
56+
use OCP\Collaboration\Reference\RenderReferenceEvent;
5557
use OCP\Collaboration\Resources\IProviderManager;
5658
use OCP\IConfig;
5759
use OCP\IL10N;
@@ -116,6 +118,7 @@ public function register(IRegistrationContext $context): void {
116118

117119
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
118120
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
121+
$context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
119122

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

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

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 } from '@nextcloud/vue-richtext'
26+
27+
import FileWidget from './views/ReferenceFileWidget.vue'
28+
29+
Vue.mixin({
30+
methods: {
31+
t,
32+
},
33+
})
34+
35+
registerWidget('file', (el, { richObjectType, richObject, accessible }) => {
36+
const Widget = Vue.extend(FileWidget)
37+
new Widget({
38+
propsData: {
39+
richObjectType,
40+
richObject,
41+
accessible,
42+
},
43+
}).$mount(el)
44+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
<template>
23+
<div v-if="!accessible" class="widget-file widget-file--no-access">
24+
<div class="widget-file--image widget-file--image--icon icon-folder" />
25+
<div class="widget-file--details">
26+
<p class="widget-file--title">{{ t('files', 'File cannot be accessed') }}</p>
27+
<p class="widget-file--description">{{ t('files', 'You might not have have permissions to view it, ask the sender to share it') }}</p>
28+
</div>
29+
</div>
30+
<a v-else
31+
class="widget-file"
32+
:href="richObject.link"
33+
@click.prevent="navigate">
34+
<div class="widget-file--image" :class="filePreviewClass" :style="filePreview" />
35+
<div class="widget-file--details">
36+
<p class="widget-file--title">{{ richObject.name }}</p>
37+
<p class="widget-file--description">{{ fileSize }}<br>{{ fileMtime }}</p>
38+
<p class="widget-file--link">{{ filePath }}</p>
39+
</div>
40+
</a>
41+
</template>
42+
<script>
43+
import { generateUrl } from '@nextcloud/router'
44+
import path from 'path'
45+
46+
export default {
47+
name: 'ReferenceFileWidget',
48+
props: {
49+
richObject: {
50+
type: Object,
51+
required: true,
52+
},
53+
accessible: {
54+
type: Boolean,
55+
default: true,
56+
},
57+
},
58+
data() {
59+
return {
60+
previewUrl: window.OC.MimeType.getIconUrl(this.richObject.mimetype),
61+
}
62+
},
63+
computed: {
64+
fileSize() {
65+
return window.OC.Util.humanFileSize(this.richObject.size)
66+
},
67+
fileMtime() {
68+
return window.OC.Util.relativeModifiedDate(this.richObject.mtime * 1000)
69+
},
70+
filePath() {
71+
return path.dirname(this.richObject.path)
72+
},
73+
filePreview() {
74+
if (this.previewUrl) {
75+
return {
76+
backgroundImage: 'url(' + this.previewUrl + ')',
77+
}
78+
}
79+
80+
return {
81+
backgroundImage: 'url(' + window.OC.MimeType.getIconUrl(this.richObject.mimetype) + ')',
82+
}
83+
84+
},
85+
filePreviewClass() {
86+
if (this.previewUrl) {
87+
return 'widget-file--image--preview'
88+
}
89+
return 'widget-file--image--icon'
90+
91+
},
92+
},
93+
mounted() {
94+
if (this.richObject['preview-available']) {
95+
const previewUrl = generateUrl('/core/preview?fileId={fileId}&x=250&y=250', {
96+
fileId: this.richObject.id,
97+
})
98+
const img = new Image()
99+
img.onload = () => {
100+
this.previewUrl = previewUrl
101+
}
102+
img.onerror = err => {
103+
console.error('could not load recommendation preview', err)
104+
}
105+
img.src = previewUrl
106+
}
107+
},
108+
methods: {
109+
navigate() {
110+
if (OCA.Viewer && OCA.Viewer.mimetypes.indexOf(this.richObject.mimetype) !== -1) {
111+
OCA.Viewer.open({ path: this.richObject.path })
112+
return
113+
}
114+
window.location = generateUrl('/f/' + this.id)
115+
},
116+
},
117+
}
118+
</script>
119+
<style lang="scss" scoped>
120+
.widget-file {
121+
display: flex;
122+
123+
&--image {
124+
min-width: 40%;
125+
background-position: center;
126+
background-size: cover;
127+
background-repeat: no-repeat;
128+
129+
&.widget-file--image--icon {
130+
min-width: 88px;
131+
background-size: 44px;
132+
}
133+
}
134+
135+
&--title {
136+
overflow: hidden;
137+
text-overflow: ellipsis;
138+
white-space: nowrap;
139+
font-weight: bold;
140+
}
141+
142+
&--details {
143+
padding: 12px;
144+
flex-grow: 1;
145+
display: flex;
146+
flex-direction: column;
147+
148+
p {
149+
margin: 0;
150+
padding: 0;
151+
}
152+
}
153+
154+
&--description {
155+
overflow: hidden;
156+
text-overflow: ellipsis;
157+
display: -webkit-box;
158+
-webkit-line-clamp: 3;
159+
line-clamp: 3;
160+
-webkit-box-orient: vertical;
161+
}
162+
163+
&--link {
164+
color: var(--color-text-maxcontrast);
165+
}
166+
167+
&.widget-file--no-access {
168+
padding: 12px;
169+
170+
.widget-file--details {
171+
padding: 0;
172+
}
173+
}
174+
}
175+
</style>

dist/core-common.js

+2-2
Large diffs are not rendered by default.

dist/core-common.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-reference-files.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
*/

dist/files-reference-files.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/composer/composer/autoload_classmap.php

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
'OCP\\Collaboration\\Reference\\IReference' => $baseDir . '/lib/public/Collaboration/Reference/IReference.php',
146146
'OCP\\Collaboration\\Reference\\IReferenceManager' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceManager.php',
147147
'OCP\\Collaboration\\Reference\\IReferenceProvider' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
148+
'OCP\\Collaboration\\Reference\\RenderReferenceEvent' => $baseDir . '/lib/public/Collaboration/Reference/RenderReferenceEvent.php',
148149
'OCP\\Collaboration\\Resources\\CollectionException' => $baseDir . '/lib/public/Collaboration/Resources/CollectionException.php',
149150
'OCP\\Collaboration\\Resources\\ICollection' => $baseDir . '/lib/public/Collaboration/Resources/ICollection.php',
150151
'OCP\\Collaboration\\Resources\\IManager' => $baseDir . '/lib/public/Collaboration/Resources/IManager.php',

lib/composer/composer/autoload_static.php

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
178178
'OCP\\Collaboration\\Reference\\IReference' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReference.php',
179179
'OCP\\Collaboration\\Reference\\IReferenceManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceManager.php',
180180
'OCP\\Collaboration\\Reference\\IReferenceProvider' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
181+
'OCP\\Collaboration\\Reference\\RenderReferenceEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/RenderReferenceEvent.php',
181182
'OCP\\Collaboration\\Resources\\CollectionException' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/CollectionException.php',
182183
'OCP\\Collaboration\\Resources\\ICollection' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/ICollection.php',
183184
'OCP\\Collaboration\\Resources\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/IManager.php',

0 commit comments

Comments
 (0)