diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 63d82f97..99eb0288 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -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('',''); - if ($this->input->post('edit_log_message')) + if ($this->form_validation->run()) { - $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')) { - 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) { - $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['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('',''); + + 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 { - $data['edit_error_message'] = 'Invalid revision log message'; + // 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); @@ -321,17 +354,28 @@ class Code extends Controller } else { - $data['project'] = $project; - $data['headpath'] = $path; - $data['file'] = $file; - - $data['revision'] = $rev; - $data['prev_revision'] = - $this->subversion->getPrevRev ($projectid, $path, $rev); - $data['next_revision'] = - $this->subversion->getNextRev ($projectid, $path, $rev); - - $this->load->view ($this->VIEW_REVISION, $data); + $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'] = + $this->subversion->getPrevRev ($projectid, $path, $rev); + $data['next_revision'] = + $this->subversion->getNextRev ($projectid, $path, $rev); + + $this->load->view ($this->VIEW_REVISION, $data); + } } } } diff --git a/codepot/src/codepot/models/codereviewmodel.php b/codepot/src/codepot/models/codereviewmodel.php new file mode 100644 index 00000000..df3903ff --- /dev/null +++ b/codepot/src/codepot/models/codereviewmodel.php @@ -0,0 +1,99 @@ +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(); + } +} + +?> diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index 8e603309..0bb6a530 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -14,6 +14,8 @@ @@ -247,28 +297,39 @@ $history = $file['history']; -
lang->line('Comment')?>
+
lang->line('Comment')?>  + + + lang->line('New'), + array ('id' => 'code_revision_new_review_comment_button')); + ?> + + +
+
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 "
\n"; + printf (" %d", $rc->sno); + printf (" %s", $rc->updatedby); + printf (" %s", $rc->updatedon); + print ("
\n"); - print "
"; + print "
\n"; + print "\n"; + print "
\n"; + } - print form_close(); ?>
@@ -302,13 +363,30 @@ $history = $file['history']; ?> + - 0): ?> -
- +
+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(); +?> +
+ + 0): ?> +
+
- + diff --git a/codepot/src/css/code.css b/codepot/src/css/code.css index c706a7c8..be1d934a 100644 --- a/codepot/src/css/code.css +++ b/codepot/src/css/code.css @@ -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; } + +