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

FEATURE: Some tweaks and improvements #1

Merged
merged 1 commit into from Sep 17, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 23 additions & 14 deletions Classes/DataSource/PreviewLinkViewDataSource.php
Expand Up @@ -14,6 +14,11 @@
*/
class PreviewLinkViewDataSource implements DataSourceInterface
{
private const ERROR_NONE = 'none';
private const ERROR_MISSING_NODE = 'missingNode';
private const ERROR_PUBLIC_WORKSPACE = 'publicWorkspace';
private const ERROR_MISSING_TOKEN = 'missingToken';

/**
* @var ControllerContext
*/
Expand Down Expand Up @@ -52,46 +57,50 @@ public static function getIdentifier()
*/
public function getData(NodeInterface $node = null, array $arguments)
{
if ($node === null) {
return [
'data' => [
'link' => '---'
]
];
}

$link = $this->getLink($node, $error);
return [
'data' => [
'link' => $this->getLink($node)
'link' => $link,
'error' => $error,
]
];
}

/**
* @param NodeInterface $node
* @param NodeInterface|null $node
* @param string $error
* @return string
* @throws MissingActionNameException
*/
protected function getLink(NodeInterface $node): string
protected function getLink(NodeInterface $node = null, string &$error = null): string
{
if ($node === null) {
$error = self::ERROR_MISSING_NODE;
return '';
}
$personalWorkspace = $this->userService->getPersonalWorkspace();
$baseWorkspace = $personalWorkspace->getBaseWorkspace();

if ($baseWorkspace->isPublicWorkspace()) {
return '---';
$error = self::ERROR_PUBLIC_WORKSPACE;
return '';
}

$hashAndRoles = $this->getHashTokenForWorkspace($baseWorkspace->getName());
if ($hashAndRoles === null) {
return 'No token';
$error = self::ERROR_MISSING_TOKEN;
return '';
}

$contextPath = str_replace('@' . $personalWorkspace->getName(), '@' . $hashAndRoles->getSettings()['workspaceName'], $node->getContextPath());

return $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)
$url = $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)
->uriFor('authenticate', [
'_authenticationHashToken' => $hashAndRoles->getHash(),
'node' => $contextPath
], 'HashTokenLogin', 'Flownative.WorkspacePreview', null);
$error = self::ERROR_NONE;
return $url;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions Configuration/NodeTypes.yaml
Expand Up @@ -3,14 +3,12 @@
inspector:
views:
previewlink:
label: 'Preview'
label: i18n
group: 'nodeInfo'
position: 20
view: 'Flownative.WorkspacePreview/LinkView'
viewOptions:
dataSource: 'PreviewLinkView'
columns:
- data: 'link'

'Neos.Neos:Document':
superTypes:
Expand Down
6 changes: 6 additions & 0 deletions Configuration/Settings.yaml
Expand Up @@ -26,6 +26,12 @@ Neos:
'Flownative.WorkspacePreview': true

Neos:
userInterface:
translation:
autoInclude:
'Flownative.WorkspacePreview':
- Main
- 'NodeTypes/*'
Ui:
resources:
javascript:
Expand Down
20 changes: 16 additions & 4 deletions Resources/Private/JavaScript/LinkView/src/LinkView.js
Expand Up @@ -3,25 +3,37 @@ import PropTypes from 'prop-types';
import Clipboard from 'react-clipboard.js';
import {dataLoader} from '@neos-project/neos-ui-views';
import {$get} from "plow-js";
import {neos} from '@neos-project/neos-ui-decorators';
import {Icon, Button} from '@neos-project/react-ui-components';

@dataLoader()
@neos(globalRegistry => ({
i18nRegistry: globalRegistry.get('i18n'),
}))
export default class LinkView extends PureComponent {
static propTypes = {
data: PropTypes.object.isRequired
};

render() {
const linkUrl = $get(['link'], this.props.data);
const error = $get(['error'], this.props.data);

if (linkUrl === '---') {
if (error !== 'none') {
return (
<div>---</div>
<div>{this.props.i18nRegistry.translate('Flownative.WorkspacePreview:Main:error.' + error, 'Error: ' + error)}</div>
)
}

return (
<div>
<Clipboard data-clipboard-text={linkUrl}>Copy Preview Link</Clipboard>
<Clipboard
data-clipboard-text={linkUrl}
component={Button}
button-style="lighter"
>
<Icon icon="copy" padded="right" />
{this.props.i18nRegistry.translate('Flownative.WorkspacePreview:Main:copyPreviewLink', 'Copy Preview Link')}
</Clipboard>
</div>
);
}
Expand Down
23 changes: 23 additions & 0 deletions Resources/Private/Translations/de/Main.xlf
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Flownative.WorkspacePreview" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="copyPreviewLink" xml:space="preserve">
<source>Copy Preview Link</source>
<target xml:lang="de">Vorschau-Link kopieren</target>
</trans-unit>
<trans-unit id="error.missingNode" xml:space="preserve">
<source>The currently selected node can't be found</source>
<target xml:lang="de">Der aktuell ausgewählte Node kann nicht gefunden werden</target>
</trans-unit>
<trans-unit id="error.publicWorkspace" xml:space="preserve">
<source>Preview link is not required for public workspaces</source>
<target xml:lang="de">Für öffentliche Workspaces sind keine Vorschau-Links erforderlich</target>
</trans-unit>
<trans-unit id="error.missingToken" xml:space="preserve">
<source>For this workspace no preview token has been generated yet. This can be changed in the "Workspaces"-module</source>
<target xml:lang="de">Für diesen Workspace wurde noch kein Vorschau-Token generiert. Das kann im "Arbeitsbereiche"-Modul geändert werden</target>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 11 additions & 0 deletions Resources/Private/Translations/de/NodeTypes/PreviewLinkMixin.xlf
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="" product-name="Flownative.WorkspacePreview" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="views.previewlink" xml:space="preserve">
<source>Preview Link</source>
<target xml:lang="de">Vorschau-Link</target>
</trans-unit>
</body>
</file>
</xliff>
19 changes: 19 additions & 0 deletions Resources/Private/Translations/en/Main.xlf
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Flownative.WorkspacePreview" source-language="en" datatype="plaintext">
<body>
<trans-unit id="copyPreviewLink" xml:space="preserve">
<source>Copy Preview Link</source>
</trans-unit>
<trans-unit id="error.missingNode" xml:space="preserve">
<source>The currently selected node can't be found</source>
</trans-unit>
<trans-unit id="error.publicWorkspace" xml:space="preserve">
<source>Preview link is not required for public workspaces</source>
</trans-unit>
<trans-unit id="error.missingToken" xml:space="preserve">
<source>For this workspace no preview token has been generated yet. This can be changed in the "Workspaces"-module</source>
</trans-unit>
</body>
</file>
</xliff>
9 changes: 9 additions & 0 deletions Resources/Public/LinkView/Plugin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Resources/Public/LinkView/Plugin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 61 additions & 8 deletions Resources/Public/LinkView/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/Public/LinkView/Plugin.js.map

Large diffs are not rendered by default.