The Unified and Autonomous Development Platform
much better
robin shine857fcfa0ed7c
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.javaindex 213d228cb1..c561aff237 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java@@ -8,6 +8,7 @@ import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.apache.wicket.request.resource.CssResourceReference;import org.apache.wicket.request.resource.JavaScriptResourceReference;+import org.apache.wicket.request.resource.ResourceReference;import com.google.common.collect.ImmutableList;import com.google.common.collect.Iterables;@@ -29,7 +30,8 @@ public class CodeMirrorResourceReference extends JavaScriptResourceReference {@Overridepublic Iterable<? extends HeaderItem> getDependencies() {- String modeBase = StringUtils.substringBeforeLast(RequestCycle.get().urlFor(this, new PageParameters()).toString(), "/");+ ResourceReference meta = new WebjarsJavaScriptResourceReference("codemirror/current/mode/meta.js");+ String modeBase = StringUtils.substringBeforeLast(RequestCycle.get().urlFor(meta, new PageParameters()).toString(), "/");return Iterables.concat(super.getDependencies(), ImmutableList.<HeaderItem>of(JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/lib/codemirror.js")),JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/mode/loadmode.js")),@@ -55,7 +57,7 @@ public class CodeMirrorResourceReference extends JavaScriptResourceReference {JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "gotoline.js")),JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "identifier-highlighter.js")),- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/mode/meta.js")),+ JavaScriptHeaderItem.forReference(meta),JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE),CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/lib/codemirror.css")),diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.jsindex f1f3600014..e410dda571 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js@@ -1,5 +1,5 @@gitplex.codemirror = {- initState: function(cm, stateStr) {+ initState: function(cm, clientStateStr) {// use timer to minimize performance impactvar cursorTimer;cm.on("cursorActivity", function() {@@ -10,15 +10,16 @@ gitplex.codemirror = {var cursor = cm.getCursor();pmease.commons.history.setCursor(cursor);$(".preserve-cm-state").each(function() {- var state = $(this).data("state");- if (!state)- state = {};- state.cursor = cursor;- $(this).data("state", state);- var uri = new URI(this);- uri.removeSearch("state");- uri.addSearch("state", JSON.stringify(state));+ var clientState = $(this).data("client_state");+ if (!clientState)+ clientState = {};+ clientState.cursor = cursor;+ $(this).data("client_state", clientState);+ var uri = new URI(this);+ uri.removeSearch("client_state");+ uri.addSearch("client_state", JSON.stringify(clientState));+ $(this).attr("href", uri.href());});}, 500);});@@ -37,14 +38,18 @@ gitplex.codemirror = {scrollTimer = undefined;var scrollInfo = cm.getScrollInfo();var scroll = {left: scrollInfo.left, top: scrollInfo.top};- console.log(scroll.top);pmease.commons.history.setScroll(scroll);$(".preserve-cm-state").each(function() {- var state = $(this).data("state");- if (!state)- state = {};- state.scroll = scroll;- $(this).data("state", state);+ var clientState = $(this).data("client_state");+ if (!clientState)+ clientState = {};+ clientState.scroll = scroll;+ $(this).data("client_state", clientState);++ var uri = new URI(this);+ uri.removeSearch("client_state");+ uri.addSearch("client_state", JSON.stringify(clientState));+ $(this).attr("href", uri.href());});}, 500);});@@ -52,12 +57,12 @@ gitplex.codemirror = {if (scroll)cm.scrollTo(scroll.left, scroll.top);- if (stateStr) {- var state = JSON.parse(stateStr);- if (state.cursor)- cm.setCursor(state.cursor);- if (state.scroll)- cm.scrollTo(state.scroll.left, state.scroll.top);+ if (clientStateStr) {+ var clientState = JSON.parse(clientStateStr);+ if (clientState.cursor)+ cm.setCursor(clientState.cursor);+ if (clientState.scroll)+ cm.scrollTo(clientState.scroll.left, clientState.scroll.top);}}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.javaindex 76510952a0..676d5e284d 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java@@ -23,9 +23,9 @@ public abstract class ClientStateAwareAjaxLink<T> extends AjaxLink<T> {attributes.setMethod(Method.POST);String script = String.format(""- + "var state = $('#%s').data('state');"- + "return state?JSON.stringify(state):'';", getMarkupId());- attributes.getDynamicExtraParameters().add("return {state: function() {" + script + "}}");+ + "var clientState = $('#%s').data('client_state');"+ + "return clientState?JSON.stringify(clientState):'';", getMarkupId());+ attributes.getDynamicExtraParameters().add("return {client_state: function() {" + script + "}}");}public ClientStateAwareAjaxLink(String id, IModel<T> model) {@@ -34,7 +34,8 @@ public abstract class ClientStateAwareAjaxLink<T> extends AjaxLink<T> {@Overridepublic final void onClick(AjaxRequestTarget target) {- String value = RequestCycle.get().getRequest().getRequestParameters().getParameterValue("state").toString();+ String value = RequestCycle.get().getRequest().getRequestParameters()+ .getParameterValue("client_state").toString();if (StringUtils.isNotBlank(value))onClick(target, value);elsediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.javaindex 6288fac434..948c1c7fbf 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java@@ -168,6 +168,20 @@ public abstract class BlobViewPanel extends Panel {add(new Label("label", "Edit on source branch"));elseadd(new Label("label", "Edit"));++ PageParameters params;+ if (context.isOnBranch()) {+ params = RepoFilePage.paramsOf(context.getRepository(),+ context.getBlobIdent().revision, context.getBlobIdent().path, Mode.EDIT);+ } else if (context.isAtSourceBranchHead()) {+ params = getEditSourceBranchParams(null);+ } else {+ params = null;+ }+ if (params != null) {+ CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);+ add(AttributeAppender.replace("href", url.toString()));+ }}@Override@@ -186,16 +200,21 @@ public abstract class BlobViewPanel extends Panel {}@Override- public void onClick(AjaxRequestTarget target, String state) {+ public void onClick(AjaxRequestTarget target, String clientState) {if (context.isOnBranch()) {- context.onEdit(target, state);+ context.onEdit(target, clientState);} else {- PageParameters params = RepoFilePage.paramsOf(context.getRepository(),- context.getPullRequest().getSourceBranch(), context.getBlobIdent().path, Mode.EDIT);+ PageParameters params = getEditSourceBranchParams(clientState);setResponsePage(RepoFilePage.class, params);}}+ private PageParameters getEditSourceBranchParams(String clientState) {+ return RepoFilePage.paramsOf(context.getPullRequest().getSourceRepo(),+ context.getPullRequest().getSourceBranch(), context.getBlobIdent().path,+ null, null, null, Mode.EDIT, null, clientState);+ }+});changeActions.add(new AjaxLink<Void>("delete") {@@ -208,6 +227,21 @@ public abstract class BlobViewPanel extends Panel {add(new Label("label", "Delete from source branch"));elseadd(new Label("label", "Delete"));++ PageParameters params;+ if (context.isOnBranch()) {+ params = RepoFilePage.paramsOf(context.getRepository(),+ context.getBlobIdent().revision, context.getBlobIdent().path, Mode.EDIT);+ } else if (context.isAtSourceBranchHead()) {+ params = RepoFilePage.paramsOf(context.getRepository(),+ context.getPullRequest().getSourceBranch(), context.getBlobIdent().path, Mode.DELETE);+ } else {+ params = null;+ }+ if (params != null) {+ CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);+ add(AttributeAppender.replace("href", url.toString()));+ }}@Override@@ -223,7 +257,7 @@ public abstract class BlobViewPanel extends Panel {if (context.isOnBranch()) {context.onDelete(target);} else {- PageParameters params = RepoFilePage.paramsOf(context.getRepository(),+ PageParameters params = RepoFilePage.paramsOf(context.getPullRequest().getSourceRepo(),context.getPullRequest().getSourceBranch(), context.getBlobIdent().path, Mode.DELETE);setResponsePage(RepoFilePage.class, params);}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.javaindex 0f40982977..3625c6480e 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@@ -110,6 +110,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private static final String PARAM_QUERY = "query";+ private static final String PARAM_CLIENT_STATE = "client_state";+private static final String PARAM_HIGHLIGHT = "highlight";private static final String REVISION_SELECTOR_ID = "revisionSelector";@@ -169,6 +171,9 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private final RevisionIndexed trait = new RevisionIndexed();private transient List<QueryHit> queryHits;++ // client state holding CodeMirror cursor, scroll, marks, etc.+ private transient String clientState;public RepoFilePage(final PageParameters params) {super(params);@@ -229,6 +234,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}}}++ clientState = params.get(PARAM_CLIENT_STATE).toString();}private ObjectId getCommitId() {@@ -369,7 +376,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {});newLastCommit(null);- newFileViewer(null, null);+ newFileViewer(null, clientState);add(searchResultContainer = new WebMarkupContainer("searchResultContainer"));@@ -752,6 +759,14 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {public static PageParameters paramsOf(Repository repository, @Nullable String revision,@Nullable String path, @Nullable Highlight highlight, @Nullable Long commentId,@Nullable Long requestId, @Nullable Mode mode, @Nullable String query) {+ return paramsOf(repository, revision, path, highlight, commentId, requestId, mode,+ query, null);+ }++ public static PageParameters paramsOf(Repository repository, @Nullable String revision,+ @Nullable String path, @Nullable Highlight highlight, @Nullable Long commentId,+ @Nullable Long requestId, @Nullable Mode mode, @Nullable String query,+ @Nullable String clientState) {PageParameters params = paramsOf(repository);if (revision != null)params.set(PARAM_REVISION, revision);@@ -767,6 +782,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {params.set(PARAM_MODE, mode.name().toLowerCase());if (query != null)params.set(PARAM_QUERY, query);+ if (clientState != null)+ params.set(PARAM_CLIENT_STATE, clientState);return params;}@@ -908,12 +925,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}@Override- public void onBlameChange(AjaxRequestTarget target, @Nullable String clientState) {+ public void onBlameChange(AjaxRequestTarget target, @Nullable String cmState) {if (mode == null)mode = Mode.BLAME;elsemode = null;- newFileViewer(target, clientState);+ newFileViewer(target, cmState);pushState(target);resizeWindow(target);}@@ -928,11 +945,11 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}@Override- public void onEdit(AjaxRequestTarget target, @Nullable String clientState) {+ public void onEdit(AjaxRequestTarget target, @Nullable String cmState) {mode = Mode.EDIT;newFileNavigator(target);- newFileViewer(target, clientState);+ newFileViewer(target, cmState);pushState(target);resizeWindow(target);}