Skip to content

Commit

Permalink
Merge branch 'master' into fix-page
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer authored Jan 26, 2024
2 parents a6d445f + 40a58cb commit 856c70d
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/task-for-the-development-fund.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Task for the development fund
about: A working package which may be sponsored by the Kitodo e.V. development fund.
title: "[FUND] "
labels: ⭐ development fund 2023
labels: ⭐ development fund 2024
assignees: ''

---
Expand Down
296 changes: 175 additions & 121 deletions Classes/Common/MetsDocument.php

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Classes/Common/Solr/SolrSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Common\Solr\SearchResult\ResultDocument;
use Kitodo\Dlf\Domain\Model\Collection;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Solarium\QueryType\Select\Result\Document;
use TYPO3\CMS\Core\Cache\CacheManager;
Expand Down Expand Up @@ -38,8 +37,9 @@ class SolrSearch implements \Countable, \Iterator, \ArrayAccess, QueryResultInte

/**
* @access private
* @var QueryResult|Collection|null
* @var array|null
*/
// TODO: confusing naming, here is passed array of collections and it is used as array in prepare()
private $collection;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ class SolrSearch implements \Countable, \Iterator, \ArrayAccess, QueryResultInte
* @access public
*
* @param DocumentRepository $documentRepository
* @param QueryResult|Collection|null $collection
* @param array|null $collection
* @param array $settings
* @param array $searchParams
* @param QueryResult $listedMetadata
Expand Down Expand Up @@ -433,6 +433,7 @@ public function prepare()
}

