Add field filter for galaxy cluster

pull/2508/head
root 2017-09-25 17:34:26 +02:00
parent ec8d283ff5
commit cb608817e1
5 changed files with 69 additions and 5 deletions

View File

@ -39,6 +39,9 @@ class GalaxiesController extends AppController {
public function view($id) {
if (!is_numeric($id)) throw new NotFoundException('Invalid galaxy.');
if (isset($this->params['named']['searchall']) && strlen($this->params['named']['searchall']) > 0) {
$this->set('passedArgsArray', array('all' => $this->params['named']['searchall']));
}
if ($this->_isRest()) {
$galaxy = $this->Galaxy->find('first', array(
'contain' => array('GalaxyCluster' => array('GalaxyElement'/*, 'GalaxyReference'*/)),

View File

@ -31,6 +31,26 @@ class GalaxyClustersController extends AppController {
public function index($id) {
$this->paginate['conditions'] = array('GalaxyCluster.galaxy_id' => $id);
$clusters = $this->paginate();
if ( isset($this->params['named']['searchall']) && strlen($this->params['named']['searchall']) > 0) {
$synonym_hits = $this->GalaxyCluster->GalaxyElement->find(
'list', array(
'recursive' => -1,
'conditions' => array(
'LOWER(GalaxyElement.value) LIKE' => '%' . strtolower($this->params['named']['searchall']) . '%',
'GalaxyElement.key' => 'synonyms' ),
'fields' => array(
'GalaxyElement.galaxy_cluster_id')
));
$this->paginate['conditions'] =
array("AND" => array(
'OR' => array(
"LOWER(GalaxyCluster.value) LIKE" => '%'. strtolower($this->params['named']['searchall']) .'%',
"GalaxyCluster.id" => array_values($synonym_hits)
),
"GalaxyCluster.galaxy_id" => $id
));
$this->set('passedArgsArray', array('all'=>$this->params['named']['searchall']));
}
$tagIds = array();
$sightings = array();
if (!empty($clusters)) {

View File

@ -24,7 +24,11 @@
</div>
<script type="text/javascript">
$(document).ready(function () {
$.get("/galaxy_clusters/index/<?php echo $galaxy['Galaxy']['id']; ?>", function(data) {
<?php
$uri = "/galaxy_clusters/index/" . $galaxy['Galaxy']['id'];
if (isset($passedArgsArray)) $uri .= '/searchall:' . $passedArgsArray['all'];
?>
$.get("<?php echo $uri;?>", function(data) {
$("#clusters_div").html(data);
});
});

View File

@ -14,6 +14,38 @@
?>
</ul>
</div>
<?php
$tab = "Center";
$filtered = false;
if (count($list) > 0){
$galaxy_id = $list[0]['GalaxyCluster']['galaxy_id'];
}else{
$galaxy_id = "";
}
if(isset($passedArgsArray)){
if (count($passedArgsArray) > 0) {
$tab = "Left";
$filtered = true;
}
}
?>
<div class="tabMenuFixedContainer" style="display:inline-block;">
<?php if ($filtered):
foreach ($passedArgsArray as $k => $v):?>
<span class="tabMenuFixed tabMenuFixedElement">
<?php echo h(ucfirst($k)) . " : " . h($v); ?>
</span>
<?php endforeach; ?>
<span class="tabMenuFixed tabMenuFixedRight tabMenuSides">
<?php echo $this->Html->link('', array('controller' => 'galaxies', 'action' => 'view/'. $galaxy_id), array('class' => 'icon-remove', 'title' => 'Remove filters'));?>
</span>
<?php endif;?>
<span style="border-right:0px !important;">
<span id="quickFilterButton" role="button" tabindex="0" aria-label="Filter value galaxie cluster" class="tabMenuFilterFieldButton useCursorPointer"
onClick="quickFilter('', '<?php echo $baseurl . '/galaxies/view/' . $galaxy_id; ?>');">Filter</span>
<input class="tabMenuFilterField" type="text" id="quickFilterField"></input>
</span>
</div>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo $this->Paginator->sort('value');?></th>

View File

@ -1416,10 +1416,15 @@ function indexEvaluateFiltering() {
}
function quickFilter(passedArgs, url) {
passedArgs["searchall"] = $('#quickFilterField').val().trim();
for (var key in passedArgs) {
if (key !== 'page') {
url += "/" + key + ":" + passedArgs[key];
if(!passedArgs){
var passedArgs = [];
}
if( $('#quickFilterField').val().trim().length > 0){
passedArgs["searchall"] = $('#quickFilterField').val().trim();
for (var key in passedArgs) {
if (key !== 'page') {
url += "/" + key + ":" + passedArgs[key];
}
}
}
window.location.href=url;