-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch advanced search to simple "block" system
The current filters are each separated into their own partial and the view simply loops over the partials. The existing "after"-style event is converted to a filter of the array of partials. (#852)
- Loading branch information
1 parent
c5f7448
commit cd56af1
Showing
6 changed files
with
138 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,24 @@ | ||
<?php | ||
$this->headLink()->prependStylesheet($this->assetUrl('css/advanced-search.css', 'Omeka')); | ||
|
||
// Prepare the resource class query. | ||
if (isset($query['resource_class_id'])) { | ||
$resourceClassId = $query['resource_class_id'] ; | ||
} else { | ||
$resourceClassId = null; | ||
} | ||
|
||
// Prepare the site query. | ||
if (isset($query['site_id'])) { | ||
$siteId = $query['site_id'] ; | ||
} else { | ||
$siteId = null; | ||
} | ||
|
||
// Prepare the property queries. | ||
$properties = isset($query['property']) ? $query['property'] : []; | ||
$properties = array_filter($properties, function ($value) { | ||
return isset($value['text']) ? '' !== trim($value['text']) : true; | ||
}); | ||
if (!$properties) { | ||
$properties[] = []; | ||
} | ||
|
||
if (isset($query['search'])) { | ||
unset($properties[0]['joiner']); | ||
array_unshift($properties, [ | ||
'property' => '', | ||
'type' => 'in', | ||
'text' => $query['search'] | ||
]); | ||
} | ||
$partials = [ | ||
'common/advanced-search/resource-class', | ||
'common/advanced-search/properties', | ||
'common/advanced-search/site-pool', | ||
]; | ||
|
||
// Convenience functions to minimize inline code. | ||
$queryOption = function($value, array $search, $key, $text) { | ||
$selected = null; | ||
if (isset($search[$key]) && $value === $search[$key]) { | ||
$selected = ' selected'; | ||
} | ||
return sprintf('<option value="%s"%s>%s</option>', $value, $selected, $text); | ||
}; | ||
$queryText = function(array $search, $index) { | ||
$text = isset($search['text']) ? $search['text'] : null; | ||
return sprintf('<input type="text" class="query-text" name="%s" value="%s">', | ||
$this->escapeHtml("property[$index][text]"), | ||
$this->escapeHtml($text)); | ||
} | ||
?> | ||
|
||
<div class="field"> | ||
<div class="field-meta"> | ||
<label for="resource_class_id"><?php echo $this->translate('Search by class'); ?></label> | ||
</div> | ||
<div class="inputs"> | ||
<?php echo $this->resourceClassSelect([ | ||
'name' => 'resource_class_id', | ||
'attributes' => ['id' => 'resource_class_id', 'value' => $resourceClassId] | ||
]); ?> | ||
</div> | ||
</div> | ||
|
||
<div id="property-queries" class="field removable multi-value" role="group" aria-labelledby="by-value-label"> | ||
<div class="field-meta"> | ||
<span id="by-value-label" class="label"><?php echo $this->translate('Search by value'); ?></span> | ||
</div> | ||
<div class="inputs"> | ||
<?php | ||
$index = 0; | ||
foreach ($properties as $property): | ||
$stem = "property[$index]"; | ||
?> | ||
<div class="value"> | ||
<select class="joiner" name="<?php echo $this->escapeHtml($stem . '[joiner]'); ?>"> | ||
<?php echo $queryOption('and', $property, 'joiner', $this->translate('AND')); ?> | ||
<?php echo $queryOption('or', $property, 'joiner', $this->translate('OR')); ?> | ||
</select> | ||
<?php echo $this->propertySelect([ | ||
'name' => $stem . '[property]', | ||
'attributes' => [ | ||
'class' => 'query-property', | ||
'value' => isset($property['property']) ? $property['property'] : null, | ||
], | ||
'options' => [ | ||
'empty_option' => '[Any Property]', // @translate | ||
] | ||
]); ?> | ||
<select class="query-type" name="<?php echo $this->escapeHtml($stem . '[type]'); ?>"> | ||
<?php echo $queryOption('eq', $property, 'type', $this->translate('is exactly')); ?> | ||
<?php echo $queryOption('neq', $property, 'type', $this->translate('is not exactly')); ?> | ||
<?php echo $queryOption('in', $property, 'type', $this->translate('contains')); ?> | ||
<?php echo $queryOption('nin', $property, 'type', $this->translate('does not contain')); ?> | ||
<?php echo $queryOption('ex', $property, 'type', $this->translate('has any value')); ?> | ||
<?php echo $queryOption('nex', $property, 'type', $this->translate('has no values')); ?> | ||
</select> | ||
<?php echo $queryText($property, $index); ?> | ||
<button type="button" class="o-icon-delete remove-value button"><?php echo $this->translate('Remove value'); ?></button> | ||
</div> | ||
<?php | ||
$index++; | ||
endforeach; | ||
?> | ||
<a href="#" class="add-value button"><?php echo $this->translate('Add new value'); ?></a> | ||
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="field-meta"> | ||
<label for="site_id"><?php echo $this->translate('In site pool'); ?></label> | ||
</div> | ||
<div class="inputs"> | ||
<?php echo $this->siteSelect([ | ||
'name' => 'site_id', | ||
'attributes' => ['id' => 'site_id', 'value' => $siteId] | ||
]); ?> | ||
</div> | ||
</div> | ||
|
||
<?php $this->trigger( | ||
$filterResults = $this->trigger( | ||
'view.advanced_search', | ||
[ | ||
'query' => isset($query) ? $query : null, | ||
'resourceType' => isset($resourceType) ? $resourceType : null | ||
] | ||
); ?> | ||
'resourceType' => isset($resourceType) ? $resourceType : null, | ||
'partials' => $partials, | ||
], | ||
true | ||
); | ||
$partials = $filterResults['partials']; | ||
|
||
foreach ($partials as $partial) { | ||
echo $this->partial($partial, ['query' => $query]); | ||
} | ||
?> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
// Prepare the property queries. | ||
$properties = isset($query['property']) ? $query['property'] : []; | ||
$properties = array_filter($properties, function ($value) { | ||
return isset($value['text']) ? '' !== trim($value['text']) : true; | ||
}); | ||
if (!$properties) { | ||
$properties[] = []; | ||
} | ||
|
||
if (isset($query['search'])) { | ||
unset($properties[0]['joiner']); | ||
array_unshift($properties, [ | ||
'property' => '', | ||
'type' => 'in', | ||
'text' => $query['search'] | ||
]); | ||
} | ||
|
||
$queryOption = function($value, array $search, $key, $text) { | ||
$selected = null; | ||
if (isset($search[$key]) && $value === $search[$key]) { | ||
$selected = ' selected'; | ||
} | ||
return sprintf('<option value="%s"%s>%s</option>', $value, $selected, $text); | ||
}; | ||
$queryText = function(array $search, $index) { | ||
$text = isset($search['text']) ? $search['text'] : null; | ||
return sprintf('<input type="text" class="query-text" name="%s" value="%s">', | ||
$this->escapeHtml("property[$index][text]"), | ||
$this->escapeHtml($text)); | ||
} | ||
?> | ||
|
||
<div id="property-queries" class="field removable multi-value" role="group" aria-labelledby="by-value-label"> | ||
<div class="field-meta"> | ||
<span id="by-value-label" class="label"><?php echo $this->translate('Search by value'); ?></span> | ||
</div> | ||
<div class="inputs"> | ||
<?php | ||
$index = 0; | ||
foreach ($properties as $property): | ||
$stem = "property[$index]"; | ||
?> | ||
<div class="value"> | ||
<select class="joiner" name="<?php echo $this->escapeHtml($stem . '[joiner]'); ?>"> | ||
<?php echo $queryOption('and', $property, 'joiner', $this->translate('AND')); ?> | ||
<?php echo $queryOption('or', $property, 'joiner', $this->translate('OR')); ?> | ||
</select> | ||
<?php echo $this->propertySelect([ | ||
'name' => $stem . '[property]', | ||
'attributes' => [ | ||
'class' => 'query-property', | ||
'value' => isset($property['property']) ? $property['property'] : null, | ||
], | ||
'options' => [ | ||
'empty_option' => '[Any Property]', // @translate | ||
] | ||
]); ?> | ||
<select class="query-type" name="<?php echo $this->escapeHtml($stem . '[type]'); ?>"> | ||
<?php echo $queryOption('eq', $property, 'type', $this->translate('is exactly')); ?> | ||
<?php echo $queryOption('neq', $property, 'type', $this->translate('is not exactly')); ?> | ||
<?php echo $queryOption('in', $property, 'type', $this->translate('contains')); ?> | ||
<?php echo $queryOption('nin', $property, 'type', $this->translate('does not contain')); ?> | ||
<?php echo $queryOption('ex', $property, 'type', $this->translate('has any value')); ?> | ||
<?php echo $queryOption('nex', $property, 'type', $this->translate('has no values')); ?> | ||
</select> | ||
<?php echo $queryText($property, $index); ?> | ||
<button type="button" class="o-icon-delete remove-value button"><?php echo $this->translate('Remove value'); ?></button> | ||
</div> | ||
<?php | ||
$index++; | ||
endforeach; | ||
?> | ||
<a href="#" class="add-value button"><?php echo $this->translate('Add new value'); ?></a> | ||
</div> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
application/view/common/advanced-search/resource-class.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
// Prepare the resource class query. | ||
if (isset($query['resource_class_id'])) { | ||
$resourceClassId = $query['resource_class_id'] ; | ||
} else { | ||
$resourceClassId = null; | ||
} | ||
?> | ||
|
||
<div class="field"> | ||
<div class="field-meta"> | ||
<label for="resource_class_id"><?php echo $this->translate('Search by class'); ?></label> | ||
</div> | ||
<div class="inputs"> | ||
<?php echo $this->resourceClassSelect([ | ||
'name' => 'resource_class_id', | ||
'attributes' => ['id' => 'resource_class_id', 'value' => $resourceClassId] | ||
]); ?> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
// Prepare the site query. | ||
if (isset($query['site_id'])) { | ||
$siteId = $query['site_id'] ; | ||
} else { | ||
$siteId = null; | ||
} | ||
?> | ||
<div class="field"> | ||
<div class="field-meta"> | ||
<label for="site_id"><?php echo $this->translate('In site pool'); ?></label> | ||
</div> | ||
<div class="inputs"> | ||
<?php echo $this->siteSelect([ | ||
'name' => 'site_id', | ||
'attributes' => ['id' => 'site_id', 'value' => $siteId] | ||
]); ?> | ||
</div> | ||
</div> |