Added primitive commenting feature to the code revision view

This commit is contained in:
hyung-hwan 2015-01-29 13:46:47 +00:00
parent f54a47e46b
commit d6a2a3ad31
4 changed files with 298 additions and 49 deletions

View File

@ -246,7 +246,7 @@ class Code extends Controller
{
$this->load->model ('ProjectModel', 'projects');
$this->load->model ('SubversionModel', 'subversion');
$this->load->model ('CodeReviewModel', 'code_review');
$login = $this->login->getUser ();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
@ -278,9 +278,10 @@ class Code extends Controller
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
}
$data['edit_error_message'] = '';
$data['popup_error_message'] = '';
if ($login['id'] != '' &&
$login['id'] == $this->subversion->getRevProp($projectid, $rev, 'svn:author'))
$login['id'] == $this->subversion->getRevProp($projectid, $rev, 'svn:author') &&
$this->input->post('edit_log_message'))
{
// the current user must be the author of the revision to be able to
// change the log message.
@ -290,26 +291,58 @@ class Code extends Controller
$this->form_validation->set_rules ('edit_log_message', 'Message', 'required|min_length[2]');
$this->form_validation->set_error_delimiters('<span class="form_field_error">','</span>');
if ($this->input->post('edit_log_message'))
{
$logmsg = $this->input->post('edit_log_message');
if ($this->form_validation->run())
{
$logmsg = $this->input->post('edit_log_message');
if ($logmsg != $this->subversion->getRevProp ($projectid, $rev, 'svn:log'))
{
$actual_rev = $this->subversion->setRevProp (
$projectid, $rev, 'svn:log', $logmsg, $login['id']);
if ($actual_rev === FALSE)
{
$data['edit_error_message'] = 'Cannot change revision log message';
$data['popup_error_message'] = 'Cannot change revision log message';
}
else
{
$this->form_validation->_field_data = array();
}
}
}
else
{
$data['edit_error_message'] = 'Invalid revision log message';
$data['popup_error_message'] = 'Invalid revision log message';
}
}
if ($login['id'] != '' && $this->input->post('edit_review_comment'))
{
// Note that edit_log_message and edit_review_comment are not
// supposed to be/ POSTed at the same time.
// this program may break if that happens.
$this->load->helper ('form');
$this->load->library ('form_validation');
$this->form_validation->set_rules ('edit_review_comment', $this->lang->line('Comment'), 'required|min_length[10]');
$this->form_validation->set_error_delimiters('<span class="form_field_error">','</span>');
if ($this->form_validation->run())
{
$review_comment = $this->input->post('edit_review_comment');
if ($this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment) === FALSE)
{
$data['popup_error_message'] = 'Cannot add code review';
}
else
{
// this is a hack to clear form data upon success
$this->form_validation->_field_data = array();
}
}
else
{
$data['popup_error_message'] = 'Invalid review comment';
}
}
$file = $this->subversion->getRevHistory ($projectid, $path, $rev);
@ -320,10 +353,20 @@ class Code extends Controller
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
$reviews = $this->code_review->getReviews ($projectid, $rev);
if ($reviews === FALSE)
{
$data['project'] = $project;
$data['message'] = 'Failed to get code reviews';
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
$data['project'] = $project;
$data['headpath'] = $path;
$data['file'] = $file;
$data['reviews'] = $reviews;
$data['revision'] = $rev;
$data['prev_revision'] =
@ -335,6 +378,7 @@ class Code extends Controller
}
}
}
}
function _do_diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD, $full = FALSE)
{

View File

@ -0,0 +1,99 @@
<?php
class CodeReviewModel extends Model
{
function CodeReviewModel ()
{
parent::Model ();
$this->load->database ();
}
function getReviews ($projectid, $revision)
{
$this->db->trans_start ();
$this->db->where ('projectid', (string)$projectid);
$this->db->where ('rev', $revision);
$query = $this->db->get ('code_review');
//if ($query === FALSE)
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_complete ();
return FALSE;
}
$result = $query->result ();
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return $result;
}
function insertReview ($projectid, $revision, $userid, $comment)
{
// TODO: check if userid can do this..
$this->db->trans_start ();
$this->db->where ('projectid', $projectid);
$this->db->where ('rev', $revision);
$this->db->select ('MAX(sno) as maxsno');
$query = $this->db->get ('code_review');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_complete ();
return FALSE;
}
$result = $query->result();
$maxsno = (empty($result) || $result[0] == NULL)? 0: $result[0]->maxsno;
$newsno = $maxsno + 1;
$this->db->set ('projectid', $projectid);
$this->db->set ('rev', $revision);
$this->db->set ('sno', $newsno);
$this->db->set ('comment', $comment);
$this->db->set ('createdon', date('Y-m-d H:i:s'));
$this->db->set ('updatedon', date('Y-m-d H:i:s'));
$this->db->set ('createdby', $userid);
$this->db->set ('updatedby', $userid);
$this->db->insert ('code_review');
/*$this->db->set ('createdon', date('Y-m-d H:i:s'));
$this->db->set ('type', 'code_review');
$this->db->set ('action', 'insert');
$this->db->set ('projectid', $projectid);
$this->db->set ('userid', $userid);
$this->db->set ('message', "$rev,$sno");
$this->db->insert ('log');*/
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return $newsno;
}
function deleteReview ($projectid, $revision, $sno, $userid)
{
// TODO: check if userid can do this..
$this->db->trans_start ();
$this->db->where ('projectid', $projectid);
$this->db->where ('rev', $revision);
$this->db->where ('sno', $sno);
$this->db->delete ('code_review');
/*$this->db->set ('createdon', date('Y-m-d H:i:s'));
$this->db->set ('type', 'issue');
$this->db->set ('action', 'delete');
$this->db->set ('projectid', $projectid);
$this->db->set ('userid', $userid);
$this->db->set ('message', "$rev,$sno");
$this->db->insert ('log');*/
$this->db->trans_complete ();
return $this->db->trans_status();
}
}
?>

