Merge pull request #588 from beatrycze-volk/search-highlight-word

Add configuration for fields which need to be highlighted in the image
This commit is contained in:
Sebastian Meyer 2021-03-22 23:32:51 +01:00 committed by GitHub
commit 7b60b2d17d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 14 deletions

View File

@ -77,7 +77,13 @@ class FulltextTool extends \Kitodo\Dlf\Common\AbstractPlugin
$this->getTemplate(); $this->getTemplate();
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']]; $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
if (!empty($fullTextFile)) { if (!empty($fullTextFile)) {
$markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="fulltext:' . htmlspecialchars($this->pi_getLL('fulltext', '')) . ';fulltext-on:' . htmlspecialchars($this->pi_getLL('fulltext-on', '')) . ';fulltext-off:' . htmlspecialchars($this->pi_getLL('fulltext-off', '')) . ';activate-full-text-initially:' . MathUtility::forceIntegerInRange($this->conf['activateFullTextInitially'], 0, 1, 0) . ';full-text-scroll-element:' . $this->conf['fullTextScrollElement'] . '">&nbsp;</a>'; $markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="'
. 'fulltext:' . htmlspecialchars($this->pi_getLL('fulltext', ''))
. ';fulltext-on:' . htmlspecialchars($this->pi_getLL('fulltext-on', ''))
. ';fulltext-off:' . htmlspecialchars($this->pi_getLL('fulltext-off', ''))
. ';activate-full-text-initially:' . MathUtility::forceIntegerInRange($this->conf['activateFullTextInitially'], 0, 1, 0)
. ';full-text-scroll-element:' . $this->conf['fullTextScrollElement']
. ';search-hl-parameters:' . $this->conf['searchHlParameters'] . '">&nbsp;</a>';
} else { } else {
$markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>'; $markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>';
} }

View File

@ -1,6 +1,7 @@
plugin.tx_dlf_annotationtool.templateFile = EXT:dlf/Resources/Private/Templates/AnnotationTool.tmpl plugin.tx_dlf_annotationtool.templateFile = EXT:dlf/Resources/Private/Templates/AnnotationTool.tmpl
plugin.tx_dlf_fulltexttool.activateFullTextInitially = 0 plugin.tx_dlf_fulltexttool.activateFullTextInitially = 0
plugin.tx_dlf_fulltexttool.fullTextScrollElement = html, body plugin.tx_dlf_fulltexttool.fullTextScrollElement = html, body
plugin.tx_dlf_fulltexttool.searchHlParameters = tx_dlf[highlight_word]
plugin.tx_dlf_fulltexttool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextTool.tmpl plugin.tx_dlf_fulltexttool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextTool.tmpl
plugin.tx_dlf_fulltextdownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextDownloadTool.tmpl plugin.tx_dlf_fulltextdownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextDownloadTool.tmpl
plugin.tx_dlf_imagedownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/ImageDownloadTool.tmpl plugin.tx_dlf_imagedownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/ImageDownloadTool.tmpl

View File

@ -1037,7 +1037,9 @@ Fulltext Tool
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
This plugin adds an activation link for fulltext to the toolbox. If no fulltext is available for the current page, a span-tag is rendered instead. This plugin adds an activation link for fulltext to the toolbox. If no fulltext is available for the current page, a span-tag is rendered instead.
The default behaviour is to show the fulltext after click on the toggle link. There is a TypoScript configuration to show the fulltext initially. The default behavior is to show the fulltext after click on the toggle link. There is a TypoScript configuration to show the fulltext initially.
Plugin allows also to configure (searchHlParameters) by which URL parameters words will be highlighted in the image. The first defined parameter on the configuration has highest priority, if not found it checks the next ones.
:typoscript:`plugin.tx_dlf_fulltexttool.` :typoscript:`plugin.tx_dlf_fulltexttool.`
@ -1069,9 +1071,16 @@ The default behaviour is to show the fulltext after click on the toggle link. Th
:Data Type: :Data Type:
:ref:`t3tsref:data-type-string` :ref:`t3tsref:data-type-string`
:Default: :Default:
html, body html, body
- :Property:
searchHlParameters
:Data Type:
:ref:`t3tsref:data-type-string`
:Default:
tx_dlf[highlight_word]
The fulltext is fetched and rendered by JavaSript into the `<div id="tx-dlf-fulltextselection">` of the pageview plugin. The fulltext is fetched and rendered by JavaScript into the `<div id="tx-dlf-fulltextselection">` of the pageview plugin.
**Please note**: To allow JavaScript fetching the fulltext, the `CORS headers <https://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`_ muste be configured appropriate on the providing webserver. **Please note**: To allow JavaScript fetching the fulltext, the `CORS headers <https://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`_ must be configured appropriate on the providing webserver.

View File

