From f1689b4dea0fe3bcf2c30a0afc49e431b7242f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Thu, 9 Dec 2021 11:24:14 +0800 Subject: [PATCH 01/24] * code for task #45504. --- db/update16.0.beta1.sql | 7 + module/mr/control.php | 38 +-- module/mr/css/common.css | 40 +-- module/mr/js/diff.js | 376 ++++++-------------------- module/mr/lang/zh-cn.php | 7 +- module/mr/model.php | 195 ++++++++++--- module/mr/view/diff.html.php | 2 +- module/mr/view/header.review.html.php | 262 +++++++++--------- module/repo/lang/zh-cn.php | 1 + 9 files changed, 427 insertions(+), 501 deletions(-) create mode 100644 db/update16.0.beta1.sql diff --git a/db/update16.0.beta1.sql b/db/update16.0.beta1.sql new file mode 100644 index 0000000000..6634ac2b81 --- /dev/null +++ b/db/update16.0.beta1.sql @@ -0,0 +1,7 @@ +ALTER TABLE `zt_task` ADD `repo` mediumint unsigned NOT NULL AFTER `activatedDate`; +ALTER TABLE `zt_task` ADD `entry` varchar(255) NOT NULL AFTER `repo`; +ALTER TABLE `zt_task` ADD `lines` varchar(10) NOT NULL AFTER `entry`; +ALTER TABLE `zt_task` ADD `v1` varchar(40) NOT NULL AFTER `lines`; +ALTER TABLE `zt_task` ADD `v2` varchar(40) NOT NULL AFTER `v1`; +ALTER TABLE `zt_task` ADD `mr` mediumint(8) unsigned NOT NULL AFTER `repo`; +ALTER TABLE `zt_bug` ADD `mr` mediumint(8) unsigned NOT NULL AFTER `repo`; diff --git a/module/mr/control.php b/module/mr/control.php index aba3903a58..b8eb5917c6 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -300,7 +300,7 @@ class mr extends control * @access public * @return void */ - public function diff($MRID, $encoding= '') + public function diff($MRID, $encoding = '') { $this->app->loadLang('productplan'); $this->app->loadLang('bug'); @@ -316,7 +316,7 @@ class mr extends control $this->view->rawMR = $rawMR; if(!isset($rawMR->id) or (isset($rawMR->message) and $rawMR->message == '404 Not found') or empty($rawMR)) return $this->display(); - $diffs = $this->mr->getDiffs($MR, $encoding = ''); + $diffs = $this->mr->getDiffs($MR, $encoding); $arrange = $this->cookie->arrange ? $this->cookie->arrange : 'inline'; if($this->server->request_method == 'POST') @@ -782,49 +782,37 @@ class mr extends control } /** - * Add a Bug for this review. + * Add a review for this review. * * @param int $repoID - * @param string $file + * @param int $mr * @param int $v1 * @param int $v2 * @access public * @return void */ - public function addBug($repoID, $file, $v1, $v2) + public function addReview($repoID, $mr, $v1, $v2) { /* Handle the exception that when $repoID is empty. */ if($repoID == "0") $this->send(array()); $this->loadModel('repo'); - if($this->get->repoPath) $file = $this->get->repoPath; if(!empty($_POST)) { - $result = $this->mr->saveBug($repoID, $file, $v1, $v2); + if($this->post->reviewType == 'bug') $result = $this->mr->saveBug($repoID, $mr, $v1, $v2); + if($this->post->reviewType == 'task') $result = $this->mr->saveTask($repoID, $mr, $v1, $v2); if(dao::isError()) die(json_encode($result)); - $bugID = $result['id']; + $objectID = $result['id']; $repo = $this->repo->getRepoById($repoID); /* Handle the exception that when $repo is empty. */ - if(empty($repo)) $this->send(array()); + if(empty($repo) or empty($result)) $this->send(json_encode(array())); - $entry = isset($repo->name) ? $repo->name . '/' . $this->repo->decodePath($file) : ''; - $location = sprintf($this->lang->repo->reviewLocation, $entry, $repo->SCM != 'Subversion' ? substr($v2, 0, 10) : $v2, $this->post->begin, $this->post->end); - if(empty($v1)) - { - $revision = $repo->SCM != 'Subversion' ? substr($v2, 0, 10) : $v2; - $link = $this->repo->createLink('view', "repoID=$repoID&objectID=0&entry={$file}&revision=$v2&showBug=true") . '#L' . $this->post->begin; - } - else - { - $revision = $repo->SCM != 'Subversion' ? substr($v1, 0, 10) : $v1; - $revision .= ' : '; - $revision .= $repo->SCM != 'Subversion' ? substr($v2, 0, 10) : $v2; - $link = $this->repo->createLink('diff', "repoID=$repoID&objectID=0&entry={$file}&oldRevision=$v1&newRevision=$v2&showBug=true") . '#L' . $this->post->begin; - } + $location = sprintf($this->lang->repo->reviewLocation, $this->post->entry ? base64_decode($this->post->entry) : '', $repo->SCM != 'Subversion' ? substr($v2, 0, 10) : $v2, $this->post->begin, $this->post->end); + $link = $this->createLink('mr', 'diff', "mr=$mr") . '#L' . $this->post->begin; - $actionID = $this->loadModel('action')->create('bug', $bugID, 'repoCreated', '', html::a($link, $location)); - $this->loadModel('mail')->sendmail($bugID, $actionID); + $actionID = $this->loadModel('action')->create($this->post->reviewType, $objectID, 'repoCreated', '', html::a($link, $location)); + $this->loadModel('mail')->sendmail($objectID, $actionID); echo json_encode($result); } diff --git a/module/mr/css/common.css b/module/mr/css/common.css index a2da70383a..488645d71d 100644 --- a/module/mr/css/common.css +++ b/module/mr/css/common.css @@ -88,8 +88,8 @@ h3 {font-size: 16px;} /* repo action form */ .repoCode .comment-list, .repoCode .comment-actions {max-width: 900px;} -.repoCode .bugFormContainer {border: 1px solid #bbb; margin: 0 0 0 15px; padding: 10px 20px 10px 10px; max-width: 880px; background: #fff;} -.repoCode .bugFormContainer th {width: 70px;} +.repoCode .reviewFormContainer {border: 1px solid #bbb; margin: 0 0 0 15px; padding: 10px 20px 10px 10px; max-width: 880px; background: #fff;} +.repoCode .reviewFormContainer th {width: 70px;} .repoCode .action-row {display: none;} .repoCode .with-action-row .action-row {display: table-row;} @@ -106,26 +106,26 @@ h3 {font-size: 16px;} .repoCode .comment-cell .panel-body {padding: 6px 10px;} .repoCode .comment-cell .panel-actions.pull-right {margin-right: 0; margin-top: 0;} .repoCode .comment-cell .editing .panel-body, .repoCode .comment-cell .commentContainer.show-form .panel-body {display: none;} -.repoCode .comment-cell .bug-edit-form, {padding: 10px; display: none;} -.repoCode .comment-cell .editing .bug-edit-form, .repoCode .comment-cell .commentContainer.show-form .comment-edit-form {display: block;} +.repoCode .comment-cell .review-edit-form, {padding: 10px; display: none;} +.repoCode .comment-cell .editing .review-edit-form, .repoCode .comment-cell .commentContainer.show-form .comment-edit-form {display: block;} .repoCode .comment {border: 1px solid #e5e5e5; background: #fafafa; padding: 5px 10px; margin-bottom: 10px;} .repoCode .comment .comment-edit-form {margin-top: 10px;} -.repoCode .panel-bug .steps {background: #f1f1f1; padding: 5px 10px;} -.repoCode .panel-bug .bug-edit-form {margin-bottom: 10px;} -.repoCode .panel-bug .panel-body {display: none;} -.repoCode .panel-bug .panel-heading {cursor: pointer;} -.repoCode .panel-bug.show .panel-body {display: block;} -.repoCode .panel-bug.show .icon-chevron-sign-down:before {content: '\e711';} -.repoCode .panel-bug.show-edit-form .bug-edit-form, -.repoCode .panel-bug.show-form .commentForm, +.repoCode .panel-review .steps {background: #f1f1f1; padding: 5px 10px;} +.repoCode .panel-review .review-edit-form {margin-bottom: 10px;} +.repoCode .panel-review .panel-body {display: none;} +.repoCode .panel-review .panel-heading {cursor: pointer;} +.repoCode .panel-review.show .panel-body {display: block;} +.repoCode .panel-review.show .icon-chevron-sign-down:before {content: '\e711';} +.repoCode .panel-review.show-edit-form .review-edit-form, +.repoCode .panel-review.show-form .commentForm, .repoCode .comment.show-form .comment-edit-form {display: block;} -.repoCode .panel-bug .bug-edit-form, -.repoCode .panel-bug.show-form .addComment, -.repoCode .panel-bug .commentForm, +.repoCode .panel-review .review-edit-form, +.repoCode .panel-review.show-form .addComment, +.repoCode .panel-review .commentForm, .repoCode .comment .comment-edit-form, -.repoCode .panel-bug.show-edit-form .panel-body .title, -.repoCode .panel-bug.show-edit-form .bug-date, +.repoCode .panel-review.show-edit-form .panel-body .title, +.repoCode .panel-review.show-edit-form .bug-date, .repoCode .comment.show-form .comment-content, .repoCode .comment.show-form .comment-date {display: none;} .repoCode .text-content {white-space: normal; white-space: pre-line;} @@ -154,8 +154,8 @@ h3 {font-size: 16px;} .repoCode #diff tr.commented .row-tip {right: 0;} .repoCode #diff tr.commented .icon-chat-dot {left: 0;} -.repoCode .panel, .bugFormContainer {transition: border 0.4s;} -.repoCode .panel.highlight, #bugForm.highlight .bugFormContainer {border-color: #e48600;} +.repoCode .panel, .reviewFormContainer {transition: border 0.4s;} +.repoCode .panel.highlight, #reviewForm.highlight .reviewFormContainer {border-color: #e48600;} #bugsPreview {white-space: normal;} #bugsPreview .dropdown-menu {top: -100%; left: 30%; padding-top: 0; min-width: 300px; max-width: 500px;} @@ -166,7 +166,7 @@ h3 {font-size: 16px;} .icon-comments {position: relative; left: -50px;} /* bug form */ -#bugForm, #bugForm table {margin: 0; padding: 0;} +#reviewForm, #reviewForm table {margin: 0; padding: 0;} .panel .table + .panel-footer {border-top: 0; background: #fff;} diff --git a/module/mr/js/diff.js b/module/mr/js/diff.js index a076f1628f..b0ab2c451a 100644 --- a/module/mr/js/diff.js +++ b/module/mr/js/diff.js @@ -15,8 +15,8 @@ $(document).ready(function() { var $diffCode = $('.diff'); var hidePreview; - var $bugsPreview = $('#bugsPreview'); - var $bugsPreviewMenu = $('#bugsPreview').children('.dropdown-menu'); + var $reviewsPreview = $('#reviewsPreview'); + var $reviewsPreviewMenu = $('#reviewsPreview').children('.dropdown-menu'); var $rows = $diffCode.find('tr'); var rowTip = $('#rowTip').html(); var lastLine; @@ -49,12 +49,10 @@ $(document).ready(function() }); var isInline = $.cookie('arrange') == 'inline'; - var $bugFormRow = $('' + (isInline ? '' : '') + ''); - var $bugForm = $('#bugForm'); - var $commentCell = $('#commentCell'); - var $bugPanel = $('#bugPanel'); -// $bugForm.find('input[name="begin"], input[name="end"]').attr('max', lastLine); - $bugFormRow.find('td').append($bugForm.removeClass('hide')); + var $reviewFormRow = $('' + (isInline ? '' : '') + ''); + var $reviewForm = $('#reviewForm'); + var $reviewPanel = $('#reviewPanel'); + $reviewFormRow.find('td').append($reviewForm.removeClass('hide')); var highlight = function($e) { @@ -62,76 +60,48 @@ $(document).ready(function() $e.addClass('highlight'); }; - var createComment = function(comment, $comments) - { - console.log(); - var $comment = $commentCell.clone() - .removeClass('hide') - .attr('id', 'comment-' + comment.id) - .attr('data-comment', comment.id); - $comment.find('.realname').text(comment.realname); - $comment.find('.comment-content').text(comment.comment); - $comment.find('.date').text(comment.date); - $comment.find('.edit').toggle(comment.edit); - $comment.find('.comment-edit-form').attr('action', createLink('repo', 'editComment', 'commentID=' + comment.id)); - - if($comments) - { - if(typeof $comments !== 'object') $comments = $('#bug-' + $comments + ' .comments'); - ($comments.hasClass('comments') ? $comments : $comments.find('.comments')).append($comment); - } - - return $comment; - }; - - var createBug = function(bug, line, $commentRow, show) + var createReview = function(review, line, show) { var commentCount, j; - var $bug = $bugPanel.clone().removeClass('hide').attr('id', 'bug-' + bug.id).attr('data-bug', bug.id); - $bug.find('.bugid').text(bug.id); - $bug.find('.realname').text(bug.realname); - $bug.find('.openedDate').text(bug.openedDate); - $bug.find('.title').text(bug.title); - $bug.find('.steps').toggle(bug.steps != '').html(bug.steps); - $bug.find('.edit').toggle(bug.edit); - $bug.find('.code-lines').text(bug.lines); - $bug.find('.delete').toggle(bug.delete); - $bug.find('input[name="objectID"]').val(bug.id); - $bug.find('.bug-edit-form').attr('action', createLink('repo', 'editBug', 'bugID=' + bug.id)); - $bug.find('a.view-bug').attr('href', createLink('bug', 'view', "bugID=" + bug.id)); - $bug.data('data', bug); - $bug.toggleClass('show', show > 1); - if(show > 2) highlight($bug); + var $review = $reviewPanel.clone().removeClass('hide').attr('id', review.objectType + '-' + review.id); + $review.find('.realname').text(review.realname); + $review.find('.openedDate').text(review.openedDate); + $review.find('.title').text(review.title); + $review.find('.content').toggle(review.content != '').html(review.content); + $review.find('.code-lines').text(review.lines); + $review.find('input[name="objectID"]').val(review.id); + $review.data(review); - if(bug.comments) - { - commentCount = bug.comments.length; - $bugComments = $bug.find('.comments'); - for(j = 0; j < commentCount; j++) - { - createComment(bug.comments[j], $bugComments); - } - } + id = review.objectType == 'bug' ? 'Bug' : 'Task'; + id += '#' + review.id; + if(review.view) id = "" + id + ""; + $review.find('.title').closest('.panel-heading').find('.panel-actions').prepend(id); + if(!review.delete) $review.find('.title').closest('.panel-heading').find('.panel-actions .reviewDelete').hide(); - if(!line && bug.line) line = bug.line; + $review.toggleClass('show', show > 1); + if(show > 2) highlight($review); + + if(!line && review.line) line = review.line; if(line) { - if(!$commentRow) + var $row = $rows.filter('[data-line="' + line + '"]').last(); + if(review.entry) $row = $('#diff[data-entry="' + review.entry + '"]').find('tr').filter('[data-line="' + line + '"]'); + if($row.length == 0) return false; + + $commentRow = $row.next('tr'); + if($row.hasClass('commented')) $commentRow = $row.nextAll('tr.comment-row').first(); + if(!$commentRow.hasClass('comment-row')) { - var $row = $rows.filter('[data-line="' + line + '"]').last(); - $commentRow = $row.next('tr'); - if(!$commentRow.hasClass('comment-row')) - { - $commentRow = $('' + (isInline ? '
' : '
') + ''); - $row.addClass('commented').after($commentRow); - } + $commentRow = $('' + (isInline ? '
' : '
') + ''); + $row.addClass('commented').after($commentRow); } - ($commentRow.hasClass('comment-list') ? $commentRow : $commentRow.find('.comment-list')).append($bug); + + $commentRow.find('.comment-list').append($review); if(show && $commentRow.hasClass('comment-row')) $commentRow.addClass('show'); } - return $bug; + return $review; }; var toggleComment = function($row, show) @@ -182,233 +152,50 @@ $(document).ready(function() $rows.removeClass('with-action-row') $row.addClass('with-action-row'); - $bugForm.find('input[name="begin"]').val(line); - $bugForm.find('input[name="end"]').attr('min', line).val(line); - $bugForm.find('select#assignedTo').val(blamePairs[line]); - $bugForm.find('select#assignedTo').trigger("chosen:updated"); + $reviewForm.find('input[name="begin"]').val(line); + $reviewForm.find('input[name="end"]').attr('min', line).val(line); + $reviewForm.find('select#assignedTo').trigger("chosen:updated"); + $reviewForm.find('input#entry').val($row.closest('table#diff').data('entry')); - $row.after($bugFormRow); + $row.after($reviewFormRow); KindEditor.remove('#commentText'); $('#commentText').kindeditor(); - - var getCommiterLink = createLink('repo', 'ajaxgetcommitter', 'repoID=' + repoID + "&entry=" + file + "&revision=" + revision + "&line=" + line); - var connector = getCommiterLink.indexOf('&') >= 0 ? '&' : '?'; - getCommiterLink = getCommiterLink + connector + 'entry=' + file; - $.ajax({url: getCommiterLink}).done(function(responseText) - { - $bugForm.find('#assignedTo').val(responseText).trigger("chosen:updated"); - }); } - highlight($bugForm); - $bugForm.find('input[name="title"]').focus(); + highlight($reviewForm); + $reviewForm.find('input[name="title"]').focus(); $row.addClass('selected'); } e.stopPropagation(); - }).on('click', '.bugCancel', function() + }).on('click', '.reviewDelete', function(e) { - $rows.removeClass('selected'); - $diffCode.removeClass('with-action-row'); - }).on('click', '.bugEdit', function(e) - { - var $panelBug = $(this).closest('.panel-bug'); + var $review = $(this).closest('.panel-review'); + if(!$review.length) return; - if($panelBug.hasClass('show-edit-form')) + if(confirm(confirmDelete)) { - $panelBug.removeClass('show-edit-form'); - e.stopPropagation(); - return; - } - - $panelBug.addClass('show show-edit-form').find('input[name="commentText"]').val($panelBug.find('.title').first().text()).focus(); - e.stopPropagation(); - return false; - }).on('submit', '.bug-edit-form', function() - { - var $form = $(this); - $(this).ajaxSubmit( - { - success:function(text) - { - var $bug = $form.closest('.panel-bug'); - $bug.find('.title').text(text); - $bug.removeClass('show-edit-form'); - }, - beforeSubmit:function(formData, jqForm) - { - var form = jqForm[0]; - if(!form.commentText.value) - { - alert(contentError); - return false; - } - } - }); - return false; - }).on('click', '.bugEditCancel', function() - { - $(this).closest('.panel-bug').removeClass('show-edit-form'); - }).on('click', '.bugDelete', function(e) - { - var $bug = $(this).closest('.panel-bug'); - if(!$bug.length) return; - - if(confirm(confirmDelete)) - { - var link = createLink('repo', 'deleteBug', 'bugID=' + $bug.data('bug') + '&confirm=yes'); + var link = createLink($review.data('objectType'), 'delete', 'id=' + $review.data('id') + '&confirm=yes'); $.get(link, function(data) { - if(data == 'deleted') + var $commentRow = $review.closest('.comment-row'); + if($commentRow.find('.panel-review').length === 1) { - var $commentRow = $bug.closest('.comment-row'); - if($commentRow.find('.panel-bug').length === 1) - { - $commentRow.removeClass('show').prev('tr').removeClass('commented'); - } - $bug.remove(); + $commentRow.removeClass('show').prev('tr').removeClass('commented'); } + $review.remove(); }); } e.stopPropagation(); return false; - }).on('click', '.addComment', function() - { - $(this).closest('.panel-bug').addClass('show-form').find('.commentForm textarea').focus(); - }).on('click', '.commentCancel', function() - { - $(this).closest('.panel-bug').removeClass('show-form'); - }).on('submit', '.commentForm', function() - { - var $form = $(this); - $form.ajaxSubmit( - { - success:function(json) - { - var $panelBug = $form.closest('.panel-bug'); - $form.find('textarea').val(''); - $panelBug.removeClass('show-form'); - createComment($.parseJSON(json), $panelBug.data('bug')); - }, - beforeSubmit:function(formData, jqForm) - { - var form = jqForm[0]; - if(!form.comment.value) - { - alert(commentError); - return false; - } - } - }); - return false; - }).on('click', '.commentEdit', function() - { - var $comment = $(this).closest('.comment'); - - if($comment.hasClass('show-form')) - { - $comment.removeClass('show-form'); - return; - } - $comment.addClass('show-form').find('textarea').val($comment.find('.comment-content').text()).focus(); - }).on('click', '.commentEditCancel', function() - { - $(this).closest('.comment').removeClass('show-form'); - }).on('submit', '.comment-edit-form', function() - { - var $form = $(this); - $form.ajaxSubmit( - { - success:function(html) - { - var $comment = $form.closest('.comment'); - $comment.find('.comment-content').html(html); - $comment.removeClass('show-form'); - }, - beforeSubmit:function(formData, jqForm) - { - var form = jqForm[0]; - if(!form.commentText.value) - { - alert(contentError); - return false; - } - } - }); - return false; - }).on('click', '.commentDelete', function() - { - var $container = $(this).closest('.commentContainer'); - if(!$container.length) return; - - if(confirm(confirmDeleteComment)) - { - var commentID = $container.data('comment'); - var link = createLink('repo', 'deleteComment', 'commentID=' + commentID + '&confirm=yes'); - - $.get(link, function(data) - { - if(data == 'deleted') - { - var $commentRow = $container.closest('.comment-row'); - if($commentRow.find('.bugContainer, .commentContainer').length === 1) - { - $commentRow.removeClass('show').prev('tr').removeClass('commented'); - } - $container.remove(); - } - }); - } - return false; }).on('click', 'tr.commented', function() { toggleComment($(this)); - }).on('click', '.panel-bug > .panel-heading', function() + }).on('click', '.panel-review > .panel-heading', function() { - $(this).closest('.panel-bug').toggleClass('show'); - }).on('mouseenter', 'tr.commented td .preview-icon', function(e) - { - var $cell = $(this).closest('td'); - var $row = $cell.closest('tr'); - var $commentRow = $row.next('tr'); - - var $bugs = $commentRow.find('.panel-bug'), line = '?'; - $bugsPreviewMenu.children('li:not(.dropdown-header)').remove(); - $bugsPreviewMenu.find('.bug-count').text($bugs.length); - $bugsPreviewMenu.find('.comment-count').text($commentRow.find('.comment').length); - $bugs.each(function() - { - var bug = $(this).data('data'); - line = bug.line; - $bugsPreviewMenu.append('
  • #' + bug.id + ' ' + bug.title + '
  • '); - }); - $bugsPreviewMenu.find('.code-line').text(line); - - $bugsPreview.prependTo($cell); - clearTimeout(hidePreview); - $bugsPreviewMenu.css({top: 0-$bugsPreviewMenu.outerHeight(), left: Math.max(0, e.offsetX-$bugsPreviewMenu.outerWidth())}).addClass('show'); - setTimeout(function(){$bugsPreviewMenu.addClass('in');}, 50); - }).on('mouseleave', 'tr.commented td', function() - { - $bugsPreviewMenu.removeClass('in'); - hidePreview = setTimeout(function(){$bugsPreviewMenu.removeClass('show');}, 200); + $(this).closest('.panel-review').toggleClass('show'); }); - $bugsPreviewMenu.on('click', 'li', function(e) - { - var $bug = $($(this).find('a').data('id')); - if($bug.length) - { - $bug.addClass('show'); - toggleComment($bug.closest('tr.comment-row'), true); - highlight($bug); - - $bugsPreviewMenu.removeClass('in'); - hidePreview = setTimeout(function(){$bugsPreviewMenu.removeClass('show');}, 200); - } - e.stopPropagation(); - }); - - $bugForm.submit(function() + $reviewForm.submit(function() { $(this).ajaxSubmit( { @@ -417,20 +204,42 @@ $(document).ready(function() json = $.parseJSON(json); if(json.result == 'fail') { - alert(json.message); - return false; + var message = ''; + if(typeof(json.message) != 'string') + { + for(i in json.message) + { + if(typeof(json.message[i]) == 'string') + { + message += json.message[i] + '\n'; + } + else + { + for(j in json.message[i]) + { + message += json.message[i][j] + '\n'; + } + } + } + } + else + { + message += json.message + '\n'; + } + alert(message); + return false; } - createBug(json, null, null, 3); + createReview(json, json.line, 3); $diffCode.removeClass('with-action-row'); $diffCode.find('tr.with-action-row.selected').removeClass('selected'); - $bugForm.find('#title').val(''); + $reviewForm.find('#title').val(''); KindEditor.html('#commentText', ''); }, beforeSubmit:function(formData, jqForm) { var form = jqForm[0]; - if(!form.product.value) + if(!form.product.value) { alert(productError); return false; @@ -438,7 +247,7 @@ $(document).ready(function() if(!form.title.value) { alert(titleError); - $bugForm.find('input[name="title"]').focus(); + $reviewForm.find('input[name="title"]').focus(); return false; } } @@ -447,27 +256,22 @@ $(document).ready(function() }).on('change', 'input[name="begin"]', function() { var begin = $(this).val(); - var $end = $bugForm.find('input[name="end"]').attr('min', begin); + var $end = $reviewForm.find('input[name="end"]').attr('min', begin); if(parseInt($end.val()) < parseInt(begin)) { $end.val(begin); } }); - if(bugs) + if(reviews) { - var lineBugs, bugsCount, i; - for(var line in bugs) + var lineReviews; + for(var line in reviews) { if(line) - { - lineBugs = bugs[line]; - bugsCount = lineBugs.length; - - for(i = 0; i < bugsCount; i++) - { - createBug(lineBugs[i], line); - } + { + lineReviews = reviews[line]; + for(var i in lineReviews) createReview(lineReviews[i], line); } } } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 4598f1d2de..c5c87e9a91 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -21,7 +21,7 @@ $lang->mr->linkStory = '关联需求'; $lang->mr->linkBug = '关联Bug'; $lang->mr->linkTask = '关联任务'; $lang->mr->unlink = '取消关联需求、Bug、任务'; -$lang->mr->addBug = '添加评审'; +$lang->mr->addReview = '添加评审'; $lang->mr->id = 'ID'; $lang->mr->mriid = "MR原始ID"; @@ -46,6 +46,11 @@ $lang->mr->reject = '拒绝'; $lang->mr->close = '关闭'; $lang->mr->reopen = '重新打开'; +$lang->mr->reviewType = '评审类型'; +$lang->mr->reviewTypeList = array(); +$lang->mr->reviewTypeList['bug'] = 'Bug'; +$lang->mr->reviewTypeList['task'] = '任务'; + $lang->mr->approvalResult = '评审意见'; $lang->mr->approvalResultList = array(); $lang->mr->approvalResultList['approve'] = '通过'; diff --git a/module/mr/model.php b/module/mr/model.php index 5ff5ec1588..43a9f97221 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -549,7 +549,7 @@ class mrModel extends model public function getDiffs($MR, $encoding = '') { $diffVersions = $this->apiGetDiffVersions($MR->gitlabID, $MR->targetProject, $MR->mriid); - $gitlab = $this->gitlab->getByID($MR->gitlabID); + $gitlab = $this->gitlab->getByID($MR->gitlabID); $this->loadModel('repo'); $repo = new stdclass; @@ -567,7 +567,7 @@ class mrModel extends model foreach ($diffVersions as $diffVersion) { $singleDiff = $this->apiGetSingleDiffVersion($MR->gitlabID, $MR->targetProject, $MR->mriid, $diffVersion->id); - if ($singleDiff->state == 'empty') continue; + if($singleDiff->state == 'empty') continue; $commits = $singleDiff->commits; $diffs = $singleDiff->diffs; foreach ($diffs as $index => $diff) @@ -583,9 +583,10 @@ class mrModel extends model $lines[] = sprintf("--a/%s", $diff->old_path); $lines[] = sprintf("--b/%s", $diff->new_path); $diffLines = explode("\n", $diff->diff); - foreach ($diffLines as $diffLine) $lines[] = $diffLine; + foreach($diffLines as $diffLine) $lines[] = $diffLine; } } + $scm = $this->app->loadClass('scm'); $scm->setEngine($repo); $diff = $scm->engine->parseDiff($lines); @@ -782,45 +783,46 @@ class mrModel extends model * Get review. * * @param int $repoID - * @param string $entry + * @param int $MRID * @param string $revision * @access public * @return array */ - public function getReview($repoID, $entry, $revision) + public function getReview($repoID, $MRID, $revision = '') { $reviews = array(); $bugs = $this->dao->select('t1.*, t2.realname')->from(TABLE_BUG)->alias('t1') - ->leftJoin(TABLE_USER)->alias('t2') - ->on('t1.openedBy = t2.account') + ->leftJoin(TABLE_USER)->alias('t2')->on('t1.openedBy = t2.account') ->where('t1.repo')->eq($repoID) - ->andWhere('t1.entry')->eq($entry) - ->andWhere('t1.v2')->eq($revision) + ->andWhere('t1.mr')->eq($MRID) + ->beginIF($revision)->andWhere('t1.v2')->eq($revision)->fi() ->andWhere('t1.deleted')->eq(0) ->fetchAll('id'); - $comments = $this->dao->select('t1.*, t2.realname')->from(TABLE_ACTION)->alias('t1') - ->leftJoin(TABLE_USER)->alias('t2') - ->on('t1.actor = t2.account') - ->where('t1.objectType')->eq('bug') - ->andWhere('t1.objectID')->in(array_keys($bugs)) - ->andWhere('t1.action')->eq('commented') - ->fetchGroup('objectID', 'id'); foreach($bugs as $bug) { if(common::hasPriv('bug', 'edit')) $bug->edit = true; if(common::hasPriv('bug', 'delete')) $bug->delete = true; + if(common::hasPriv('bug', 'view')) $bug->view = true; $lines = explode(',', trim($bug->lines, ',')); $line = $lines[0]; - $reviews[$line]['bugs'][$bug->id] = $bug; + $reviews[$line]['bug'][$bug->id] = $bug; + } - if(isset($comments[$bug->id])) - { - foreach($comments[$bug->id] as $key => $comment) - { - if($comment->actor == $this->app->user->account) $comment->edit = true; - } - $reviews[$line]['comments'] = $comments; - } + $tasks = $this->dao->select('t1.*, t2.realname')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_USER)->alias('t2')->on('t1.openedBy = t2.account') + ->where('t1.repo')->eq($repoID) + ->andWhere('t1.mr')->eq($MRID) + ->beginIF($revision)->andWhere('t1.v2')->eq($revision)->fi() + ->andWhere('t1.deleted')->eq(0) + ->fetchAll('id'); + foreach($tasks as $task) + { + if(common::hasPriv('task', 'edit')) $task->edit = true; + if(common::hasPriv('task', 'delete')) $task->delete = true; + if(common::hasPriv('task', 'view')) $task->view = true; + $lines = explode(',', trim($task->lines, ',')); + $line = $lines[0]; + $reviews[$line]['task'][$task->id] = $task; } return $reviews; @@ -878,43 +880,154 @@ class mrModel extends model * Save bug. * * @param int $repoID - * @param string $file + * @param int $mr * @param int $v1 * @param int $v2 * @access public * @return array */ - public function saveBug($repoID, $file, $v1, $v2) + public function saveBug($repoID, $mr, $v1, $v2) { $now = helper::now(); $data = fixer::input('post') - ->add('severity', 3) + ->stripTags('commentText', $this->config->allowedTags) + ->add('pri', 2) + ->add('severity', 2) ->add('openedBy', $this->app->user->account) ->add('openedDate', $now) ->add('openedBuild', 'trunk') - ->add('assignedDate', $now) ->add('type', 'codeimprovement') ->add('repo', $repoID) - ->add('entry', $file) + ->add('mr', $mr) ->add('lines', $this->post->begin . ',' . $this->post->end) ->add('v1', $v1) ->add('v2', $v2) - ->remove('commentText,begin,end,uid') + ->cleanInt('module,execution,mr,repo') + ->remove('begin,end,uid,reviewType,taskExecution,taskModule,taskAssignedTo') ->get(); - $data->steps = $this->loadModel('file')->pasteImage($this->post->commentText, $this->post->uid); - $this->dao->insert(TABLE_BUG)->data($data)->exec(); + $data->steps = $this->loadModel('file')->pasteImage($data->commentText, $this->post->uid); + if($data->assignedTo) $data->assignedDate = $now; + unset($data->commentText); + + $this->loadModel('bug'); + foreach(explode(',', $this->config->bug->create->requiredFields) as $requiredField) + { + $requiredField = trim($requiredField); + if(empty($requiredField)) continue; + if(!isset($data->$requiredField)) continue; + if(empty($data->$requiredField)) + { + $fieldName = $requiredField; + if(isset($this->lang->bug->$requiredField)) $fieldName = $this->lang->bug->$requiredField; + dao::$errors[] = sprintf($this->lang->error->notempty, $fieldName); + } + } + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + + $this->dao->insert(TABLE_BUG)->data($data)->autocheck()->exec(); if(!dao::isError()) { $bugID = $this->dao->lastInsertID(); - $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); + $this->loadModel('file')->updateObjectID($this->post->uid, $bugID, 'bug'); setcookie("repoPairs[$repoID]", $data->product); - return array('result' => 'success', 'id' => $bugID, 'realname' => $this->app->user->realname, 'openedDate' => substr($now, 5, 11), 'edit' => true, 'delete' => true, 'lines' => $data->lines, 'line' => $this->post->begin, 'steps' => $data->steps, 'title' => $data->title); + $bugInfo = array(); + $bugInfo['result'] = 'success'; + $bugInfo['id'] = $bugID; + $bugInfo['realname'] = $this->app->user->realname; + $bugInfo['openedDate'] = substr($now, 5, 11); + $bugInfo['edit'] = common::hasPriv('bug', 'edit'); + $bugInfo['view'] = common::hasPriv('bug', 'view'); + $bugInfo['delete'] = common::hasPriv('bug', 'delete'); + $bugInfo['lines'] = $data->lines; + $bugInfo['line'] = $this->post->begin; + $bugInfo['content'] = $data->steps; + $bugInfo['title'] = $data->title; + $bugInfo['objectType'] = 'bug'; + $bugInfo['entry'] = $data->entry; + return $bugInfo; } - return array('result' => 'fail', 'message' => join("\n", dao::getError())); + return array('result' => 'fail', 'message' => dao::getError()); + } + + /** + * Save task. + * + * @param int $repoID + * @param int $mr + * @param int $v1 + * @param int $v2 + * @access public + * @return array + */ + public function saveTask($repoID, $mr, $v1, $v2) + { + $now = helper::now(); + $data = fixer::input('post')->stripTags('commentText', $this->config->allowedTags)->get(); + + $task = new stdclass(); + $task->execution = (int)$data->taskExecution; + $task->project = (int)$this->dao->select('project')->from(TABLE_PROJECT)->where('id')->eq($task->execution)->fetch('project'); + $task->module = (int)$data->taskModule; + $task->name = $data->title; + $task->type = 'devel'; + $task->pri = '2'; + $task->status = 'wait'; + $task->version = '1'; + $task->openedBy = $this->app->user->account; + $task->assignedTo = $data->taskAssignedTo; + $task->repo = (int)$repoID; + $task->mr = (int)$mr; + $task->lines = $this->post->begin . ',' . $this->post->end; + $task->entry = $data->entry; + $task->v1 = $v1; + $task->v2 = $v2; + $task->desc = $this->loadModel('file')->pasteImage($data->commentText, $this->post->uid); + if($task->assignedTo) $task->assignedDate = $now; + + $this->loadModel('task'); + foreach(explode(',', $this->config->task->create->requiredFields) as $requiredField) + { + $requiredField = trim($requiredField); + if(empty($requiredField)) continue; + if(!isset($task->$requiredField)) continue; + if(empty($task->$requiredField)) + { + $fieldName = $requiredField; + if(isset($this->lang->task->$requiredField)) $fieldName = $this->lang->task->$requiredField; + dao::$errors[] = sprintf($this->lang->error->notempty, $fieldName); + } + } + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + + $this->dao->insert(TABLE_TASK)->data($task)->autocheck()->exec(); + + if(!dao::isError()) + { + $taskID = $this->dao->lastInsertID(); + $this->file->updateObjectID($this->post->uid, $taskID, 'task'); + + $taskInfo = array(); + $taskInfo['result'] = 'success'; + $taskInfo['id'] = $taskID; + $taskInfo['realname'] = $this->app->user->realname; + $taskInfo['openedDate'] = substr($now, 5, 11); + $taskInfo['edit'] = common::hasPriv('task', 'edit'); + $taskInfo['view'] = common::hasPriv('task', 'view'); + $taskInfo['delete'] = common::hasPriv('task', 'delete'); + $taskInfo['lines'] = $data->lines; + $taskInfo['line'] = $this->post->begin; + $taskInfo['content'] = $task->desc; + $taskInfo['title'] = $data->title; + $taskInfo['objectType'] = 'task'; + $taskInfo['entry'] = $task->entry; + return $taskInfo; + } + + return array('result' => 'fail', 'message' => dao::getError()); } /** @@ -960,13 +1073,17 @@ class mrModel extends model /** * Get last review info. * - * @param string $entry + * @param int $repoID * @access public * @return object */ - public function getLastReviewInfo($entry) + public function getLastReviewInfo($repoID) { - return $this->dao->select('*')->from(TABLE_BUG)->where('entry')->eq($entry)->orderby('id_desc')->fetch(); + $lastReview = new stdclass(); + $lastReview->bug = $this->dao->select('*')->from(TABLE_BUG)->where('repo')->eq($repoID)->orderby('id_desc')->fetch(); + $lastReview->task = $this->dao->select('*')->from(TABLE_TASK)->where('repo')->eq($repoID)->orderby('id_desc')->fetch(); + + return $lastReview; } /** diff --git a/module/mr/view/diff.html.php b/module/mr/view/diff.html.php index 85d2afadbe..e43199ba35 100644 --- a/module/mr/view/diff.html.php +++ b/module/mr/view/diff.html.php @@ -69,7 +69,7 @@
    - +
    contents)) continue;?> contents as $content):?> diff --git a/module/mr/view/header.review.html.php b/module/mr/view/header.review.html.php index 0bcae252cc..0511c5d59a 100644 --- a/module/mr/view/header.review.html.php +++ b/module/mr/view/header.review.html.php @@ -1,9 +1,6 @@ mr->getLastReviewInfo($file); -$repoModule = isset($lastReview) && isset($lastReview->module) ? $lastReview->module : ''; +$lastReview = $this->mr->getLastReviewInfo($repo->id); /* Get product pairs. */ if(isset($repo->product) and $repo->product) @@ -16,108 +13,91 @@ else } /* get product by cookie or last review in this file. */ -$repoProduct = isset($_COOKIE['repoPairs'][$repoID]) ? $_COOKIE['repoPairs'][$repoID] : ''; -$repoProduct = isset($lastReview) && isset($lastReview->product) ? $lastReview->product : $repoProduct; -$repoProduct = isset($products[$repoProduct]) ? $repoProduct : key($products); -$executions = $this->mr->getExecutionPairs($repoProduct); -$modules = $this->loadModel('tree')->getOptionMenu($repoProduct, $viewType = 'bug', $startModuleID = 0); -$users = $this->loadModel('user')->getPairs('devfirst|nodeleted|noclosed'); -$products = array('' => '') + $products; -$executions = array('' => '') + $executions; +$repoProduct = isset($_COOKIE['repoPairs'][$repoID]) ? $_COOKIE['repoPairs'][$repoID] : ''; +$repoProduct = $lastReview->bug && isset($lastReview->bug->product) ? $lastReview->bug->product : $repoProduct; +$repoProduct = isset($products[$repoProduct]) ? $repoProduct : key($products); +$bugRepoModule = (isset($lastReview->bug) && $lastReview->bug->product == $repoProduct) ? $lastReview->bug->module : ''; +$executions = $this->mr->getExecutionPairs($repoProduct); +$modules = $this->loadModel('tree')->getOptionMenu($repoProduct, $viewType = 'bug', $startModuleID = 0); +$users = $this->loadModel('user')->getPairs('devfirst|nodeleted|noclosed'); +$products = array('' => '') + $products; +$executions = array('' => '') + $executions; -$cwd = getcwd(); -$commiters = $this->user->getCommiters(); -$blamePairs = array(); -if($suffix and $suffix != 'binary' and strpos($this->config->repo->images, "|$suffix|") === false) +$taskExecutions = $executions; +if(empty($repo->product)) $taskExecutions = array('' => '') + $this->loadModel('execution')->getPairs(); +$repoExecution = $lastReview->task && isset($lastReview->task->execution) ? $lastReview->task->execution : $this->session->execution; +$repoExecution = isset($taskExecutions[$repoExecution]) ? $repoExecution : key($taskExecutions); +$taskModules = array('' => ''); +$taskMembers = array('' => ''); +if($repoExecution) { - $blames = $this->scm->blame($entry, $info->revision); - foreach($blames as $line => $blame) - { - if(!isset($blame['committer'])) - { - if(isset($blamePairs[$line - 1])) $blamePairs[$line] = $blamePairs[$line - 1]; - continue; - } - $blamePairs[$line] = zget($commiters, $blame['committer'], $blame['committer']); - } + $taskModules = $this->loadModel('tree')->getTaskOptionMenu($repoExecution, 0, 0, 'allModule'); + $taskRepoModule = (isset($lastReview->task) && $lastReview->task->execution == $repoExecution) ? $lastReview->task->module : ''; + $taskMembers = $this->loadModel('user')->getTeamMemberPairs($repoExecution, 'execution', 'nodeleted'); } -chdir($cwd); -//$reviews = $this->mr->getReview($repoID, $file, $info->revision); -$reviews = $this->mr->getReview($repoID, $file, ''); -$v1 = isset($oldRevision) ? $oldRevision : 0; +$reviews = $this->mr->getReview($repoID, $MR->id); +$v1 = isset($oldRevision) ? $oldRevision : 0; + $this->loadModel('repo'); -// $bugUrl = $this->repo->createLink('addBug', "repoID=$repoID&file=$file&v1=$v1&v2={$info->revision}"); -$bugUrl = $this->createLink('mr', 'addBug', "repoID=$repoID&file=$file&v1=$v1&v2="); -$commentUrl = $this->createLink('mr', 'addComment'); + +$taskModuleSelect = html::select('taskModule', $taskModules, $taskRepoModule, 'class="form-control chosen"'); +$taskUserSelect = html::select('taskAssignedTo', $taskMembers, '', 'class="form-control chosen"'); +$taskExecutionSelect = html::select('taskExecution', $taskExecutions, $repoExecution, 'class="form-control chosen"'); + +$reviewUrl = $this->createLink('mr', 'addReview', "repoID=$repoID&mr={$MR->id}&v1=$v1&v2="); $productSelect = html::select('product', $products, $repoProduct, 'class="product form-control chosen" onchange="changeProduct(this)"'); $branches = $this->loadModel('branch')->getPairs($repoProduct); -$moduleSelect = html::select('module', $modules, $repoModule, 'class="form-control chosen"'); -$executionSelect = html::select('execution', $executions, '', 'class="form-control chosen"'); +$moduleSelect = html::select('module', $modules, $bugRepoModule, 'class="form-control chosen"'); +$executionSelect = html::select('execution', $executions, '', 'class="form-control chosen" onchange="changeExecution(this)"'); $typeSelect = html::select('repoType', $lang->repo->typeList, '', 'class="form-control chosen"'); $userSelect = html::select('assignedTo', $users, '', 'class="form-control chosen assignedTo"'); -$bugs = array(); + +$lineReviews = array(); foreach($reviews as $line => $lineReview) { - $lineBugs = array(); - foreach ($lineReview['bugs'] as $bugID => $bug) + foreach($lineReview as $objectType => $objects) { - $lineBug = array(); - $lineBug['id'] = $bugID; - $lineBug['line'] = $line; - $lineBug['title'] = $bug->title; - $lineBug['steps'] = $bug->steps; - $lineBug['realname'] = $bug->realname; - $lineBug['openedDate'] = substr($bug->openedDate, 5, 11); - $lineBug['lines'] = $bug->lines; - if($bug->edit) $lineBug['edit'] = true; - if($bug->delete) $lineBug['delete'] = true; - - if(isset($lineReview['comments'])) + foreach($objects as $objectID => $object) { - if(isset($lineReview['comments'][$bugID])) - { - $comments = $lineReview['comments'][$bugID]; - $bugComments = array(); - foreach ($comments as $commentID => $comment) - { - $bugComment = array( - 'id' => $comment->id, - 'edit' => $comment->edit, - 'realname' => $comment->realname, - 'date' => substr($comment->date, 5, 11), - 'comment' => $comment->comment, - ); - $bugComments[] = $bugComment; - } - $lineBug['comments'] = $bugComments; - } + $lineReview = array(); + $lineReview['id'] = $objectID; + $lineReview['line'] = $line; + $lineReview['title'] = $objectType == 'bug' ? $object->title : $object->name; + $lineReview['content'] = $objectType == 'bug' ? $object->steps : $object->desc; + $lineReview['realname'] = $object->realname; + $lineReview['openedDate'] = substr($object->openedDate, 5, 11); + $lineReview['lines'] = $object->lines; + $lineReview['objectType'] = $objectType; + $lineReview['entry'] = $object->entry; + $lineReview['edit'] = common::hasPriv($objectType, 'edit'); + $lineReview['delete'] = common::hasPriv($objectType, 'delete'); + $lineReview['view'] = common::hasPriv($objectType, 'view'); + $lineReviews[$line][] = $lineReview; } - $lineBugs[] = $lineBug; } - - $bugs[$line] = $lineBugs; } -js::set('bugs', $bugs); +js::set('reviews', $lineReviews); js::set('productError', $lang->repo->error->product); js::set('contentError', $lang->repo->error->commentText); js::set('titleError', $lang->repo->error->title); js::set('commentError', $lang->repo->error->comment); js::set('submit', $lang->repo->submit); js::set('cancel', $lang->repo->cancel); -js::set('confirmDelete', $lang->repo->notice->deleteBug); -js::set('confirmDeleteComment', $lang->repo->notice->deleteComment); +js::set('confirmDelete', $lang->repo->notice->deleteReview); js::set('repoID', $repoID); -// js::set('revision', $info->revision); +js::set('MRID', $MR->id); js::set('revision', ''); -js::set('file', $file); -js::set('blamePairs', $blamePairs); ?> - - -
    + + +
    fileName;?>
    + + + + - + + + + - + - @@ -160,8 +149,9 @@ js::set('blamePairs', $blamePairs);
    mr->reviewType;?>mr->reviewTypeList, 'bug', "class='form-control' onchange=changeReviewType(this)")?>
    repo->product?> @@ -131,13 +111,22 @@ js::set('blamePairs', $blamePairs);
    repo->execution?> +
    +
    +
    repo->type?>
    repo->module?>
    repo->assign?> +
    +
    +
    repo->lines?>
    @@ -149,7 +138,7 @@ js::set('blamePairs', $blamePairs);
    repo->title?> +
    - repo->submit, '', 'btn btn-wide btn-primary bugSubmit');?> + repo->submit, '', 'btn btn-wide btn-primary reviewSubmit');?> cancel, "onclick='hiddenForm()'", 'btn btn-wide');?> +
    @@ -169,73 +159,87 @@ js::set('blamePairs', $blamePairs);
    -
    -user->errorDeny, $lang->repo->common, $lang->repo->addBug);?> + +user->errorDeny, $lang->repo->common, $lang->repo->addReview);?>
    -
    +
    - - Bug# - - Bug# - - - - - - - +
    - +

    repo->lines?>    

    -
    - - - -
    -

    -
    - - -
    - - - - -
    -
    - +

    -
    - :     -
    - - - -
    -
    -