The Unified and Autonomous Development Platform
midwork
robin shine875af4d32581
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex db6ea85f13..f45b190635 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -66,7 +66,6 @@ import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;import com.pmease.gitplex.web.component.diff.revision.DiffMode;import com.pmease.gitplex.web.component.repofile.blobview.BlobViewContext.Mode;import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;-import com.pmease.gitplex.web.page.repository.file.Highlight;import com.pmease.gitplex.web.page.repository.file.RepoFilePage;import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;@@ -325,37 +324,25 @@ public class TextDiffPanel extends Panel {add(commentRows);- SymbolTooltipPanel symbolTooltip = new SymbolTooltipPanel("symbols", repoModel) {+ SymbolTooltipPanel symbolTooltip = new SymbolTooltipPanel("symbols", repoModel, requestModel) {@Override- protected void onSelect(AjaxRequestTarget target, String revision, QueryHit hit) {- Long requestId;- if (requestModel.getObject() != null)- requestId = requestModel.getObject().getId();- else- requestId = null;- PageParameters params = RepoFilePage.paramsOf(repoModel.getObject(), revision,- hit.getBlobPath(), null, new Highlight(hit.getTokenPos()), null, requestId);- setResponsePage(RepoFilePage.class, params);+ protected void onSelect(AjaxRequestTarget target, QueryHit hit) {+ setResponsePage(RepoFilePage.class, getQueryHitParams(hit));}@Override- protected void onOccurrencesQueried(AjaxRequestTarget target, String revision, List<QueryHit> hits) {- Long requestId;- if (requestModel.getObject() != null)- requestId = requestModel.getObject().getId();- else- requestId = null;-- String blobPath;- if (revision.equals(change.getNewBlobIdent().revision))- blobPath = change.getNewBlobIdent().path;- else- blobPath = change.getOldBlobIdent().path;- PageParameters params = RepoFilePage.paramsOf(repoModel.getObject(), revision,- blobPath, null, null, null, requestId);+ protected void onOccurrencesQueried(AjaxRequestTarget target, List<QueryHit> hits) {WebSession.get().setMetaData(RepoFilePage.SEARCH_RESULT_KEY, (Serializable)hits);- setResponsePage(RepoFilePage.class, params);+ setResponsePage(RepoFilePage.class, getFindOccurrencesParams());+ }++ @Override+ protected String getBlobPath() {+ if (getRevision().equals(change.getNewBlobIdent().revision))+ return change.getNewBlobIdent().path;+ else+ return change.getOldBlobIdent().path;}};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.javaindex 7800a1421d..b4eb5cd7d6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java@@ -187,19 +187,31 @@ public class SourceViewPanel extends BlobViewPanel {return context.getRepository();}+ }, new AbstractReadOnlyModel<PullRequest>() {++ @Override+ public PullRequest getObject() {+ return context.getPullRequest();+ }+}) {@Override- protected void onSelect(AjaxRequestTarget target, String revision, QueryHit hit) {+ protected void onSelect(AjaxRequestTarget target, QueryHit hit) {BlobIdent blobIdent = new BlobIdent(- revision, hit.getBlobPath(), FileMode.REGULAR_FILE.getBits());+ getRevision(), hit.getBlobPath(), FileMode.REGULAR_FILE.getBits());context.onSelect(target, blobIdent, hit.getTokenPos());}@Override- protected void onOccurrencesQueried(AjaxRequestTarget target, String revision, List<QueryHit> hits) {+ protected void onOccurrencesQueried(AjaxRequestTarget target, List<QueryHit> hits) {context.onSearchComplete(target, hits);}++ @Override+ protected String getBlobPath() {+ return context.getBlobIdent().path;+ }});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.javaindex 11b4cc10df..2745264ef7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java@@ -10,6 +10,7 @@ import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;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.ComponentTag;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;@@ -32,6 +33,7 @@ import org.apache.wicket.request.resource.ResourceReference;import com.pmease.commons.wicket.behavior.RunTaskBehavior;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.search.SearchManager;import com.pmease.gitplex.search.hit.QueryHit;@@ -39,6 +41,8 @@ import com.pmease.gitplex.search.query.BlobQuery;import com.pmease.gitplex.search.query.SymbolQuery;import com.pmease.gitplex.search.query.TextQuery;import com.pmease.gitplex.web.component.repofile.blobsearch.result.SearchResultPanel;+import com.pmease.gitplex.web.page.repository.file.Highlight;+import com.pmease.gitplex.web.page.repository.file.RepoFilePage;@SuppressWarnings("serial")public abstract class SymbolTooltipPanel extends Panel {@@ -47,16 +51,19 @@ public abstract class SymbolTooltipPanel extends Panel {private final IModel<Repository> repoModel;- private String revision;+ private final IModel<PullRequest> requestModel;++ private String revision = "";private String symbol = "";private List<QueryHit> symbolHits = new ArrayList<>();- public SymbolTooltipPanel(String id, IModel<Repository> repoModel) {+ public SymbolTooltipPanel(String id, IModel<Repository> repoModel, IModel<PullRequest> requestModel) {super(id);this.repoModel = repoModel;+ this.requestModel = requestModel;}@Override@@ -94,10 +101,13 @@ public abstract class SymbolTooltipPanel extends Panel {String script = String.format("gitplex.symboltooltip.removeTooltip(document.getElementById('%s'));",SymbolTooltipPanel.this.getMarkupId());target.prependJavaScript(script);- onSelect(target, revision, hit);+ onSelect(target, hit);}};++ CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, getQueryHitParams(hit));+ link.add(AttributeAppender.replace("href", url.toString()));link.add(hit.render("label"));link.add(new Label("scope", hit.getScope()).setVisible(hit.getScope()!=null));@@ -133,7 +143,7 @@ public abstract class SymbolTooltipPanel extends Panel {try {SearchManager searchManager = GitPlex.getInstance(SearchManager.class);List<QueryHit> hits = searchManager.search(repoModel.getObject(), revision, query);- onOccurrencesQueried(target, revision, hits);+ onOccurrencesQueried(target, hits);} catch (InterruptedException e) {throw new RuntimeException(e);}@@ -143,6 +153,15 @@ public abstract class SymbolTooltipPanel extends Panel {});}+ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);++ // set href in onComponentTag in order to keep it up to date with symbol value+ CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, getFindOccurrencesParams());+ tag.put("href", url.toString());+ }+@Overridepublic void onClick(AjaxRequestTarget target) {runTaskBehavior.requestRun(target);@@ -199,14 +218,43 @@ public abstract class SymbolTooltipPanel extends Panel {setOutputMarkupId(true);}+ private Long getRequestId() {+ if (requestModel.getObject() != null)+ return requestModel.getObject().getId();+ else+ return null;+ }++ public PageParameters getQueryHitParams(QueryHit hit) {+ return RepoFilePage.paramsOf(+ repoModel.getObject(), revision, hit.getBlobPath(), null,+ new Highlight(hit.getTokenPos()), null, null, getRequestId());+ }++ public PageParameters getFindOccurrencesParams() {+ return RepoFilePage.paramsOf(repoModel.getObject(), revision,+ getBlobPath(), null, null, symbol, null, getRequestId());+ }++ public String getSymbol() {+ return symbol;+ }++ public String getRevision() {+ return revision;+ }+@Overrideprotected void onDetach() {repoModel.detach();+ requestModel.detach();super.onDetach();}- protected abstract void onSelect(AjaxRequestTarget target, String revision, QueryHit hit);+ protected abstract String getBlobPath();++ protected abstract void onSelect(AjaxRequestTarget target, QueryHit hit);- protected abstract void onOccurrencesQueried(AjaxRequestTarget target, String revision, List<QueryHit> hits);+ protected abstract void onOccurrencesQueried(AjaxRequestTarget target, List<QueryHit> hits);}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 561d3ca207..94eec8cf76 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@@ -61,7 +61,10 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.search.IndexListener;import com.pmease.gitplex.search.IndexManager;+import com.pmease.gitplex.search.SearchManager;import com.pmease.gitplex.search.hit.QueryHit;+import com.pmease.gitplex.search.query.BlobQuery;+import com.pmease.gitplex.search.query.TextQuery;import com.pmease.gitplex.web.WebSession;import com.pmease.gitplex.web.component.repofile.blobsearch.advanced.AdvancedSearchPanel;import com.pmease.gitplex.web.component.repofile.blobsearch.instant.InstantSearchPanel;@@ -105,6 +108,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private static final String PARAM_HIGHLIGHT = "highlight";+ private static final String PARAM_QUERY_SYMBOL = "query_symbol";+private static final String REVISION_SELECTOR_ID = "revisionSelector";private static final String FILE_NAVIGATOR_ID = "fileNavigator";@@ -149,6 +154,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private Highlight highlight;+ private String querySymbol;+private Mode mode;private Component revisionSelector;@@ -199,6 +206,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {String highlightStr = params.get(PARAM_HIGHLIGHT).toString();if (highlightStr != null)highlight = new Highlight(highlightStr);++ querySymbol = params.get(PARAM_QUERY_SYMBOL).toString();commentId = params.get(PARAM_COMMENT).toOptionalLong();requestId = params.get(PARAM_REQUEST).toOptionalLong();}@@ -317,6 +326,16 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {List<QueryHit> hits = WebSession.get().getMetaData(SEARCH_RESULT_KEY);WebSession.get().setMetaData(SEARCH_RESULT_KEY, null);+ if (hits == null && querySymbol != null) {+ BlobQuery blobQuery = new TextQuery(querySymbol, false, true, true,+ null, null, SearchResultPanel.MAX_QUERY_ENTRIES);+ try {+ SearchManager searchManager = GitPlex.getInstance(SearchManager.class);+ hits = searchManager.search(repoModel.getObject(), blobIdent.revision, blobQuery);+ } catch (InterruptedException e) {+ throw new RuntimeException(e);+ }+ }if (hits != null)add(newSearchResult(hits));else@@ -606,7 +625,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private void pushState(AjaxRequestTarget target) {PageParameters params = paramsOf(getRepository(), blobIdent.revision, blobIdent.path,- mode, highlight, commentId, requestId);+ mode, highlight, null, commentId, requestId);CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);HistoryState state = new HistoryState();state.mode = mode;@@ -635,12 +654,13 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}public static PageParameters paramsOf(PullRequest request, String commitHash, @Nullable String path) {- return paramsOf(request.getTargetRepo(), commitHash, path, null, null, null, request.getId());+ return paramsOf(request.getTargetRepo(), commitHash, path, null, null,+ null, null, request.getId());}public static PageParameters paramsOf(Comment comment) {return paramsOf(comment.getRepository(), comment.getBlobIdent().revision,- comment.getBlobIdent().path, null, null, comment.getId(), null);+ comment.getBlobIdent().path, null, null, null, comment.getId(), null);}public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent) {@@ -653,12 +673,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {public static PageParameters paramsOf(Repository repository, @Nullable String revision,@Nullable String path, @Nullable Mode mode) {- return paramsOf(repository, revision, path, mode, null, null, null);+ return paramsOf(repository, revision, path, mode, null, null, null, null);}public static PageParameters paramsOf(Repository repository, @Nullable String revision,@Nullable String path, Mode mode, @Nullable Highlight highlight,- @Nullable Long commentId, @Nullable Long requestId) {+ @Nullable String querySymbol,@Nullable Long commentId, @Nullable Long requestId) {PageParameters params = paramsOf(repository);if (revision != null)params.set(PARAM_REVISION, revision);@@ -668,6 +688,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {params.set(PARAM_MODE, mode.name().toLowerCase());if (highlight != null)params.set(PARAM_HIGHLIGHT, highlight.toString());+ if (querySymbol != null)+ params.set(PARAM_QUERY_SYMBOL, querySymbol);if (commentId != null)params.set(PARAM_COMMENT, commentId);if (requestId != null)