Skip to content

Commit

Permalink
start to build the homepage for trac projects, show summarys for each
Browse files Browse the repository at this point in the history
project.  Using jQuery.masonry to layout the each project div.
  • Loading branch information
seanchen committed Mar 20, 2013
1 parent 0887951 commit 4697856
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 4 deletions.
5 changes: 5 additions & 0 deletions wp-trac-client/admin-testing.php
Expand Up @@ -50,10 +50,15 @@
<option>wptc_get_ticket_priorities</option>
<option>wptc_get_ticket_components</option>
<option>wptc_get_ticket_metas</option>
<option>wptc_get_ticket_meta</option>
<option>wptc_get_ticket_actions</option>
<option>wptc_get_ticket_status</option>
<option>wptc_ticket_query</option>
<option>wptc_milestone_ticket_summary</option>
<option>wptc_update_ticket_meta</option>
<option>wptc_remove_ticket_meta</option>
<option>wptc_widget_ticket_defaults</option>
<option>wptc_widget_milestone_summary</option>
<option>wptc_widget_version_nav</option>
<option>get_wiki_client</option>
<option>wptc_widget_parse_content</option>
Expand Down
10 changes: 10 additions & 0 deletions wp-trac-client/js/jquery.masonry.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions wp-trac-client/tags.php
Expand Up @@ -148,6 +148,38 @@ function wptc_build_query($milestone, $version=null, $max=25, $page=1) {
return $queryStr;
}

/**
* generic way to query tickets.
*/
function wptc_ticket_query($query, $max=25, $page=1) {

$proxy = get_wptc_client()->getProxy('ticket');
$query = $query . '&max=' . $max . '&page=' . $page;
$ids = $proxy->query($query);
return $ids;
}

/**
* multicall query tickets.
*/
function wptc_ticket_query_m($querys) {

// preparing the signature.
$signatures = array();
foreach ($querys as $query) {
$sign = array(
'methodName' => 'ticket.query',
'params' => array($query)
);
array_push($signatures, $sign);
}
// get the system proxy.
$proxy = get_wptc_client()->getProxy('system');
$results = $proxy->multicall($signatures);

return $results;
}

/**
* return all details about a ticket.
*
Expand Down Expand Up @@ -217,6 +249,22 @@ function wptc_get_ticket_metas($metaName) {
return $metas;
}

/**
* return the details attributes for the given meta.
*
* @param $metaType the type of metadata: type, milestone, veraion,
* etc.
* @param $metaName the name of the metadata.
* @return the full attributes for the given metadata.
*/
function wptc_get_ticket_meta($metaType, $metaName) {

$proxy = get_wptc_client()->getProxy('ticket.' . $metaType);
$attrs = $proxy->get($metaName);

return $attrs;
}

/**
* update a milestone of version, create new one if it is not exist.
*
Expand Down Expand Up @@ -287,6 +335,21 @@ function wptc_get_ticket_priorities() {
array_combine($prios, $prios));
}

/**
* return all ticket status names, which are defined in the workflow.
* we assume all projects are using the same workflow.
*/
function wptc_get_ticket_status() {

$status = wptc_get_ticket_metas('status');
$ret = array();
foreach($status as $s) {
$s == 'closed' ? array_unshift($ret, $s) :
array_push($ret, $s);
}
return $ret;
}

/**
* return all ticket milestone names.
* grouped by due-date: future due-date in group Running
Expand Down Expand Up @@ -318,6 +381,27 @@ function wptc_get_ticket_milestones($project) {
$optgroups);
}

/**
* return the ticket summary for the gieven milestone.
*/
function wptc_milestone_ticket_summary($milestone) {

$queryBase = 'milestone=' . $milestone;
$status = wptc_get_ticket_status();

foreach ($status as $s) {
$querys[$s] = $queryBase. '&status=' . $s . '&max=0';
}

$ids = wptc_ticket_query_m($querys);
foreach($ids as $id) {
$counts[] = count($id[0]);
}

return array_combine($status, $counts);
//return round(($counts[0] / array_sum($counts)) * 100);
}

/**
* retrun all ticket components.
*/
Expand Down
17 changes: 14 additions & 3 deletions wp-trac-client/templates/page-tickets.php
Expand Up @@ -8,14 +8,15 @@
<?php
get_header();
wp_enqueue_style('wptc-trac-ticket');
wp_enqueue_script('jquery-masonry');

// the page slug will be the project name.
$version = $_GET['version'];
if (empty($version)) {
// using the default sprint.
$defaults = wptc_widget_ticket_defaults();
$version = $defaults['version'];
$project = $defaults['project'];
//$defaults = wptc_widget_ticket_defaults();
//$version = $defaults['version'];
//$project = $defaults['project'];
} else {
$project = wptc_get_project_name($version);
}
Expand All @@ -25,12 +26,14 @@

