added top committers and top projects to the side home page

This commit is contained in:
hyung-hwan 2016-03-17 14:22:50 +00:00
parent f09fde59c7
commit 1b5773b15f
8 changed files with 360 additions and 148 deletions

View File

@ -104,8 +104,15 @@ class Site extends Controller
$login['id'], $this->issuehelper->_get_open_status_array($this->lang), 0); $login['id'], $this->issuehelper->_get_open_status_array($this->lang), 0);
} }
// TODO: make count_limit configurable instead of using 20
$commit_counts_per_project = $this->logs->countCodeCommitsPerProject ('', 0, 20);
$commit_counts_per_user = $this->logs->countCodeCommitsPerUser ('', 0, 20);
if (/*$issues === FALSE || $recently_resolved_issues === FALSE ||*/ if (/*$issues === FALSE || $recently_resolved_issues === FALSE ||*/
$open_issue_counts_per_project === FALSE || $your_open_issue_counts_per_project === FALSE) $open_issue_counts_per_project === FALSE ||
$your_open_issue_counts_per_project === FALSE ||
$commit_counts_per_project === FALSE ||
$commit_counts_per_user === FALSE)
{ {
$data['login'] = $login; $data['login'] = $login;
$data['message'] = 'DATABASE ERROR'; $data['message'] = 'DATABASE ERROR';
@ -121,6 +128,8 @@ class Site extends Controller
$data['recently_resolved_issues'] = $recently_resolved_issues;*/ $data['recently_resolved_issues'] = $recently_resolved_issues;*/
$data['open_issue_counts_per_project'] = $open_issue_counts_per_project; $data['open_issue_counts_per_project'] = $open_issue_counts_per_project;
$data['your_open_issue_counts_per_project'] = $your_open_issue_counts_per_project; $data['your_open_issue_counts_per_project'] = $your_open_issue_counts_per_project;
$data['commit_counts_per_project'] = $commit_counts_per_project;
$data['commit_counts_per_user'] = $commit_counts_per_user;
$data['issue_type_array'] = $this->issuehelper->_get_type_array($this->lang); $data['issue_type_array'] = $this->issuehelper->_get_type_array($this->lang);
$data['issue_status_array'] = $this->issuehelper->_get_status_array($this->lang); $data['issue_status_array'] = $this->issuehelper->_get_status_array($this->lang);
$data['issue_priority_array'] = $this->issuehelper->_get_priority_array($this->lang); $data['issue_priority_array'] = $this->issuehelper->_get_priority_array($this->lang);

View File

@ -109,6 +109,8 @@ $lang['System'] = 'System';
$lang['Tag'] = 'Tag'; $lang['Tag'] = 'Tag';
$lang['Text'] = 'Text'; $lang['Text'] = 'Text';
$lang['Time'] = 'Time'; $lang['Time'] = 'Time';
$lang['Top committers'] = 'Top committers';
$lang['Top projects'] = 'Top projects';
$lang['Type'] = 'Type'; $lang['Type'] = 'Type';
$lang['Undo'] = 'Undo'; $lang['Undo'] = 'Undo';
$lang['Unzip a zip file'] = 'Unzip a zip file'; $lang['Unzip a zip file'] = 'Unzip a zip file';

View File

@ -108,6 +108,8 @@ $lang['System'] = 'Sistem';
$lang['Tag'] = 'Label'; $lang['Tag'] = 'Label';
$lang['Text'] = 'Teks'; $lang['Text'] = 'Teks';
$lang['Time'] = 'Waktu'; $lang['Time'] = 'Waktu';
$lang['Top committers'] = 'Top committers';
$lang['Top projects'] = 'Top projects';
$lang['Type'] = 'Type'; $lang['Type'] = 'Type';
$lang['Undo'] = 'Undo'; $lang['Undo'] = 'Undo';
$lang['Unzip a zip file'] = 'Unzip a zip file'; $lang['Unzip a zip file'] = 'Unzip a zip file';

View File

@ -109,6 +109,8 @@ $lang['System'] = '시스템';
$lang['Tag'] = '태그'; $lang['Tag'] = '태그';
$lang['Text'] = '본문'; $lang['Text'] = '본문';
$lang['Time'] = '시간'; $lang['Time'] = '시간';
$lang['Top committers'] = '톱 커미터';
$lang['Top projects'] = '톱 프로젝트';
$lang['Type'] = '종류'; $lang['Type'] = '종류';
$lang['Undo'] = '되돌림'; $lang['Undo'] = '되돌림';
$lang['Unzip a zip file'] = 'zip파일 풀기'; $lang['Unzip a zip file'] = 'zip파일 풀기';

View File

@ -214,6 +214,70 @@ class LogModel extends Model
return TRUE; return TRUE;
} }
} }
function countCodeCommitsPerProject ($userid, $hour_limit = 0, $count_limit = 0)
{
$this->db->trans_begin ();
if (strlen($userid) > 0) $this->db->where ('userid', $userid);
if ($hour_limit > 0)
{
//$this->db->where ("updatedon >= SYSDATE() - INTERVAL {$hour_limit} HOUR");
$this->db->where ("createdon >= CURRENT_TIMESTAMP - INTERVAL '{$hour_limit}' HOUR");
}
$this->db->where ('type', 'code');
$this->db->where ('action', 'commit');
if ($count_limit > 0) $this->db->limit ($count_limit);
$this->db->select ('projectid, COUNT(id) AS commit_count');
$this->db->group_by ('projectid');
if ($count_limit > 0) $this->db->order_by ('commit_count', 'desc');
$query = $this->db->get ('log');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$this->db->trans_commit();
return $query->result ();
}
function countCodeCommitsPerUser ($projectid, $hour_limit = 0, $count_limit = 0)
{
$this->db->trans_begin ();
if (strlen($projectid) > 0) $this->db->where ('projectid', $projectid);
if ($hour_limit > 0)
{
//$this->db->where ("updatedon >= SYSDATE() - INTERVAL {$hour_limit} HOUR");
$this->db->where ("createdon >= CURRENT_TIMESTAMP - INTERVAL '{$hour_limit}' HOUR");
}
$this->db->where ('type', 'code');
$this->db->where ('action', 'commit');
if ($count_limit > 0) $this->db->limit ($count_limit);
$this->db->select ('userid, COUNT(id) AS commit_count');
$this->db->group_by ('userid');
if ($count_limit > 0) $this->db->order_by ('commit_count', 'desc');
$query = $this->db->get ('log');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$this->db->trans_commit();
return $query->result ();
}
} }
?> ?>

