Merge pull request #3 from elkuku/ordering

Ordering
This commit is contained in:
ianmacl 2011-10-14 06:46:56 -07:00
commit dedc949af0
3 changed files with 48 additions and 9 deletions

View File

@ -12,3 +12,4 @@ COM_PATCHTESTER_FIELD_ORG_DESC="Name of account on Github of which to monitor pu
COM_PATCHTESTER_FIELD_REPO_LABEL="Github Repository"
COM_PATCHTESTER_FIELD_REPO_DESC="Name of repository on Github of which to monitor pull requests"
COM_PATCHTESTER_JOOMLACODE_ISSUE="Joomlacode Issue"
COM_PATCHTESTER_PULL_ID="Pull ID"

View File

@ -48,17 +48,19 @@ class PatchtesterModelPulls extends JModelList
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication('administrator');
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
// Load the parameters.
$params = JComponentHelper::getParams('com_patchtester');
$this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
// List state information.
parent::populateState('title', 'asc');
parent::populateState('number', 'desc');
}
/**
@ -83,7 +85,7 @@ class PatchtesterModelPulls extends JModelList
$query->select('*');
$query->from('#__tests');
$query->where('applied = 1');
$this->_db->setQuery($query);
$tests = $this->_db->loadObjectList('pull_id');
return $tests;
@ -97,12 +99,20 @@ class PatchtesterModelPulls extends JModelList
return array();
}
$this->ordering = $this->getState('list.ordering', 'title');
$this->orderDir = $this->getState('list.direction', 'asc');
$search = $this->getState('filter.search');
$github = new JGithub();
$pulls = $github->pulls->getAll($this->getState('github_user'), $this->getState('github_repo'));
usort($pulls, array($this, 'sortItems'));
foreach ($pulls AS &$pull)
foreach ($pulls AS $i => &$pull)
{
if($search && false === strpos($pull->title, $search)) {
unset($pulls[$i]);
continue;
}
$matches = array();
preg_match('#\[\#([0-9]+)\]#', $pull->title, $matches);
$pull->joomlacode_issue = isset($matches[1]) ? $matches[1] : 0;
@ -112,6 +122,14 @@ class PatchtesterModelPulls extends JModelList
public function sortItems($a, $b)
{
return strcasecmp($a->title, $b->title);
switch ($this->ordering)
{
case 'title' :
return ($this->orderDir == 'asc') ? strcasecmp($a->title, $b->title) : strcasecmp($b->title, $a->title);
case 'number' :
default :
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
}
}
}

View File

@ -11,6 +11,9 @@ defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
JHtml::_('behavior.modal');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<script type="text/javascript">
var submitpatch = function(task, id) {
@ -20,6 +23,15 @@ JHtml::_('behavior.modal');
</script>
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm" id="adminForm">
<fieldset id="filter-bar">
<div class="filter-search fltlft">
<label class="filter-search-lbl" for="filter_search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></label>
<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'); ?>" />
<button type="submit"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" onclick="document.id('filter_search').value='';this.form.submit();"><?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?></button>
</div>
</fieldset>
<div class="clr"> </div>
<table class="adminlist">
<thead>
@ -27,8 +39,11 @@ JHtml::_('behavior.modal');
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
</th>
<th width="5%">
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
</th>
<th class="title">
<?php echo JText::_('JGLOBAL_TITLE'); ?>
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
</th>
<th class="title">
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
@ -59,6 +74,9 @@ JHtml::_('behavior.modal');
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td class="center">
<?php echo $item->number; ?>
</td>
<td>
<a href="<?php echo $item->html_url; ?>" title="<?php echo htmlspecialchars($item->body); ?>"><?php echo $item->title; ?></a>
</td>
@ -98,6 +116,8 @@ JHtml::_('behavior.modal');
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="pull_id" id="pull_id" value="" />
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>