Merge pull request #14664 from nextcloud/bugfix/noid/absolute-paths-of-images-for-linked-collaboration-resources

Replace the icon-class with an absolute link to an image
This commit is contained in:
Roeland Jago Douma 2019-03-19 19:23:29 +01:00 committed by GitHub
commit 2fcb6ddc22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 96 additions and 189 deletions

4
.gitattributes vendored
View file

@ -5,8 +5,8 @@
/apps/accessibility/js/accessibility.js.map binary /apps/accessibility/js/accessibility.js.map binary
/apps/comments/js/*.js binary /apps/comments/js/*.js binary
/apps/comments/js/*.js.map binary /apps/comments/js/*.js.map binary
/apps/files_sharing/js/additionalScripts.js binary /apps/files_sharing/js/dist/*.js binary
/apps/files_sharing/js/additionalScripts.js.map binary /apps/files_sharing/js/dist/*.js.map binary
/apps/files_versions/js/files_versions.js binary /apps/files_versions/js/files_versions.js binary
/apps/files_versions/js/files_versions.js.map binary /apps/files_versions/js/files_versions.js.map binary
/apps/oauth2/js/oauth2.js binary /apps/oauth2/js/oauth2.js binary

View file

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com> * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
* *
@ -27,24 +28,29 @@ use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException; use OCP\Collaboration\Resources\ResourceException;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\IPreview;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
class ResourceProvider implements IProvider { class ResourceProvider implements IProvider {
const RESOURCE_TYPE = 'files'; public const RESOURCE_TYPE = 'file';
/** @var IRootFolder */ /** @var IRootFolder */
protected $rootFolder; protected $rootFolder;
/** @var IPreview */
private $preview;
/** @var IURLGenerator */ /** @var IURLGenerator */
private $urlGenerator; private $urlGenerator;
/** @var array */ /** @var array */
protected $nodes = []; protected $nodes = [];
public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) { public function __construct(IRootFolder $rootFolder,
IPreview $preview,
IURLGenerator $urlGenerator) {
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->preview = $preview;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
@ -61,21 +67,34 @@ class ResourceProvider implements IProvider {
} }
/** /**
* Get the display name of a resource
*
* @param IResource $resource * @param IResource $resource
* @return string * @return array
* @since 15.0.0 * @since 16.0.0
*/ */
public function getName(IResource $resource): string { public function getResourceRichObject(IResource $resource): array {
if (isset($this->nodes[(int) $resource->getId()])) { if (isset($this->nodes[(int) $resource->getId()])) {
return $this->nodes[(int) $resource->getId()]->getPath(); $node = $this->nodes[(int) $resource->getId()]->getPath();
} else {
$node = $this->getNode($resource);
} }
$node = $this->getNode($resource);
if ($node) { if ($node instanceof Node) {
return $node->getName(); $link = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile',
['fileid' => $resource->getId()]
);
return [
'type' => 'file',
'id' => $resource->getId(),
'name' => $node->getName(),
'path' => $node->getInternalPath(),
'link' => $link,
'mimetype' => $node->getMimetype(),
'preview-available' => $this->preview->isAvailable($node),
];
} }
return '';
throw new ResourceException('File not found');
} }
/** /**
@ -84,7 +103,7 @@ class ResourceProvider implements IProvider {
* @param IResource $resource * @param IResource $resource
* @param IUser $user * @param IUser $user
* @return bool * @return bool
* @since 15.0.0 * @since 16.0.0
*/ */
public function canAccessResource(IResource $resource, IUser $user = null): bool { public function canAccessResource(IResource $resource, IUser $user = null): bool {
if (!$user instanceof IUser) { if (!$user instanceof IUser) {
@ -102,39 +121,13 @@ class ResourceProvider implements IProvider {
return false; return false;
} }
/**
* Get the icon class of a resource
*
* @param IResource $resource
* @return string
* @since 15.0.0
*/
public function getIconClass(IResource $resource): string {
$node = $this->getNode($resource);
if ($node && $node->getMimetype() === 'httpd/unix-directory') {
return 'icon-files-dark';
}
return 'icon-filetype-file';
}
/** /**
* Get the resource type of the provider * Get the resource type of the provider
* *
* @return string * @return string
* @since 15.0.0 * @since 16.0.0
*/ */
public function getType(): string { public function getType(): string {
return self::RESOURCE_TYPE; return self::RESOURCE_TYPE;
} }
/**
* Get the link to a resource
*
* @param IResource $resource
* @return string
* @since 15.0.0
*/
public function getLink(IResource $resource): string {
return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]);
}
} }