@ -57,7 +57,13 @@ var dlfViewerFullTextControl = function(map, image, fulltextUrl) {
*/ */
this.dic = $('#tx-dlf-tools-fulltext').length > 0 && $('#tx-dlf-tools-fulltext').attr('data-dic') ? this.dic = $('#tx-dlf-tools-fulltext').length > 0 && $('#tx-dlf-tools-fulltext').attr('data-dic') ?
dlfUtils.parseDataDic($('#tx-dlf-tools-fulltext')) : dlfUtils.parseDataDic($('#tx-dlf-tools-fulltext')) :
{'fulltext':'Fulltext', 'fulltext-on':'Activate Fulltext','fulltext-off':'Deactivate Fulltext', 'activate-full-text-initially':'0', 'full-text-scroll-element':'html, body'}; {
'fulltext':'Fulltext',
'fulltext-on':'Activate Fulltext',
'fulltext-off':'Deactivate Fulltext',
'activate-full-text-initially':'0',
'full-text-scroll-element':'html, body',
'search-hl-parameters':'tx_dlf[highlight_word]'};
/** /**
* @type {number} * @type {number}
@ -70,6 +76,12 @@ var dlfViewerFullTextControl = function(map, image, fulltextUrl) {
* @private * @private
*/ */
this.fullTextScrollElement = this.dic['full-text-scroll-element']; this.fullTextScrollElement = this.dic['full-text-scroll-element'];
/**
* @type {string}
* @private
*/
this.searchHlParameters = this.dic['search-hl-parameters'];
/** /**
* @type {ol.Feature|undefined} * @type {ol.Feature|undefined}

View File

@ -73,6 +73,12 @@ var dlfViewer = function(settings){
*/ */
this.highlightFieldParams = undefined; this.highlightFieldParams = undefined;
/**
* @type {string|undefined}
* @private
*/
this.highlightKeys = undefined;
/** /**
* @type {Object|undefined} * @type {Object|undefined}
* @private * @private
@ -149,7 +155,7 @@ var dlfViewer = function(settings){
* *
* @param {Array.<string>} controlNames * @param {Array.<string>} controlNames
*/ */
dlfViewer.prototype.addCustomControls = function(controlNames) { dlfViewer.prototype.addCustomControls = function() {
var fulltextControl = undefined, var fulltextControl = undefined,
fulltextDownloadControl = undefined, fulltextDownloadControl = undefined,
annotationControl = undefined, annotationControl = undefined,
@ -161,6 +167,7 @@ dlfViewer.prototype.addCustomControls = function(controlNames) {
if (this.fulltexts[0] !== undefined && this.fulltexts[0].length !== 0 && this.fulltexts[0].url !== '' && this.images.length === 1) { if (this.fulltexts[0] !== undefined && this.fulltexts[0].length !== 0 && this.fulltexts[0].url !== '' && this.images.length === 1) {
fulltextControl = new dlfViewerFullTextControl(this.map, this.images[0], this.fulltexts[0].url); fulltextControl = new dlfViewerFullTextControl(this.map, this.images[0], this.fulltexts[0].url);
fulltextDownloadControl = new dlfViewerFullTextDownloadControl(this.map, this.images[0], this.fulltexts[0].url); fulltextDownloadControl = new dlfViewerFullTextDownloadControl(this.map, this.images[0], this.fulltexts[0].url);
this.highlightKeys = fulltextControl.searchHlParameters;
} else { } else {
$('#tx-dlf-tools-fulltext').remove(); $('#tx-dlf-tools-fulltext').remove();
} }
@ -280,7 +287,7 @@ dlfViewer.prototype.createControls_ = function(controlNames, layers) {
}; };
/** /**
* Displayes highlight words * Displays highlight words
*/ */
dlfViewer.prototype.displayHighlightWord = function() { dlfViewer.prototype.displayHighlightWord = function() {
@ -322,12 +329,24 @@ dlfViewer.prototype.displayHighlightWord = function() {
} }
} }
// check keys for which highlighting should be made
var keys = this.highlightKeys.split(',');
// check if highlight by words is set // check if highlight by words is set
var key = 'tx_dlf[highlight_word]', var urlParams = dlfUtils.getUrlParams();
urlParams = dlfUtils.getUrlParams();
if (urlParams !== undefined && urlParams.hasOwnProperty(key) && this.fulltexts[0] !== undefined && this.fulltexts[0].url !== '' && this.images.length > 0) { var hasOwnProperty = false;
var value = urlParams[key], var param = '';
for(let key of keys) {
if(urlParams !== undefined && urlParams.hasOwnProperty(key.trim())) {
hasOwnProperty = true;
param = key.trim();
break;
}
};
if (hasOwnProperty && this.fulltexts[0] !== undefined && this.fulltexts[0].url !== '' && this.images.length > 0) {
var value = urlParams[param],
values = value.split(';'), values = value.split(';'),
fulltextData = dlfFullTextUtils.fetchFullTextDataFromServer(this.fulltexts[0].url, this.images[0]), fulltextData = dlfFullTextUtils.fetchFullTextDataFromServer(this.fulltexts[0].url, this.images[0]),
fulltextDataImageTwo = undefined; fulltextDataImageTwo = undefined;
@ -418,11 +437,11 @@ dlfViewer.prototype.init = function(controlNames) {
} }
} }
this.addCustomControls();
// highlight word in case a highlight field is registered // highlight word in case a highlight field is registered
this.displayHighlightWord(); this.displayHighlightWord();
this.addCustomControls(controls);
// trigger event after all has been initialize // trigger event after all has been initialize
$(window).trigger("map-loadend", window); $(window).trigger("map-loadend", window);