// if collections are given, we prepare the collection query string
// TODO: this->collection should not be actually called collections?
if ($this->collection) {
$collectionsQueryString = '';
$virtualCollectionsQueryString = '';
Expand Down
8 changes: 4 additions & 4 deletions Classes/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function showAction(Collection $collection): void
// get all documents of given collection
$solrResults = null;
if (is_array($searchParams) && !empty($searchParams)) {
$solrResults = $this->documentRepository->findSolrByCollection($collection, $this->settings, $searchParams, $listedMetadata);
$solrResults = $this->documentRepository->findSolrByCollection([$collection], $this->settings, $searchParams, $listedMetadata);

$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
if (empty($itemsPerPage)) {
Expand Down Expand Up @@ -206,12 +206,12 @@ public function showSortedAction(): void
*
* @access private
*
* @param array $collections to be processed
* @param QueryResultInterface|array|object $collections to be processed
* @param Solr $solr for query
*
* @return array
*/
private function processCollections(array $collections, Solr $solr): array
private function processCollections($collections, Solr $solr): array
{
$processedCollections = [];

Expand Down Expand Up @@ -253,7 +253,7 @@ private function processCollections(array $collections, Solr $solr): array

// Generate random but unique array key taking amount of documents into account.
do {
$key = (count($collection['priority']) * 1000) + random_int(0, 1000);
$key = ($collection->getPriority() * 1000) + random_int(0, 1000);
} while (!empty($processedCollections[$key]));

$processedCollections[$key]['collection'] = $collection;
Expand Down
5 changes: 2 additions & 3 deletions Classes/Controller/ListViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function mainAction(): void
$this->searchParams = $this->getParametersSafely('searchParameter');

// extract collection(s) from collection parameter
$collection = null;
$collection = [];
if ($this->searchParams['collection']) {
foreach(explode(',', $this->searchParams['collection']) as $collectionEntry) {
$collection[] = $this->collectionRepository->findByUid((int) $collectionEntry);
Expand All @@ -102,8 +102,7 @@ public function mainAction(): void
$solrResults = null;
$numResults = 0;
if (is_array($this->searchParams) && !empty($this->searchParams)) {
// @phpstan-ignore-next-line
$solrResults = $this->documentRepository->findSolrByCollection($collection ? : null, $this->settings, $this->searchParams, $listedMetadata);
$solrResults = $this->documentRepository->findSolrByCollection($collection, $this->settings, $this->searchParams, $listedMetadata);
$numResults = $solrResults->getNumFound();

$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
Expand Down
4 changes: 3 additions & 1 deletion Classes/Domain/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,15 @@ public function findChildrenOfEach(array $uids)
*
* @access public
*
* @param QueryResult|Collection|null $collection
* @param array|null $collection
* @param array $settings
* @param array $searchParams
* @param QueryResult $listedMetadata
*
* @return SolrSearch
*/
// TODO: function name says ByCollection, but inside the SolrSearch->prepare() is expected
// TODO: that collection is an array of collections
public function findSolrByCollection($collection, $settings, $searchParams, $listedMetadata = null)
{
// set settings global inside this repository
Expand Down
75 changes: 62 additions & 13 deletions Resources/Public/JavaScript/PageView/FulltextControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ dlfFulltextSegments.prototype.populate = function (features) {
dlfFulltextSegments.prototype.coordinateToFeature = function (coordinate) {
for (var i = 0; i < this.segments_.length; i++) {
var segment = this.segments_[i];

if (ol.extent.containsCoordinate(segment.extent, coordinate)) {
return segment.feature;
}
Expand All @@ -86,15 +85,15 @@ var dlfViewerFullTextControl = function(map) {
* @type {Object}
* @private
*/
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').data('dic') ?
dlfUtils.parseDataDic($('#tx-dlf-tools-fulltext')) :
{
'fulltext':'Fulltext',
'fulltext-loading':'Loading full text...',
'fulltext-on':'Activate Fulltext',
'fulltext-off':'Deactivate Fulltext',
'activate-full-text-initially':'0',
'full-text-scroll-element':'html, body'};
'full-text-scroll-element':'#tx-dlf-fulltextselection'};

/**
* @private
Expand All @@ -112,7 +111,13 @@ var dlfViewerFullTextControl = function(map) {
* @type {string}
* @private
*/
this.fullTextScrollElement = this.dic['full-text-scroll-element'];
let regex = /[^A-Za-z0-9\.\-\#\s_]/g;
let fullTextScrollElementUnChecked = this.dic['full-text-scroll-element'];
if (regex.fullTextScrollElementUnChecked) {
this.fullTextScrollElement = "";
} else {
this.fullTextScrollElement = fullTextScrollElementUnChecked;
}

/**
* @type {Object}
Expand Down Expand Up @@ -158,6 +163,13 @@ var dlfViewerFullTextControl = function(map) {
*/
this.lastRenderedFeatures_ = undefined;

/**
* @type {Array}
* @private
*/
this.positions = {};


/**
* @type {dlfFulltextSegments}
* @private
Expand Down Expand Up @@ -230,7 +242,7 @@ var dlfViewerFullTextControl = function(map) {
this)
};

$('#tx-dlf-fulltextselection').text(this.dic['fulltext-loading']);
$('html').find(this.fullTextScrollElement).text(this.dic['fulltext-loading']);

this.changeActiveBehaviour();
};
Expand Down Expand Up @@ -329,6 +341,34 @@ dlfViewerFullTextControl.prototype.addActiveBehaviourForSwitchOff = function() {
}
};

/**
* Recalculate position of text lines if full text container was resized
*/
dlfViewerFullTextControl.prototype.onResize = function() {
if (this.element != undefined && this.element.css('width') != this.lastHeight) {
this.lastHeight = this.element.css('width');
this.calculatePositions();
}
};

/**
* Calculate positions of text lines for scrolling
*/
dlfViewerFullTextControl.prototype.calculatePositions = function() {
this.positions.length = 0;

let texts = $('html').find(this.fullTextScrollElement).children('span.textline');
// check if fulltext exists for this page
if (texts.length > 0) {
let offset = $('#' + texts[0].id).position().top;

for(let text of texts) {
let pos = $('#' + text.id).position().top;
this.positions[text.id] = pos - offset;
}
}
};

/**
* Handle layers for click
* @param {ol.Feature|undefined} feature
Expand Down Expand Up @@ -416,7 +456,8 @@ dlfViewerFullTextControl.prototype.addHighlightEffect = function(textlineFeature

if (targetElem.length > 0 && !targetElem.hasClass('highlight')) {
targetElem.addClass('highlight');
setTimeout(this.scrollToText, 1000, targetElem, this.fullTextScrollElement);
this.onResize();
setTimeout(this.scrollToText, 1000, targetElem, this.fullTextScrollElement, this.positions);
hoverSourceTextline_.addFeature(textlineFeature);
}
}
Expand All @@ -427,10 +468,10 @@ dlfViewerFullTextControl.prototype.addHighlightEffect = function(textlineFeature
* @param {any} element
* @param {string} fullTextScrollElement
*/
dlfViewerFullTextControl.prototype.scrollToText = function(element, fullTextScrollElement) {
dlfViewerFullTextControl.prototype.scrollToText = function(element, fullTextScrollElement, positions) {
if (element.hasClass('highlight')) {
$(fullTextScrollElement).animate({
scrollTop: element.offset().top
scrollTop: positions[element[0].id]
}, 500);
}
};
Expand Down Expand Up @@ -498,8 +539,9 @@ dlfViewerFullTextControl.prototype.disableFulltextSelect = function() {
.attr('title', this.dic['fulltext-on']);
}

$('#tx-dlf-fulltextselection').removeClass(className);
$('#tx-dlf-fulltextselection').hide();
$('html').find(this.fullTextScrollElement).removeClass(className);
$('html').find(this.fullTextScrollElement).hide();

$('body').removeClass(className);

};
Expand Down Expand Up @@ -530,8 +572,8 @@ dlfViewerFullTextControl.prototype.enableFulltextSelect = function() {
.attr('title', this.dic['fulltext-off']);
}

$('#tx-dlf-fulltextselection').addClass(className);
$('#tx-dlf-fulltextselection').show();
$('html').find(this.fullTextScrollElement).addClass(className);
$('html').find(this.fullTextScrollElement).show();
$('body').addClass(className);
};

Expand Down Expand Up @@ -564,7 +606,13 @@ dlfViewerFullTextControl.prototype.showFulltext = function(features) {
return;
}

var target = document.getElementById('tx-dlf-fulltextselection');
// in getElementById no '#' is necessary / allowed at the beginning
// of the string. Therefor remove '#' if present
let fullTextScrollElementId = this.fullTextScrollElement;
if (fullTextScrollElementId.substr(0,1) === '#') {
fullTextScrollElementId = fullTextScrollElementId.substr(1);
}
var target = document.getElementById(fullTextScrollElementId);
if (target !== null) {
target.innerHTML = "";
for (var feature of features) {
Expand All @@ -576,6 +624,7 @@ dlfViewerFullTextControl.prototype.showFulltext = function(features) {
target.append(document.createElement('br'), document.createElement('br'));
}

this.calculatePositions();
this.lastRenderedFeatures_ = features;
}
};
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/PageView/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ dlfUtils.isFulltextDescriptor = function (obj) {
* @return {Object}
*/
dlfUtils.parseDataDic = function (element) {
var dataDicString = $(element).attr('data-dic') || '',
var dataDicString = $('html').find(element).data('dic') || '',
dataDicRecords = dataDicString.split(';'),
dataDic = {};

Expand Down
1 change: 1 addition & 0 deletions Tests/Functional/Common/SolrSearchQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class SolrSearchQueryTest extends FunctionalTestCase
{
private $solrCoreRepository;

private static array $databaseFixtures = [
__DIR__ . '/../../Fixtures/Common/documents_1.csv',
Expand Down

0 comments on commit 856c70d

Please sign in to comment.