View file

@ -45,6 +45,9 @@ $eventDispatcher->addListener(
\OCP\Util::addScript('files_sharing', 'dist/additionalScripts'); \OCP\Util::addScript('files_sharing', 'dist/additionalScripts');
} }
); );
\OC::$server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
\OCP\Util::addScript('files_sharing', 'dist/collaboration');
});
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$shareManager = \OC::$server->getShareManager(); $shareManager = \OC::$server->getShareManager();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -33,5 +33,6 @@ $tmpl = new OCP\Template('files_sharing', 'list', '');
$tmpl->assign('showgridview', $showgridview && !$isIE); $tmpl->assign('showgridview', $showgridview && !$isIE);
OCP\Util::addScript('files_sharing', 'dist/files_sharing'); OCP\Util::addScript('files_sharing', 'dist/files_sharing');
\OC::$server->getEventDispatcher()->dispatch('\OCP\Collaboration\Resources::loadAdditionalScripts');
$tmpl->printPage(); $tmpl->printPage();

View file

@ -8,22 +8,6 @@ import './sharebreadcrumbview'
import './style/sharetabview.scss' import './style/sharetabview.scss'
import './style/sharebreadcrumb.scss' import './style/sharebreadcrumb.scss'
window.OCP.Collaboration.registerType('files', { import './collaborationresourceshandler.js'
action: () => {
return new Promise((resolve, reject) => {
OC.dialogs.filepicker('Link to a file', function (f) {
const client = OC.Files.getClient();
client.getFileInfo(f).then((status, fileInfo) => {
resolve(fileInfo.id);
}, () => {
reject();
});
}, false);
});
},
/** used in "Link to a {typeString}" */
typeString: t('files_sharing', 'file'),
typeIconClass: 'icon-files-dark'
});
window.OCA.Sharing = OCA.Sharing; window.OCA.Sharing = OCA.Sharing;

View file

@ -0,0 +1,20 @@
__webpack_public_path__ = OC.linkTo('files_sharing', 'js/dist/');
__webpack_nonce__ = btoa(OC.requestToken);
window.OCP.Collaboration.registerType('file', {
action: () => {
return new Promise((resolve, reject) => {
OC.dialogs.filepicker('Link to a file', function (f) {
const client = OC.Files.getClient();
client.getFileInfo(f).then((status, fileInfo) => {
resolve(fileInfo.id);
}, () => {
reject();
});
}, false);
});
},
/** used in "Link to a {typeString}" */
typeString: t('files_sharing', 'file'),
typeIconClass: 'icon-files-dark'
});

View file

@ -21,7 +21,7 @@
--> -->
<template> <template>
<collection-list v-if="fileId" type="files" :id="fileId" :name="filename"></collection-list> <collection-list v-if="fileId" type="file" :id="fileId" :name="filename"></collection-list>
</template> </template>
<script> <script>

View file

@ -5,6 +5,7 @@ module.exports = {
entry: { entry: {
'additionalScripts': path.join(__dirname, 'src', 'additionalScripts.js'), 'additionalScripts': path.join(__dirname, 'src', 'additionalScripts.js'),
'files_sharing': path.join(__dirname, 'src', 'files_sharing.js'), 'files_sharing': path.join(__dirname, 'src', 'files_sharing.js'),
'collaboration': path.join(__dirname, 'src', 'collaborationresourceshandler.js'),
}, },
output: { output: {
path: path.resolve(__dirname, './js/dist/'), path: path.resolve(__dirname, './js/dist/'),

View file

@ -166,7 +166,7 @@ class CollaborationResourcesController extends OCSController {
try { try {
$resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser());
} catch (ResourceException $e) { } catch (ResourceException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND); $resource = $this->manager->createResource($resourceType, $resourceId);
} }
if (!$resource->canAccess($this->userSession->getUser())) { if (!$resource->canAccess($this->userSession->getUser())) {
@ -241,12 +241,6 @@ class CollaborationResourcesController extends OCSController {
return null; return null;
} }
return [ return $resource->getRichObject();
'type' => $resource->getType(),
'id' => $resource->getId(),
'name' => $resource->getName(),
'iconClass' => $resource->getIconClass(),
'link' => $resource->getLink(),
];
} }
} }

