Skip to content

Commit 27c6852

Browse files
committed
Add ordering and filter
1 parent 3babe57 commit 27c6852

2 files changed

Lines changed: 47 additions & 9 deletions

File tree

administrator/components/com_patchtester/models/pulls.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ public function __construct($config = array())
4848
*/
4949
protected function populateState($ordering = null, $direction = null)
5050
{
51-
// Initialise variables.
52-
$app = JFactory::getApplication('administrator');
53-
51+
// Load the filter state.
52+
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
53+
$this->setState('filter.search', $search);
54+
5455
// Load the parameters.
5556
$params = JComponentHelper::getParams('com_patchtester');
56-
57+
5758
$this->setState('params', $params);
5859
$this->setState('github_user', $params->get('org', 'joomla'));
5960
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
61+
6062
// List state information.
61-
parent::populateState('title', 'asc');
63+
parent::populateState('number', 'desc');
6264
}
6365

6466
/**
@@ -83,7 +85,7 @@ public function getAppliedPatches()
8385
$query->select('*');
8486
$query->from('#__tests');
8587
$query->where('applied = 1');
86-
88+
8789
$this->_db->setQuery($query);
8890
$tests = $this->_db->loadObjectList('pull_id');
8991
return $tests;
@@ -97,12 +99,20 @@ public function getItems()
9799
return array();
98100
}
99101

102+
$this->ordering = $this->getState('list.ordering', 'title');
103+
$this->orderDir = $this->getState('list.direction', 'asc');
104+
$search = $this->getState('filter.search');
105+
100106
$github = new JGithub();
101107
$pulls = $github->pulls->getAll($this->getState('github_user'), $this->getState('github_repo'));
102108
usort($pulls, array($this, 'sortItems'));
103109

104-
foreach ($pulls AS &$pull)
110+
foreach ($pulls AS $i => &$pull)
105111
{
112+
if($search && false === strpos($pull->title, $search)) {
113+
unset($pulls[$i]);
114+
continue;
115+
}
106116
$matches = array();
107117
preg_match('#\[\#([0-9]+)\]#', $pull->title, $matches);
108118
$pull->joomlacode_issue = isset($matches[1]) ? $matches[1] : 0;
@@ -112,6 +122,14 @@ public function getItems()
112122

113123
public function sortItems($a, $b)
114124
{
115-
return strcasecmp($a->title, $b->title);
125+
switch ($this->ordering)
126+
{
127+
case 'title' :
128+
return ($this->orderDir == 'asc') ? strcasecmp($a->title, $b->title) : strcasecmp($b->title, $a->title);
129+
130+
case 'number' :
131+
default :
132+
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
133+
}
116134
}
117135
}

administrator/components/com_patchtester/views/pulls/tmpl/default.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
JHtml::_('behavior.tooltip');
1212
JHtml::_('behavior.modal');
1313

14+
$listOrder = $this->escape($this->state->get('list.ordering'));
15+
$listDirn = $this->escape($this->state->get('list.direction'));
16+
1417
?>
1518
<script type="text/javascript">
1619
var submitpatch = function(task, id) {
@@ -20,15 +23,27 @@
2023
</script>
2124

2225
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm" id="adminForm">
26+
<fieldset id="filter-bar">
27+
<div class="filter-search fltlft">
28+
<label class="filter-search-lbl" for="filter_search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></label>
29+
<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo JText::_('COM_BANNERS_SEARCH_IN_TITLE'); ?>" />
30+
<button type="submit"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
31+
<button type="button" onclick="document.id('filter_search').value='';this.form.submit();"><?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?></button>
32+
</div>
33+
</fieldset>
34+
<div class="clr"> </div>
2335

2436
<table class="adminlist">
2537
<thead>
2638
<tr>
2739
<th width="1%">
2840
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
2941
</th>
42+
<th width="5%">
43+
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
44+
</th>
3045
<th class="title">
31-
<?php echo JText::_('JGLOBAL_TITLE'); ?>
46+
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
3247
</th>
3348
<th class="title">
3449
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
@@ -59,6 +74,9 @@
5974
<td class="center">
6075
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
6176
</td>
77+
<td class="center">
78+
<?php echo $item->number; ?>
79+
</td>
6280
<td>
6381
<a href="<?php echo $item->html_url; ?>" title="<?php echo htmlspecialchars($item->body); ?>"><?php echo $item->title; ?></a>
6482
</td>
@@ -98,6 +116,8 @@
98116
<input type="hidden" name="task" value="" />
99117
<input type="hidden" name="boxchecked" value="0" />
100118
<input type="hidden" name="pull_id" id="pull_id" value="" />
119+
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
120+
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
101121
<?php echo JHtml::_('form.token'); ?>
102122
</div>
103123
</form>

0 commit comments

Comments
 (0)