View File

@ -14,6 +14,8 @@
<script type="text/javascript">
<?php $review_count = count($reviews); ?>
<?php $is_loggedin = ($login['id'] != ''); ?>
<?php $can_edit = ($login['id'] == $file['history']['author']); ?>
<?php if ($can_edit): ?>
@ -45,9 +47,44 @@ $(function() {
return false;
}
);
});
<?php endif; ?>
<?php if (strlen($edit_error_message) > 0): ?>
$("#code_revision_edit_error_div").dialog( {
<?php if ($is_loggedin): ?>
$(function() {
$("#code_revision_new_comment_div").dialog (
{
title: '<?=$this->lang->line('Comment')?>',
width: 'auto',
height: 'auto',
resizable: false,
autoOpen: false,
modal: true,
buttons: {
'<?=$this->lang->line('OK')?>': function () {
$('#code_revision_new_review_comment_form').submit ();
$(this).dialog('close');
},
'<?=$this->lang->line('Cancel')?>': function () {
$(this).dialog('close');
}
},
close: function() { }
}
);
$("#code_revision_new_review_comment_button").button().click (
function () {
$("#code_revision_new_comment_div").dialog('open');
return false;
}
);
});
<?php endif; ?>
<?php if (strlen($popup_error_message) > 0): ?>
$(function() {
$("#code_revision_popup_error_div").dialog( {
title: '<?=$this->lang->line('Error')?>',
width: 'auto',
height: 'auto',
@ -59,8 +96,6 @@ $(function() {
}
}
});
<?php endif; ?>
});
<?php endif; ?>
@ -76,6 +111,21 @@ function render_wiki()
"<?=site_url()?>/wiki/show/<?=$project->id?>/",
""
);
<?php
print "for (i = 0; i < $review_count; i++) {\n";
?>
creole_render_wiki (
"code_revision_mainarea_review_comment_text_" + i ,
"code_revision_mainarea_review_comment_" + i,
"<?=site_url()?>/wiki/show/<?=$project->id?>/",
""
);
<?php
print "}\n";
?>
}
</script>
@ -247,28 +297,39 @@ $history = $file['history'];
<div class="title"><?=$this->lang->line('Comment')?></div>
<div class="title"><?=$this->lang->line('Comment')?>&nbsp;
<?php if ($is_loggedin): ?>
<span class='anchor'>
<?=anchor ("#", $this->lang->line('New'),
array ('id' => 'code_revision_new_review_comment_button'));
?>
</span>
<?php endif; ?>
</div>
<div id="code_revision_mainarea_review_comment">
<?php
//foreach ($review_comments as $rc)
//{
//
// delete box, edit box???
//}
print form_open("code/revision/{$project->id}${revreqroot}", 'id="code_revision_review_comment_form"');
for ($i = $review_count; $i > 0; )
{
$i--;
print form_textarea (
array ('name' => 'edit_review_comment',
'value' => '', 'rows'=> 20, 'cols' => 120,
'id' => 'code_revision_edit_review_comment')
);
$rc = $reviews[$i];
print "<div id='code_revision_mainarea_review_comment_title_$i' class='review_comment_title'>\n";
printf (" <span class='review_comment_title_no'>%d</span>", $rc->sno);
printf (" <span class='review_comment_title_updatedby'>%s</span>", $rc->updatedby);
printf (" <span class='review_comment_title_updatedon'>%s</span>", $rc->updatedon);
print ("</div>\n");
print "<br/>";
print "<div id='code_revision_mainarea_review_comment_$i' class='review_comment_text'>\n";
print "<pre id='code_revision_mainarea_review_comment_text_$i' style='visibility: hidden'>\n";
//print form_submit ('submit_review_comment', $this->lang->line('Submit'));
print form_submit ('submit_review_comment', 'Submit');
// TODO: delete box, edit box???
print $rc->comment;
print "</pre>\n";
print "</div>\n";
}
print form_close();
?>
</div> <!-- code_revision_mainarea_review_comment -->
@ -302,13 +363,30 @@ $history = $file['history'];
?>
<?=form_close()?>
</div>
<?php endif; ?> <!-- $can_edit -->
<?php if (strlen($edit_error_message) > 0): ?>
<div id="code_revision_edit_error_div">
<?=$edit_error_message?>
<div id="code_revision_new_comment_div">
<?php
print form_open("code/revision/{$project->id}${revreqroot}", 'id="code_revision_new_review_comment_form"');
print form_error('edit_review_comment');
print form_textarea (
array ('name' => 'edit_review_comment',
'value' => set_value('edit_review_comment', ''),
'rows'=> 25, 'cols' => 100,
'id' => 'code_revision_edit_review_comment')
);
print form_close();
?>
</div>
<?php if (strlen($popup_error_message) > 0): ?>
<div id="code_revision_popup_error_div">
<?=$popup_error_message?>
</div>
<?php endif; ?>
<?php endif; ?> <!-- $can_edit -->
</body>

View File

@ -243,6 +243,32 @@
padding: 0;
}
.review_comment_title {
padding: 3px 3px 3px 3px;
margin-top: 5px;
background-color: #DDDDF0;
font-size: 90%;
font-weight: bold;
}
.review_comment_title_no {
}
.review_comment_title_updatedby {
font-style: italic;
}
.review_comment_title_updatedon {
}
.review_comment_text {
border:1px solid #F0F0FC;
background-color: #F0F0FC;
padding-left: 5px;
padding-right: 5px;
}
/*-----------------------------------------------
* project source diff view
*-----------------------------------------------*/
@ -383,3 +409,5 @@
//background-color:#ffff00;
text-decoration: underline;
}