BIN
core/js/dist/main.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -39,7 +39,6 @@ export default {
* @param {TypeDefinition} typeDefinition * @param {TypeDefinition} typeDefinition
*/ */
registerType(type, typeDefinition) { registerType(type, typeDefinition) {
console.log('Type ' + type + ' registered')
types[type] = typeDefinition; types[type] = typeDefinition;
}, },
trigger(type) { trigger(type) {

View file

@ -285,41 +285,23 @@ class Manager implements IManager {
} }
/** /**
* Get the display name of a resource * Get the rich object data of a resource
* *
* @param IResource $resource * @param IResource $resource
* @return string * @return array
* @since 16.0.0 * @since 16.0.0
*/ */
public function getName(IResource $resource): string { public function getResourceRichObject(IResource $resource): array {
foreach ($this->getProviders() as $provider) { foreach ($this->getProviders() as $provider) {
if ($provider->getType() === $resource->getType()) { if ($provider->getType() === $resource->getType()) {
try { try {
return $provider->getName($resource); return $provider->getResourceRichObject($resource);
} catch (ResourceException $e) { } catch (ResourceException $e) {
} }
} }
} }
return ''; return [];
}
/**
*
* @param IResource $resource
* @return string
*/
public function getIconClass(IResource $resource): string {
foreach ($this->getProviders() as $provider) {
if ($provider->getType() === $resource->getType()) {
try {
return $provider->getIconClass($resource);
} catch (ResourceException $e) {
}
}
}
return '';
} }
/** /**
@ -541,24 +523,4 @@ class Manager implements IManager {
public function getType(): string { public function getType(): string {
return ''; return '';
} }
/**
* Get the link to a resource
*
* @param IResource $resource
* @return string
* @since 16.0.0
*/
public function getLink(IResource $resource): string {
foreach ($this->getProviders() as $provider) {
if ($provider->getType() === $resource->getType()) {
try {
return $provider->getLink($resource);
} catch (ResourceException $e) {
}
}
}
return '';
}
} }

View file

