Skip to content

The Unified and Autonomous Development Platform

Add CompareResultPanel to display navigatable commit comparison results.

robin shineb40638aea17e
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java
index ce058e8b9d..621d5a56ef 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/AbstractWicketConfig.java
@@ -12,6 +12,7 @@ import org.apache.wicket.markup.html.pages.AbstractErrorPage;
import org.apache.wicket.protocol.http.WebApplication;
import com.pmease.commons.bootstrap.Bootstrap;
+import com.pmease.commons.wicket.behavior.StickyBehavior;
import de.agilecoders.wicket.core.settings.BootstrapSettings;
@@ -62,7 +63,8 @@ public abstract class AbstractWicketConfig extends WebApplication {
target.add(page.getSessionFeedback());
for (Component component: map.values()) {
- target.prependJavaScript(String.format("$('#%s').trigger('sticky_kit:detach');", component.getMarkupId()));
+ if (!component.getBehaviors(StickyBehavior.class).isEmpty())
+ target.prependJavaScript(String.format("$('#%s').trigger('sticky_kit:detach');", component.getMarkupId()));
target.appendJavaScript((String.format("$(document).trigger('replace', '%s');", component.getMarkupId())));
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
index c20c5731c2..da2d01c274 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
@@ -1,9 +1,10 @@
package com.pmease.gitplex.core.comment;
+import java.io.Serializable;
import java.util.List;
import java.util.Map;
-public interface InlineCommentSupport {
+public interface InlineCommentSupport extends Serializable {
Map<Integer, List<InlineComment>> getOldComments();
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java
index 9b72873174..4a788de23d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java
@@ -1,7 +1,10 @@
package com.pmease.gitplex.core.comment;
+import javax.annotation.Nullable;
+
public interface InlineContextAware {
+ @Nullable
InlineContext getInlineContext(InlineComment comment);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index d0882bf84b..4d52aa6960 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -5,8 +5,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
@@ -27,8 +29,11 @@ import org.hibernate.criterion.Restrictions;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.commons.util.LockUtils;
+import com.pmease.commons.util.Triple;
+import com.pmease.gitplex.core.comment.ChangeComments;
import com.pmease.gitplex.core.gatekeeper.checkresult.Approved;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Disapproved;
@@ -121,6 +126,8 @@ public class PullRequest extends AbstractEntity {
private transient Set<String> pendingCommits;
+ private transient Map<ChangeKey, ChangeComments> commentsCache = new HashMap<>();
+
/**
* Get title of this merge request.
*
@@ -523,5 +530,22 @@ public class PullRequest extends AbstractEntity {
&& getIntegrationInfo() != null
&& getIntegrationInfo().getIntegrationHead() != null;
}
+
+ public ChangeComments getComments(RevAwareChange change) {
+ ChangeKey key = new ChangeKey(change.getOldRevision(), change.getNewRevision(), change.getPath());
+ ChangeComments comments = commentsCache.get(key);
+ if (comments == null) {
+ comments = new ChangeComments(this, change);
+ commentsCache.put(key, comments);
+ }
+ return comments;
+ }
+ private static class ChangeKey extends Triple<String, String, String> {
+
+ public ChangeKey(String oldCommit, String newCommit, String file) {
+ super(oldCommit, newCommit, file);
+ }
+
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
index 443c6cbd52..2c9edbfc2e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
@@ -766,10 +766,18 @@ h2.section-title { margin: 18px 0; font-size: 16px; }
.changed-files li:before {font-family: "ponticons"; font-size: 17px;}
.changed-files a {color: black;}
+/* COMPARE RESULT */
+.compare-result>tbody>tr>td {border: 1px solid #DDD;}
+.compare-result>tbody>tr>td.nav {width: 20%; padding: 8px;}
+.compare-result>tbody>tr>td.nav>div {overflow-x: auto;}
+.compare-result>tbody>tr>td.nav a.active {background: #0F89E7; color: white; border-radius: 2px; padding: 2px;}
+.compare-result>tbody>tr>td.content>div>div.error {padding: 20px; font-size: 24px; font-style: italic;}
+
/* TEXT DIFF */
-.text-diff>.panel-heading {z-index: 10; border-top: 1px solid #DDD;}
-.text-diff>.panel-heading .pull-right {margin-left: 12px;}
-.text-diff>.body {overflow: auto;}
+.text-diff>.head {border: 1px solid #DDD; padding: 8px; z-index: 10; background: white;}
+.text-diff>.body {border: 1px solid #DDD; border-top: none;}
+.text-diff>.head .title {font-size: 16px;}
+.text-diff>.head .pull-right {margin-left: 12px;}
.table-diff .line.diff>td.line-no {color: #999; width: 1%; text-align: right; white-space: nowrap;}
.table-diff .line.diff td.text, .table-diff .hunk-head td.content {
@@ -999,8 +1007,12 @@ ul.status-help li:last-child .description {border-bottom: none;}
.request-detail>.updates>.update>.commits tr:hover td {background: #F7ECB9;}
.request-detail>.updates>.update>.commits .commit-message>.full {margin-bottom: 4px;}
-.request-detail .compare>.head {background: white; z-index: 90; padding-bottom: 20px;}
+.request-detail .compare>.head {background: #F2F2F2; z-index: 90; padding: 8px;
+ border: 1px solid #DDD;}
+.request-detail .compare>.head>.pull-left:FIRST-CHILD {margin-right: 16px;}
+.request-detail .compare>.head>.pull-left:LAST-CHILD {margin-top: 3px;}
.request-detail .compare>.head .tooltip-inner {max-width: 500px;}
+
.content>.commit-choice {max-height: 600px; padding: 8px 0; overflow-y: scroll;}
.content>.commit-choice a {text-decoration: none; color: #333; display: block; padding: 8px;}
.content>.commit-choice li {border-bottom: 1px dotted #BBB;}
@@ -1012,12 +1024,6 @@ table.old-vs-new td.old {width: 140px; text-align: left;}
table.old-vs-new td.new {width: 140px; text-align: right;}
table.old-vs-new td.vs {width: 1px; text-align: center; font-weight: bold;}
-.content>.compare-result {overflow-y: auto; max-height: 600px; width: 400px;
- white-space: nowrap; border: none; margin-bottom: 0;}
-.content>.compare-result a {padding: 2px;}
-.content>.compare-result a.active {background: #0F89E7; color: white; border-radius: 2px;}
-.content>.compare-result>.panel-heading .pull-right {color: #888;}
-
table.verifications td {vertical-align: top; white-space: nowrap; color: #444;}
table.verifications {margin-bottom: 1px;}
table.verifications .fa {display: none;}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
index 8070adb88a..4d9186489b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
@@ -17,28 +17,22 @@
</wicket:enclosure>
<div wicket:id="blobContent"></div>
<wicket:fragment wicket:id="notChangedFrag">
- <div class="panel panel-default">
- <div class="panel-heading">
- <div class="panel-title"><span wicket:id="title"></span> <span class="label label-warning">unchanged</span></div>
- </div>
- <div wicket:id="content" class="panel-body"></div>
+ <div class="head">
+ <div class="title"><span wicket:id="title"></span> <span class="label label-warning">unchanged</span></div>
+ <div wicket:id="content" class="body"></div>
</div>
</wicket:fragment>
<wicket:fragment wicket:id="emptyFileFrag">
- <div class="panel panel-default">
- <div class="panel-heading"><span wicket:id="summary"></span></div>
- <div class="panel-body">
- <i class='fa fa-info-circle'></i> <em>File is empty</em>
- </div>
- </div>
+ <div class="head"><span wicket:id="summary"></span></div>
+ <div class="body">
+ <i class='fa fa-info-circle'></i> <em>File is empty</em>
+ </div>
</wicket:fragment>
<wicket:fragment wicket:id="binaryFileFrag">
- <div class="panel panel-default">
- <div class="panel-heading"><span wicket:id="summary"></span></div>
- <div class="panel-body">
- <i class='fa fa-info-circle'></i> <em>Binary files</em>
- </div>
- </div>
+ <div class="head"><span wicket:id="summary"></span></div>
+ <div class="body">
+ <i class='fa fa-info-circle'></i> <em>Binary files</em>
+ </div>
</wicket:fragment>
<wicket:fragment wicket:id="nonFileDiffFrag">
<div class="blob-diff">
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.html
new file mode 100644
index 0000000000..4a26b851cc
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.html
@@ -0,0 +1,8 @@
+<wicket:panel>
+ <table class="compare-result">
+ <tr>
+ <td class="nav"><div wicket:id="nav"></div></td>
+ <td class="content"><div wicket:id="content"></div></td>
+ </tr>
+ </table>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java
new file mode 100644
index 0000000000..2700eb930d
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java
@@ -0,0 +1,196 @@
+package com.pmease.gitplex.web.component.diff;
+
+import static com.pmease.commons.git.Change.Status.UNCHANGED;
+
+import java.util.List;
+import java.util.Objects;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
+import org.eclipse.jgit.lib.FileMode;
+
+import com.pmease.commons.git.Change;
+import com.pmease.commons.git.RevAwareChange;
+import com.pmease.commons.git.TreeNode;
+import com.pmease.commons.wicket.behavior.StickyBehavior;
+import com.pmease.gitplex.core.comment.InlineComment;
+import com.pmease.gitplex.core.comment.InlineCommentSupport;
+import com.pmease.gitplex.core.comment.InlineContext;
+import com.pmease.gitplex.core.comment.InlineContextAware;
+import com.pmease.gitplex.core.model.Repository;
+
+@SuppressWarnings("serial")
+public abstract class CompareResultPanel extends Panel implements InlineContextAware {
+
+ private final IModel<Repository> repoModel;
+
+ private final String oldCommit;
+
+ private final String newCommit;
+
+ private Change activeChange;
+
+ private WebMarkupContainer changeNav;
+
+ private Component changeContent;
+
+ public CompareResultPanel(String id, IModel<Repository> repoModel,
+ String oldCommit, String newCommit, @Nullable String file) {
+ super(id);
+
+ this.repoModel = repoModel;
+ this.oldCommit = oldCommit;
+ this.newCommit = newCommit;
+
+ List<Change> changes = repoModel.getObject().getChanges(oldCommit, newCommit);
+ if (file != null) {
+ for (Change each: repoModel.getObject().getChanges(oldCommit, newCommit)) {
+ if (each.getPath().equals(file)) {
+ activeChange = each;
+ break;
+ }
+ }
+ if (activeChange == null) {
+ List<TreeNode> result = repoModel.getObject().git().listTree(newCommit, file);
+ if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {
+ activeChange = new Change(UNCHANGED, file, file,
+ result.get(0).getMode(), result.get(0).getMode());
+ }
+ }
+ } else if (!changes.isEmpty()) {
+ activeChange = changes.get(0);
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(changeNav = newChangeNav(activeChange == null || activeChange.getStatus() != UNCHANGED));
+
+ if (activeChange != null) {
+ changeContent = new BlobDiffPanel("content", repoModel,
+ new RevAwareChange(activeChange, oldCommit, newCommit),
+ getInlineCommentSupport(activeChange));
+ } else {
+ changeContent = new Label("content", "<div class='error fa fa-alert-o'> File not exist.</div>");
+ changeContent.setEscapeModelStrings(false);
+ }
+ changeContent.setOutputMarkupId(true);
+ add(changeContent);
+ }
+
+ private WebMarkupContainer newChangeNav(boolean changedOnly) {
+ if (changedOnly) {
+ changeNav = new ChangedFilesPanel("nav", repoModel, oldCommit, newCommit) {
+
+ @Override
+ protected WebMarkupContainer newBlobLink(String id, Change change) {
+ return new BlobLink(id, change);
+ }
+ };
+ } else {
+ changeNav = new DiffTreePanel("nav", repoModel, oldCommit, newCommit) {
+
+ @Override
+ protected WebMarkupContainer newBlobLink(String id, final Change change) {
+ return new BlobLink(id, change);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (activeChange != null)
+ reveal(activeChange);
+ }
+
+ };
+ }
+ changeNav.add(new StickyBehavior(this));
+ return changeNav;
+ }
+
+ public boolean isChangedOnly() {
+ return changeNav instanceof ChangedFilesPanel;
+ }
+
+ @Override
+ protected void onDetach() {
+ repoModel.detach();
+ super.onDetach();
+ }
+
+ protected abstract InlineCommentSupport getInlineCommentSupport(Change change);
+
+ private class BlobLink extends AjaxLink<Void> {
+
+ private final Change change;
+
+ BlobLink(String id, Change change) {
+ super(id);
+
+ this.change = change;
+ }
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+
+ if (activeChange != null
+ && Objects.equals(change.getOldPath(), activeChange.getOldPath())
+ && Objects.equals(change.getNewPath(), activeChange.getNewPath())) {
+ tag.put("class", "active");
+ }
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ activeChange = change;
+ changeContent = new BlobDiffPanel(changeContent.getId(), repoModel,
+ new RevAwareChange(change, oldCommit, newCommit), getInlineCommentSupport(change));
+ CompareResultPanel.this.replace(changeContent);
+ target.add(changeContent);
+
+ String script = String.format("$('#%s').find('a.active').removeClass('active');", changeNav.getMarkupId());
+ target.prependJavaScript(script);
+
+ target.add(this);
+
+ onChangeSelection(target, change);
+ }
+
+ }
+
+ protected abstract void onChangeSelection(AjaxRequestTarget target, Change change);
+
+ public void toggleChangedOnly(AjaxRequestTarget target) {
+ changeNav = newChangeNav(!(changeNav instanceof ChangedFilesPanel));
+ replace(changeNav);
+ target.add(changeNav);
+ }
+
+ @Override
+ public InlineContext getInlineContext(final InlineComment comment) {
+ return visitChildren(InlineContextAware.class, new IVisitor<Component, InlineContext>() {
+
+ @Override
+ public void component(Component object, IVisit<InlineContext> visit) {
+ InlineContextAware inlineContextAware = (InlineContextAware) object;
+ visit.stop(inlineContextAware.getInlineContext(comment));
+ }
+
+ });
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
index d1f558082b..65ba575c74 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
@@ -1,33 +1,32 @@
<wicket:panel>
- <div class="text-diff panel panel-default">
- <div wicket:id="head" class="panel-heading clearfix">
+ <div class="text-diff">
+ <div wicket:id="head" class="head clearfix">
<div class="pull-left">
<span wicket:id="diffStat"></span>
- <span wicket:id="title" class="panel-title"></span>
+ <span wicket:id="title" class="title"></span>
</div>
<div class="pull-right">
- <span wicket:id="diffOptionsTrigger" class="btn btn-sm btn-default" title="Diff options"><i class="fa fa-gear"></i> <i class="caret"></i></span>
+ <span wicket:id="diffOptionsTrigger" class="btn btn-xs btn-default" title="Diff options"><i class="fa fa-gear"></i> <i class="caret"></i></span>
<div wicket:id="diffOptions"></div>
</div>
<div class="pull-right">
- <span wicket:id="displayFull" class="btn btn-sm btn-default" title="Expand to display full file"><i class="fa fa-file-txt"></i> </span>
+ <span wicket:id="displayFull" class="btn btn-xs btn-default" title="Expand to display full file"><i class="fa fa-file-txt"></i> </span>
</div>
<div class="btn-group pull-right">
- <span wicket:id="prevComment" class="btn btn-default btn-sm comments-nav" title="Previous commented line"><i class="fa fa-arrow-up"></i> <i class="fa fa-comments"></i></span>
- <span wicket:id="nextComment" class="btn btn-default btn-sm comments-nav" title="Next commented line"><i class="fa fa-arrow-down"></i> <i class="fa fa-comments"></i></span>
- <span wicket:id="showComments" class="btn btn-default btn-sm show-comments" title="Show comments"><i class="fa fa-eye-open"></i> <i class="fa fa-comments"></i></span>
- <span wicket:id="hideComments" class="btn btn-default btn-sm hide-comments" title="Hide comments"><i class="fa fa-eye-slash"></i> <i class="fa fa-comments"></i></span>
+ <span wicket:id="prevComment" class="btn btn-default btn-xs comments-nav" title="Previous commented line"><i class="fa fa-arrow-up"></i> <i class="fa fa-comments"></i></span>
+ <span wicket:id="nextComment" class="btn btn-default btn-xs comments-nav" title="Next commented line"><i class="fa fa-arrow-down"></i> <i class="fa fa-comments"></i></span>
+ <span wicket:id="showComments" class="btn btn-default btn-xs show-comments" title="Show comments"><i class="fa fa-eye-open"></i> <i class="fa fa-comments"></i></span>
+ <span wicket:id="hideComments" class="btn btn-default btn-xs hide-comments" title="Hide comments"><i class="fa fa-eye-slash"></i> <i class="fa fa-comments"></i></span>
</div>
<div wicket:id="diffNavs" class="btn-group pull-right">
- <span wicket:id="prevDiff" class="btn btn-default btn-sm" title="Previous changed block"><i class="fa fa-arrow-up"></i> <i class="fa fa-diff"></i></span>
- <span wicket:id="nextDiff" class="btn btn-default btn-sm" title="Next changed block"><i class="fa fa-arrow-down"></i> <i class="fa fa-diff"></i></span>
+ <span wicket:id="prevDiff" class="btn btn-default btn-xs" title="Previous changed block"><i class="fa fa-arrow-up"></i> <i class="fa fa-diff"></i></span>
+ <span wicket:id="nextDiff" class="btn btn-default btn-xs" title="Next changed block"><i class="fa fa-arrow-down"></i> <i class="fa fa-diff"></i></span>
</div>
<div class="pull-right">
<span wicket:id="identical" class="label label-warning">Identical Content</span>
</div>
</div>
-
- <table id="diffs-table" class="table-diff">
+ <table id="diffs-table" class="table-diff body">
<wicket:container wicket:id="hunks">
<tr wicket:id="head" class="line hunk-head">
<td colspan="2" class="action">
@@ -64,36 +63,5 @@
</div>
</form>
</div>
-
- <!-- table class="table-diff">
- <wicket:container wicket:id="lines">
- <tr wicket:id="contentRow" class="line content">
- <td class="old line-no">
- <a wicket:id="addComment" class="add-comment"><i class="fa fa-comment-add"></i></a>
- <span wicket:id="oldLineNo"></span>
- </td>
- <td class="new line-no">
- <span wicket:id="newLineNo"></span>
- </td>
- <td class="text"><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td>
- </tr>
- <tr wicket:id="commentsRow" class="line comments">
- <td colspan="3">
- <table class="comments">
- <tr wicket:id="comments">
- <td class="avatar">
- <div wicket:id="avatar"></div>
- <div wicket:id="concerned" class="fa fa-flag concerned-comment" title="Concerned comment"></div>
- </td>
- <td class="comment">
- <div wicket:id="comment"></div>
- </td>
- </tr>
- </table>
- <div wicket:id="addComment"></div>
- </td>
- </tr>
- </wicket:container>
- </table-->
</div>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html
index b5ecb8ca99..b7a227996f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html
@@ -1,32 +1,25 @@
<wicket:extend>
<div class="compare">
- <div wicket:id="compareHead" class="head clearfix">
+ <div wicket:id="compareOptions" class="head clearfix">
<div class="pull-left btn-group">
- <span class="btn btn-default old" wicket:id="oldSelector">
+ <span class="btn btn-sm btn-default old" wicket:id="oldSelector">
<i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i>
</span>
- <span wicket:id="comparisonSelector" class="btn btn-default" title="Commonly used comparisons">
+ <span wicket:id="comparisonSelector" class="btn btn-sm btn-default" title="Commonly used comparisons">
<i class="fa fa-arrow-left"></i> <i class="caret"></i> <i class="fa fa-arrow-right"></i>
</span>
- <span class="btn btn-default new" wicket:id="newSelector">
+ <span class="btn btn-sm btn-default new" wicket:id="newSelector">
<i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i>
</span>
</div>
<div wicket:id="oldChoices"></div>
<div wicket:id="newChoices"></div>
<div wicket:id="comparisonChoices"></div>
- <div class="pull-right btn-group">
- <button wicket:id="prevChange" class="btn btn-default" title="Previous changed file">
- <i class="fa fa-arrow-slim-left"></i>
- </button>
- <button wicket:id="changesTrigger" class="btn btn-default">Changes: <span wicket:id="label"></span> <i class="caret"></i></button>
- <button wicket:id="nextChange" class="btn btn-default" title="Next changed file">
- <i class="fa fa-arrow-slim-right"></i>
- </button>
+ <div class="pull-left">
+ <input wicket:id="changedOnly" type="checkbox"> Show changed files only</input>
</div>
- <div wicket:id="changesDropdown"></div>
</div>
- <div wicket:id="blobDiff"></div>
+ <div wicket:id="compareResult" class="body"></div>
</div>
<wicket:fragment wicket:id="commitChoiceFrag">
<ul class="commit-choice list-unstyled">
@@ -55,15 +48,4 @@
</table>
</a>
</wicket:fragment>
- <wicket:fragment wicket:id="changesFrag">
- <div class="panel panel-default compare-result">
- <div class="panel-heading clearfix">
- <div class="panel-title pull-left">Compare Result</div>
- <div class="pull-right">
- <input wicket:id="changesOnly" type="checkbox"> changes only</input>
- </div>
- </div>
- <div wicket:id="changes" class="panel-body"></div>
- </div>
- </wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java
index 0d742bd80c..166105a5ae 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java
@@ -1,7 +1,5 @@
package com.pmease.gitplex.web.page.repository.info.pullrequest;
-import static com.pmease.commons.git.Change.Status.UNCHANGED;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
@@ -9,16 +7,13 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import javax.annotation.Nullable;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.event.IEvent;
-import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
@@ -28,16 +23,13 @@ import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.eclipse.jgit.lib.FileMode;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.RevAwareChange;
-import com.pmease.commons.git.TreeNode;
import com.pmease.commons.hibernate.HibernateUtils;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.behavior.StickyBehavior;
@@ -48,9 +40,9 @@ import com.pmease.commons.wicket.behavior.menu.MenuBehavior;
import com.pmease.commons.wicket.behavior.menu.MenuItem;
import com.pmease.commons.wicket.behavior.menu.MenuPanel;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.ChangeComments;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
+import com.pmease.gitplex.core.comment.InlineContext;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.model.InlineInfo;
import com.pmease.gitplex.core.model.IntegrationInfo;
@@ -60,38 +52,20 @@ import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
import com.pmease.gitplex.web.component.comment.event.CommentReplied;
-import com.pmease.gitplex.web.component.diff.BlobDiffPanel;
-import com.pmease.gitplex.web.component.diff.ChangedFilesPanel;
-import com.pmease.gitplex.web.component.diff.DiffTreePanel;
-import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.PullRequestActivity;
+import com.pmease.gitplex.web.component.diff.CompareResultPanel;
import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.RequestActivitiesModel;
-import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.UpdatePullRequest;
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;
@SuppressWarnings("serial")
-public class RequestComparePage extends RequestDetailPage implements InlineCommentSupport {
+public class RequestComparePage extends RequestDetailPage {
- private static final String HEAD_ID = "compareHead";
-
- private static final String CHANGES_TRIGGER_ID = "changesTrigger";
-
- private static final String CHANGES_DROPDOWN_ID = "changesDropdown";
-
- private static final String LABEL_ID = "label";
-
- private static final String PREV_CHANGE_ID = "prevChange";
-
- private static final String NEXT_CHANGE_ID = "nextChange";
-
- private static final String CHANGES_ID = "changes";
-
- private static final String BLOB_DIFF_ID = "blobDiff";
-
private static final String TARGET_BRANCH_HEAD = "Head of Target Branch";
private static final String INTEGRATION_PREVIEW = "Integration Preview";
+
+ public static final String LATEST_COMMIT = "latest";
private String file;
@@ -99,8 +73,6 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
private String newCommit;
- private RevAwareChange change;
-
private final IModel<PullRequestComment> concernedCommentModel;
private final RequestActivitiesModel activitiesModel = new RequestActivitiesModel() {
@@ -164,20 +136,12 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
};
- private final IModel<ChangeComments> commentsModel = new LoadableDetachableModel<ChangeComments>() {
-
- @Override
- protected ChangeComments load() {
- Preconditions.checkNotNull(change);
- return new ChangeComments(getPullRequest(), change);
- }
-
- };
+ private CompareResultPanel compareResult;
public RequestComparePage(PageParameters params) {
super(params);
- file = params.get("path").toString();
+ file = params.get("file").toString();
final Long concernedCommentId = params.get("comment").toOptionalLong();
concernedCommentModel = new LoadableDetachableModel<PullRequestComment>() {
@@ -195,77 +159,33 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
oldCommit = params.get("original").toString();
newCommit = params.get("revised").toString();
- if (oldCommit != null && newCommit == null) {
- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();
- } else if (oldCommit == null && newCommit != null) {
- oldCommit = getPullRequest().getBaseCommit();
- }
-
if (oldCommit != null) {
- if (!commitsModel.getObject().containsKey(oldCommit))
+ if (oldCommit.equals(LATEST_COMMIT))
+ oldCommit = getPullRequest().getLatestUpdate().getHeadCommit();
+ else if (!commitsModel.getObject().containsKey(oldCommit))
throw new IllegalArgumentException("Commit '" + oldCommit + "' is not relevant to current pull request.");
}
if (newCommit != null) {
- if (!commitsModel.getObject().containsKey(newCommit))
+ if (newCommit.equals(LATEST_COMMIT))
+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();
+ else if (!commitsModel.getObject().containsKey(newCommit))
throw new IllegalArgumentException("Commit '" + newCommit + "' is not relevant to current pull request.");
}
- if (file != null && oldCommit == null)
- throw new IllegalArgumentException("Param 'path' can only be used together with param 'original' and 'revised'.");
-
PullRequestComment comment = getConcernedComment();
- if (oldCommit != null) {
- if (file != null) {
- change = resolveChange();
- } else if (comment != null) {
+ if (comment != null) {
+ if (file == null)
file = comment.getInlineInfo().getFile();
- change = resolveChange();
- }
- } else if (comment == null) {
- User user = GitPlex.getInstance(UserManager.class).getCurrent();
- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();
- if (user == null) {
- oldCommit = getPullRequest().getBaseCommit();
- } else {
- List<PullRequestActivity> activities = activitiesModel.getObject();
- boolean found = false;
- for (int i=activities.size()-1; i>=0; i--) {
- PullRequestActivity activity = activities.get(i);
- if (found) {
- if (activity instanceof UpdatePullRequest) {
- oldCommit = ((UpdatePullRequest) activity).getUpdate().getHeadCommit();
- break;
- }
- } else if (activity.getUser().equals(user)) {
- found = true;
- }
- }
- if (oldCommit == null || oldCommit.equals(newCommit))
- oldCommit = getPullRequest().getBaseCommit();
- }
+ if (oldCommit == null)
+ oldCommit = comment.getInlineInfo().getOldCommit();
+ if (newCommit == null)
+ newCommit = comment.getInlineInfo().getNewCommit();
} else {
- file = comment.getInlineInfo().getFile();
- oldCommit = comment.getInlineInfo().getOldCommit();
- newCommit = comment.getInlineInfo().getNewCommit();
- change = resolveChange();
- }
- if (change == null && !getChanges().isEmpty()) {
- file = getChanges().get(0).getPath();
- change = resolveChange();
- }
- }
-
- @Nullable
- private InlineCommentSupport getInlineCommentSupport() {
- Map<String, CommitDescription> commits = commitsModel.getObject();
- String oldCommitName = Preconditions.checkNotNull(commits.get(oldCommit)).getName();
- String newCommitName = Preconditions.checkNotNull(commits.get(newCommit)).getName();
- if (oldCommitName.equals(TARGET_BRANCH_HEAD) || oldCommitName.equals(INTEGRATION_PREVIEW)
- || newCommitName.equals(TARGET_BRANCH_HEAD) || newCommitName.equals(INTEGRATION_PREVIEW)) {
- return null;
- } else {
- return this;
+ if (oldCommit == null)
+ oldCommit = getPullRequest().getBaseCommit();
+ if (newCommit == null)
+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();
}
}
@@ -273,13 +193,13 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
protected void onInitialize() {
super.onInitialize();
- WebMarkupContainer head = new WebMarkupContainer(HEAD_ID);
- head.add(new StickyBehavior());
+ WebMarkupContainer options = new WebMarkupContainer("compareOptions");
+ options.add(new StickyBehavior());
- add(head);
+ add(options);
WebMarkupContainer oldSelector = new WebMarkupContainer("oldSelector");
- head.add(oldSelector);
+ options.add(oldSelector);
oldSelector.add(new Label("label", new LoadableDetachableModel<String>() {
@Override
@@ -311,11 +231,11 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
}
};
- head.add(oldChoicesDropdown);
+ options.add(oldChoicesDropdown);
oldSelector.add(new DropdownBehavior(oldChoicesDropdown).alignWithTrigger(0, 0, 0, 100));
WebMarkupContainer newSelector = new WebMarkupContainer("newSelector");
- head.add(newSelector);
+ options.add(newSelector);
newSelector.add(new Label("label", new LoadableDetachableModel<String>() {
@Override
@@ -348,7 +268,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
}
};
- head.add(newChoicesDropdown);
+ options.add(newChoicesDropdown);
newSelector.add(new DropdownBehavior(newChoicesDropdown).alignWithTrigger(0, 0, 0, 100));
MenuPanel commonComparisons = new MenuPanel("comparisonChoices") {
@@ -389,7 +309,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
PageParameters params = paramsOf(getPullRequest(),
getPullRequest().getBaseCommit(),
getPullRequest().getLatestUpdate().getHeadCommit(),
- change.getPath(), getConcernedComment());
+ file, getConcernedComment());
setResponsePage(RequestComparePage.class, params);
}
@@ -407,7 +327,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
PageParameters params = paramsOf(getPullRequest(),
getPullRequest().getLatestUpdate().getHeadCommit(),
integrationInfo.getIntegrationHead(),
- change.getPath(), getConcernedComment());
+ file, getConcernedComment());
setResponsePage(RequestComparePage.class, params);
}
@@ -430,7 +350,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
@Override
protected void onSelect() {
PageParameters params = paramsOf(getPullRequest(), baseCommit, headCommit,
- change.getPath(), getConcernedComment());
+ file, getConcernedComment());
setResponsePage(RequestComparePage.class, params);
}
@@ -442,156 +362,92 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
};
- head.add(commonComparisons);
- head.add(new WebMarkupContainer("comparisonSelector")
+ options.add(commonComparisons);
+ options.add(new WebMarkupContainer("comparisonSelector")
.add(new MenuBehavior(commonComparisons)
.alignWithTrigger(50, 100, 50, 0)));
- DropdownPanel changesDropdown = new DropdownPanel("changesDropdown") {
+ options.add(new CheckBox("changedOnly", new LoadableDetachableModel<Boolean>() {
@Override
- protected Component newContent(String id) {
- final Fragment fragment = new Fragment(id, "changesFrag", RequestComparePage.this);
-
- boolean changesOnly = (change == null || change.getStatus() != UNCHANGED);
- fragment.add(new CheckBox("changesOnly", Model.of(changesOnly)).add(new OnChangeAjaxBehavior() {
-
- @Override
- protected void onUpdate(AjaxRequestTarget target) {
- Component changeLister = fragment.get(CHANGES_ID);
- changeLister = newChangeLister(!(changeLister instanceof ChangedFilesPanel));
- fragment.replace(changeLister);
- target.add(changeLister);
- }
-
- }));
-
- fragment.add(newChangeLister(changesOnly));
- return fragment;
+ protected Boolean load() {
+ return compareResult.isChangedOnly();
}
- };
-
- head.add(changesDropdown);
- WebMarkupContainer changesTrigger = new WebMarkupContainer(CHANGES_TRIGGER_ID);
- changesTrigger.add(new DropdownBehavior(changesDropdown));
- changesTrigger.add(new Label(LABEL_ID, new LoadableDetachableModel<String>() {
-
+ }).add(new OnChangeAjaxBehavior() {
+
@Override
- protected String load() {
- int index = getChangedFiles().indexOf(file);
- if (index == -1)
- return String.valueOf(getChanges().size());
- else
- return String.valueOf(index+1) + "/" + getChanges().size();
+ protected void onUpdate(AjaxRequestTarget target) {
+ compareResult.toggleChangedOnly(target);
}
- }).setOutputMarkupId(true));
- head.add(changesTrigger);
-
- head.add(new AjaxLink<Void>(PREV_CHANGE_ID) {
+ }));
+ add(compareResult = new CompareResultPanel("compareResult", repoModel, oldCommit, newCommit, file) {
+
@Override
- public void onClick(AjaxRequestTarget target) {
- int index = getChangedFiles().indexOf(file) - 1;
- onChangeSelected(target, getChanges().get(index));
+ protected InlineCommentSupport getInlineCommentSupport(final Change change) {
+ Map<String, CommitDescription> commits = commitsModel.getObject();
+ String oldCommitName = Preconditions.checkNotNull(commits.get(oldCommit)).getName();
+ String newCommitName = Preconditions.checkNotNull(commits.get(newCommit)).getName();
+ if (oldCommitName.equals(TARGET_BRANCH_HEAD) || oldCommitName.equals(INTEGRATION_PREVIEW)
+ || newCommitName.equals(TARGET_BRANCH_HEAD) || newCommitName.equals(INTEGRATION_PREVIEW)) {
+ return null;
+ } else {
+ return new InlineCommentSupport() {
+
+ @Override
+ public Map<Integer, List<InlineComment>> getOldComments() {
+ RevAwareChange revAwareChange = new RevAwareChange(change, oldCommit, newCommit);
+ return getPullRequest().getComments(revAwareChange).getOldComments();
+ }
+
+ @Override
+ public Map<Integer, List<InlineComment>> getNewComments() {
+ RevAwareChange revAwareChange = new RevAwareChange(change, oldCommit, newCommit);
+ return getPullRequest().getComments(revAwareChange).getNewComments();
+ }
+
+ @Override
+ public InlineComment getConcernedComment() {
+ return RequestComparePage.this.getConcernedComment();
+ }
+
+ @Override
+ public InlineComment addComment(String commit, String file, int line, String content) {
+ User user = GitPlex.getInstance(UserManager.class).getCurrent();
+ Preconditions.checkNotNull(user);
+ PullRequestComment comment = new PullRequestComment();
+ getPullRequest().getComments().add(comment);
+ comment.setUser(user);
+ comment.setDate(new Date());
+ comment.setContent(content);
+ comment.setRequest(getPullRequest());
+ InlineInfo inlineInfo = new InlineInfo();
+ comment.setInlineInfo(inlineInfo);
+ inlineInfo.setCommit(commit);
+ inlineInfo.setOldCommit(oldCommit);
+ inlineInfo.setNewCommit(newCommit);
+ inlineInfo.setFile(file);
+ inlineInfo.setLine(line);
+ InlineContext context = getInlineContext(comment);
+ Preconditions.checkNotNull(context);
+ inlineInfo.setContext(context);
+ comment.setInlineInfo(inlineInfo);
+ GitPlex.getInstance(Dao.class).persist(comment);
+ return comment;
+ }
+ };
+ }
}
@Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
-
- if (getChangedFiles().indexOf(file) <= 0)
- tag.put("disabled", "disabled");
+ protected void onChangeSelection(AjaxRequestTarget target, Change change) {
+ file = change.getPath();
}
- }.setOutputMarkupId(true));
-
- head.add(new AjaxLink<Void>(NEXT_CHANGE_ID) {
+ });
- @Override
- public void onClick(AjaxRequestTarget target) {
- int index = getChangedFiles().indexOf(file) + 1;
- onChangeSelected(target, getChanges().get(index));
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
-
- List<String> changedFiles = getChangedFiles();
- if (changedFiles.isEmpty() || changedFiles.indexOf(file) >= changedFiles.size()-1)
- tag.put("disabled", "disabled");
- }
-
- }.setOutputMarkupId(true));
-
- if (change != null) {
- BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, getInlineCommentSupport());
- blobDiffPanel.setOutputMarkupId(true);
- add(blobDiffPanel);
- } else {
- add(new WebMarkupContainer(BLOB_DIFF_ID).setOutputMarkupId(true));
- }
-
- }
-
- private List<Change> getChanges() {
- return getRepository().getChanges(oldCommit, newCommit);
- }
-
- private List<String> getChangedFiles() {
- List<String> files = new ArrayList<>();
- for (Change change: getChanges())
- files.add(change.getPath());
- return files;
- }
-
- private RevAwareChange resolveChange() {
- for (Change each: getChanges()) {
- if (file.equals(each.getPath()))
- return new RevAwareChange(each, oldCommit, newCommit);
- }
- List<TreeNode> result = getRepository().git().listTree(newCommit, file);
- if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {
- TreeNode blobNode = result.get(0);
- return new RevAwareChange(UNCHANGED, file, file,
- blobNode.getMode(), blobNode.getMode(), oldCommit, newCommit);
- } else {
- return null;
- }
- }
-
- private Component newChangeLister(boolean changesOnly) {
- Component changeLister;
- if (changesOnly) {
- changeLister = new ChangedFilesPanel(CHANGES_ID, repoModel, oldCommit, newCommit) {
-
- @Override
- protected WebMarkupContainer newBlobLink(String id, Change change) {
- return new BlobLink(id, change);
- }
- };
- } else {
- changeLister = new DiffTreePanel(CHANGES_ID, repoModel, oldCommit, newCommit) {
-
- @Override
- protected WebMarkupContainer newBlobLink(String id, final Change change) {
- return new BlobLink(id, change);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- if (change != null)
- reveal(change);
- }
-
- };
- }
- changeLister.setOutputMarkupId(true);
- return changeLister;
}
@Override
@@ -599,22 +455,20 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
commitsModel.detach();
concernedCommentModel.detach();
activitiesModel.detach();
- commentsModel.detach();
super.onDetach();
}
public static PageParameters paramsOf(PullRequest request, @Nullable String oldCommit,
- @Nullable String newCommit, @Nullable String filePath,
- @Nullable PullRequestComment concernedComment) {
+ @Nullable String newCommit, @Nullable String file, @Nullable PullRequestComment concernedComment) {
PageParameters params = RequestDetailPage.paramsOf(request);
if (oldCommit != null)
params.set("original", oldCommit);
if (newCommit != null)
params.set("revised", newCommit);
- if (filePath != null)
- params.set("path", filePath);
+ if (file != null)
+ params.set("file", file);
if (concernedComment != null)
params.set("comment", concernedComment.getId());
@@ -642,7 +496,10 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
PullRequestComment comment = (PullRequestComment) commentReplied.getReply().getComment();
comment.getInlineInfo().setOldCommit(oldCommit);
comment.getInlineInfo().setNewCommit(newCommit);
- comment.getInlineInfo().setContext(getBlobDiffPanel().getInlineContext(comment));
+
+ InlineContext context = compareResult.getInlineContext(comment);
+ Preconditions.checkNotNull(context);
+ comment.getInlineInfo().setContext(context);
GitPlex.getInstance(Dao.class).persist(comment);
}
}
@@ -731,53 +588,6 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
}
- private class BlobLink extends AjaxLink<Void> {
-
- private final Change change;
-
- BlobLink(String id, Change change) {
- super(id);
-
- this.change = change;
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
-
- if (change != null
- && Objects.equals(change.getOldPath(), RequestComparePage.this.change.getOldPath())
- && Objects.equals(change.getNewPath(), RequestComparePage.this.change.getNewPath())) {
- tag.put("class", "active");
- }
- }
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onChangeSelected(target, change);
- }
-
- }
-
- private void onChangeSelected(AjaxRequestTarget target, Change change) {
- file = change.getPath();
- this.change = new RevAwareChange(change, oldCommit, newCommit);
- BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, this.change, getInlineCommentSupport());
- getPage().replace(diffPanel);
- target.add(diffPanel);
-
- target.add(get(HEAD_ID).get(PREV_CHANGE_ID));
- target.add(get(HEAD_ID).get(NEXT_CHANGE_ID));
- target.add(get(HEAD_ID).get(CHANGES_TRIGGER_ID).get(LABEL_ID));
-
- Component changesDropdown = get(HEAD_ID).get(CHANGES_DROPDOWN_ID);
- String script = String.format("$('#%s').find('a.active').removeClass('active');",
- changesDropdown.getMarkupId());
- target.prependJavaScript(script);
-
- target.add(this);
- }
-
private abstract class ComparisonChoiceItem extends MenuItem {
private final String oldName;
@@ -811,45 +621,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme
}
}
- @Override
- public Map<Integer, List<InlineComment>> getOldComments() {
- return commentsModel.getObject().getOldComments();
- }
-
- @Override
- public Map<Integer, List<InlineComment>> getNewComments() {
- return commentsModel.getObject().getNewComments();
- }
-
- @Override
- public InlineComment addComment(String commit, String file, int line, String content) {
- User user = GitPlex.getInstance(UserManager.class).getCurrent();
- Preconditions.checkNotNull(user);
- PullRequestComment comment = new PullRequestComment();
- getPullRequest().getComments().add(comment);
- comment.setUser(user);
- comment.setDate(new Date());
- comment.setContent(content);
- comment.setRequest(getPullRequest());
- InlineInfo inlineInfo = new InlineInfo();
- comment.setInlineInfo(inlineInfo);
- inlineInfo.setCommit(commit);
- inlineInfo.setOldCommit(oldCommit);
- inlineInfo.setNewCommit(newCommit);
- inlineInfo.setFile(file);
- inlineInfo.setLine(line);
- inlineInfo.setContext(getBlobDiffPanel().getInlineContext(comment));
- comment.setInlineInfo(inlineInfo);
- GitPlex.getInstance(Dao.class).persist(comment);
- return comment;
- }
-
- private BlobDiffPanel getBlobDiffPanel() {
- return (BlobDiffPanel) getPage().get(BLOB_DIFF_ID);
- }
-
- @Override
- public PullRequestComment getConcernedComment() {
+ private PullRequestComment getConcernedComment() {
return concernedCommentModel.getObject();
}
}