Skip to content

The Unified and Autonomous Development Platform

Further blame feature improvements.

robin shine05056bb875c8
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
index 06fd0641a6..89c99c2157 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
@@ -1,14 +1,28 @@
package com.pmease.commons.wicket;
+import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;
+
+import java.io.Serializable;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.wicket.Component;
import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.head.PriorityHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.time.Duration;
import org.eclipse.jetty.server.SessionManager;
@@ -44,6 +58,36 @@ public abstract class CommonPage extends WebPage {
protected void onInitialize() {
super.onInitialize();
+
+ add(new AbstractDefaultAjaxBehavior() {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(Method.POST);
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
+ String encodedData = params.getParameterValue("data").toString();
+
+ byte[] bytes = Base64.decodeBase64(encodedData.getBytes());
+ Serializable data = (Serializable) SerializationUtils.deserialize(bytes);
+ onPopState(target, data);
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ String script = String.format("pmease.commons.history.init(%s);",
+ getCallbackFunction(explicit("data")));
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
+ });
+
sessionFeedback = new SessionFeedbackPanel("sessionFeedback");
add(sessionFeedback);
sessionFeedback.setOutputMarkupId(true);
@@ -63,12 +107,6 @@ public abstract class CommonPage extends WebPage {
super.onBeforeRender();
}
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(CommonResourceReference.INSTANCE)));
- }
-
protected void backToPrevPage() {
if (prevPageRef != null)
setResponsePage(prevPageRef.getPage());
@@ -78,4 +116,27 @@ public abstract class CommonPage extends WebPage {
params.set(PARAM_PREV_PAGE, getPage().getId());
}
+ public void pushState(AjaxRequestTarget target, String url, Serializable data) {
+ String encodedData = new String(Base64.encodeBase64(SerializationUtils.serialize(data)));
+ target.prependJavaScript(String.format("history.pushState({data:'%s'}, '', '%s');",
+ encodedData, url));
+ }
+
+ public void replaceState(AjaxRequestTarget target, Serializable data) {
+ String encodedData = new String(Base64.encodeBase64(SerializationUtils.serialize(data)));
+ target.prependJavaScript(String.format("history.pushState({data:'%s'}, '', window.location.href);",
+ encodedData));
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(CommonResourceReference.INSTANCE)));
+ }
+
+ protected void onPopState(AjaxRequestTarget target, Serializable data) {
+
+ }
+
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
index 62153db067..e488d3ce55 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
@@ -819,24 +819,24 @@ pmease.commons = {
},
history: {
- init: function() {
+ init: function(callback) {
// Use a timeout here solve the problem that Safari (and previous versions of Chrome)
// fires event "onpopstate" on initial page load and this causes the page to reload
// infinitely
setTimeout(function() {
window.onpopstate = function(event) {
- if (!event.state || !event.state.state)
+ if (!event.state || !event.state.data)
location.reload();
else
- $(document).trigger("onpopstate", [event.state.component, event.state.state]);
+ callback(event.state.data);
};
- }, 1000);
+ }, 100);
},
setScrollPos: function(scrollPos) {
var state = history.state;
if (!state)
state = {};
- history.replaceState({scrollPos: scrollPos, state: state.state, component: state.component}, '', window.location.href );
+ history.replaceState({scrollPos: scrollPos, data: state.data}, '', window.location.href );
},
getScrollPos: function() {
if (history.state && history.state.scrollPos)
@@ -855,5 +855,4 @@ $(function() {
pmease.commons.focus.setupAutoFocus();
pmease.commons.scroll.setupScrollStop();
pmease.commons.websocket.setupCallback();
- pmease.commons.history.init();
});
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/HistoryBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/HistoryBehavior.java
deleted file mode 100644
index 95fc537945..0000000000
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/HistoryBehavior.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.pmease.commons.wicket.behavior;
-
-import static org.apache.wicket.ajax.attributes.CallbackParameter.resolved;
-
-import java.io.Serializable;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.SerializationUtils;
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
-import org.apache.wicket.request.IRequestParameters;
-import org.apache.wicket.request.cycle.RequestCycle;
-
-@SuppressWarnings("serial")
-public abstract class HistoryBehavior extends AbstractDefaultAjaxBehavior {
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.setMethod(Method.POST);
- }
-
- @Override
- protected void respond(AjaxRequestTarget target) {
- IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
- String encodedState = params.getParameterValue("state").toString();
-
- byte[] bytes = Base64.decodeBase64(encodedState.getBytes());
- Serializable state = (Serializable) SerializationUtils.deserialize(bytes);
- onPopState(target, state);
- }
-
- protected abstract void onPopState(AjaxRequestTarget target, Serializable state);
-
- @Override
- public void renderHead(Component component, IHeaderResponse response) {
- super.renderHead(component, response);
-
- String script = String.format(""
- + "$(document).on('onpopstate', function(event, component, state) {"
- + " if (component === '%s') {"
- + " %s"
- + " }"
- + "});",
- getComponent().getPageRelativePath(),
- getCallbackFunctionBody(resolved("state", "state")));
- response.render(OnDomReadyHeaderItem.forScript(script));
- }
-
- public void pushState(AjaxRequestTarget target, String url, Serializable state) {
- String encodedState = new String(Base64.encodeBase64(SerializationUtils.serialize(state)));
- target.prependJavaScript(String.format("history.pushState({state:'%s', component:'%s'}, '', '%s');",
- encodedState, getComponent().getPageRelativePath(), url));
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
index a72c17e393..176cfb782a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
@@ -551,7 +551,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
final File cacheDir = new File(
GitPlex.getInstance(StorageManager.class).getCacheDir(this),
- "history/" + path + "/gitplex_last_commits_of_children");
+ "last_commits/" + path + "/gitplex_last_commits");
final ReadWriteLock lock;
try {
diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.java
index b10dd53b80..33b47f05bd 100644
--- a/gitplex.product/src/test/java/gitplex/product/Test.java
+++ b/gitplex.product/src/test/java/gitplex/product/Test.java
@@ -2,10 +2,13 @@ package gitplex.product;
import java.io.IOException;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.errors.RevisionSyntaxException;
+
public class Test {
@org.junit.Test
- public void test() throws IOException {
+ public void test() throws IOException, RevisionSyntaxException, GitAPIException {
}
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewContext.java
index 975c3772e4..0c86378522 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewContext.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewContext.java
@@ -55,6 +55,8 @@ public abstract class BlobViewContext implements Serializable {
public abstract void onSelect(AjaxRequestTarget target, BlobIdent blobIdent, TokenPosition tokenPos);
public abstract void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits);
+
+ public abstract void onBlameChange(AjaxRequestTarget target);
public BlobIdent getBlobIdent() {
return blobIdent;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
index 50357532ce..831eb0aa6a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
@@ -3,6 +3,7 @@ package com.pmease.gitplex.web.component.blobview;
import org.apache.commons.io.FileUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
@@ -17,7 +18,6 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
import com.google.common.base.Preconditions;
import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;
-import com.pmease.gitplex.web.component.blobview.source.SourceViewPanel;
import com.pmease.gitplex.web.resource.BlobResource;
import com.pmease.gitplex.web.resource.BlobResourceReference;
@@ -84,32 +84,16 @@ public abstract class BlobViewPanel extends Panel {
add(new AjaxLink<Void>("blame") {
@Override
- public void onClick(AjaxRequestTarget target) {
- BlobViewPanel blobView = BlobViewPanel.this;
+ protected void onInitialize() {
+ super.onInitialize();
- if (blobView instanceof SourceViewPanel) {
- SourceViewPanel sourceView = (SourceViewPanel) blobView;
- if (sourceView.isBlamed()) {
- BlobViewPanel newBlobView = sourceView.getContext().render(sourceView.getId());
- if (newBlobView instanceof SourceViewPanel) {
- sourceView.blame(target, false);
- target.appendJavaScript("$('.blame-toggle').removeClass('active').blur();");
- } else {
- blobView.replaceWith(newBlobView);
- target.add(newBlobView);
- target.appendJavaScript("$(window).resize();");
- }
- } else {
- sourceView.blame(target, true);
- target.appendJavaScript("$('.blame-toggle').addClass('active');");
- }
- } else {
- SourceViewPanel sourceView = new SourceViewPanel(blobView.getId(), context, true);
- blobView.replaceWith(sourceView);
- target.add(sourceView);
- target.appendJavaScript("$(window).resize();");
- target.appendJavaScript("$('.blame-toggle').addClass('active');");
- }
+ if (context.isBlame())
+ add(AttributeAppender.append("class", " active"));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ context.onBlameChange(target);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
index 9fccf5f685..a5d5669d00 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
@@ -72,18 +72,10 @@ public class SourceViewPanel extends BlobViewPanel {
private String symbol = "";
- private boolean blamed;
-
private List<QueryHit> symbolHits = new ArrayList<>();
private final List<Symbol> symbols = new ArrayList<>();
- public SourceViewPanel(String id, BlobViewContext context, boolean blamed) {
- this(id, context);
-
- this.blamed = blamed;
- }
-
public SourceViewPanel(String id, BlobViewContext context) {
super(id, context);
@@ -287,7 +279,7 @@ public class SourceViewPanel extends BlobViewPanel {
}
private String getBlameBlocks() {
- if (blamed) {
+ if (context.isBlame()) {
int fromLine = 0;
List<BlameBlock> blocks = new ArrayList<>();
for (Blame blame: context.getRepository().git().blame(
@@ -314,17 +306,6 @@ public class SourceViewPanel extends BlobViewPanel {
}
}
- public void blame(AjaxRequestTarget target, boolean blamed) {
- this.blamed = blamed;
- String script = String.format("gitplex.sourceview.blame('%s', %s);",
- codeContainer.getMarkupId(), getBlameBlocks());
- target.appendJavaScript(script);
- }
-
- public boolean isBlamed() {
- return blamed;
- }
-
@SuppressWarnings("unused")
private static class BlameBlock {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
index eca832616b..907b777183 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
@@ -40,7 +40,6 @@ import com.pmease.commons.hibernate.UnitOfWork;
import com.pmease.commons.lang.TokenPosition;
import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
-import com.pmease.commons.wicket.behavior.HistoryBehavior;
import com.pmease.commons.wicket.behavior.modal.ModalBehavior;
import com.pmease.commons.wicket.behavior.modal.ModalPanel;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
@@ -69,6 +68,8 @@ public class RepoFilePage extends RepositoryPage {
private static final String PARAM_PATH = "path";
+ private static final String PARAM_BLAME = "blame";
+
private static final String REVISION_SELECTOR_ID = "revisionSelector";
private static final String FILE_NAVIGATOR_ID = "fileNavigator";
@@ -83,6 +84,8 @@ public class RepoFilePage extends RepositoryPage {
private TokenPosition tokenPos;
+ private boolean blame;
+
private Component revisionSelector;
private Component fileNavigator;
@@ -93,8 +96,6 @@ public class RepoFilePage extends RepositoryPage {
private Component fileViewer;
- private HistoryBehavior historyBehavior;
-
private final RevisionIndexed trait = new RevisionIndexed();
public RepoFilePage(PageParameters params) {
@@ -127,6 +128,7 @@ public class RepoFilePage extends RepositoryPage {
}
}
+ blame = params.get(PARAM_BLAME).toBoolean(false);
}
private ObjectId getCommitId() {
@@ -252,22 +254,6 @@ public class RepoFilePage extends RepositoryPage {
});
- add(historyBehavior = new HistoryBehavior() {
-
- @Override
- protected void onPopState(AjaxRequestTarget target, Serializable state) {
- file = ((State) state).file;
- tokenPos = ((State) state).tokenPos;
-
- trait.revision = file.revision;
-
- target.add(revisionIndexing);
- newRevisionSelector(target);
- newFileNavigator(target);
- newFileViewer(target);
- }
-
- });
}
private void newRevisionSelector(AjaxRequestTarget target) {
@@ -291,6 +277,7 @@ public class RepoFilePage extends RepositoryPage {
}
}
tokenPos = null;
+ blame = false;
target.add(revisionIndexing);
newRevisionSelector(target);
@@ -317,6 +304,7 @@ public class RepoFilePage extends RepositoryPage {
protected void onSelect(AjaxRequestTarget target, BlobIdent file) {
RepoFilePage.this.file = file;
tokenPos = null;
+ blame = false;
newFileNavigator(target);
newFileViewer(target);
@@ -336,7 +324,8 @@ public class RepoFilePage extends RepositoryPage {
private void newFileViewer(AjaxRequestTarget target) {
if (target != null && fileViewer instanceof SourceViewPanel) {
SourceViewPanel sourceViewer = (SourceViewPanel) fileViewer;
- if (sourceViewer.getContext().getBlobIdent().equals(file)) {
+ BlobViewContext context = sourceViewer.getContext();
+ if (context.getBlobIdent().equals(file) && context.isBlame() == blame) {
sourceViewer.getContext().setTokenPosition(tokenPos);
if (tokenPos != null) {
sourceViewer.highlightToken(target, tokenPos);
@@ -360,6 +349,7 @@ public class RepoFilePage extends RepositoryPage {
protected void onSelect(AjaxRequestTarget target, BlobIdent file) {
RepoFilePage.this.file = file;
tokenPos = null;
+ blame = false;
newFileViewer(target);
newFileNavigator(target);
@@ -381,6 +371,7 @@ public class RepoFilePage extends RepositoryPage {
RepoFilePage.this.file = new BlobIdent(file.revision, blobIdent.path,
FileMode.REGULAR_FILE.getBits());
RepoFilePage.this.tokenPos = tokenPos;
+ blame = false;
newFileNavigator(target);
newFileViewer(target);
@@ -392,9 +383,19 @@ public class RepoFilePage extends RepositoryPage {
public void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits) {
renderSearchResult(target, hits);
}
+
+ @Override
+ public void onBlameChange(AjaxRequestTarget target) {
+ blame = !blame;
+
+ newFileViewer(target);
+
+ pushState(target);
+ }
};
context.setTokenPosition(tokenPos);
+ context.setBlame(blame);
fileViewer = context.render(FILE_VIEWER_ID);
}
@@ -426,12 +427,13 @@ public class RepoFilePage extends RepositoryPage {
}
private void pushState(AjaxRequestTarget target) {
- PageParameters params = paramsOf(getRepository(), file.revision, file.path);
+ PageParameters params = paramsOf(getRepository(), file.revision, file.path, blame);
CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);
- State state = new State();
+ HistoryData state = new HistoryData();
state.file = file;
state.tokenPos = tokenPos;
- historyBehavior.pushState(target, url.toString(), state);
+ state.blame = blame;
+ pushState(target, url.toString(), state);
}
@Override
@@ -448,16 +450,26 @@ public class RepoFilePage extends RepositoryPage {
}
public static PageParameters paramsOf(Repository repository, @Nullable String revision, @Nullable String path) {
+ return paramsOf(repository, revision, path, false);
+ }
+
+ public static PageParameters paramsOf(Repository repository, @Nullable String revision, @Nullable String path, boolean blame) {
PageParameters params = paramsOf(repository);
if (revision != null)
params.set(PARAM_REVISION, revision);
if (path != null)
params.set(PARAM_PATH, path);
+ if (blame)
+ params.set(PARAM_BLAME, blame);
return params;
}
public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent) {
- return paramsOf(repository, blobIdent.revision, blobIdent.path);
+ return paramsOf(repository, blobIdent, false);
+ }
+
+ public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent, boolean blame) {
+ return paramsOf(repository, blobIdent.revision, blobIdent.path, blame);
}
private void renderSearchResult(AjaxRequestTarget target, List<QueryHit> hits) {
@@ -497,6 +509,21 @@ public class RepoFilePage extends RepositoryPage {
};
}
+ @Override
+ protected void onPopState(AjaxRequestTarget target, Serializable data) {
+ HistoryData historyData = (HistoryData) data;
+ file = historyData.file;
+ tokenPos = historyData.tokenPos;
+ blame = historyData.blame;
+
+ trait.revision = file.revision;
+
+ target.add(revisionIndexing);
+ newRevisionSelector(target);
+ newFileNavigator(target);
+ newFileViewer(target);
+ }
+
private static class RevisionIndexed implements Serializable {
Long repoId;
@@ -513,12 +540,13 @@ public class RepoFilePage extends RepositoryPage {
}
- private static class State implements Serializable {
+ private static class HistoryData implements Serializable {
BlobIdent file = new BlobIdent();
TokenPosition tokenPos;
+ boolean blame;
}
public static class IndexedListener implements IndexListener {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
index 0628be98ca..d39d340d66 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
@@ -36,7 +36,6 @@ import com.pmease.commons.hibernate.HibernateUtils;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.loader.InheritableThreadLocalData;
import com.pmease.commons.util.diff.AroundContext;
-import com.pmease.commons.wicket.behavior.HistoryBehavior;
import com.pmease.commons.wicket.behavior.StickyBehavior;
import com.pmease.commons.wicket.behavior.TooltipBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;
@@ -83,6 +82,8 @@ public class RequestComparePage extends RequestDetailPage {
private String newCommitHash;
+ private WebMarkupContainer optionsContainer;
+
private final IModel<PullRequestComment> commentModel;
private final IModel<Map<String, CommitDescription>> commitsModel =
@@ -176,7 +177,7 @@ public class RequestComparePage extends RequestDetailPage {
protected void onInitialize() {
super.onInitialize();
- final WebMarkupContainer optionsContainer = new WebMarkupContainer("compareOptions") {
+ optionsContainer = new WebMarkupContainer("compareOptions") {
@Override
public void onEvent(IEvent<?> event) {
@@ -387,23 +388,6 @@ public class RequestComparePage extends RequestDetailPage {
add(compareResult = new CompareResultPanel("compareResult", repoModel, oldCommitHash, newCommitHash, file) {
- private HistoryBehavior historyBehavior;
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(historyBehavior = new HistoryBehavior() {
-
- @Override
- protected void onPopState(AjaxRequestTarget target, Serializable state) {
- compareResult.select(target, (String) state);
- target.add(optionsContainer);
- }
-
- });
- }
-
@Override
protected InlineCommentSupport getInlineCommentSupport(final Change change) {
List<String> commentables = getPullRequest().getCommentables();
@@ -473,7 +457,7 @@ public class RequestComparePage extends RequestDetailPage {
if (commentId != null)
url.append("&comment=").append(commentId);
- historyBehavior.pushState(target, url.toString(), file);
+ pushState(target, url.toString(), file);
}
});
@@ -646,4 +630,13 @@ public class RequestComparePage extends RequestDetailPage {
private PullRequestComment getComment() {
return commentModel.getObject();
}
+
+ @Override
+ protected void onPopState(AjaxRequestTarget target, Serializable data) {
+ super.onPopState(target, data);
+
+ compareResult.select(target, (String) data);
+ target.add(optionsContainer);
+ }
+
}