Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property "has / does not have data type" to advanced search #2246

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/asset/js/advanced-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 7 additions & 1 deletion application/asset/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).val('');
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();
}
},

Expand Down
11 changes: 9 additions & 2 deletions application/src/Api/Adapter/AbstractResourceEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion application/src/View/Helper/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getSelect($name, $value = null, $attributes = [], $options = [])
$valueOptions = array_merge($valueOptions, $optgroupOptions);

$element = new Select($name);
$element->setEmptyOption('')
$element->setEmptyOption($options['empty_option'] ?? '')
->setValueOptions($valueOptions)
->setAttributes($attributes);
if (!$element->getAttribute('multiple') && is_array($value)) {
Expand Down
18 changes: 13 additions & 5 deletions application/src/View/Helper/SearchFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class SearchFilters extends AbstractHelper
*/
public function __invoke($partialName = null, array $query = null)
{
$view = $this->getView();
$partialName = $partialName ?: self::PARTIAL_NAME;

$translate = $this->getView()->plugin('translate');
$translate = $view->plugin('translate');

$filters = [];
$api = $this->getView()->api();
$query ??= $this->getView()->params()->fromQuery();
$api = $view->api();
$query ??= $view->params()->fromQuery();
$queryTypes = [
'eq' => $translate('is exactly'),
'neq' => $translate('is not exactly'),
Expand All @@ -41,6 +42,8 @@ public function __invoke($partialName = null, array $query = null)
'nres' => $translate('is not resource with ID'),
'ex' => $translate('has any value'),
'nex' => $translate('has no values'),
'dt' => $translate('has data type'),
'ndt' => $translate('does not have data type'),
];

foreach ($query as $key => $value) {
Expand Down Expand Up @@ -120,6 +123,11 @@ public function __invoke($partialName = null, array $query = null)
}
}

// If this is a data type query, convert the value to
// the data type's label.
$value = in_array($queryType, ['dt', 'ndt'])
? $view->dataType()->getLabel($value)
: $value;
$filters[$filterLabel][] = $value;
$index++;
}
Expand Down Expand Up @@ -237,14 +245,14 @@ public function __invoke($partialName = null, array $query = null)
}
}

$result = $this->getView()->trigger(
$result = $view->trigger(
'view.search.filters',
['filters' => $filters, 'query' => $query],
true
);
$filters = $result['filters'];

return $this->getView()->partial(
return $view->partial(
$partialName,
[
'filters' => $filters,
Expand Down
3 changes: 3 additions & 0 deletions application/view/common/advanced-search/properties.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ if ($this->status()->isSiteRequest()) {
<?php echo $queryOption('nres', $property, 'type', $translate('is not resource with ID')); ?>
<?php echo $queryOption('ex', $property, 'type', $translate('has any value')); ?>
<?php echo $queryOption('nex', $property, 'type', $translate('has no values')); ?>
<?php echo $queryOption('dt', $property, 'type', $translate('has data type')); ?>
<?php echo $queryOption('ndt', $property, 'type', $translate('does not have data type')); ?>
</select>
<?php echo $queryText($property, $index); ?>
<?php echo $this->dataType()->getSelect($stem . '[text]', $property['text'] ?? null, ['class' => 'query-text-data-type'], ['empty_option' => $translate('Select data type…')]); ?>
<button type="button" class="o-icon-delete remove-value button" aria-label="<?php echo $translate('Remove value'); ?>" title="<?php echo $translate('Remove value'); ?>"></button>
</div>
<?php
Expand Down