Skip to content

Commit

Permalink
TASK: Implemented uri calculation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandschuetz committed Sep 27, 2021
1 parent f82bf3b commit 39671dd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 22 deletions.
36 changes: 30 additions & 6 deletions Classes/Controller/BackendController.php
Expand Up @@ -2,6 +2,8 @@

namespace CodeQ\JumpMarkers\Controller;

use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\ContentRepository\Domain\Model\NodeInterface;
Expand Down Expand Up @@ -46,6 +48,8 @@ protected function initializeNodeToUriAction(): void
/**
* Get an uri to a link that might now be live yet.
*
* The API is very lazily build, mainly focusing on the best case.
*
* @param NodeInterface|null $node
* @return void
* @throws NodeNotFoundException
Expand All @@ -55,18 +59,38 @@ protected function initializeNodeToUriAction(): void
* @throws \Neos\Flow\Property\Exception
* @throws \Neos\Flow\Security\Exception
* @throws \Neos\Neos\Exception
* @throws \Neos\Eel\Exception
* @Flow\IgnoreValidation("node")
*/
public function nodeToUriAction(NodeInterface $node = null)
{
exit('wanting to see this message');
if ($node === null) {
throw new NodeNotFoundException('The requested node does not exist or isn\'t accessible to the current user', 1430218623);
exit(json_encode([
'success' => false,
'message' => 'The requested node does not exist or isn\'t accessible to the current user.'
]));
}

$flowQuery = new FlowQuery([$node]);
$flowQuery->pushOperation('context', [['workspaceName' => 'live']]);
if($flowQuery->count() == 0) {
exit(json_encode([
'success' => false,
'message' => 'The requested pages does not exist or isn\'t published yet.'
]));
}
$publicNode = $flowQuery->get(0);

if(!$publicNode->isVisible()) {
exit(json_encode([
'success' => false,
'message' => 'The requested page is not visible to public visitors.'
]));
}
exit('part one');

print_r($this->linkingService->createNodeUri($this->controllerContext, $node, null, null, true));
//print_r($this->linkingService->resolveNodeUri($matches[0], $node, $controllerContext, $absolute);
exit();
exit(json_encode([
'success' => true,
'uri' => $this->linkingService->createNodeUri($this->controllerContext, $publicNode, null, null, true)
]));
}
}
21 changes: 13 additions & 8 deletions Resources/Private/JavaScript/AnchorView/src/AnchorView.js
Expand Up @@ -30,18 +30,23 @@ export default class AnchorView extends Component {
const documentNodeIdentifier = $get('identifier', this.props.documentNode);
const link = 'node://' + documentNodeIdentifier + '#' + this.getSectionId();
this.copyToClipboard(link);
this.setState({copyNeosLinkState: 'copied'});
this.setState({copyNeosLinkState: 'copied', copyUriState: 'default'});
};

copyUriToClipboard = () => {
this.setState({copyUriState: 'loading'});
const redirectUri = $get('uri', this.props.documentNode).replace('neos/preview', 'neos/jump-markers-node-to-uri');
console.info(redirectUri);
fetch(redirectUri).then(response => {
this.copyToClipboard(response.url + '#' + this.getSectionId());
console.info(response);
console.info(response.url + '#' + this.getSectionId());
this.setState({copyUriState: 'copied'});
const redirectUri = $get('uri', this.props.documentNode).replace('neos/preview', 'neos/jump-markers-node-to-uri').replace('neos/redirect', 'neos/jump-markers-node-to-uri');
fetch(redirectUri)
.then(response => response.json())
.then(response => {
if(!response.success) {
// ok, I'm very lazy here
alert(response.message);
this.setState({copyNeosLinkState: 'default', copyUriState: 'default'});
} else {
this.copyToClipboard(response.uri + '#' + this.getSectionId());
this.setState({copyNeosLinkState: 'default', copyUriState: 'copied'});
}
});
};

Expand Down
19 changes: 12 additions & 7 deletions Resources/Public/JavaScript/AnchorView/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/JavaScript/AnchorView/Plugin.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -4,6 +4,7 @@
"type": "neos-package",
"license": "GPL-3.0-or-later",
"require": {
"ext-json": "*",
"neos/neos": "^4.3 || ^5.0 || ^7.0 || dev-master"
},
"autoload": {
Expand Down

0 comments on commit 39671dd

Please sign in to comment.