From 1b5773b15f57dd33addcbf694041e7943a945b78 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 17 Mar 2016 14:22:50 +0000 Subject: [PATCH] added top committers and top projects to the side home page --- codepot/src/codepot/controllers/site.php | 11 +- .../codepot/language/english/common_lang.php | 2 + .../language/indonesian/common_lang.php | 2 + .../codepot/language/korean/common_lang.php | 2 + codepot/src/codepot/models/logmodel.php | 64 +++ codepot/src/codepot/views/code_file.php | 2 + codepot/src/codepot/views/project_home.php | 5 +- codepot/src/codepot/views/site_home.php | 420 ++++++++++++------ 8 files changed, 360 insertions(+), 148 deletions(-) diff --git a/codepot/src/codepot/controllers/site.php b/codepot/src/codepot/controllers/site.php index d34dae11..2d214e5d 100644 --- a/codepot/src/codepot/controllers/site.php +++ b/codepot/src/codepot/controllers/site.php @@ -104,8 +104,15 @@ class Site extends Controller $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 ||*/ - $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['message'] = 'DATABASE ERROR'; @@ -121,6 +128,8 @@ class Site extends Controller $data['recently_resolved_issues'] = $recently_resolved_issues;*/ $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['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_status_array'] = $this->issuehelper->_get_status_array($this->lang); $data['issue_priority_array'] = $this->issuehelper->_get_priority_array($this->lang); diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index b82181e8..1126b79b 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -109,6 +109,8 @@ $lang['System'] = 'System'; $lang['Tag'] = 'Tag'; $lang['Text'] = 'Text'; $lang['Time'] = 'Time'; +$lang['Top committers'] = 'Top committers'; +$lang['Top projects'] = 'Top projects'; $lang['Type'] = 'Type'; $lang['Undo'] = 'Undo'; $lang['Unzip a zip file'] = 'Unzip a zip file'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index ef58382d..a93d9b86 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -108,6 +108,8 @@ $lang['System'] = 'Sistem'; $lang['Tag'] = 'Label'; $lang['Text'] = 'Teks'; $lang['Time'] = 'Waktu'; +$lang['Top committers'] = 'Top committers'; +$lang['Top projects'] = 'Top projects'; $lang['Type'] = 'Type'; $lang['Undo'] = 'Undo'; $lang['Unzip a zip file'] = 'Unzip a zip file'; diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index 3091b7cb..8d33ec1e 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -109,6 +109,8 @@ $lang['System'] = '시스템'; $lang['Tag'] = '태그'; $lang['Text'] = '본문'; $lang['Time'] = '시간'; +$lang['Top committers'] = '톱 커미터'; +$lang['Top projects'] = '톱 프로젝트'; $lang['Type'] = '종류'; $lang['Undo'] = '되돌림'; $lang['Unzip a zip file'] = 'zip파일 풀기'; diff --git a/codepot/src/codepot/models/logmodel.php b/codepot/src/codepot/models/logmodel.php index 7d434f28..7995e9cd 100644 --- a/codepot/src/codepot/models/logmodel.php +++ b/codepot/src/codepot/models/logmodel.php @@ -214,6 +214,70 @@ class LogModel extends Model 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 (); + } } ?> diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index 411b0ee6..90a17d72 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -333,10 +333,12 @@ $(function () { $(document).keydown (function(event) { if (event.keyCode == 37) { + // left-arrow on_prev_pdf_page(); } else if (event.keyCode == 39) { + // right-arrow on_next_pdf_page(); } }); diff --git a/codepot/src/codepot/views/project_home.php b/codepot/src/codepot/views/project_home.php index d9420bea..26eaa381 100644 --- a/codepot/src/codepot/views/project_home.php +++ b/codepot/src/codepot/views/project_home.php @@ -228,7 +228,7 @@ foreach ($urls as $url) print ''; print anchor ( "code/revision/{$x['repo']}/{$xdot}/{$x['rev']}", - "r{$x['rev']}"); + "#R{$x['rev']}"); print ''; print ''; @@ -293,7 +293,8 @@ foreach ($urls as $url) { $hex = $this->converter->AsciiToHex ($log['message']); $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 != '') diff --git a/codepot/src/codepot/views/site_home.php b/codepot/src/codepot/views/site_home.php index 60655fe8..c7598246 100644 --- a/codepot/src/codepot/views/site_home.php +++ b/codepot/src/codepot/views/site_home.php @@ -28,8 +28,10 @@ + + @@ -191,172 +296,197 @@ $this->load->view (
-
- lang->line('Latest projects'); ?> -
+
+ lang->line('Latest projects'); ?> +
-
    -name, $project->id) != 0) - $cap = "{$project->name} ($project->id)"; - else $cap = $project->name; +
      + name, $project->id) != 0) + $cap = "{$project->name} ($project->id)"; + else $cap = $project->name; - $sum = $project->summary; - //$sum = preg_replace("/(.{15}).+/u", "$1…", $project->summary); - $sum = htmlspecialchars ($sum); + $sum = $project->summary; + //$sum = preg_replace("/(.{15}).+/u", "$1…", $project->summary); + $sum = htmlspecialchars ($sum); - $anc = anchor ("project/home/{$project->id}", - htmlspecialchars($cap), "title='$sum'"); - print "
    • {$anc}
    • "; -} -?> -
    + $anc = anchor ("project/home/{$project->id}", + htmlspecialchars($cap), "title='$sum'"); + print "
  • {$anc}
  • "; + } + ?> +
+ 0): ?> +
+
+ lang->line('Top projects'); ?> +
+ +
+
+
+
+ + + 0): ?> +
+
+ lang->line('Top committers'); ?> +
+ +
+
+
+
+ +
-
-lang->line('Change log'); ?> -lang->line('All'); ?> -
+
+ lang->line('Change log'); ?> + lang->line('All'); ?> +
-
- -converter->AsciiToHex ('.'); - foreach ($log_entries as $log) - { - if (CODEPOT_DATABASE_STORE_GMT) - $createdon = $log['createdon'] . ' +0000'; - else - $createdon = $log['createdon']; - - if ($log['type'] == 'code') +
+
+ converter->AsciiToHex ('.'); + foreach ($log_entries as $log) { - $x = $log['message']; + if (CODEPOT_DATABASE_STORE_GMT) + $createdon = $log['createdon'] . ' +0000'; + else + $createdon = $log['createdon']; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - - print ''; - print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + print ''; } else { + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + print ''; - if ($log['action'] != 'revpropchange') - { - print '
';
-				$sm = strtok (trim ($x['message']), "\r\n");
-				print htmlspecialchars ($sm);
-				print '
'; + print ''; } - print ''; - print ''; } - else - { - print ''; - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - print ''; - - print ''; - } - } -?> -
'; - print strftime ('%m-%d', strtotime($createdon)); - print ''; - /* - print anchor ( - "code/file/{$x['repo']}/{$xdot}/{$x['rev']}", - $x['repo']); - */ - print anchor ("project/home/{$x['repo']}", $x['repo']); - print ''; - print anchor ( - "code/revision/{$x['repo']}/{$xdot}/{$x['rev']}", - "r{$x['rev']}"); - print '
'; - print ''; - - if ($log['action'] == 'revpropchange') + if ($log['type'] == 'code') { - $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']))); + $x = $log['message']; + + print '
'; + print strftime ('%m-%d', strtotime($createdon)); + print ''; + /* + print anchor ( + "code/file/{$x['repo']}/{$xdot}/{$x['rev']}", + $x['repo']); + */ + print anchor ("project/home/{$x['repo']}", $x['repo']); + print ''; + print anchor ( + "code/revision/{$x['repo']}/{$xdot}/{$x['rev']}", + "#R{$x['rev']}"); + print '
'; + print ''; + + 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 ''; + + if ($log['action'] != 'revpropchange') + { + print '
';
+					$sm = strtok (trim ($x['message']), "\r\n");
+					print htmlspecialchars ($sm);
+					print '
'; + } + print '
'; + print strftime ('%m-%d', strtotime($createdon)); + print ''; + print anchor ("/project/home/{$log['projectid']}", $log['projectid']); + print ''; + $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 '
'; + print ''; $fmt = $this->lang->line ( 'MSG_LOG_'.strtoupper($log['action']).'_BY'); - //print htmlspecialchars (sprintf($fmt, $x['author'])); + //print htmlspecialchars (sprintf($fmt, $log['userid'])); printf ( htmlspecialchars ($fmt), - anchor ("/site/userlog/{$x['author']}", htmlspecialchars ($x['author']))); - } - print ''; + anchor ("/site/userlog/{$log['userid']}", htmlspecialchars ($log['userid']))); + print ''; + print '
'; - print strftime ('%m-%d', strtotime($createdon)); - print ''; - print anchor ("/project/home/{$log['projectid']}", $log['projectid']); - print ''; - $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 '
'; - print ''; - $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 ''; - print '
-
+ ?> + +