From 25ef3203ba724ecda4bd9cc572838dbe860f912f Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Tue, 10 Dec 2024 14:08:40 -0500 Subject: [PATCH] Add property "is/is not data type" to advanced search --- application/asset/js/advanced-search.js | 1 + application/asset/js/global.js | 8 +++++++- .../src/Api/Adapter/AbstractResourceEntityAdapter.php | 11 +++++++++-- .../view/common/advanced-search/properties.phtml | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/application/asset/js/advanced-search.js b/application/asset/js/advanced-search.js index 88104215d7..b7df947733 100644 --- a/application/asset/js/advanced-search.js +++ b/application/asset/js/advanced-search.js @@ -7,6 +7,7 @@ $(document).ready(function () { var template = fieldContainer.data('field-template'); var newValue = $(template); newValue.children('input[type="text"]').val(null); + newValue.find('.query-text-data-type').prop('disabled', true).hide(); newValue.children('select').prop('selectedIndex', 0); newValue.appendTo(fieldContainer.find('.inputs')); newValue.trigger('o:value-created'); diff --git a/application/asset/js/global.js b/application/asset/js/global.js index d40dc42725..6da2df96ba 100644 --- a/application/asset/js/global.js +++ b/application/asset/js/global.js @@ -322,10 +322,16 @@ var Omeka = { disableQueryTextInput: function() { var queryType = $(this); var queryText = queryType.siblings('.query-text'); - if (queryType.val() === 'ex' || queryType.val() === 'nex') { + var queryTextDataType = queryType.siblings('.query-text-data-type'); + if (['dt', 'ndt'].includes(queryType.val())) { queryText.prop('disabled', true); + queryTextDataType.prop('disabled', false).show(); + } else if (['ex', 'nex'].includes(queryType.val())) { + queryText.prop('disabled', true); + queryTextDataType.prop('disabled', true).hide(); } else { queryText.prop('disabled', false); + queryTextDataType.prop('disabled', true).hide(); } }, diff --git a/application/src/Api/Adapter/AbstractResourceEntityAdapter.php b/application/src/Api/Adapter/AbstractResourceEntityAdapter.php index 3fab50c0f8..0d61191af6 100644 --- a/application/src/Api/Adapter/AbstractResourceEntityAdapter.php +++ b/application/src/Api/Adapter/AbstractResourceEntityAdapter.php @@ -277,11 +277,11 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query) } $positive = true; - if (in_array($queryType, ['neq', 'nin', 'nsw', 'new', 'nres', 'nex'])) { + if (in_array($queryType, ['neq', 'nin', 'nsw', 'new', 'nres', 'nex', 'ndt'])) { $positive = false; $queryType = substr($queryType, 1); } - if (!in_array($queryType, ['eq', 'in', 'sw', 'ew', 'res', 'ex'])) { + if (!in_array($queryType, ['eq', 'in', 'sw', 'ew', 'res', 'ex', 'dt'])) { continue; } @@ -382,6 +382,13 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query) $predicateExpr = $qb->expr()->isNotNull("$valuesAlias.id"); break; + case 'dt': + $predicateExpr = $qb->expr()->eq( + "$valuesAlias.type", + $this->createNamedParameter($qb, $value) + ); + break; + default: continue 2; } diff --git a/application/view/common/advanced-search/properties.phtml b/application/view/common/advanced-search/properties.phtml index 55cea9165f..c523493d18 100644 --- a/application/view/common/advanced-search/properties.phtml +++ b/application/view/common/advanced-search/properties.phtml @@ -85,8 +85,11 @@ if ($this->status()->isSiteRequest()) { + + + dataType()->getSelect($stem . '[text]', $property['text'] ?? null, ['class' => 'query-text-data-type']); ?>