View File

@ -333,10 +333,12 @@ $(function () {
$(document).keydown (function(event) { $(document).keydown (function(event) {
if (event.keyCode == 37) if (event.keyCode == 37)
{ {
// left-arrow
on_prev_pdf_page(); on_prev_pdf_page();
} }
else if (event.keyCode == 39) else if (event.keyCode == 39)
{ {
// right-arrow
on_next_pdf_page(); on_next_pdf_page();
} }
}); });

View File

@ -228,7 +228,7 @@ foreach ($urls as $url)
print '<td class="object">'; print '<td class="object">';
print anchor ( print anchor (
"code/revision/{$x['repo']}/{$xdot}/{$x['rev']}", "code/revision/{$x['repo']}/{$xdot}/{$x['rev']}",
"r{$x['rev']}"); "#R{$x['rev']}");
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -293,7 +293,8 @@ foreach ($urls as $url)
{ {
$hex = $this->converter->AsciiToHex ($log['message']); $hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/issue/show/{$log['projectid']}/{$hex}"; $uri = "/issue/show/{$log['projectid']}/{$hex}";
$trimmed = $this->lang->line('Issue') . " {$log['message']}"; //$trimmed = $this->lang->line('Issue') . " {$log['message']}";
$trimmed = "#I{$log['message']}";
} }
if ($uri != '') if ($uri != '')

View File

@ -28,8 +28,10 @@
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.time.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.time.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.categories.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.categories.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.pie.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.tickrotor.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.tickrotor.js')?>"></script>
<script type="text/javascript"> <script type="text/javascript">
function render_wiki() function render_wiki()
{ {
@ -44,6 +46,10 @@ function render_wiki()
prettyPrint (); prettyPrint ();
} }
function labelFormatter(label, series)
{
return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + series.data[0][1] + "(" + Math.round(series.percent) + "%)</div>";
}
<?php if (count($open_issue_counts_per_project) > 0): ?> <?php if (count($open_issue_counts_per_project) > 0): ?>
function show_open_issues_per_project() function show_open_issues_per_project()
@ -126,6 +132,90 @@ function show_open_issues_per_project()
} }
<?php endif; ?> <?php endif; ?>
<?php if (count($commit_counts_per_project) > 0): ?>
function show_commits_per_project()
{
var commits_per_project_data = [
<?php
$first = TRUE;
foreach ($commit_counts_per_project as $commit)
{
if ($commit->commit_count > 0)
{
if ($first) $first = FALSE;
else print "\n,";
printf ("{ label: '%s', data: %d}", $commit->projectid, $commit->commit_count);
}
}
?>
];
var options =
{
series: {
shadowSize: 0,
pie: {
show: true,
innerRadius: 0.1,
label: {
show: true,
radius: 7/10,
formatter: labelFormatter,
background: { opacity: 0.8 }
}
}
},
legend: {
show: false
}
};
var commit_graph_plot = $.plot($("#site_home_commits_per_project"), commits_per_project_data, options);
}
<?php endif; ?>
<?php if (count($commit_counts_per_user) > 0): ?>
function show_commits_per_user()
{
var commits_per_user_data = [
<?php
$first = TRUE;
foreach ($commit_counts_per_user as $commit)
{
if ($commit->commit_count > 0)
{
if ($first) $first = FALSE;
else print "\n,";
printf ("{ label: '%s', data: %d}", $commit->userid, $commit->commit_count);
}
}
?>
];
var options =
{
series: {
shadowSize: 0,
pie: {
show: true,
innerRadius: 0.1,
label: {
show: true,
radius: 7/10,
formatter: labelFormatter,
background: { opacity: 0.8 }
}
}
},
legend: {
show: false
}
};
var commit_graph_plot = $.plot($("#site_home_commits_per_user"), commits_per_user_data, options);
}
<?php endif; ?>
$(function () { $(function () {
render_wiki (); render_wiki ();
@ -145,6 +235,21 @@ $(function () {
<?php if (count($open_issue_counts_per_project) > 0): ?> <?php if (count($open_issue_counts_per_project) > 0): ?>
show_open_issues_per_project(); show_open_issues_per_project();
<?php endif; ?> <?php endif; ?>
<?php if (count($commit_counts_per_project) > 0): ?>
$("#site_home_sidebar_top_projects_box").accordion ({
collapsible: true
});
show_commits_per_project();
<?php endif; ?>
<?php if (count($commit_counts_per_user) > 0): ?>
$("#site_home_sidebar_top_committers_box").accordion ({
collapsible: true
});
show_commits_per_user();
<?php endif; ?>
}); });
</script> </script>
@ -191,172 +296,197 @@ $this->load->view (
<div class="codepot-sidebar" id="site_home_sidebar"> <div class="codepot-sidebar" id="site_home_sidebar">
<div id="site_home_sidebar_latest_projects_box" class="collapsible-box"> <div id="site_home_sidebar_latest_projects_box" class="collapsible-box">
<div id="site_home_sidebar_latest_projects_header" class="collapsible-box-header"> <div id="site_home_sidebar_latest_projects_header" class="collapsible-box-header">
<?php print $this->lang->line('Latest projects'); ?> <?php print $this->lang->line('Latest projects'); ?>
</div> </div>
<ul id="site_home_sidebar_latest_projects_list" class="collapsible-box-list"> <ul id="site_home_sidebar_latest_projects_list" class="collapsible-box-list">
<?php <?php
foreach ($latest_projects as $project) foreach ($latest_projects as $project)
{ {
if (strcasecmp ($project->name, $project->id) != 0) if (strcasecmp ($project->name, $project->id) != 0)
$cap = "{$project->name} ($project->id)"; $cap = "{$project->name} ($project->id)";
else $cap = $project->name; else $cap = $project->name;
$sum = $project->summary; $sum = $project->summary;
//$sum = preg_replace("/(.{15}).+/u", "$1…", $project->summary); //$sum = preg_replace("/(.{15}).+/u", "$1…", $project->summary);
$sum = htmlspecialchars ($sum); $sum = htmlspecialchars ($sum);
$anc = anchor ("project/home/{$project->id}", $anc = anchor ("project/home/{$project->id}",
htmlspecialchars($cap), "title='$sum'"); htmlspecialchars($cap), "title='$sum'");
print "<li>{$anc}</li>"; print "<li>{$anc}</li>";
} }
?> ?>
</ul> </ul>
</div> </div>
<?php if (count($commit_counts_per_project) > 0): ?>
<div id="site_home_sidebar_top_projects_box" class="collapsible-box">
<div id="site_home_sidebar_top_projects_header" class="collapsible-box-header">
<?php print $this->lang->line('Top projects'); ?>
</div>
<div id="site_home_result_commits_per_project_graph" style="overflow:auto;">
<div id="site_home_commits_per_project" style="width:100%;height:200px;"></div>
</div>
</div>
<?php endif; ?>
<?php if (count($commit_counts_per_user) > 0): ?>
<div id="site_home_sidebar_top_committers_box" class="collapsible-box">
<div id="site_home_sidebar_top_committers_header" class="collapsible-box-header">
<?php print $this->lang->line('Top committers'); ?>
</div>
<div id="site_home_result_commits_per_user_graph" style="overflow:auto;">
<div id="site_home_commits_per_user" style="width:100%;height:200px;"></div>
</div>
</div>
<?php endif; ?>
<div id="site_home_sidebar_log_box" class="collapsible-box"> <div id="site_home_sidebar_log_box" class="collapsible-box">
<div id="site_home_sidebar_log_header" class="collapsible-box-header"> <div id="site_home_sidebar_log_header" class="collapsible-box-header">
<span><?php print $this->lang->line('Change log'); ?></span> <span><?php print $this->lang->line('Change log'); ?></span>
<span id="site_home_sidebar_log_all_span"><a href='#' id="site_home_sidebar_log_all_button"><?php print $this->lang->line('All'); ?></a></span> <span id="site_home_sidebar_log_all_span"><a href='#' id="site_home_sidebar_log_all_button"><?php print $this->lang->line('All'); ?></a></span>
</div> </div>
<div id="site_home_sidebar_log_table_container" class="collapsible-box-panel"> <div id="site_home_sidebar_log_table_container" class="collapsible-box-panel">
<table id="site_home_sidebar_log_table" class="collapsible-box-table"> <table id="site_home_sidebar_log_table" class="collapsible-box-table">
<?php <?php
$xdot = $this->converter->AsciiToHex ('.'); $xdot = $this->converter->AsciiToHex ('.');
foreach ($log_entries as $log) foreach ($log_entries as $log)
{
if (CODEPOT_DATABASE_STORE_GMT)
$createdon = $log['createdon'] . ' +0000';
else
$createdon = $log['createdon'];
if ($log['type'] == 'code')
{ {
$x = $log['message']; if (CODEPOT_DATABASE_STORE_GMT)
$createdon = $log['createdon'] . ' +0000';
else
$createdon = $log['createdon'];
print '<tr class="odd">'; if ($log['type'] == 'code')
print '<td class="date">';
print strftime ('%m-%d', strtotime($createdon));
print '</td>';
print '<td class="projectid">';
/*
print anchor (
"code/file/{$x['repo']}/{$xdot}/{$x['rev']}",
$x['repo']);
*/
print anchor ("project/home/{$x['repo']}", $x['repo']);
print '</td>';
print '<td class="object">';
print anchor (
"code/revision/{$x['repo']}/{$xdot}/{$x['rev']}",
"r{$x['rev']}");
print '</td>';
print '</tr>';
print '<tr class="even">';
print '<td></td>';
print '<td colspan="2" class="details">';
print '<span class="description">';
if ($log['action'] == 'revpropchange')
{ {
$fmt = $this->lang->line ('MSG_LOG_REVPROP_CHANGE_BY'); $x = $log['message'];
//print htmlspecialchars (sprintf($fmt, $x['propname'], $x['author']));
printf ( print '<tr class="odd">';
htmlspecialchars ($fmt), print '<td class="date">';
htmlspecialchars ($x['propname']), print strftime ('%m-%d', strtotime($createdon));
anchor ("/site/userlog/{$x['author']}", htmlspecialchars ($x['author']))); print '</td>';
print '<td class="projectid">';
/*
print anchor (
"code/file/{$x['repo']}/{$xdot}/{$x['rev']}",
$x['repo']);
*/
print anchor ("project/home/{$x['repo']}", $x['repo']);
print '</td>';
print '<td class="object">';
print anchor (
"code/revision/{$x['repo']}/{$xdot}/{$x['rev']}",
"#R{$x['rev']}");
print '</td>';
print '</tr>';
print '<tr class="even">';
print '<td></td>';
print '<td colspan="2" class="details">';
print '<span class="description">';
if ($log['action'] == 'revpropchange')
{
$fmt = $this->lang->line ('MSG_LOG_REVPROP_CHANGE_BY');
//print htmlspecialchars (sprintf($fmt, $x['propname'], $x['author']));
printf (
htmlspecialchars ($fmt),
htmlspecialchars ($x['propname']),
anchor ("/site/userlog/{$x['author']}", htmlspecialchars ($x['author'])));
}
else
{
$fmt = $this->lang->line (
'MSG_LOG_'.strtoupper($log['action']).'_BY');
//print htmlspecialchars (sprintf($fmt, $x['author']));
printf (
htmlspecialchars ($fmt),
anchor ("/site/userlog/{$x['author']}", htmlspecialchars ($x['author'])));
}
print '</span>';
if ($log['action'] != 'revpropchange')
{
print '<div class="codepot-plain-text-view"><pre>';
$sm = strtok (trim ($x['message']), "\r\n");
print htmlspecialchars ($sm);
print '</pre></div>';
}
print '</td>';
print '</tr>';
} }
else else
{ {
print '<tr class="odd">';
print '<td class="date">';
print strftime ('%m-%d', strtotime($createdon));
print '</td>';
print '<td class="project">';
print anchor ("/project/home/{$log['projectid']}", $log['projectid']);
print '</td>';
print '<td class="object">';
$uri = '';
if ($log['type'] == 'project')
{
$uri = "/project/home/{$log['projectid']}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'wiki')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/wiki/show_r/{$log['projectid']}/{$hex}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'file')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/file/show/{$log['projectid']}/{$hex}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'issue')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/issue/show/{$log['projectid']}/{$hex}";
//$trimmed = $this->lang->line('Issue') . " {$log['message']}";
$trimmed = "#I{$log['message']}";
}
if ($uri != '' && $trimmed != '')
print anchor ($uri, htmlspecialchars($trimmed));
else
print htmlspecialchars($trimmed);
print '</td>';
print '</tr>';
print '<tr class="even">';
print '<td></td>';
print '<td colspan="2" class="details">';
print '<span class="description">';
$fmt = $this->lang->line ( $fmt = $this->lang->line (
'MSG_LOG_'.strtoupper($log['action']).'_BY'); 'MSG_LOG_'.strtoupper($log['action']).'_BY');
//print htmlspecialchars (sprintf($fmt, $x['author'])); //print htmlspecialchars (sprintf($fmt, $log['userid']));
printf ( printf (
htmlspecialchars ($fmt), htmlspecialchars ($fmt),
anchor ("/site/userlog/{$x['author']}", htmlspecialchars ($x['author']))); anchor ("/site/userlog/{$log['userid']}", htmlspecialchars ($log['userid'])));
} print '</span>';
print '</span>'; print '</td>';
if ($log['action'] != 'revpropchange') print '</tr>';
{
print '<div class="codepot-plain-text-view"><pre>';
$sm = strtok (trim ($x['message']), "\r\n");
print htmlspecialchars ($sm);
print '</pre></div>';
} }
print '</td>';
print '</tr>';
} }
else ?>
{ </table>
print '<tr class="odd">'; </div>
print '<td class="date">';
print strftime ('%m-%d', strtotime($createdon));
print '</td>';
print '<td class="project">';
print anchor ("/project/home/{$log['projectid']}", $log['projectid']);
print '</td>';
print '<td class="object">';
$uri = '';
if ($log['type'] == 'project')
{
$uri = "/project/home/{$log['projectid']}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'wiki')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/wiki/show_r/{$log['projectid']}/{$hex}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'file')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/file/show/{$log['projectid']}/{$hex}";
$trimmed = preg_replace("/(.{15}).+/u", "$1…", $log['message']);
}
else if ($log['type'] == 'issue')
{
$hex = $this->converter->AsciiToHex ($log['message']);
$uri = "/issue/show/{$log['projectid']}/{$hex}";
$trimmed = $this->lang->line('Issue') . " {$log['message']}";
}
if ($uri != '' && $trimmed != '')
print anchor ($uri, htmlspecialchars($trimmed));
else
print htmlspecialchars($trimmed);
print '</td>';
print '</tr>';
print '<tr class="even">';
print '<td></td>';
print '<td colspan="2" class="details">';
print '<span class="description">';
$fmt = $this->lang->line (
'MSG_LOG_'.strtoupper($log['action']).'_BY');
//print htmlspecialchars (sprintf($fmt, $log['userid']));
printf (
htmlspecialchars ($fmt),
anchor ("/site/userlog/{$log['userid']}", htmlspecialchars ($log['userid'])));
print '</span>';
print '</td>';
print '</tr>';
}
}
?>
</table>
</div>
</div> <!-- box --> </div> <!-- box -->
</div> <!-- site_home_sidebar --> </div> <!-- site_home_sidebar -->