-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Julius Härtl <[email protected]>
- Loading branch information
1 parent
ec8e0f9
commit 363e890
Showing
14 changed files
with
442 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @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 } from '@nextcloud/vue-richtext' | ||
|
||
import FileWidget from './views/ReferenceFileWidget.vue' | ||
|
||
Vue.mixin({ | ||
methods: { | ||
t, | ||
}, | ||
}) | ||
|
||
registerWidget('file', (el, { richObjectType, richObject, accessible }) => { | ||
const Widget = Vue.extend(FileWidget) | ||
new Widget({ | ||
propsData: { | ||
richObjectType, | ||
richObject, | ||
accessible, | ||
}, | ||
}).$mount(el) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net> | ||
- | ||
- @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 v-if="!accessible" class="widget-file widget-file--no-access"> | ||
<div class="widget-file--image widget-file--image--icon icon-folder" /> | ||
<div class="widget-file--details"> | ||
<p class="widget-file--title">{{ t('files', 'File cannot be accessed') }}</p> | ||
<p class="widget-file--description">{{ t('files', 'You might not have have permissions to view it, ask the sender to share it') }}</p> | ||
</div> | ||
</div> | ||
<a v-else | ||
class="widget-file" | ||
:href="richObject.link" | ||
@click.prevent="navigate"> | ||
<div class="widget-file--image" :class="filePreviewClass" :style="filePreview" /> | ||
<div class="widget-file--details"> | ||
<p class="widget-file--title">{{ richObject.name }}</p> | ||
<p class="widget-file--description">{{ fileSize }}<br>{{ fileMtime }}</p> | ||
<p class="widget-file--link">{{ filePath }}</p> | ||
</div> | ||
</a> | ||
</template> | ||
<script> | ||
import { generateUrl } from '@nextcloud/router' | ||
import path from 'path' | ||
|
||
export default { | ||
name: 'ReferenceFileWidget', | ||
props: { | ||
richObject: { | ||
type: Object, | ||
required: true, | ||
}, | ||
accessible: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
previewUrl: window.OC.MimeType.getIconUrl(this.richObject.mimetype), | ||
} | ||
}, | ||
computed: { | ||
fileSize() { | ||
return window.OC.Util.humanFileSize(this.richObject.size) | ||
}, | ||
fileMtime() { | ||
return window.OC.Util.relativeModifiedDate(this.richObject.mtime * 1000) | ||
}, | ||
filePath() { | ||
return path.dirname(this.richObject.path) | ||
}, | ||
filePreview() { | ||
if (this.previewUrl) { | ||
return { | ||
backgroundImage: 'url(' + this.previewUrl + ')', | ||
} | ||
} | ||
|
||
return { | ||
backgroundImage: 'url(' + window.OC.MimeType.getIconUrl(this.richObject.mimetype) + ')', | ||
} | ||
|
||
}, | ||
filePreviewClass() { | ||
if (this.previewUrl) { | ||
return 'widget-file--image--preview' | ||
} | ||
return 'widget-file--image--icon' | ||
|
||
}, | ||
}, | ||
mounted() { | ||
if (this.richObject['preview-available']) { | ||
const previewUrl = generateUrl('/core/preview?fileId={fileId}&x=250&y=250', { | ||
fileId: this.richObject.id, | ||
}) | ||
const img = new Image() | ||
img.onload = () => { | ||
this.previewUrl = previewUrl | ||
} | ||
img.onerror = err => { | ||
console.error('could not load recommendation preview', err) | ||
} | ||
img.src = previewUrl | ||
} | ||
}, | ||
methods: { | ||
navigate() { | ||
if (OCA.Viewer && OCA.Viewer.mimetypes.indexOf(this.richObject.mimetype) !== -1) { | ||
OCA.Viewer.open({ path: this.richObject.path }) | ||
return | ||
} | ||
window.location = generateUrl('/f/' + this.id) | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.widget-file { | ||
display: flex; | ||
|
||
&--image { | ||
min-width: 40%; | ||
background-position: center; | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
|
||
&.widget-file--image--icon { | ||
min-width: 88px; | ||
background-size: 44px; | ||
} | ||
} | ||
|
||
&--title { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
font-weight: bold; | ||
} | ||
|
||
&--details { | ||
padding: 12px; | ||
flex-grow: 1; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
p { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
} | ||
|
||
&--description { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
display: -webkit-box; | ||
-webkit-line-clamp: 3; | ||
line-clamp: 3; | ||
-webkit-box-orient: vertical; | ||
} | ||
|
||
&--link { | ||
color: var(--color-text-maxcontrast); | ||
} | ||
|
||
&.widget-file--no-access { | ||
padding: 12px; | ||
|
||
.widget-file--details { | ||
padding: 0; | ||
} | ||
} | ||
} | ||
</style> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @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/>. | ||
*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.