@ -49,14 +49,8 @@ class Resource implements IResource {
/** @var bool|null */ /** @var bool|null */
protected $access; protected $access;
/** @var string|null */ /** @var array|null */
protected $name; protected $data;
/** @var string|null */
protected $iconClass;
/** @var string|null */
protected $link;
public function __construct( public function __construct(
IManager $manager, IManager $manager,
@ -91,35 +85,15 @@ class Resource implements IResource {
} }
/** /**
* @return string * @return array
* @since 16.0.0 * @since 16.0.0
*/ */
public function getName(): string { public function getRichObject(): array {
if ($this->name === null) { if ($this->data === null) {
$this->name = $this->manager->getName($this); $this->data = $this->manager->getResourceRichObject($this);
} }
return $this->name; return $this->data;
}
/**
* @return string
* @since 16.0.0
*/
public function getIconClass(): string {
if ($this->iconClass === null) {
$this->iconClass = $this->manager->getIconClass($this);
}
return $this->iconClass;
}
public function getLink(): string {
if ($this->link === null) {
$this->link = $this->manager->getLink($this);
}
return $this->link;
} }
/** /**

View file

@ -38,31 +38,13 @@ interface IProvider {
public function getType(): string; public function getType(): string;
/** /**
* Get the display name of a resource * Get the rich object data of a resource
* *
* @param IResource $resource * @param IResource $resource
* @return string * @return array
* @since 16.0.0 * @since 16.0.0
*/ */
public function getName(IResource $resource): string; public function getResourceRichObject(IResource $resource): array;
/**
* Get the icon class of a resource
*
* @param IResource $resource
* @return string
* @since 16.0.0
*/
public function getIconClass(IResource $resource): string;
/**
* Get the link to a resource
*
* @param IResource $resource
* @return string
* @since 16.0.0
*/
public function getLink(IResource $resource): string;
/** /**
* Can a user/guest access the collection * Can a user/guest access the collection

View file

@ -42,22 +42,10 @@ interface IResource {
public function getId(): string; public function getId(): string;
/** /**
* @return string * @return array
* @since 16.0.0 * @since 16.0.0
*/ */
public function getName(): string; public function getRichObject(): array;
/**
* @return string
* @since 16.0.0
*/
public function getIconClass(): string;
/**
* @return string
* @since 16.0.0
*/
public function getLink(): string;
/** /**
* Can a user/guest access the resource * Can a user/guest access the resource

20
package-lock.json generated
View file

@ -4812,12 +4812,12 @@
} }
}, },
"nextcloud-vue-collections": { "nextcloud-vue-collections": {
"version": "0.1.2", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/nextcloud-vue-collections/-/nextcloud-vue-collections-0.1.2.tgz", "resolved": "https://registry.npmjs.org/nextcloud-vue-collections/-/nextcloud-vue-collections-0.2.0.tgz",
"integrity": "sha512-GoGvQSbBQWJQCjIPQVyKXvY2C289rZnqOo6LhpI8c7J9SuviHrbfUe5nAUZoyY5L6nsUHy5BUXtP6ppa+oiwbw==", "integrity": "sha512-LDbJyUZffu8ZIkkXAMXkfqkUK36GaUiuS4IdgoOLe/z9prV/Iic7uwrDME015FsCv9GmfheOs7cfiU6xBIidGA==",
"requires": { "requires": {
"nextcloud-axios": "^0.1.2", "nextcloud-axios": "^0.1.2",
"nextcloud-vue": "^0.7.0", "nextcloud-vue": "^0.9.0",
"v-tooltip": "^2.0.0-rc.33", "v-tooltip": "^2.0.0-rc.33",
"vue": "^2.6.6", "vue": "^2.6.6",
"vue-click-outside": "^1.0.7", "vue-click-outside": "^1.0.7",
@ -4825,9 +4825,9 @@
}, },
"dependencies": { "dependencies": {
"nextcloud-vue": { "nextcloud-vue": {
"version": "0.7.1", "version": "0.9.1",
"resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.7.1.tgz", "resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.9.1.tgz",
"integrity": "sha512-7KtOuZh2hGlppN8zyxGU+tg/8SxO/DYxed7NG4m6YpaCpFJXg/OKADlKTy44meHXnnCW/+TPeDTh+KvPKxU/Sw==", "integrity": "sha512-8Lmout8Y6+zNPHqZ8rV7GcuKRbFpM8EserkvhkXAJYymq9mblz2NkfmOzhOGxhRICfPHnZ/xFUTxUuaSus4p+Q==",
"requires": { "requires": {
"hammerjs": "^2.0.8", "hammerjs": "^2.0.8",
"md5": "^2.2.1", "md5": "^2.2.1",
@ -4836,6 +4836,7 @@
"vue": "^2.6.7", "vue": "^2.6.7",
"vue-click-outside": "^1.0.7", "vue-click-outside": "^1.0.7",
"vue-multiselect": "^2.1.3", "vue-multiselect": "^2.1.3",
"vue-visible": "^1.0.2",
"vue2-datepicker": "^2.10.0" "vue2-datepicker": "^2.10.0"
} }
} }
@ -7190,6 +7191,11 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true "dev": true
}, },
"vue-visible": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/vue-visible/-/vue-visible-1.0.2.tgz",
"integrity": "sha512-yaX2its9XAJKGuQqf7LsiZHHSkxsIK8rmCOQOvEGEoF41blKRK8qr9my4qYoD6ikdLss4n8tKqYBecmaY0+WJg=="
},
"vue2-datepicker": { "vue2-datepicker": {
"version": "2.10.0", "version": "2.10.0",
"resolved": "https://registry.npmjs.org/vue2-datepicker/-/vue2-datepicker-2.10.0.tgz", "resolved": "https://registry.npmjs.org/vue2-datepicker/-/vue2-datepicker-2.10.0.tgz",

View file

@ -44,7 +44,7 @@
"nextcloud-axios": "^0.1.3", "nextcloud-axios": "^0.1.3",
"nextcloud-password-confirmation": "^0.4.1", "nextcloud-password-confirmation": "^0.4.1",
"nextcloud-vue": "^0.8.0", "nextcloud-vue": "^0.8.0",
"nextcloud-vue-collections": "^0.1.2", "nextcloud-vue-collections": "^0.2.0",
"snap.js": "^2.0.9", "snap.js": "^2.0.9",
"strengthify": "git+https://github.com/MorrisJobke/strengthify.git", "strengthify": "git+https://github.com/MorrisJobke/strengthify.git",
"underscore": "^1.9.1", "underscore": "^1.9.1",