Skip to content

Commit

Permalink
Updated for new property filter in Omeka S v4.2 (dt and ntp, see #ome…
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Jan 6, 2025
1 parent 8dc3791 commit 93a98c5
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 20 deletions.
4 changes: 2 additions & 2 deletions asset/js/advanced-search-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $(document).ready(function() {
const typeQuery = queryType.val();
const isTypeWithoutText = ['ex', 'nex', 'exs', 'nexs', 'exm', 'nexm', 'lex', 'nlex', 'tpl', 'ntpl', 'tpr', 'ntpr', 'tpu', 'ntpu', 'dup', 'ndup', 'dupl', 'ndupl', 'dupt', 'ndupt', 'duptl', 'nduptl', 'dupv', 'ndupv', 'dupvl', 'ndupvl', 'dupvt', 'ndupvt', 'dupvtl', 'ndupvtl', 'dupr', 'ndupr', 'duprl', 'nduprl', 'duprt', 'nduprt', 'duprtl', 'nduprtl', 'dupu', 'ndupu', 'dupul', 'ndupul', 'duput', 'nduput', 'duputl', 'nduputl'].includes(typeQuery);
const isTypeSubQuery = ['resq', 'nresq', 'lkq', 'nlkq'].includes(typeQuery);
const isTypeDataType = ['dtp', 'ndtp'].includes(typeQuery);
const isTypeDataType = ['dt', 'ndt', 'dtp', 'ndtp'].includes(typeQuery);
const isTypeMainType = ['tp', 'ntp'].includes(typeQuery);
const queryTextInput = queryType.siblings('.query-text:not(.query-data-type):not(.query-main-type)');
const queryTextSubQuery = queryType.closest('.value').find('.sub-query .query-form-query');
Expand Down Expand Up @@ -121,7 +121,7 @@ $(document).ready(function() {
'seconds',
'integer',
];
const fieldQueryTypeWithText = ['eq', 'neq', 'in', 'nin', 'sw', 'nsw', 'ew', 'new', 'near', 'nnear', 'ma', 'nma', 'lt', 'lte', 'gte', 'gt', '<', '≤', '≥', '>', 'yreq', 'nyreq', 'yrlt', 'yrlte', 'yrgte', 'yrgt', 'list', 'nlist', 'res', 'nres', 'resq', 'nresq', 'lres', 'nlres', 'lkq', 'nlkq', 'dtp', 'ndtp', 'tp', 'ntp'];
const fieldQueryTypeWithText = ['eq', 'neq', 'in', 'nin', 'sw', 'nsw', 'ew', 'new', 'near', 'nnear', 'ma', 'nma', 'lt', 'lte', 'gte', 'gt', '<', '≤', '≥', '>', 'yreq', 'nyreq', 'yrlt', 'yrlte', 'yrgte', 'yrgt', 'list', 'nlist', 'res', 'nres', 'resq', 'nresq', 'lres', 'nlres', 'lkq', 'nlkq', 'dt', 'ndt', 'dtp', 'ndtp', 'tp', 'ntp'];
form.find(":input[name]:not([name='']):not(:disabled)").each(function(index) {
const input = $(this);
const inputName = input.attr('name');
Expand Down
7 changes: 3 additions & 4 deletions asset/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ var Omeka = {
parent.children('span.selector-child-count').text(count);
});
if (filter == '') {
selector.find('li.selector-parent').removeClass('show');
$('.filter-match').removeClass('filter-match');
}
selector.find('span.selector-total-count').text(totalCount);
Expand Down Expand Up @@ -329,13 +328,13 @@ var Omeka = {
var queryType = $(this);
var queryText = queryType.siblings('.query-text');
queryText.prop('disabled',
['ex', 'nex', 'exs', 'nexs', 'exm', 'nexm', 'resq', 'nresq', 'lex', 'nlex', 'lkq', 'nlkq', 'dtp', 'ndtp', 'tp', 'ntp', 'tpl', 'ntpl', 'tpr', 'ntpr', 'tpu', 'ntpu', 'dup', 'ndup', 'dupl', 'ndupl', 'dupt', 'ndupt', 'duptl', 'nduptl', 'dupv', 'ndupv', 'dupvl', 'ndupvl', 'dupvt', 'ndupvt', 'dupvtl', 'ndupvtl', 'dupr', 'ndupr', 'duprl', 'nduprl', 'duprt', 'nduprt', 'duprtl', 'nduprtl', 'dupu', 'ndupu', 'dupul', 'ndupul', 'duput', 'nduput', 'duputl', 'nduputl']
['ex', 'nex', 'exs', 'nexs', 'exm', 'nexm', 'resq', 'nresq', 'lex', 'nlex', 'lkq', 'nlkq', 'dt', 'ndt', 'dtp', 'ndtp', 'tp', 'ntp', 'tpl', 'ntpl', 'tpr', 'ntpr', 'tpu', 'ntpu', 'dup', 'ndup', 'dupl', 'ndupl', 'dupt', 'ndupt', 'duptl', 'nduptl', 'dupv', 'ndupv', 'dupvl', 'ndupvl', 'dupvt', 'ndupvt', 'dupvtl', 'ndupvtl', 'dupr', 'ndupr', 'duprl', 'nduprl', 'duprt', 'nduprt', 'duprtl', 'nduprtl', 'dupu', 'ndupu', 'dupul', 'ndupul', 'duput', 'nduput', 'duputl', 'nduputl']
.includes(queryType.val()));
},

// Clean the search query of empty or otherwise unneeded inputs.
cleanSearchQuery: function(form) {
form.find(":input[name]:not([name='']):not(:disabled)").each(function(index) {
form.find(':input[name]:not([name=""]):not(:disabled)').each(function(index) {
const input = $(this);
const inputName = input.attr('name');
const inputValue = input.val();
Expand All @@ -360,7 +359,7 @@ var Omeka = {
const match = inputName.match(/property\[(\d+)\]\[text\]/);
if (match) {
const propertyType = form.find(`[name="property[${match[1]}][type]"]`);
if (['eq', 'neq', 'in', 'nin', 'sw', 'nsw', 'ew', 'new', 'near', 'nnear', 'ma', 'nma', 'lt', 'lte', 'gte', 'gt', '<', '≤', '≥', '>', 'yreq', 'nyreq', 'yrlt', 'yrlte', 'yrgte', 'yrgt', 'list', 'nlist', 'res', 'nres', 'resq', 'nresq', 'lres', 'nlres', 'lkq', 'nlkq', 'dtp', 'ndtp', 'tp', 'ntp']
if (['eq', 'neq', 'in', 'nin', 'sw', 'nsw', 'ew', 'new', 'near', 'nnear', 'ma', 'nma', 'lt', 'lte', 'gte', 'gt', '<', '≤', '≥', '>', 'yreq', 'nyreq', 'yrlt', 'yrlte', 'yrgte', 'yrgt', 'list', 'nlist', 'res', 'nres', 'resq', 'nresq', 'lres', 'nlres', 'lkq', 'nlkq', 'dt', 'ndt', 'dtp', 'ndtp', 'tp', 'ntp']
.includes(propertyType.val())
) {
form.find(`[name="property[${match[1]}][joiner]"]`).prop('name', '');
Expand Down
2 changes: 1 addition & 1 deletion asset/js/query-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $(document).ready(function () {
$.get(`${url}?${query}`, function(data) {
selectingElement.find('.query-form-search-filters').html(data);
});
selectingElement.find('.query-form-query').prop('type', 'hidden');
selectingElement.find('.query-form-query').prop('type', 'hidden').val(query);
show('.query-form-edit');
show('.query-form-advanced-edit-show');
hide('.query-form-advanced-edit-apply');
Expand Down
2 changes: 2 additions & 0 deletions asset/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ var Search = (function() {
'nlres',
'lkq',
'nlkq',
'dt',
'ndt',
'dtp',
'ndtp',
'tp',
Expand Down
14 changes: 10 additions & 4 deletions src/Stdlib/SearchResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class SearchResources
'exm' => 'nexm',
'nexm' => 'exm',
// Data type.
'dt' => 'ndt',
'ndt' => 'dt',
'dtp' => 'ndtp',
'ndtp' => 'dtp',
'tp' => 'ntp',
'ntp' => 'tp',
'tpl' => 'ntpl',
Expand All @@ -88,8 +92,6 @@ class SearchResources
'ntpr' => 'tpr',
'tpu' => 'ntpu',
'ntpu' => 'tpu',
'dtp' => 'ndtp',
'ndtp' => 'dtp',
// Curation (duplicates).
'dup' => 'ndup',
'ndup' => 'dup',
Expand Down Expand Up @@ -147,11 +149,12 @@ class SearchResources
'nexs',
'nexm',
// Data type.
'ndt',
'ndtp',
'ntp',
'ntpl',
'ntpr',
'ntpu',
'ndtp',
// Curation (duplicates).
'ndup',
'ndupl',
Expand Down Expand Up @@ -1351,8 +1354,8 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query): self
* - filter[{index}][join]: "and" OR "or" OR "not" joiner with previous query
* - filter[{index}][field]: property ID, term or indexed field, or array of
* property IDs, terms or indexed fields
* - filter[{index}][val]: search text or array of texts or values
* - filter[{index}][type]: search type
* - filter[{index}][val]: search text or array of texts or values
* - filter[{index}][datatype]: filter on data type(s)
*
* @see self::buildQueryForRow() for details.
Expand Down Expand Up @@ -1485,6 +1488,8 @@ protected function buildFilterQuery(QueryBuilder $qb, array $query): self
* - exm: has multiple values
* - nexm: does not have multiple values
* Data type
* - dt: has data type (core)
* - ndt: does not have data type (core)
* - dtp: has data type
* - ndtp: does not have data type
* - tp: has main type
Expand Down Expand Up @@ -2027,6 +2032,7 @@ protected function buildQueryForRow(QueryBuilder $qb, array $vars, bool $isPrope
);
break;

case 'dt':
case 'dtp':
if (count($value) <= 1) {
$dataTypeAlias = $this->adapter->createNamedParameter($qb, reset($value));
Expand Down
24 changes: 20 additions & 4 deletions src/View/Helper/SearchFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __invoke($partialName = null, ?array $query = null): string
$params = $plugins->get('params');
$translate = $plugins->get('translate');
$cleanQuery = $plugins->get('cleanQuery');
$dataTypeHelper = $plugins->get('dataType');

$filters = [];
$query ??= $params->fromQuery();
Expand Down Expand Up @@ -221,7 +222,12 @@ public function __invoke($partialName = null, ?array $query = null): string
$filterLabel = $translate('AND') . ' ' . $filterLabel;
}
}
if (in_array($queryType, ['resq', 'nresq', 'lkq', 'nlkq']) && !$noValue) {
// If this is a data type query, convert the value to
// the data type's label.
// This is a single value, so don't use improved 'dtp'/'ndtp'.
if (in_array($queryType, ['dt', 'ndt'])) {
$text = $dataTypeHelper->getLabel($text);
} elseif (in_array($queryType, ['resq', 'nresq', 'lkq', 'nlkq']) && !$noValue) {
$text = array_map('urldecode', $text);
}
$filters[$filterLabel][$this->urlQuery($key, $subKey)] = $noValue
Expand Down Expand Up @@ -461,9 +467,19 @@ public function __invoke($partialName = null, ?array $query = null): string
$filterLabel = ($joiners[$joiner] ?? $joiners['and']) . ' ' . $filterLabel;
}

$vals = in_array($queryType, SearchResources::FIELD_QUERY['value_subject'])
? $flatArrayValueResourceIds($val, $vrTitles)
: $flatArray($val);
if (in_array($queryType, SearchResources::FIELD_QUERY['value_subject'])) {
$vals = $flatArrayValueResourceIds($val, $vrTitles);
} else {
$vals = $flatArray($val);
// If this is a data type query, convert the value
// to the data type's label.
if (in_array($queryType, ['dt', 'ndt', 'dtp', 'ndtp'])) {
$vals = array_map(fn ($v) => $dataTypeHelper->getLabel($v), $vals);
} elseif (in_array($queryType, ['resq', 'nresq', 'lkq', 'nlkq']) && !$noValue) {
$vals = array_map(fn ($v) => urldecode($v), $vals);
}
}

$filters[$filterLabel][$this->urlQuery($key, $subKey)] = implode(', ', $vals);

++$index;
Expand Down
6 changes: 4 additions & 2 deletions src/View/Helper/SearchFiltersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ protected function getQueryTypesLabels(): array
'exm' => $this->translator->translate('has multiple values'), // @translate
'nexm' => $this->translator->translate('does not have multiple values'), // @translate
// Data type.
'dt' => $this->translator->translate('has data type'), // @translate
'ndt' => $this->translator->translate('does not have data type'), // @translate
'dtp' => $this->translator->translate('has data type'), // @translate
'ndtp' => $this->translator->translate('does not have data type'), // @translate
'tp' => $this->translator->translate('has main type'), // @translate
'ntp' => $this->translator->translate('does not have main type'), // @translate
'tpl' => $this->translator->translate('has type literal-like'), // @translate
Expand All @@ -83,8 +87,6 @@ protected function getQueryTypesLabels(): array
'ntpr' => $this->translator->translate('does not have type resource-like'), // @translate
'tpu' => $this->translator->translate('has type uri-like'), // @translate
'ntpu' => $this->translator->translate('does not have type uri-like'), // @translate
'dtp' => $this->translator->translate('has data type'), // @translate
'ndtp' => $this->translator->translate('does not have data type'), // @translate
// Curation (duplicates).
'dup' => $this->translator->translate('has duplicate values'), // @translate
'ndup' => $this->translator->translate('does not have duplicate values'), // @translate
Expand Down
2 changes: 1 addition & 1 deletion view/common/advanced-search/filters.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ if ($isSiteRequest) {
</optgroup>
<optgroup label="<?= $translate('Data type') ?>">
<?= $queryOption('dtp', $filter, 'type', $translate('has data type')) ?>
<?= $queryOption('ndtp', $filter, 'type', $translate('has not data type')) ?>
<?= $queryOption('ndtp', $filter, 'type', $translate('does not have data type')) ?>
<?= $queryOption('tp', $filter, 'type', $translate('has main type')) ?>
<?= $queryOption('ntp', $filter, 'type', $translate('does not have main type')) ?>
<?= $queryOption('tpl', $filter, 'type', $translate('has type literal-like')) ?>
Expand Down
4 changes: 2 additions & 2 deletions view/common/advanced-search/properties-improved.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ if ($isSiteRequest) {
<?= $queryOption('nexm', $property, 'type', $translate('does not have multiple values')) ?>
</optgroup>
<optgroup label="<?= $translate('Data type') ?>">
<?= $queryOption('dtp', $property, 'type', $translate('has data type')) ?>
<?= $queryOption('ndtp', $property, 'type', $translate('has not data type')) ?>
<?= $queryOption('dt', $property, 'type', $translate('has data type')) ?>
<?= $queryOption('ndt', $property, 'type', $translate('does not have data type')) ?>
<?= $queryOption('tp', $property, 'type', $translate('has main type')) ?>
<?= $queryOption('ntp', $property, 'type', $translate('does not have main type')) ?>
<?= $queryOption('tpl', $property, 'type', $translate('has type literal-like')) ?>
Expand Down

0 comments on commit 93a98c5

Please sign in to comment.