<div id="left_column">
<div class='leftnav'>
<?php if (!empty($version)) { ?>
<div id='sprint-nav' class="widget">
<h2 class='widgettitle'>
Project: <b><?php echo $project;?></b>
</h2>
<?php echo wptc_widget_version_nav($project)?>
</div>
<?php } ?>
<div id='ticket-finder' class="widget">
<h2 class='widgettitle'>Ticket Finder</h2>
<?php echo wptc_widget_ticket_finder('trac/ticket')?>
Expand All @@ -40,13 +43,21 @@

<div id="right_column">

<?php if (empty($version)) {

echo wptc_widget_trac_homepage();

} else { ?>

<h2>Tickets for Version: <em><?php echo $version ?></em></h2>

<?php
$tickets = wptc_get_tickets_by_version($version);
echo wptc_widget_tickets_list($tickets, 'trac/ticket');
?>

<?php } ?>

</div> <?php // END right_column ?>

<?php get_footer(); ?>
130 changes: 130 additions & 0 deletions wp-trac-client/widgets.php
Expand Up @@ -1168,3 +1168,133 @@ function wptc_widget_ticket_defaults() {

return $ticket;
}

/**
* Preparing the summary div html for a milestone.
*
*/
function wptc_widget_milestone_summary($milestone) {

// get all necessary information.
$attrs = wptc_get_ticket_meta('milestone', $milestone);
$tickets = wptc_milestone_ticket_summary($milestone);
$total = array_sum($tickets);
if($total === 0) {
// skip this milestone.
return "";
}
$percent = round(($tickets['closed'] / $total) * 100);

$progressTds = "";
$progressDts = "";
// get ready the progress bar. using table.
foreach($tickets as $status => $subtotal) {

$tdPercent = round(($subtotal / $total) * 100);
$tdStyle = $tdPercent < 1 ?
"display: none" : "width: " . $tdPercent . "%";
$td = <<<EOT
<td class="{$status}" style="{$tdStyle}">
</td>
EOT;
$progressTds = $progressTds . $td;

// the summary label for each status.
$dt = "<dt>" . $status . ":</dt>";
$dt = $dt . "<dd>" . $subtotal . "</dd>";
$progressDts = $progressDts . $dt;
}

// total tickets
$dt = "<dt>Total:</dt><dd>" . $total . "</dd>";
$progressDts = $progressDts . $dt;

$html = <<<EOT
<div class="milestone">
<h3>Milestone: {$attrs['name']}</h3>
<div class="info">
<p class="date"><strong>Due Date: </strong>
{$attrs['due']}
</p>
<table class="progress"><tbody>
<tr>
{$progressTds}
</tr>
</tbody></table>
<p class="percent">{$percent}%</p>
<dl>
<dt>Number of ticket: </dt><dd></dd>
{$progressDts}
</dl>
</div>
</div>
EOT;

return $html;
}

/**
* preparing the div html for the project summary page.
*/
function wptc_widget_project_summary($project) {

// get running milestone for the given project.
$all = wptc_get_ticket_milestones($project);
if (empty($all)) {
return "";
}
$running = $all['Running (by Due Date)'];
$milestoneDivs = "";
foreach(array_keys($running) as $milestone) {
$milestoneDivs = $milestoneDivs .
wptc_widget_milestone_summary($milestone);
}

$div = <<<EOT
<div class="project">
<h3>Project: {$project}</h3>
{$milestoneDivs}
</div>
EOT;

return $div;
}

/**
* proeparing hte trac home page.
*/
function wptc_widget_trac_homepage() {

// get all projects.
$projects = wptc_get_projects();
$projectDivs = "";
foreach($projects as $project) {
$projectDivs = $projectDivs .
wptc_widget_project_summary($project['name']);
}

$div = <<<EOT
<div id="projects">
{$projectDivs}
</div>
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function($) {
$('#projects').masonry({
// options.
itemSelector : '.project',
columnWidth : 175,
isAnimated : true,
animationOptions : {
duration: 1750,
easing: 'linear',
queue: false
}
});
});
</script>
EOT;

return $div;
}
6 changes: 5 additions & 1 deletion wp-trac-client/wp-trac-client.php
Expand Up @@ -112,7 +112,11 @@ function register_resources() {
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
// javascript for autocomplete.
wp_register_script('wptc-autocomplete',
plugins_url('wt-trac-client/js/wptc-autocomplete.js'));
plugins_url('wp-trac-client/js/wptc-autocomplete.js'));
// js lib for jQuery masonry.
wp_register_script('jquery-masonry',
plugins_url('wp-trac-client/js/jquery.masonry.min.js'),
array('jquery'), '2.1.08');
}

function get_wptc_client() {
Expand Down

0 comments on commit 4697856

Please sign in to comment.