33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-12-23 03:19:00 +00:00

Add J! 3.0 compat and pagination

This commit is contained in:
Nikolai Plath 2012-09-08 20:53:44 -05:00
parent b44df81fd3
commit 227109ed4b
12 changed files with 258 additions and 174 deletions

View File

@ -13,7 +13,7 @@ defined('_JEXEC') or die;
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchTesterController extends JController class PatchTesterController extends JControllerLegacy
{ {
protected $default_view = 'Pulls'; protected $default_view = 'Pulls';

View File

@ -15,17 +15,17 @@ jimport('joomla.application.component.controllerform');
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterControllerPull extends JController class PatchtesterControllerPull extends JControllerLegacy
{ {
public function apply() public function apply()
{ {
try try
{ {
$this->getModel('pull') $this->getModel('pull')
->apply(JRequest::getVar('pull_id')); ->apply(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_APPLY_OK'); $msg = JText::_('COM_PATCHTESTER_APPLY_OK');
$type = 'message'; $type = 'success';
} }
catch (Exception $e) catch (Exception $e)
{ {
@ -41,10 +41,10 @@ class PatchtesterControllerPull extends JController
try try
{ {
$this->getModel('pull') $this->getModel('pull')
->revert(JRequest::getVar('pull_id')); ->revert(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_REVERT_OK'); $msg = JText::_('COM_PATCHTESTER_REVERT_OK');
$type = 'message'; $type = 'success';
} }
catch (Exception $e) catch (Exception $e)
{ {

View File

@ -37,7 +37,7 @@ class PTCurl extends JURI
* *
* @throws Exception * @throws Exception
* *
* @return JCurl * @return PTCurl
*/ */
public static function getAdapter($uri = null) public static function getAdapter($uri = null)
{ {
@ -72,7 +72,7 @@ class PTCurl extends JURI
* *
* @param array $options The cURL options. * @param array $options The cURL options.
* *
* @return JCurl * @return PTCurl
*/ */
public function setOptions($options) public function setOptions($options)
{ {
@ -94,7 +94,7 @@ class PTCurl extends JURI
curl_setopt_array($ch, $this->curlOptions); curl_setopt_array($ch, $this->curlOptions);
curl_setopt($ch, CURLOPT_URL, $this->_uri); curl_setopt($ch, CURLOPT_URL, $this->uri);
if ( ! array_key_exists(CURLOPT_SSL_VERIFYHOST, $this->curlOptions)) if ( ! array_key_exists(CURLOPT_SSL_VERIFYHOST, $this->curlOptions))
{ {

View File

@ -0,0 +1,35 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 19:08
*
* @property-read PtGithubRepos $repos GitHub API object for repos.
*/
class PtGithub extends JGithub
{
/**
* @var PtGithubRepos
*/
protected $repos;
public static function getInstance(JRegistry $options = null, JGithubHttp $client = null)
{
return new PtGithub($options, $client);
}
public function __get($name)
{
if ($name == 'repos')
{
if ($this->repos == null)
{
$this->repos = new PtGithubRepos($this->options, $this->client);
}
return $this->repos;
}
return parent::__get($name);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 18:54
*/
/**
* A.
*/
class PtGithubRepos extends JGithubObject
{
public function get($user, $repo)
{
$path = '/repos/'.$user.'/'.$repo;
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
// Validate the response code.
if($response->code != 200)
{
// Decode the error response and throw an exception.
$error = json_decode($response->body);
throw new DomainException($error->message, $response->code);
}
return json_decode($response->body);
}
/**
* @param string $user
* @param string $type all, owner, public, private, member. Default: all.
* @param string $sort created, updated, pushed, full_name, default: full_name.
* @param string $direction asc or desc, default: when using full_name: asc, otherwise desc.
*
* @return mixed
* @throws DomainException
*/
public function getPublicRepos($user, $type = 'all', $sort = 'full_name', $direction = 'desc')
{
$path = '/users/'.$user.'/repos';
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
// Validate the response code.
if($response->code != 200)
{
// Decode the error response and throw an exception.
$error = json_decode($response->body);
throw new DomainException($error->message, $response->code);
}
return json_decode($response->body);
}
}

View File

@ -12,7 +12,7 @@ defined('_JEXEC') or die;
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterModelPull extends JModel class PatchtesterModelPull extends JModelLegacy
{ {
/** /**
* Method to auto-populate the model state. * Method to auto-populate the model state.
@ -92,7 +92,7 @@ class PatchtesterModelPull extends JModel
public function apply($id) public function apply($id)
{ {
//@todo Use the JCurl class //@todo Use the JCurl class
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/curl.php'; // require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/curl.php';
$table = JTable::getInstance('tests', 'PatchTesterTable'); $table = JTable::getInstance('tests', 'PatchTesterTable');
$github = new JGithub; $github = new JGithub;
@ -195,11 +195,6 @@ class PatchtesterModelPull extends JModel
if ($table->applied_version != $version->getShortVersion()) if ($table->applied_version != $version->getShortVersion())
{ {
/*
$table->applied = 0;
$table->applied_version = '';
$table->store();
*/
$table->delete(); $table->delete();
return $this; return $this;
@ -249,11 +244,6 @@ class PatchtesterModelPull extends JModel
} }
} }
/*
$table->applied_version = '';
$table->applied = 0;
$table->store();
*/
$table->delete(); $table->delete();
return true; return true;

View File

@ -66,6 +66,9 @@ class PatchtesterModelPulls extends JModelList
// List state information. // List state information.
parent::populateState('number', 'desc'); parent::populateState('number', 'desc');
//-- GitHubs default list limit is 30
$this->state->set('list.limit', 30);
} }
/** /**
@ -111,10 +114,12 @@ class PatchtesterModelPulls extends JModelList
$search = $this->getState('filter.search'); $search = $this->getState('filter.search');
$searchId = $this->getState('filter.searchid'); $searchId = $this->getState('filter.searchid');
$page = $this->getPagination()->pagesCurrent;
try try
{ {
$github = new JGithub(); $github = new JGithub;
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo')); $pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'), 'open', $page);
usort($pulls, array($this, 'sortItems')); usort($pulls, array($this, 'sortItems'));
foreach ($pulls as $i => &$pull) foreach ($pulls as $i => &$pull)
@ -180,4 +185,17 @@ class PatchtesterModelPulls extends JModelList
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number; return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
} }
} }
public function getTotal()
{
// $g = new PtGithub;
//$repo = $g->repos->get('joomla', 'joomla-cms');
return PtGithub::getInstance()
->repos->get('joomla', 'joomla-cms')
->open_issues_count;
//return $repo->open_issues_count;
}
} }

View File

@ -16,8 +16,10 @@ if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester'))
} }
// Include dependencies // Include dependencies
jimport('joomla.application.component.controller'); //jimport('joomla.application.component.controller');
$controller = JController::getInstance('PatchTester'); JLoader::registerPrefix('Pt', __DIR__.'/helpers');
$controller = JControllerLegacy::getInstance('PatchTester');
$controller->execute(JRequest::getCmd('task')); $controller->execute(JRequest::getCmd('task'));
$controller->redirect(); $controller->redirect();

View File

@ -8,7 +8,7 @@
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>ianlenmac@gmail.com</authorEmail> <authorEmail>ianlenmac@gmail.com</authorEmail>
<authorUrl>http://github.com/ianmacl</authorUrl> <authorUrl>http://github.com/ianmacl</authorUrl>
<version>1.1</version> <version>1.2</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description> <description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<install> <install>
<sql> <sql>

View File

@ -24,50 +24,29 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm" <form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm"
id="adminForm"> id="adminForm">
<table class="adminlist">
<thead> <div>
<tr> <button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<th colspan="7" style="text-align: left;"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></th> <button type="button" class="btn"
</tr>
<tr>
<td>
<button type="submit"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button"
onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();"> onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?> <?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button> </button>
</td> </div>
<td>
<label class="filter-search-lbl" <table class="table table-striped table-hover table-condensed">
for="filter_searchid"><?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_PULL_ID'); ?></label> <thead>
<input type="text" name="filter_searchid" id="filter_searchid" size="5"
value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>"
title="<?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_PULL_ID'); ?>"/>
</td>
<td>
<label class="filter-search-lbl"
for="filter_search"><?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_TITLE'); ?></label>
<br/>
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>"
title="<?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_TITLE'); ?>"/>
</td>
<td colspan="4">
</td>
</tr>
<tr> <tr>
<th colspan="7" style="text-align: left;"><?php echo JText::_('COM_PATCHTESTER_SORT'); ?></th> <th width="8%">
</tr>
<tr>
<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); ?> <?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_searchid" id="filter_searchid" class="span10"
value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>" />
</th> </th>
<th class="title"> <th class="title">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?> <?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>" />
</th> </th>
<th>I</th> <th>I</th>
<th class="title"> <th class="title">
@ -83,7 +62,7 @@ $listDirn = $this->escape($this->state->get('list.direction'));
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="10"> <td colspan="6">
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
@ -91,7 +70,10 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<?php echo $this->loadTemplate('items'); ?> <?php echo $this->loadTemplate('items'); ?>
</tbody> </tbody>
</table> </table>
<div class="well">
<?php echo $this->pagination->getListFooter(); ?>
</div>
<div> <div>
<input type="hidden" name="task" value=""/> <input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/> <input type="hidden" name="boxchecked" value="0"/>

View File

@ -9,16 +9,15 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
foreach($this->items as $i => $item) : foreach($this->items as $i => $item) :
$status = '';
if(isset($this->patches[$item->number])) : if(isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number]; $patch = $this->patches[$item->number];
$status = ($patch->applied) ? 'success' : '';
else : else :
$patch = false; $patch = false;
endif; endif;
?> ?>
<tr class="row<?php echo $i % 2; ?>"> <tr class="<?= $status ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td class="center"> <td class="center">
<?php echo $item->number; ?> <?php echo $item->number; ?>
</td> </td>
@ -61,28 +60,22 @@ foreach ($this->items as $i => $item) :
</td> </td>
<td class="center"> <td class="center">
<?php <?php
if ($patch && $patch->applied) if($patch && $patch->applied) :
{
echo '<div class="patchApplied" style="background-color: #adff2f;">'; echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED'); echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>'; echo '</div>';
} else :
else
{
echo JText::_('COM_PATCHTESTER_NOT_APPLIED'); echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
} endif;
?> ?>
</td> </td>
<td class="center"> <td class="center">
<?php <?php
if ($patch && $patch->applied) if($patch && $patch->applied) :
{
echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>'; echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
} else :
else
{
echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>'; echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>';
} endif;
?> ?>
</td> </td>
</tr> </tr>

View File

@ -15,10 +15,11 @@ jimport('joomla.application.component.view');
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterViewPulls extends JView class PatchtesterViewPulls extends JViewLegacy
{ {
protected $items; protected $items;
protected $state; protected $state;
protected $pagination;
/** /**
* Display the view * Display the view
@ -53,12 +54,17 @@ class PatchtesterViewPulls extends JView
$this->state = $this->get('State'); $this->state = $this->get('State');
$this->items = $this->get('Items'); $this->items = $this->get('Items');
$this->patches = $this->get('AppliedPatches'); $this->patches = $this->get('AppliedPatches');
$this->pagination = $this->get('Pagination');
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) $errors = $this->get('Errors');
if (count($errors))
{ {
JError::raiseError(500, implode("\n", $errors)); var_dump($errors);
return false; var_dump($this->pagination);
// JError::raiseError(500, implode("\n", $errors));
// return false;
} }
$this->addToolbar(); $this->addToolbar();