Skip to content

Commit

Permalink
[TASK] Make the preview work
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer authored and dkd-kaehm committed Aug 15, 2023
1 parent 5677a79 commit 488084f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
6 changes: 5 additions & 1 deletion Classes/ContextMenu/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceFactory;
Expand Down Expand Up @@ -85,7 +86,10 @@ public function getPriority(): int
*/
protected function getAdditionalAttributes(string $itemName): array
{
return ['data-callback-module' => 'TYPO3/CMS/Tika/ContextMenuActions'];
return [
'data-callback-module' => 'TYPO3/CMS/Tika/ContextMenuActions',
'data-action-url' => htmlspecialchars((string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute('tika_preview')),
];
}

/**
Expand Down
1 change: 0 additions & 1 deletion Classes/Controller/Backend/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ protected function getInitializedPreviewView(): StandaloneView
{
/** @var $view StandaloneView */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->getRequest()->setControllerExtensionName('tika');
$templatePathAndFile = 'EXT:tika/Resources/Private/Templates/Backend/Preview.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFile));
return $view;
Expand Down
13 changes: 13 additions & 0 deletions Configuration/JavaScriptModules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'dependencies' => [
'backend',
],
'tags' => [
'backend.contextmenu',
],
'imports' => [
'TYPO3/CMS/Tika/' => 'EXT:tika/Resources/Public/JavaScript/',
],
];
5 changes: 3 additions & 2 deletions Resources/Private/Templates/Backend/Preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<div>
<h4>Extracted content:</h4>
<pre style="height: 20em; width:100%; max-width: 1000px; overflow:scroll;">{content}</pre>

<f:if condition="{content}">
<pre style="height: 20em; width:100%; max-width: 1000px; overflow:scroll;">{content}</pre>
</f:if>
<table class="table table-bordered table-striped">
<thead>
<tr>
Expand Down
43 changes: 15 additions & 28 deletions Resources/Public/JavaScript/ContextMenuActions.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
/**
* Module: TYPO3/CMS/Tika/ContextMenuActions
*
* JavaScript to handle import/export actions from context menu
* @exports TYPO3/CMS/Tika/ContextMenuActions
*/
define(function () {
'use strict';
import Modal from "@typo3/backend/modal.js";
import $ from 'jquery';

/**
* @exports TYPO3/CMS/Tika/ContextMenuActions
*/
const ContextMenuActions = {};
class ContextMenuActions {

ContextMenuActions.tikaPreview = function (table, uid) {
if (table === 'sys_file') {

require([
'jquery',
'TYPO3/CMS/Backend/Modal'
], function ($, Modal) {
tikaPreview = function (table, uid) {
if (table === 'sys_file') {

const configuration = {
title: 'Tika Preview',
content: top.TYPO3.settings.TikaPreview.moduleUrl + '&identifier=' + encodeURIComponent(uid).replace(/\*/g, '%2A'),
size: Modal.sizes.large,
type: Modal.types.ajax
};
Modal.advanced(configuration);
});
const configuration = {
title: 'Tika Preview',
content: $(this).data('action-url') + '&identifier=' + encodeURIComponent(uid).replace(/\*/g, '%2A'),
size: Modal.sizes.large,
type: Modal.types.ajax
};
Modal.advanced(configuration);
}

};

return ContextMenuActions;
});
}

export default new ContextMenuActions();

0 comments on commit 488084f

Please sign in to comment.