Made build hitory paging work

This commit is contained in:
Pauli Nieminen 2008-08-12 22:27:58 +00:00
parent 1e20cfe385
commit fffd8f131d
5 changed files with 129 additions and 24 deletions

View file

@ -71,3 +71,43 @@ table.test_error {
.test_error td {
text-align: center;
}
table.build_history {
width: auto;
max-width:60em;
min-width:10em;
margin: auto auto auto auto;
}
div.paginate {
color: #225599;
font-weight: bold;
text-align: right;
margin-left: auto;
margin-right: 0;
font-size: 0.8em;
}
.paginate a {
color: #225599;
font-weight: bold;
text-decoration: none;
}
.paginate a:hoover {
text-decoration: underline;
font-weight: bold;
color: #225599;
}
.paginate .active {
color: #104060;
}
.paginate a.hidden {
visibility: hidden;
}
/*.paginate span {
color: #225599;
}*/

View file

@ -257,14 +257,38 @@ class Build {
public static function getVisibleBuilds(ParameterValidator $user_params)
{
$ret = array();
$builds_per_page = 6; // TODO: get from config
$ret['paginate']['number_of_pages'] = self::getNumberOfVisiblePages($builds_per_page);
$page = $user_params->getInt('page', 1);
$builds_per_page = 15; // TODO: get from config
if ($page < 0)
$page = 1;
if ($page > $get['number_of_pages'])
$page = $get['number_of_pages'];
if ($page > $ret['paginate']['number_of_pages'])
$page = $ret['paginate']['number_of_pages'];
$ret['paginate']['page'] = $page;
$ret['paginate']['link'] = 'build_history.php?page=';
$visible = 5;
$visible_minus = 0;
$start = $page - floor(($visible-1)/2);
if ($start <= 1)
{
$start = 1;
$visible_minus = 1;
}
$last = $start + $visible + $visible_minus;
if ($last >= $ret['paginate']['number_of_pages'] + 1)
{
$last = $ret['paginate']['number_of_pages'] + 1;
$start = $last - $visible - 1;
if ($start < 1)
$start = 1;
}
$ret['paginate']['first_page'] = $start;
$ret['paginate']['last_page'] = $last;
$ret['paginate']['visible'] = $last - $start;
$ret['builds'] = array();
$builds = self::fetchVisibleBuilds($page, $builds_per_page);
@ -273,7 +297,8 @@ class Build {
$ret['builds'][] = $build->getBuildStats();
}
$ret['paginate']['page'] = $page;
return $ret;
}

View file

@ -25,10 +25,10 @@ class ParameterValidator {
function getInt($name, $default)
{
if (isset($user_params[$name])
&& is_numeric($user_params[$name]))
if (isset($this->user_params[$name])
&& is_numeric($this->user_params[$name]))
{
return (int)$user_params[$name];
return (int)$this->user_params[$name];
} else {
return $default;
}

View file

@ -1,4 +1,8 @@
<h3>Build history</h3>
<table class="build_history">
<tr><td>
{include file='paginate.tpl'}
{include file='build_list.tpl'}
{include file='paginate.tpl'}
</td></tr>
</table>

View file

@ -1,22 +1,58 @@
{strip}
<div class="paginate">
{if $paginate.page > 1}
<a href="{$paginate.link}{$paginate.page-1}">Previous</a>
{/if}
{if $paginate.first_page > 1}
<a href="{$paginate.link}1">1</a>
{/if}
{if $paginate.visible > 1}
{if $paginate.page > 1}
<a href="{$paginate.link}{$paginate.page-1}">
{else}
<span class="active">
{/if}
Previous
{if $paginate.page > 1}
</a>
{else}
</span>
{/if}
&nbsp;
{if $paginate.first_page > 1}
<a href="{$paginate.link}1">1</a>
{if $paginate.first_page > 2}
...
{else}
,&nbsp;
{/if}
{/if}
{section name=pager loop=$paginate.last_page start=$paginate.first_page max=$paginate.visible}
<a href="{$paginate.link}{$smarty.section.pager.index}">{$smarty.section.pager.index}</a>
{if $smarty.section.pager.last == false}
,
{/if}
{/section}
{section name=pager loop=$paginate.last_page start=$paginate.first_page max=$paginate.visible}
<a href="{$paginate.link}{$smarty.section.pager.index}"
{if $paginate.page == $smarty.section.pager.index}
class="active"
{/if}
>{$smarty.section.pager.index}</a>
{if $smarty.section.pager.last == false}
,&nbsp;
{/if}
{/section}
{if $paginate.last_page < $paginate.number_of_pages}
<a href="{$paginate.link}{$paginate.number_of_pages}">{$paginate.number_of_pages}</a>
{/if}
{if $paginate.page < $paginate.number_of_pages}
<a href="{$paginate.link}{$paginate.page+1}">next</a>
{if $paginate.last_page <= $paginate.number_of_pages}
{if $paginate.last_page <= $paginate.number_of_pages - 1}
...
{else}
,&nbsp;
{/if}
<a href="{$paginate.link}{$paginate.number_of_pages}">{$paginate.number_of_pages}</a>
{/if}
&nbsp;
{if $paginate.page < $paginate.number_of_pages}
<a href="{$paginate.link}{$paginate.page+1}">
{else}
<span class="active">
{/if}
next
{if $paginate.page < $paginate.number_of_pages}
</a>
{else}
</span>
{/if}
{/if}
</div>
{/strip}