From 229742079760d37a275cc29abb8565f0d89b5450 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 6 Feb 2015 14:03:12 +0000 Subject: [PATCH] finished primitive code review editing --- codepot/src/codepot/controllers/code.php | 80 ++++++++++++++----- .../src/codepot/models/codereviewmodel.php | 35 ++++++-- codepot/src/codepot/views/code_revision.php | 45 +++++------ 3 files changed, 112 insertions(+), 48 deletions(-) diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index c845927d..ba7220cf 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -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('',''); - - 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('',''); + + 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('',''); + + 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'; + } } } diff --git a/codepot/src/codepot/models/codereviewmodel.php b/codepot/src/codepot/models/codereviewmodel.php index df3903ff..9ac07e93 100644 --- a/codepot/src/codepot/models/codereviewmodel.php +++ b/codepot/src/codepot/models/codereviewmodel.php @@ -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(); } } diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index a56c1187..90577b3c 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -81,14 +81,12 @@ $(function() { ); 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), "/wiki/show/id?>/", "" ); @@ -356,12 +354,10 @@ $history = $file['history'];
0; ) + for ($i = $review_count; $i > 0; $i--) { - $i--; - - $rc = $reviews[$i]; - print "
\n"; + $rc = $reviews[$i - 1]; + print "
\n"; printf (" %d", $rc->sno); printf (" %s", $rc->updatedby); printf (" %s", $rc->updatedon); @@ -377,8 +373,8 @@ $history = $file['history']; print ("
\n"); - print "
\n"; - print "