finished primitive code review editing

This commit is contained in:
hyung-hwan 2015-02-06 14:03:12 +00:00
parent 98695a00b5
commit 2297420797
3 changed files with 112 additions and 48 deletions

View File

@ -314,34 +314,76 @@ class Code extends Controller
}
}
if ($login['id'] != '' && $this->input->post('edit_review_comment'))
if ($login['id'] != '')
{
// 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())
if ($this->input->post('new_review_comment'))
{
$review_comment = $this->input->post('edit_review_comment');
if ($this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment) === FALSE)
// Note that edit_log_message and new_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 ('new_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())
{
$data['popup_error_message'] = 'Cannot add code review';
$review_comment = $this->input->post('new_review_comment');
if ($this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment) === FALSE)
{
$data['popup_error_message'] = 'Cannot add code review comment';
}
else
{
// this is a hack to clear form data upon success
$this->form_validation->_field_data = array();
}
}
else
{
// this is a hack to clear form data upon success
$this->form_validation->_field_data = array();
$data['popup_error_message'] = 'Invalid review comment';
}
}
else
else if ($this->input->post('edit_review_comment_no'))
{
$data['popup_error_message'] = 'Invalid review comment';
$this->load->helper ('form');
$this->load->library ('form_validation');
// get the comment number without validation.
$comment_no = $this->input->post('edit_review_comment_no');
if (is_numeric($comment_no))
{
$comment_field_name = "edit_review_comment_{$comment_no}";
$this->form_validation->set_rules ($comment_field_name, $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())
{
//
// TODO: should let sysadmin? to change comments???
//
$review_comment = $this->input->post($comment_field_name);
if ($this->code_review->updateReview ($projectid, $rev, (integer)$comment_no, $login['id'], $review_comment, TRUE) === FALSE)
{
$data['popup_error_message'] = 'Cannot edit code review comment';
}
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';
}
}
else
{
$data['popup_error_message'] = 'Invalid review comment number';
}
}
}

View File

@ -15,7 +15,6 @@ class CodeReviewModel extends Model
$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 ();
@ -65,14 +64,40 @@ class CodeReviewModel extends Model
$this->db->set ('projectid', $projectid);
$this->db->set ('userid', $userid);
$this->db->set ('message', "$rev,$sno");
$this->db->insert ('log');*/
$this->db->insert ('log');*/
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
if ($this->db->trans_status() === FALSE) return FALSE;
return $newsno;
}
function updateReview ($projectid, $revision, $sno, $userid, $comment, $strict = FALSE)
{
// 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);
if ($strict) $this->db->where ('updatedby', $userid);
$this->db->set ('comment', $comment);
$this->db->set ('updatedon', date('Y-m-d H:i:s'));
$this->db->set ('updatedby', $userid);
$this->db->update ('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 ();
return $this->db->trans_status();
}
function deleteReview ($projectid, $revision, $sno, $userid)
{
// TODO: check if userid can do this..
@ -89,10 +114,10 @@ class CodeReviewModel extends Model
$this->db->set ('projectid', $projectid);
$this->db->set ('userid', $userid);
$this->db->set ('message', "$rev,$sno");
$this->db->insert ('log');*/
$this->db->insert ('log');*/
$this->db->trans_complete ();
return $this->db->trans_status();
return $this->db->trans_status();
}
}

View File

@ -81,14 +81,12 @@ $(function() {
);
<?php
for ($i = $review_count; $i > 0; )
for ($i = $review_count; $i > 0; $i--)
{
$i--;
$rc = $reviews[$i];
$rc = $reviews[$i - 1];
if ($login['id'] == $rc->updatedby)
{
$edit_title = $this->lang->line('Comment') . ' ' . ($i + 1);
$edit_title = $this->lang->line('Comment') . " {$i}";
$label_ok = $this->lang->line('OK');
$label_cancel = $this->lang->line('Cancel');
print ("
@ -164,8 +162,8 @@ function render_wiki()
?>
creole_render_wiki (
"code_revision_mainarea_review_comment_text_" + i ,
"code_revision_mainarea_review_comment_" + i,
"code_revision_mainarea_review_comment_text_" + (i + 1) ,
"code_revision_mainarea_review_comment_" + (i + 1),
"<?=site_url()?>/wiki/show/<?=$project->id?>/",
""
);
@ -356,12 +354,10 @@ $history = $file['history'];
<div id="code_revision_mainarea_review_comment">
<?php
for ($i = $review_count; $i > 0; )
for ($i = $review_count; $i > 0; $i--)
{
$i--;
$rc = $reviews[$i];
print "<div id='code_revision_mainarea_review_comment_title_$i' class='review_comment_title'>\n";
$rc = $reviews[$i - 1];
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);
@ -377,8 +373,8 @@ $history = $file['history'];
print ("</div>\n");
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 "<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 $rc->comment;
@ -425,29 +421,30 @@ $history = $file['history'];
<?php
print form_open("code/revision/{$project->id}${revreqroot}", 'id="code_revision_new_review_comment_form"');
print form_error('edit_review_comment');
print form_error('new_review_comment');
print '<br />';
print form_textarea (
array ('name' => 'edit_review_comment',
'value' => set_value('edit_review_comment', ''),
'rows'=> 25, 'cols' => 100,
'id' => 'code_revision_edit_review_comment')
array ('name' => 'new_review_comment',
'value' => set_value('new_review_comment', ''),
'rows'=> 20, 'cols' => 90,
'id' => 'code_revision_new_review_comment')
);
print form_close();
for ($i = $review_count; $i > 0; )
for ($i = $review_count; $i > 0; $i--)
{
$i--;
$rc = $reviews[$i];
$rc = $reviews[$i - 1];
if ($login['id'] == $rc->updatedby)
{
print "<div id='code_revision_edit_review_comment_div_{$i}'>\n";
print form_open("code/revision/{$project->id}${revreqroot}", "id='code_revision_edit_review_comment_form_{$i}'");
print form_error("edit_review_comment_{$i}");
print '<br />';
print form_textarea (
array ('name' => "edit_review_comment_{$i}",
'value' => $rc->comment, 'rows'=> 10, 'cols' => 70,
'value' => $rc->comment, 'rows'=> 20, 'cols' => 90,
'id' => "code_revision_edit_review_comment_{$i}")
);
print form_close();