Skip to content

The Unified and Autonomous Development Platform

Draft implementation of diff mark/comment

robin shinef6a00107c100
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
index 4a8639a61a..65605545ff 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
@@ -2,6 +2,8 @@ package com.pmease.commons.git;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import javax.annotation.Nullable;
@@ -166,6 +168,15 @@ public abstract class BlobChange implements Serializable {
return getNewBlob().getText();
}
+ public Collection<String> getPaths() {
+ Collection<String> paths = new HashSet<>();
+ if (oldBlobIdent.path != null)
+ paths.add(oldBlobIdent.path);
+ if (newBlobIdent.path != null)
+ paths.add(newBlobIdent.path);
+ return paths;
+ }
+
public abstract Blob getBlob(BlobIdent blobIdent);
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/Highlighter.java b/commons.util/src/main/java/com/pmease/commons/util/Highlighter.java
index 5fe528604f..1764af3092 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/Highlighter.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/Highlighter.java
@@ -11,7 +11,7 @@ public class Highlighter {
Transformer<String> matchedTransformer, Transformer<String> unmatchedTransformer) {
StringBuffer buffer = new StringBuffer();
int start = 0;
- for (Range range: new JoinedRanges(ranges)) {
+ for (Range range: RangeUtils.merge(ranges)) {
buffer.append(unmatchedTransformer.transform(text.substring(start, range.getFrom())));
buffer.append(matchedTransformer.transform(text.substring(range.getFrom(), range.getTo())));
start = range.getTo();
diff --git a/commons.util/src/main/java/com/pmease/commons/util/JoinedRanges.java b/commons.util/src/main/java/com/pmease/commons/util/JoinedRanges.java
deleted file mode 100644
index 8f24af4a3f..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/JoinedRanges.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.pmease.commons.util;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class JoinedRanges implements Iterable<Range> {
-
- private final List<Range> result;
-
- public JoinedRanges(List<Range> ranges) {
- ranges.sort((o1, o2) -> o1.getFrom() - o2.getFrom());
- result = new ArrayList<>();
- Range currentRange = null;
- for (Range range: ranges) {
- if (currentRange == null) {
- currentRange = range;
- } else if (range.getFrom() <= currentRange.getTo()) {
- currentRange = new Range(currentRange.getFrom(), Math.max(currentRange.getTo(), range.getTo()));
- } else {
- result.add(currentRange);
- currentRange = range;
- }
- }
- if (currentRange != null)
- result.add(currentRange);
- }
-
- @Override
- public Iterator<Range> iterator() {
- return result.iterator();
- }
-
-}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java b/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java
new file mode 100644
index 0000000000..fb53115819
--- /dev/null
+++ b/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java
@@ -0,0 +1,29 @@
+package com.pmease.commons.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class RangeUtils {
+
+ public static List<Range> merge(Collection<Range> ranges) {
+ List<Range> sorted = new ArrayList<>(ranges);
+ sorted.sort((o1, o2) -> o1.getFrom() - o2.getFrom());
+ List<Range> merged = new ArrayList<>();
+ Range current = null;
+ for (Range range: ranges) {
+ if (current == null) {
+ current = range;
+ } else if (range.getFrom() <= current.getTo()) {
+ current = new Range(current.getFrom(), Math.max(current.getTo(), range.getTo()));
+ } else {
+ merged.add(current);
+ current = range;
+ }
+ }
+ if (current != null)
+ merged.add(current);
+ return merged;
+ }
+
+}
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 ff72381462..2958e51e5b 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
@@ -23,7 +23,6 @@ import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.IRequestParameters;
-import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.time.Duration;
@@ -39,8 +38,6 @@ public abstract class CommonPage extends WebPage {
private RepeatingView rootComponents;
- private Url requestUrl;
-
public CommonPage() {
}
@@ -52,16 +49,10 @@ public abstract class CommonPage extends WebPage {
super(params);
}
- public Url getRequestUrl() {
- return requestUrl;
- }
-
@Override
protected void onInitialize() {
super.onInitialize();
- requestUrl = RequestCycle.get().getRequest().getUrl();
-
add(new AbstractDefaultAjaxBehavior() {
@Override
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java
index 7dab90e929..efe1e90759 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java
@@ -1,227 +1,227 @@
-package com.pmease.commons.wicket.behavior.inputassist;
-
-import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
-import org.apache.wicket.ajax.AjaxChannel;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.markup.head.CssHeaderItem;
-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.request.IRequestParameters;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.resource.CssResourceReference;
-import org.apache.wicket.request.resource.JavaScriptResourceReference;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
-import com.pmease.commons.antlr.codeassist.InputCompletion;
-import com.pmease.commons.antlr.codeassist.InputStatus;
-import com.pmease.commons.loader.AppLoader;
-import com.pmease.commons.util.JoinedRanges;
-import com.pmease.commons.util.Range;
-import com.pmease.commons.wicket.assets.caret.CaretResourceReference;
-import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
-import com.pmease.commons.wicket.assets.scrollintoview.ScrollIntoViewResourceReference;
-import com.pmease.commons.wicket.assets.textareacaretposition.TextareaCaretPositionResourceReference;
-import com.pmease.commons.wicket.component.floating.AlignPlacement;
-import com.pmease.commons.wicket.component.floating.AlignTarget;
-import com.pmease.commons.wicket.component.floating.ComponentTarget;
-import com.pmease.commons.wicket.component.floating.FloatingPanel;
-
-@SuppressWarnings("serial")
-public abstract class InputAssistBehavior extends AbstractDefaultAjaxBehavior {
-
- static final int PAGE_SIZE = 25;
-
- private FloatingPanel dropdown;
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
-
- attributes.setChannel(new AjaxChannel(AjaxChannel.DEFAULT_NAME, AjaxChannel.Type.DROP));
- }
-
- @Override
- protected void onBind() {
- super.onBind();
-
- Component inputField = getComponent();
- inputField.setOutputMarkupId(true);
- }
-
- private int getLine(String content, int charIndex) {
- int line = 0;
- if (charIndex >= content.length())
- charIndex = content.length()-1;
- for (int i=0; i<=charIndex; i++) {
- if (content.charAt(i) == '\n')
- line++;
- }
- return line;
- }
-
- private List<Range> normalizeErrors(String inputContent, List<Range> errors) {
- List<Range> normalizedErrors = new ArrayList<>();
-
- List<String> lines = Splitter.on('\n').splitToList(inputContent);
- for (Range error: new JoinedRanges(errors)) {
- int fromLine = getLine(inputContent, error.getFrom());
- int toLine = getLine(inputContent, error.getTo());
- if (fromLine != toLine) {
- int index = getCharIndex(inputContent, fromLine, lines.get(fromLine).length()-1);
- if (index >= error.getFrom())
- normalizedErrors.add(new Range(error.getFrom(), index));
- index = getCharIndex(inputContent, toLine, 0);
- if (index <= error.getTo())
- normalizedErrors.add(new Range(index, error.getTo()));
- for (int i=fromLine+1; i<toLine; i++) {
- String line = lines.get(i);
- if (line.length() != 0) {
- int from = getCharIndex(inputContent, i, 0);
- normalizedErrors.add(new Range(from, from+line.length()-1));
- }
- }
- } else {
- normalizedErrors.add(error);
- }
- }
-
- return normalizedErrors;
- }
-
- protected int getCharIndex(String content, int line, int charIndexInLine) {
- List<String> lines = Splitter.on('\n').splitToList(content);
- int index = 0;
- for (int i=0; i<line; i++)
- index += lines.get(i).length()+1;
- return index + charIndexInLine;
- }
-
- @Override
- protected void respond(AjaxRequestTarget target) {
- IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();
- String inputContent = params.getParameterValue("input").toString();
- Integer inputCaret = params.getParameterValue("caret").toOptionalInteger();
-
- Preconditions.checkArgument(inputContent.indexOf('\r') == -1);
-
- List<Range> errors = getErrors(inputContent);
- if (errors == null)
- errors = new ArrayList<>();
- List<Range> normalizedErrors = normalizeErrors(inputContent, errors);
- String json;
- try {
- json = AppLoader.getInstance(ObjectMapper.class).writeValueAsString(normalizedErrors);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- String script = String.format("pmease.commons.inputassist.markErrors('%s', %s);",
- getComponent().getMarkupId(), json);
- target.appendJavaScript(script);
-
- if (inputCaret != null) {
- final InputStatus inputStatus = new InputStatus(inputContent, inputCaret);
- final List<InputCompletion> suggestions = getSuggestions(new InputStatus(inputContent, inputCaret), PAGE_SIZE);
- if (!suggestions.isEmpty()) {
- int anchor = getAnchor(inputContent.substring(0, inputCaret));
- if (dropdown == null) {
- dropdown = new FloatingPanel(target, new ComponentTarget(getComponent(), anchor), AlignPlacement.bottom(0)) {
-
- @Override
- protected Component newContent(String id) {
- return new AssistPanel(id, InputAssistBehavior.this, inputStatus,
- suggestions, getHints(inputStatus));
- }
-
- @Override
- protected void onClosed() {
- super.onClosed();
- dropdown = null;
- }
-
- };
- script = String.format("pmease.commons.inputassist.assistOpened('%s', '%s');",
- getComponent().getMarkupId(), dropdown.getMarkupId());
- target.appendJavaScript(script);
- } else {
- Component content = dropdown.getContent();
- Component newContent = new AssistPanel(content.getId(), InputAssistBehavior.this,
- inputStatus, suggestions, getHints(inputStatus));
- content.replaceWith(newContent);
- target.add(newContent);
-
- AlignTarget alignTarget = new ComponentTarget(getComponent(), anchor);
- script = String.format("$('#%s').data('alignment').target=%s;", dropdown.getMarkupId(), alignTarget);
- target.prependJavaScript(script);
-
- script = String.format("pmease.commons.inputassist.assistUpdated('%s', '%s');",
- getComponent().getMarkupId(), dropdown.getMarkupId());
- target.appendJavaScript(script);
- }
- } else if (dropdown != null) {
- dropdown.close();
- }
- } else if (dropdown != null) {
- dropdown.close();
- }
- }
-
- public void close() {
- if (dropdown != null)
- dropdown.close();
- }
-
- Component getInputField() {
- return super.getComponent();
- }
-
- @Override
- public void renderHead(Component component, IHeaderResponse response) {
- super.renderHead(component, response);
-
- response.render(JavaScriptHeaderItem.forReference(ScrollIntoViewResourceReference.INSTANCE));
- response.render(JavaScriptHeaderItem.forReference(CaretResourceReference.INSTANCE));
- response.render(JavaScriptHeaderItem.forReference(HotkeysResourceReference.INSTANCE));
- response.render(JavaScriptHeaderItem.forReference(TextareaCaretPositionResourceReference.INSTANCE));
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(AssistPanel.class, "input-assist.css")));
-
- response.render(JavaScriptHeaderItem.forReference(
- new JavaScriptResourceReference(InputAssistBehavior.class, "input-assist.js")));
-
- String script = String.format("pmease.commons.inputassist.init('%s', %s);",
- getComponent().getMarkupId(true),
- getCallbackFunction(explicit("input"), explicit("caret")));
-
- response.render(OnDomReadyHeaderItem.forScript(script));
- }
-
- protected abstract List<InputCompletion> getSuggestions(InputStatus inputStatus, int count);
-
- protected List<String> getHints(InputStatus inputStatus) {
- return new ArrayList<>();
- }
-
- protected abstract List<Range> getErrors(String inputContent);
-
- /**
- * Given an input content, anchor is index of the char at which place to display left side
- * of the suggestion window. This makes it possible to make the suggestion window moves
- * as one types, instead of always staying at a fixed place
- *
- * @param inputContent
- * @return
- */
- protected abstract int getAnchor(String inputContent);
-
+package com.pmease.commons.wicket.behavior.inputassist;
+
+import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
+import org.apache.wicket.ajax.AjaxChannel;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.CssHeaderItem;
+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.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.pmease.commons.antlr.codeassist.InputCompletion;
+import com.pmease.commons.antlr.codeassist.InputStatus;
+import com.pmease.commons.loader.AppLoader;
+import com.pmease.commons.util.Range;
+import com.pmease.commons.util.RangeUtils;
+import com.pmease.commons.wicket.assets.caret.CaretResourceReference;
+import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
+import com.pmease.commons.wicket.assets.scrollintoview.ScrollIntoViewResourceReference;
+import com.pmease.commons.wicket.assets.textareacaretposition.TextareaCaretPositionResourceReference;
+import com.pmease.commons.wicket.component.floating.AlignPlacement;
+import com.pmease.commons.wicket.component.floating.AlignTarget;
+import com.pmease.commons.wicket.component.floating.ComponentTarget;
+import com.pmease.commons.wicket.component.floating.FloatingPanel;
+
+@SuppressWarnings("serial")
+public abstract class InputAssistBehavior extends AbstractDefaultAjaxBehavior {
+
+ static final int PAGE_SIZE = 25;
+
+ private FloatingPanel dropdown;
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+
+ attributes.setChannel(new AjaxChannel(AjaxChannel.DEFAULT_NAME, AjaxChannel.Type.DROP));
+ }
+
+ @Override
+ protected void onBind() {
+ super.onBind();
+
+ Component inputField = getComponent();
+ inputField.setOutputMarkupId(true);
+ }
+
+ private int getLine(String content, int charIndex) {
+ int line = 0;
+ if (charIndex >= content.length())
+ charIndex = content.length()-1;
+ for (int i=0; i<=charIndex; i++) {
+ if (content.charAt(i) == '\n')
+ line++;
+ }
+ return line;
+ }
+
+ private List<Range> normalizeErrors(String inputContent, List<Range> errors) {
+ List<Range> normalizedErrors = new ArrayList<>();
+
+ List<String> lines = Splitter.on('\n').splitToList(inputContent);
+ for (Range error: RangeUtils.merge(errors)) {
+ int fromLine = getLine(inputContent, error.getFrom());
+ int toLine = getLine(inputContent, error.getTo());
+ if (fromLine != toLine) {
+ int index = getCharIndex(inputContent, fromLine, lines.get(fromLine).length()-1);
+ if (index >= error.getFrom())
+ normalizedErrors.add(new Range(error.getFrom(), index));
+ index = getCharIndex(inputContent, toLine, 0);
+ if (index <= error.getTo())
+ normalizedErrors.add(new Range(index, error.getTo()));
+ for (int i=fromLine+1; i<toLine; i++) {
+ String line = lines.get(i);
+ if (line.length() != 0) {
+ int from = getCharIndex(inputContent, i, 0);
+ normalizedErrors.add(new Range(from, from+line.length()-1));
+ }
+ }
+ } else {
+ normalizedErrors.add(error);
+ }
+ }
+
+ return normalizedErrors;
+ }
+
+ protected int getCharIndex(String content, int line, int charIndexInLine) {
+ List<String> lines = Splitter.on('\n').splitToList(content);
+ int index = 0;
+ for (int i=0; i<line; i++)
+ index += lines.get(i).length()+1;
+ return index + charIndexInLine;
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();
+ String inputContent = params.getParameterValue("input").toString();
+ Integer inputCaret = params.getParameterValue("caret").toOptionalInteger();
+
+ Preconditions.checkArgument(inputContent.indexOf('\r') == -1);
+
+ List<Range> errors = getErrors(inputContent);
+ if (errors == null)
+ errors = new ArrayList<>();
+ List<Range> normalizedErrors = normalizeErrors(inputContent, errors);
+ String json;
+ try {
+ json = AppLoader.getInstance(ObjectMapper.class).writeValueAsString(normalizedErrors);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ String script = String.format("pmease.commons.inputassist.markErrors('%s', %s);",
+ getComponent().getMarkupId(), json);
+ target.appendJavaScript(script);
+
+ if (inputCaret != null) {
+ final InputStatus inputStatus = new InputStatus(inputContent, inputCaret);
+ final List<InputCompletion> suggestions = getSuggestions(new InputStatus(inputContent, inputCaret), PAGE_SIZE);
+ if (!suggestions.isEmpty()) {
+ int anchor = getAnchor(inputContent.substring(0, inputCaret));
+ if (dropdown == null) {
+ dropdown = new FloatingPanel(target, new ComponentTarget(getComponent(), anchor), AlignPlacement.bottom(0)) {
+
+ @Override
+ protected Component newContent(String id) {
+ return new AssistPanel(id, InputAssistBehavior.this, inputStatus,
+ suggestions, getHints(inputStatus));
+ }
+
+ @Override
+ protected void onClosed() {
+ super.onClosed();
+ dropdown = null;
+ }
+
+ };
+ script = String.format("pmease.commons.inputassist.assistOpened('%s', '%s');",
+ getComponent().getMarkupId(), dropdown.getMarkupId());
+ target.appendJavaScript(script);
+ } else {
+ Component content = dropdown.getContent();
+ Component newContent = new AssistPanel(content.getId(), InputAssistBehavior.this,
+ inputStatus, suggestions, getHints(inputStatus));
+ content.replaceWith(newContent);
+ target.add(newContent);
+
+ AlignTarget alignTarget = new ComponentTarget(getComponent(), anchor);
+ script = String.format("$('#%s').data('alignment').target=%s;", dropdown.getMarkupId(), alignTarget);
+ target.prependJavaScript(script);
+
+ script = String.format("pmease.commons.inputassist.assistUpdated('%s', '%s');",
+ getComponent().getMarkupId(), dropdown.getMarkupId());
+ target.appendJavaScript(script);
+ }
+ } else if (dropdown != null) {
+ dropdown.close();
+ }
+ } else if (dropdown != null) {
+ dropdown.close();
+ }
+ }
+
+ public void close() {
+ if (dropdown != null)
+ dropdown.close();
+ }
+
+ Component getInputField() {
+ return super.getComponent();
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(ScrollIntoViewResourceReference.INSTANCE));
+ response.render(JavaScriptHeaderItem.forReference(CaretResourceReference.INSTANCE));
+ response.render(JavaScriptHeaderItem.forReference(HotkeysResourceReference.INSTANCE));
+ response.render(JavaScriptHeaderItem.forReference(TextareaCaretPositionResourceReference.INSTANCE));
+ response.render(CssHeaderItem.forReference(
+ new CssResourceReference(AssistPanel.class, "input-assist.css")));
+
+ response.render(JavaScriptHeaderItem.forReference(
+ new JavaScriptResourceReference(InputAssistBehavior.class, "input-assist.js")));
+
+ String script = String.format("pmease.commons.inputassist.init('%s', %s);",
+ getComponent().getMarkupId(true),
+ getCallbackFunction(explicit("input"), explicit("caret")));
+
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
+ protected abstract List<InputCompletion> getSuggestions(InputStatus inputStatus, int count);
+
+ protected List<String> getHints(InputStatus inputStatus) {
+ return new ArrayList<>();
+ }
+
+ protected abstract List<Range> getErrors(String inputContent);
+
+ /**
+ * Given an input content, anchor is index of the char at which place to display left side
+ * of the suggestion window. This makes it possible to make the suggestion window moves
+ * as one types, instead of always staying at a fixed place
+ *
+ * @param inputContent
+ * @return
+ */
+ protected abstract int getAnchor(String inputContent);
+
}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java
index bdf58943de..0b86f55226 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java
@@ -4,6 +4,7 @@ import java.util.Date;
import javax.annotation.Nullable;
import javax.persistence.Column;
+import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
@@ -12,11 +13,9 @@ import javax.persistence.ManyToOne;
import javax.persistence.Version;
import org.hibernate.annotations.DynamicUpdate;
-import org.hibernate.annotations.OptimisticLock;
import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.component.CompareContext;
/*
* @DynamicUpdate annotation here along with various @OptimisticLock annotations
@@ -46,8 +45,8 @@ public class CodeCommentReply extends AbstractEntity {
@Column(nullable=false)
private Date date = new Date();
- @OptimisticLock(excluded=true)
- private String compareCommit;
+ @Embedded
+ private CompareContext compareContext;
@Nullable
public Account getUser() {
@@ -86,16 +85,16 @@ public class CodeCommentReply extends AbstractEntity {
this.date = date;
}
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
+ public CompareContext getCompareContext() {
+ return compareContext;
}
- public String getCompareCommit() {
- return compareCommit;
+ public void setCompareContext(CompareContext compareContext) {
+ this.compareContext = compareContext;
}
- public void setCompareCommit(String compareCommit) {
- this.compareCommit = compareCommit;
+ public void setVersion(long version) {
+ this.version = version;
}
-
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
index 907847ff54..9db4828a2a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
@@ -575,8 +575,8 @@ public class Depot extends AbstractEntity implements AccountBelonging {
Blob blob = getBlobCache().get(blobIdent);
if (blob == null) {
try (RevWalk revWalk = new RevWalk(getRepository())) {
- ObjectId commitId = getObjectId(blobIdent.revision);
- RevTree revTree = revWalk.parseCommit(commitId).getTree();
+ ObjectId revId = getObjectId(blobIdent.revision);
+ RevTree revTree = revWalk.parseCommit(revId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(getRepository(), blobIdent.path, revTree);
if (treeWalk != null) {
if (blobIdent.isGitLink()) {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
index cac62855ed..9af0c432f6 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
@@ -4,12 +4,16 @@ import java.util.Collection;
import javax.annotation.Nullable;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.pmease.commons.hibernate.dao.EntityDao;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
public interface CodeCommentManager extends EntityDao<CodeComment> {
- Collection<CodeComment> query(Depot depot, String commit, @Nullable String path);
+ Collection<CodeComment> query(Depot depot, ObjectId commitId, @Nullable String path);
+
+ Collection<CodeComment> query(Depot depot, ObjectId...commitIds);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
index 6d84f8c007..ad745be7bd 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
@@ -1,12 +1,17 @@
package com.pmease.gitplex.core.manager.impl;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
+import org.eclipse.jgit.lib.ObjectId;
+import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import com.google.common.base.Preconditions;
import com.pmease.commons.hibernate.dao.AbstractEntityDao;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.hibernate.dao.EntityCriteria;
@@ -24,13 +29,27 @@ public class DefaultCodeCommentManager extends AbstractEntityDao<CodeComment>
}
@Override
- public Collection<CodeComment> query(Depot depot, String commit, String path) {
+ public Collection<CodeComment> query(Depot depot, ObjectId commitId, String path) {
EntityCriteria<CodeComment> criteria = newCriteria();
criteria.add(Restrictions.eq("depot", depot));
- criteria.add(Restrictions.eq("commit", commit));
+ criteria.add(Restrictions.eq("commit", commitId.name()));
if (path != null)
criteria.add(Restrictions.eq("path", path));
return query(criteria);
}
+ @Override
+ public Collection<CodeComment> query(Depot depot, ObjectId... commitIds) {
+ Preconditions.checkArgument(commitIds.length > 0);
+
+ EntityCriteria<CodeComment> criteria = newCriteria();
+ criteria.add(Restrictions.eq("depot", depot));
+ List<Criterion> criterions = new ArrayList<>();
+ for (ObjectId commitId: commitIds) {
+ criterions.add(Restrictions.eq("commit", commitId.name()));
+ }
+ criteria.add(Restrictions.or(criterions.toArray(new Criterion[criterions.size()])));
+ return query(criteria);
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
index bb5a77d0dc..439d0025e2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
@@ -9,7 +9,6 @@ import com.pmease.gitplex.core.entity.component.DepotAndBranch;
import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.web.page.depot.DepotPage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public class BranchLink extends BookmarkablePageLink<Void> {
@@ -22,7 +21,7 @@ public class BranchLink extends BookmarkablePageLink<Void> {
}
private static PageParameters getPageParams(DepotAndBranch depotAndBranch) {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = depotAndBranch.getBranch();
return DepotFilePage.paramsOf(depotAndBranch.getDepot(), state);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
index a6d9ced3a2..32ef9ff9a2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
@@ -8,7 +8,6 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-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.html.WebMarkupContainer;
@@ -472,9 +471,6 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {
add(repliesView);
add(newAddReplyContainer());
- add(AttributeAppender.append("data-line", getComment().getMark().getBeginLine()));
- add(AttributeAppender.append("data-comment", getComment().getId()));
-
setOutputMarkupId(true);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
index 01cf690564..faa9ada416 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
@@ -57,7 +57,6 @@ import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.search.query.TooGeneralQueryException;
import com.pmease.gitplex.web.component.depotfile.blobsearch.result.SearchResultPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public abstract class InstantSearchPanel extends Panel {
@@ -271,7 +270,7 @@ public abstract class InstantSearchPanel extends Panel {
link.add(new Label("scope", hit.getScope()).setVisible(hit.getScope()!=null));
item.add(link);
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = revisionModel.getObject();
state.blobIdent.path = hit.getBlobPath();
state.mark = Mark.of(hit.getTokenPos());
@@ -397,7 +396,7 @@ public abstract class InstantSearchPanel extends Panel {
if (item.getIndex() + symbolHits.size() == activeHitIndex)
item.add(AttributeModifier.append("class", " active"));
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = revisionModel.getObject();
state.blobIdent.path = hit.getBlobPath();
state.mark = Mark.of(hit.getTokenPos());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
index b88e3b0094..9fb040161b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
@@ -40,7 +40,6 @@ import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.TextHit;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public abstract class SearchResultPanel extends Panel {
@@ -411,7 +410,7 @@ public abstract class SearchResultPanel extends Panel {
if (activeBlobIndex == blobItem.getIndex() && activeHitIndex == -1)
add(AttributeAppender.append("class", " active"));
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = context.getBlobIdent().revision;
state.blobIdent.path = blobPath;
state.requestId = PullRequest.idOf(context.getPullRequest());
@@ -470,7 +469,7 @@ public abstract class SearchResultPanel extends Panel {
if (activeBlobIndex == blobItem.getIndex() && activeHitIndex == hitItem.getIndex())
add(AttributeAppender.append("class", " active"));
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.requestId = PullRequest.idOf(context.getPullRequest());
state.mark = Mark.of(hit.getTokenPos());
state.blobIdent.revision = context.getBlobIdent().revision;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
index bba01afe1a..712e3e296a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
@@ -32,7 +32,7 @@ public interface BlobViewContext extends Serializable {
@Nullable
Mark getMark();
- void onMark(AjaxRequestTarget target, @Nullable Mark mark);
+ void onMark(AjaxRequestTarget target, Mark mark);
String getMarkUrl(Mark mark);
@@ -52,10 +52,14 @@ public interface BlobViewContext extends Serializable {
void onEdit(AjaxRequestTarget target, @Nullable String viewState);
- void onOpenComment(AjaxRequestTarget target, @Nullable CodeComment comment);
+ void onCommentOpened(AjaxRequestTarget target, CodeComment comment);
+ void onCommentClosed(AjaxRequestTarget target);
+
+ void onAddComment(AjaxRequestTarget target, Mark mark);
+
@Nullable
- CodeComment getComment();
+ CodeComment getOpenComment();
RevCommit getCommit();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
index 429172abf2..d2131b5394 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
@@ -64,7 +64,6 @@ import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;
-import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;
import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;
import com.pmease.commons.wicket.component.menu.MenuItem;
@@ -115,7 +114,7 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
protected Collection<CodeComment> load() {
return GitPlex.getInstance(CodeCommentManager.class).query(
- context.getDepot(), context.getCommit().name(), context.getBlobIdent().path);
+ context.getDepot(), context.getCommit(), context.getBlobIdent().path);
}
};
@@ -126,7 +125,7 @@ public class SourceViewPanel extends BlobViewPanel {
private SymbolTooltipPanel symbolTooltip;
- private AbstractDefaultAjaxBehavior commentBehavior;
+ private AbstractDefaultAjaxBehavior markBehavior;
public SourceViewPanel(String id, BlobViewContext context, @Nullable String viewState) {
super(id, context);
@@ -252,8 +251,12 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
public void onClick(AjaxRequestTarget target) {
- mark(target, context.getComment().getMark(), true);
- context.onMark(target, context.getComment().getMark());
+ CodeComment comment = context.getOpenComment();
+ if (comment != null)
+ mark(target, comment.getMark(), true);
+ else
+ mark(target, (Mark) commentContainer.getDefaultModelObject(), true);
+ context.onMark(target, context.getOpenComment().getMark());
target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));
}
@@ -265,19 +268,18 @@ public class SourceViewPanel extends BlobViewPanel {
});
-
- // use this instead of permanent link as we want to get the link
+ // use this instead of bookmarkable link as we want to get the link
// updated whenever we re-render the comment container
AttributeAppender appender = AttributeAppender.append("href", new LoadableDetachableModel<String>() {
@Override
protected String load() {
- if (context.getComment() != null) {
- DepotFilePage.HistoryState state = new DepotFilePage.HistoryState();
+ if (context.getOpenComment() != null) {
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = new BlobIdent(context.getBlobIdent());
state.blobIdent.revision = context.getCommit().name();
- state.commentId = context.getComment().getId();
- state.mark = context.getComment().getMark();
+ state.commentId = context.getOpenComment().getId();
+ state.mark = context.getOpenComment().getMark();
return urlFor(DepotFilePage.class, DepotFilePage.paramsOf(context.getDepot(), state)).toString();
} else {
return "";
@@ -285,7 +287,16 @@ public class SourceViewPanel extends BlobViewPanel {
}
});
- commentContainer.add(new WebMarkupContainer("permanent").add(appender));
+ commentContainer.add(new WebMarkupContainer("permanent") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(context.getOpenComment() != null);
+ }
+
+ }.add(appender));
+
commentContainer.add(new AjaxLink<Void>("close") {
@Override
@@ -296,18 +307,21 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
public void onClick(AjaxRequestTarget target) {
- hideComment(target);
- context.onOpenComment(target, null);
+ clearComment(target);
+ if (context.getOpenComment() != null)
+ context.onCommentClosed(target);
+ target.appendJavaScript("gitplex.sourceview.onCloseComment();");
}
});
+
commentContainer.setOutputMarkupPlaceholderTag(true);
- if (context.getComment() != null) {
+ if (context.getOpenComment() != null) {
IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
@Override
protected CodeComment load() {
- return context.getComment();
+ return context.getOpenComment();
}
};
@@ -327,7 +341,7 @@ public class SourceViewPanel extends BlobViewPanel {
}
add(commentContainer);
- add(commentBehavior = new AbstractDefaultAjaxBehavior() {
+ add(markBehavior = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
@@ -345,6 +359,7 @@ public class SourceViewPanel extends BlobViewPanel {
Preconditions.checkNotNull(SecurityUtils.getAccount());
mark = getMark(params, "param1", "param2", "param3", "param4");
+ commentContainer.setDefaultModelObject(mark);
Fragment fragment = new Fragment(BODY_ID, "newCommentFrag", SourceViewPanel.this);
fragment.setOutputMarkupId(true);
@@ -376,7 +391,8 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
public void onClick(AjaxRequestTarget target) {
- hideComment(target);
+ clearComment(target);
+ target.appendJavaScript("gitplex.sourceview.onLayoutChange();");
}
});
@@ -420,14 +436,13 @@ public class SourceViewPanel extends BlobViewPanel {
}
};
- fragment.replaceWith(commentPanel);
- target.add(commentPanel);
+ commentContainer.replace(commentPanel);
+ target.add(commentContainer);
- String script = String.format("gitplex.sourceview.onCommentAdded(%d, %s);",
- comment.getMark().getBeginLine(),
+ String script = String.format("gitplex.sourceview.onCommentAdded(%s);",
getJsonOfComment(comment));
target.appendJavaScript(script);
- context.onOpenComment(target, comment);
+ context.onCommentOpened(target, comment);
}
});
@@ -435,7 +450,8 @@ public class SourceViewPanel extends BlobViewPanel {
commentContainer.replace(fragment);
commentContainer.setVisible(true);
target.add(commentContainer);
- target.appendJavaScript("gitplex.sourceview.onAddingComment();");
+ context.onAddComment(target, mark);
+ target.appendJavaScript(String.format("gitplex.sourceview.onAddComment(%s);", mark.toJson()));
break;
case "openComment":
Long commentId = params.getParameterValue("param1").toLong();
@@ -462,7 +478,7 @@ public class SourceViewPanel extends BlobViewPanel {
script = String.format("gitplex.sourceview.onOpenComment(%s);",
getJsonOfComment(commentModel.getObject()));
target.appendJavaScript(script);
- context.onOpenComment(target, commentModel.getObject());
+ context.onCommentOpened(target, commentModel.getObject());
break;
}
}
@@ -536,9 +552,9 @@ public class SourceViewPanel extends BlobViewPanel {
}
};
- DepotFilePage.HistoryState state = new DepotFilePage.HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = context.getBlobIdent();
- state.commentId = CodeComment.idOf(context.getComment());
+ state.commentId = CodeComment.idOf(context.getOpenComment());
state.mark = Mark.of(symbol.getPos());
state.requestId = PullRequest.idOf(context.getPullRequest());
PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);
@@ -629,22 +645,19 @@ public class SourceViewPanel extends BlobViewPanel {
}
return jsonOfCommentInfo;
}
-
- private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+
+ private void clearComment(AjaxRequestTarget target) {
commentContainer.replace(new WebMarkupContainer(BODY_ID));
commentContainer.setVisible(false);
target.add(commentContainer);
- String script = String.format("gitplex.sourceview.onCommentDeleted(%d, %d);",
- comment.getMark().getBeginLine(), comment.getId());
- target.appendJavaScript(script);
- context.onOpenComment(target, null);
}
- private void hideComment(AjaxRequestTarget target) {
- commentContainer.replace(new WebMarkupContainer(BODY_ID));
- commentContainer.setVisible(false);
- target.add(commentContainer);
- target.appendJavaScript("gitplex.sourceview.onOpenComment();");
+ private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+ clearComment(target);
+ String script = String.format("gitplex.sourceview.onCommentDeleted(%s);",
+ getJsonOfComment(comment));
+ target.appendJavaScript(script);
+ context.onCommentClosed(target);
}
private List<Symbol> getChildSymbols(@Nullable Symbol parentSymbol) {
@@ -669,10 +682,10 @@ public class SourceViewPanel extends BlobViewPanel {
blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());
blameInfo.hash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);
blameInfo.message = blame.getCommit().getSubject();
- CommitDetailPage.HistoryState state = new CommitDetailPage.HistoryState();
+ CommitDetailPage.State state = new CommitDetailPage.State();
+ state.revision = blame.getCommit().getHash();
state.pathFilter = context.getBlobIdent().path;
- PageParameters params = CommitDetailPage.paramsOf(context.getDepot(),
- blame.getCommit().getHash(), state);
+ PageParameters params = CommitDetailPage.paramsOf(context.getDepot(), state);
blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();
blameInfo.ranges = blame.getRanges();
blameInfos.add(blameInfo);
@@ -692,7 +705,6 @@ public class SourceViewPanel extends BlobViewPanel {
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- response.render(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(JQueryUIResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));
@@ -731,13 +743,14 @@ public class SourceViewPanel extends BlobViewPanel {
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
- CharSequence commentCallback = commentBehavior.getCallbackFunction(
+ CharSequence commentCallback = markBehavior.getCallbackFunction(
explicit("action"), explicit("param1"), explicit("param2"),
explicit("param3"), explicit("param4"));
- String script = String.format("gitplex.sourceview.init('%s', '%s', %s, '%s', '%s', "
+ String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "
+ "%s, %s, %s, %s, %s);",
JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),
- JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),
+ JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),
+ context.getOpenComment()!=null?getJsonOfComment(context.getOpenComment()):"undefined",
context.getMark()!=null?context.getMark().toJson():"undefined",
symbolTooltip.getMarkupId(),
context.getBlobIdent().revision,
@@ -771,10 +784,10 @@ public class SourceViewPanel extends BlobViewPanel {
List<Range> ranges;
}
- @SuppressWarnings("unused")
private static class CommentInfo {
long id;
+ @SuppressWarnings("unused")
Mark mark;
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
index 9aea98199b..ddfa63ceb7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
@@ -1,10 +1,15 @@
gitplex.sourceview = {
- init: function(fileContent, filePath, mark, symbolTooltipId,
- revision, blameInfos, commentInfos, sourceCallback, viewState, loggedIn) {
+ init: function(fileContent, filePath, openComment, mark, symbolTooltipId,
+ revision, blameInfos, comments, markCallback, viewState, loggedIn) {
var cm;
var $sourceView = $(".source-view");
- $sourceView.data("sourceCallback", sourceCallback);
+ if (openComment)
+ $sourceView.data("openComment", openComment);
+ if (mark)
+ $sourceView.data("mark", mark);
+
+ $sourceView.data("markCallback", markCallback);
var $code = $sourceView.children(".code");
$sourceView.closest(".content").css("overflow", "hidden");
@@ -99,9 +104,9 @@ gitplex.sourceview = {
var gutters = cm.getOption("gutters").slice();
gutters.splice(0, 0, "CodeMirror-comments");
cm.setOption("gutters", gutters);
- for (var line in commentInfos) {
- if (commentInfos.hasOwnProperty(line)) {
- gitplex.sourceview.addCommentGutter(line, commentInfos[line][1]);
+ for (var line in comments) {
+ if (comments.hasOwnProperty(line)) {
+ gitplex.sourceview.addCommentGutter(line, comments[line][1]);
}
}
@@ -116,7 +121,7 @@ gitplex.sourceview = {
var from = cm.getCursor("from");
var to = cm.getCursor("to");
if (from.line != to.line || from.ch != to.ch) {
- sourceCallback("openSelectionPopup", from.line, from.ch, to.line, to.ch);
+ markCallback("openSelectionPopup", from.line, from.ch, to.line, to.ch);
} else {
$("#selection-popup").hide();
}
@@ -207,37 +212,30 @@ gitplex.sourceview = {
});
},
restoreMark: function() {
+ var $sourceView = $(".source-view");
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var uri = new URI(window.location.href);
- var markStr = uri.search(true).mark;
- if (markStr) {
- var splitted = markStr.split("-");
- var fromInfo = splitted[0].split(".");
- var toInfo = splitted[1].split(".");
- var mark = {
- beginLine: parseInt(fromInfo[0])-1,
- beginChar: parseInt(fromInfo[1]),
- endLine: parseInt(toInfo[0])-1,
- endChar: parseInt(toInfo[1])
- }
+ var mark = $sourceView.data("mark");
+ if (mark) {
pmease.commons.codemirror.mark(cm, mark, false);
} else {
pmease.commons.codemirror.clearMark(cm);
}
},
- addCommentGutter: function(line, commentInfos) {
+ addCommentGutter: function(line, comments) {
+ $(".comment-popover[data-line='" + line + "']").remove();
+
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var sourceCallback = $(".source-view").data("sourceCallback");
+ var markCallback = $(".source-view").data("markCallback");
var $gutter = $(document.createElement("div"));
$gutter.addClass("CodeMirror-comment");
- $gutter.data("commentInfos", commentInfos);
- if (commentInfos.length != 1) {
+ $gutter.data("comments", comments);
+ if (comments.length != 1) {
$gutter.append("<a><i class='fa fa-comments'></i></a>");
var $commentLink = $gutter.children("a");
var content = "";
- for (var i in commentInfos) {
- var commentInfo = commentInfos[i];
+ for (var i in comments) {
+ var comment = comments[i];
var index = parseInt(i) + 1;
content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + index + "</a>";
}
@@ -251,8 +249,8 @@ gitplex.sourceview = {
$commentLink.on('shown.bs.popover', function () {
$(".comment-popover[data-line='" + line + "'] a").each(function() {
$(this).mouseover(function() {
- var commentInfo = commentInfos[$(this).index()];
- pmease.commons.codemirror.mark(cm, commentInfo.mark, false);
+ var comment = comments[$(this).index()];
+ pmease.commons.codemirror.mark(cm, comment.mark, false);
});
$(this).mouseout(function() {
gitplex.sourceview.restoreMark();
@@ -262,18 +260,18 @@ gitplex.sourceview = {
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
- var commentInfo = commentInfos[$(this).index()];
- sourceCallback("openComment", commentInfo.id);
+ var comment = comments[$(this).index()];
+ markCallback("openComment", comment.id);
});
});
gitplex.sourceview.highlightCommentTrigger();
});
} else {
- var commentInfo = commentInfos[0];
+ var comment = comments[0];
$gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");
var $commentLink = $gutter.children("a");
$commentLink.mouseover(function() {
- pmease.commons.codemirror.mark(cm, commentInfo.mark, false);
+ pmease.commons.codemirror.mark(cm, comment.mark, false);
});
$commentLink.mouseout(function() {
gitplex.sourceview.restoreMark();
@@ -283,7 +281,7 @@ gitplex.sourceview = {
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
- sourceCallback("openComment", commentInfo.id);
+ markCallback("openComment", comment.id);
});
}
cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);
@@ -291,7 +289,7 @@ gitplex.sourceview = {
openSelectionPopup: function(mark, markUrl, loggedIn) {
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
var $sourceView = $(".source-view");
- var sourceCallback = $sourceView.data("sourceCallback");
+ var markCallback = $sourceView.data("markCallback");
var ch = (mark.beginChar + mark.endChar)/2;
var position = cm.charCoords({line:mark.beginLine, ch:ch});
var permanentLinkCallback = function($permanentLink) {
@@ -305,10 +303,7 @@ gitplex.sourceview = {
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
- $("#selection-popup").hide();
- pmease.commons.codemirror.clearSelection(cm);
- pmease.commons.codemirror.mark(cm, mark, false);
- sourceCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
+ markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
});
} else {
$commentLink.html("Log in to comment on selection");
@@ -317,41 +312,47 @@ gitplex.sourceview = {
$("#selection-popup").data("open")(
position, permanentLinkCallback, commentLinkCallback, $(".source-view>.code")[0]);
},
- onCommentAdded: function(line, commentInfo) {
+ onCommentAdded: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.data("openComment", comment);
+ $sourceView.data("mark", comment.mark);
+
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var sourceCallback = $(".source-view").data("sourceCallback");
+ var line = parseInt(comment.mark.beginLine);
var lineInfo = cm.lineInfo(line);
var gutter;
if (lineInfo.gutterMarkers)
gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
- var commentInfos;
+ var comments;
if (gutter) {
- commentInfos = $(gutter).data("commentInfos");
+ comments = $(gutter).data("comments");
} else {
- commentInfos = [];
+ comments = [];
}
- commentInfos.push(commentInfo);
- gitplex.sourceview.addCommentGutter(line, commentInfos);
+ comments.push(comment);
+ gitplex.sourceview.addCommentGutter(line, comments);
gitplex.sourceview.highlightCommentTrigger();
},
- onCommentDeleted: function(line, commentId) {
+ onCommentDeleted: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
+
+ var line = parseInt(comment.mark.beginLine);
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var sourceCallback = $(".source-view").data("sourceCallback");
var lineInfo = cm.lineInfo(line);
var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);
- var commentInfos = $gutter.data("commentInfos");
- if (commentInfos.length == 1) {
+ var comments = $gutter.data("comments");
+ if (comments.length == 1) {
cm.setGutterMarker(line, "CodeMirror-comments", null);
} else {
- for (var i in commentInfos) {
- var commentInfo = commentInfos[i];
- if (commentInfo.id == commentId) {
- commentInfos.splice(i, 1);
+ for (var i in comments) {
+ var comment = comments[i];
+ if (comment.id == commentId) {
+ comments.splice(i, 1);
break;
}
}
- gitplex.sourceview.addCommentGutter(line, commentInfos);
- $(".comment-popover[data-line='" + line + "']").remove();
+ gitplex.sourceview.addCommentGutter(line, comments);
}
gitplex.sourceview.highlightCommentTrigger();
},
@@ -359,17 +360,32 @@ gitplex.sourceview = {
$sourceView = $('.source-view');
$sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);
},
- onAddingComment: function() {
+ onAddComment: function(mark) {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
+ $sourceView.data("mark", mark);
+ $("#selection-popup").hide();
+
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ pmease.commons.codemirror.clearSelection(cm);
+ pmease.commons.codemirror.mark(cm, mark, false);
+
gitplex.sourceview.highlightCommentTrigger();
gitplex.sourceview.onLayoutChange();
},
- onOpenComment: function(commentInfo) {
+ onOpenComment: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.data("openComment", comment);
+ $sourceView.data("mark", comment.mark);
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.mark(comment.mark, false);
+ gitplex.sourceview.onLayoutChange();
+ },
+ onCloseComment: function() {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
gitplex.sourceview.highlightCommentTrigger();
gitplex.sourceview.onLayoutChange();
- if (commentInfo)
- gitplex.sourceview.mark(commentInfo.mark, false);
- else
- gitplex.sourceview.restoreMark();
},
onToggleOutline: function() {
gitplex.sourceview.onLayoutChange();
@@ -386,30 +402,31 @@ gitplex.sourceview = {
}
}
}
- var $comment = $(".source-view>.comment>.content>.body");
- if ($comment.length != 0) {
- var line = parseInt($comment.data("line"));
+
+ var openComment = $(".source-view").data("openComment");
+ if (openComment) {
+ var line = parseInt(openComment.mark.beginLine);
var lineInfo = cm.lineInfo(line);
if (lineInfo && lineInfo.gutterMarkers) {
var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
if (gutter) {
- var commentInfos = $(gutter).data("commentInfos");
- if (commentInfos.length == 1) {
+ var comments = $(gutter).data("comments");
+ if (comments.length == 1) {
$(gutter).children("a").addClass("active");
} else {
- var commentId = $comment.data("comment");
$(".comment-popover[data-line='" + line + "'] a").each(function() {
- var commentInfo = commentInfos[$(this).index()];
- if (commentInfo.id == commentId) {
+ var comment = comments[$(this).index()];
+ if (comment.id == openComment.id) {
$(this).addClass("active");
}
});
}
}
}
- }
+ }
},
mark: function(mark, scroll) {
+ $(".source-view").data("mark", mark);
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
pmease.commons.codemirror.mark(cm, mark, scroll);
},
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkPanel.java
index c8bf8169f8..03a893ab66 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkPanel.java
@@ -23,7 +23,6 @@ import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public class SymbolLinkPanel extends BlobViewPanel {
@@ -67,7 +66,7 @@ public class SymbolLinkPanel extends BlobViewPanel {
};
link.setEnabled(false);
} else {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = context.getBlobIdent().revision;
state.blobIdent.path = targetPath;
state.requestId = PullRequest.idOf(context.getPullRequest());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java
index 7d86837186..6d2a232b03 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java
@@ -124,7 +124,7 @@ public abstract class EditSavePanel extends Panel {
changedContainer.setOutputMarkupPlaceholderTag(true);
if (change != null) {
changedContainer.add(new BlobDiffPanel("changes", depotModel,
- new Model<PullRequest>(null), change, DiffViewMode.UNIFIED));
+ new Model<PullRequest>(null), change, DiffViewMode.UNIFIED, null));
} else {
changedContainer.add(new WebMarkupContainer("changes"));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
index 9372d8aae2..f61fb2fee1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
@@ -134,7 +134,7 @@ public abstract class FileEditPanel extends Panel {
};
BlobDiffPanel preview = new BlobDiffPanel("preview", depotModel, new Model<PullRequest>(null),
- change, DiffViewMode.UNIFIED);
+ change, DiffViewMode.UNIFIED, null);
replace(preview);
target.add(preview);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/FileListPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/FileListPanel.java
index bd19ff8780..391736b574 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/FileListPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/FileListPanel.java
@@ -40,7 +40,6 @@ import com.pmease.commons.wicket.component.markdownviewer.MarkdownViewer;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public abstract class FileListPanel extends Panel {
@@ -158,7 +157,7 @@ public abstract class FileListPanel extends Panel {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = parentIdent;
state.requestId = PullRequest.idOf(requestModel.getObject());
PageParameters params = DepotFilePage.paramsOf(depotModel.getObject(), state);
@@ -194,7 +193,7 @@ public abstract class FileListPanel extends Panel {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = blobIdent;
state.requestId = PullRequest.idOf(requestModel.getObject());
PageParameters params = DepotFilePage.paramsOf(depotModel.getObject(), state);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java
index 0f4a57ad55..e0a1733441 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java
@@ -66,7 +66,6 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;
import com.pmease.gitplex.web.page.depot.commit.DepotCommitsPage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
import com.pmease.gitplex.web.resource.BlobResource;
import com.pmease.gitplex.web.resource.BlobResourceReference;
@@ -137,7 +136,7 @@ public abstract class FileNavigator extends Panel {
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = blobIdent;
state.requestId = PullRequest.idOf(context.getPullRequest());
PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);
@@ -256,7 +255,7 @@ public abstract class FileNavigator extends Panel {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = model.getObject();
state.requestId = PullRequest.idOf(context.getPullRequest());
PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);
@@ -343,7 +342,7 @@ public abstract class FileNavigator extends Panel {
@Override
public void onClick() {
- DepotCommitsPage.HistoryState state = new DepotCommitsPage.HistoryState();
+ DepotCommitsPage.State state = new DepotCommitsPage.State();
String commitHash = context.getDepot().getObjectId(file.revision).name();
state.setCompareWith(commitHash);
if (file.path != null)
@@ -442,7 +441,7 @@ public abstract class FileNavigator extends Panel {
@Override
public AbstractLink newLink(String id) {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = context.getPullRequest().getSourceBranch();
state.blobIdent.path = context.getBlobIdent().path;
state.mode = Mode.EDIT;
@@ -500,7 +499,7 @@ public abstract class FileNavigator extends Panel {
};
PageParameters params;
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = context.getBlobIdent();
state.mode = Mode.EDIT;
state.mark = context.getMark();
@@ -530,7 +529,7 @@ public abstract class FileNavigator extends Panel {
@Override
public AbstractLink newLink(String id) {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = context.getPullRequest().getSourceBranch();
state.blobIdent.path = context.getBlobIdent().path;
state.mode = Mode.DELETE;
@@ -580,7 +579,7 @@ public abstract class FileNavigator extends Panel {
}
};
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = context.getBlobIdent();
state.mode = Mode.EDIT;
PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java
index 5a6f5f27f5..2abdbd0f03 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java
@@ -1,141 +1,196 @@
-package com.pmease.gitplex.web.component.diff.blob;
-
-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.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.resource.CssResourceReference;
-import org.eclipse.jgit.diff.DiffEntry.ChangeType;
-
-import com.pmease.commons.git.Blob;
-import com.pmease.commons.git.BlobChange;
-import com.pmease.commons.lang.diff.DiffUtils;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.web.Constants;
-import com.pmease.gitplex.web.component.diff.DiffRenderer;
-import com.pmease.gitplex.web.component.diff.blob.text.TextDiffPanel;
-import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;
-import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;
-
-@SuppressWarnings("serial")
-public class BlobDiffPanel extends Panel {
-
- private static final String CONTENT_ID = "content";
-
- private final IModel<Depot> depotModel;
-
- private final IModel<PullRequest> requestModel;
-
- private final BlobChange change;
-
- private final DiffViewMode diffMode;
-
- public BlobDiffPanel(String id, IModel<Depot> depotModel,
- IModel<PullRequest> requestModel, BlobChange change, DiffViewMode diffMode) {
- super(id);
-
- this.depotModel = depotModel;
- this.requestModel = requestModel;
- this.change = change;
- this.diffMode = diffMode;
- }
-
- private Fragment newFragment(String message, boolean warning) {
- Fragment fragment = new Fragment(CONTENT_ID, "noDiffFrag", this);
- fragment.add(new BlobDiffTitle("title", change));
- if (warning)
- fragment.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", "fa fa-warning")));
- else
- fragment.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", "fa fa-info-circle")));
- fragment.add(new Label("message", message));
- return fragment;
- }
-
- private void showBlob(Blob blob) {
- if (blob.getText() != null) {
- if (blob.getText().getLines().size() > DiffUtils.MAX_DIFF_SIZE) {
- add(newFragment("Unable to diff as the file is too large.", true));
- } else if (change.getAdditions()+change.getDeletions() > Constants.MAX_SINGLE_FILE_DIFF_LINES) {
- add(newFragment("Diff is too large to be displayed.", true));
- } else if (change.getDiffBlocks().isEmpty()) {
- if (change.getNewBlobIdent().path != null)
- add(newFragment("Empty file added.", false));
- else
- add(newFragment("Empty file removed.", false));
- } else {
- add(new TextDiffPanel(CONTENT_ID, depotModel, requestModel, change, diffMode));
- }
- } else if (blob.isPartial()) {
- add(newFragment("File is too large to be loaded.", true));
- } else {
- Panel diffPanel = null;
- for (DiffRenderer renderer: GitPlex.getExtensions(DiffRenderer.class)) {
- diffPanel = renderer.render(CONTENT_ID, blob.getMediaType(), change);
- if (diffPanel != null)
- break;
- }
- if (diffPanel != null)
- add(diffPanel);
- else
- add(newFragment("Binary file.", false));
- }
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- if (change.getType() == ChangeType.ADD || change.getType() == ChangeType.COPY) {
- showBlob(change.getNewBlob());
- } else if (change.getType() == ChangeType.DELETE) {
- showBlob(change.getOldBlob());
- } else {
- if (change.getOldText() != null && change.getNewText() != null) {
- if (change.getOldText().getLines().size() + change.getNewText().getLines().size() > DiffUtils.MAX_DIFF_SIZE) {
- add(newFragment("Unable to diff as the file is too large.", true));
- } else if (change.getAdditions() + change.getDeletions() > Constants.MAX_SINGLE_FILE_DIFF_LINES) {
- add(newFragment("Diff is too large to be displayed.", true));
- } else if (change.getAdditions() + change.getDeletions() == 0) {
- add(newFragment("Content is identical", false));
- } else {
- add(new TextDiffPanel(CONTENT_ID, depotModel, requestModel, change, diffMode));
- }
- } else if (change.getOldBlob().isPartial() || change.getNewBlob().isPartial()) {
- add(newFragment("File is too large to be loaded.", true));
- } else if (change.getOldBlob().getMediaType().equals(change.getNewBlob().getMediaType())) {
- Panel diffPanel = null;
- for (DiffRenderer renderer: GitPlex.getExtensions(DiffRenderer.class)) {
- diffPanel = renderer.render(CONTENT_ID, change.getNewBlob().getMediaType(), change);
- if (diffPanel != null)
- break;
- }
- if (diffPanel != null)
- add(diffPanel);
- else
- add(newFragment("Binary file.", false));
- } else {
- add(newFragment("Binary file.", false));
- }
- }
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new CssResourceReference(BlobDiffPanel.class, "blob-diff.css")));
- }
-
- protected void onDetach() {
- depotModel.detach();
- requestModel.detach();
-
- super.onDetach();
- }
-
-}
+package com.pmease.gitplex.web.component.diff.blob;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+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.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+
+import com.pmease.commons.git.Blob;
+import com.pmease.commons.git.BlobChange;
+import com.pmease.commons.lang.diff.DiffUtils;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.web.Constants;
+import com.pmease.gitplex.web.component.diff.DiffRenderer;
+import com.pmease.gitplex.web.component.diff.blob.text.TextDiffPanel;
+import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;
+import com.pmease.gitplex.web.component.diff.revision.BlobMarkSupport;
+import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;
+
+@SuppressWarnings("serial")
+public class BlobDiffPanel extends Panel implements CommentAware {
+
+ private static final String CONTENT_ID = "content";
+
+ private final IModel<Depot> depotModel;
+
+ private final IModel<PullRequest> requestModel;
+
+ private final BlobChange change;
+
+ private final DiffViewMode diffMode;
+
+ private final BlobMarkSupport markSupport;
+
+ public BlobDiffPanel(String id, IModel<Depot> depotModel, IModel<PullRequest> requestModel,
+ BlobChange change, DiffViewMode diffMode, @Nullable BlobMarkSupport markSupport) {
+ super(id);
+
+ this.depotModel = depotModel;
+ this.requestModel = requestModel;
+ this.change = change;
+ this.diffMode = diffMode;
+ this.markSupport = markSupport;
+ }
+
+ private Fragment newFragment(String message, boolean warning) {
+ Fragment fragment = new Fragment(CONTENT_ID, "noDiffFrag", this);
+ fragment.add(new BlobDiffTitle("title", change));
+ if (warning)
+ fragment.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", "fa fa-warning")));
+ else
+ fragment.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", "fa fa-info-circle")));
+ fragment.add(new Label("message", message));
+ return fragment;
+ }
+
+ private void showBlob(Blob blob) {
+ if (blob.getText() != null) {
+ if (blob.getText().getLines().size() > DiffUtils.MAX_DIFF_SIZE) {
+ add(newFragment("Unable to diff as the file is too large.", true));
+ } else if (change.getAdditions()+change.getDeletions() > Constants.MAX_SINGLE_FILE_DIFF_LINES) {
+ add(newFragment("Diff is too large to be displayed.", true));
+ } else if (change.getDiffBlocks().isEmpty()) {
+ if (change.getNewBlobIdent().path != null)
+ add(newFragment("Empty file added.", false));
+ else
+ add(newFragment("Empty file removed.", false));
+ } else {
+ add(new TextDiffPanel(CONTENT_ID, depotModel, requestModel, change, diffMode, markSupport));
+ }
+ } else if (blob.isPartial()) {
+ add(newFragment("File is too large to be loaded.", true));
+ } else {
+ Panel diffPanel = null;
+ for (DiffRenderer renderer: GitPlex.getExtensions(DiffRenderer.class)) {
+ diffPanel = renderer.render(CONTENT_ID, blob.getMediaType(), change);
+ if (diffPanel != null)
+ break;
+ }
+ if (diffPanel != null)
+ add(diffPanel);
+ else
+ add(newFragment("Binary file.", false));
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (change.getType() == ChangeType.ADD || change.getType() == ChangeType.COPY) {
+ showBlob(change.getNewBlob());
+ } else if (change.getType() == ChangeType.DELETE) {
+ showBlob(change.getOldBlob());
+ } else {
+ if (change.getOldText() != null && change.getNewText() != null) {
+ if (change.getOldText().getLines().size() + change.getNewText().getLines().size() > DiffUtils.MAX_DIFF_SIZE) {
+ add(newFragment("Unable to diff as the file is too large.", true));
+ } else if (change.getAdditions() + change.getDeletions() > Constants.MAX_SINGLE_FILE_DIFF_LINES) {
+ add(newFragment("Diff is too large to be displayed.", true));
+ } else if (change.getAdditions() + change.getDeletions() == 0) {
+ add(newFragment("Content is identical", false));
+ } else {
+ add(new TextDiffPanel(CONTENT_ID, depotModel, requestModel, change, diffMode, markSupport));
+ }
+ } else if (change.getOldBlob().isPartial() || change.getNewBlob().isPartial()) {
+ add(newFragment("File is too large to be loaded.", true));
+ } else if (change.getOldBlob().getMediaType().equals(change.getNewBlob().getMediaType())) {
+ Panel diffPanel = null;
+ for (DiffRenderer renderer: GitPlex.getExtensions(DiffRenderer.class)) {
+ diffPanel = renderer.render(CONTENT_ID, change.getNewBlob().getMediaType(), change);
+ if (diffPanel != null)
+ break;
+ }
+ if (diffPanel != null)
+ add(diffPanel);
+ else
+ add(newFragment("Binary file.", false));
+ } else {
+ add(newFragment("Binary file.", false));
+ }
+ }
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new CssResourceReference(BlobDiffPanel.class, "blob-diff.css")));
+ }
+
+ protected void onDetach() {
+ depotModel.detach();
+ requestModel.detach();
+
+ super.onDetach();
+ }
+
+ @Override
+ public void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+ Component content = get(CONTENT_ID);
+ if (content instanceof CommentAware) {
+ CommentAware commentAware = (CommentAware) content;
+ commentAware.onCommentDeleted(target, comment);
+ }
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target, CodeComment comment) {
+ Component content = get(CONTENT_ID);
+ if (content instanceof CommentAware) {
+ CommentAware commentAware = (CommentAware) content;
+ commentAware.onCommentClosed(target, comment);
+ }
+ }
+
+ @Override
+ public void onCommentAdded(AjaxRequestTarget target, CodeComment comment) {
+ Component content = get(CONTENT_ID);
+ if (content instanceof CommentAware) {
+ CommentAware commentAware = (CommentAware) content;
+ commentAware.onCommentAdded(target, comment);
+ }
+ }
+
+ @Override
+ public void mark(AjaxRequestTarget target, DiffMark mark) {
+ Component content = get(CONTENT_ID);
+ if (content instanceof CommentAware) {
+ CommentAware commentAware = (CommentAware) content;
+ commentAware.mark(target, mark);
+ }
+ }
+
+ @Override
+ public void clearMark(AjaxRequestTarget target) {
+ Component content = get(CONTENT_ID);
+ if (content instanceof CommentAware) {
+ CommentAware commentAware = (CommentAware) content;
+ commentAware.clearMark(target);
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java
new file mode 100644
index 0000000000..572f72ec1c
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java
@@ -0,0 +1,19 @@
+package com.pmease.gitplex.web.component.diff.blob;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+
+public interface CommentAware {
+
+ void onCommentDeleted(AjaxRequestTarget target, CodeComment comment);
+
+ void onCommentClosed(AjaxRequestTarget target, CodeComment comment);
+
+ void onCommentAdded(AjaxRequestTarget target, CodeComment comment);
+
+ void mark(AjaxRequestTarget target, DiffMark mark);
+
+ void clearMark(AjaxRequestTarget target);
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/MarkInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/MarkInfo.java
deleted file mode 100644
index 5ceec4f917..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/MarkInfo.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.pmease.gitplex.web.component.diff.blob.text;
-
-import java.io.Serializable;
-
-public class MarkInfo implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final boolean old;
-
- private final int beginLine;
-
- private final int endLine;
-
- public MarkInfo(boolean old, int beginLine, int endLine) {
- this.old = old;
- this.beginLine = beginLine;
- this.endLine = endLine;
- }
-
- /**
- * @return the old
- */
- public boolean isOld() {
- return old;
- }
-
- /**
- * @return the beginLine
- */
- public int getBeginLine() {
- return beginLine;
- }
-
- /**
- * @return the endLine
- */
- public int getEndLine() {
- return endLine;
- }
-
-}
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.java
index 58e6ada77f..1edb039f1c 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
@@ -8,8 +8,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nullable;
+
import org.apache.wicket.Component;
-import org.apache.wicket.MetaDataKey;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
@@ -26,44 +27,48 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.protocol.http.WebSession;
import org.apache.wicket.request.IRequestParameters;
-import org.apache.wicket.request.Url;
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.eclipse.jgit.revwalk.RevCommit;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobChange;
import com.pmease.commons.lang.diff.DiffBlock;
import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
import com.pmease.commons.lang.diff.DiffUtils;
import com.pmease.commons.lang.diff.LineDiff;
import com.pmease.commons.lang.tokenizers.CmToken;
+import com.pmease.commons.util.Range;
+import com.pmease.commons.util.RangeUtils;
import com.pmease.commons.util.StringUtils;
-import com.pmease.commons.wicket.CommonPage;
-import com.pmease.commons.wicket.assets.uri.URIResourceReference;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.web.Constants;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;
+import com.pmease.gitplex.web.component.diff.blob.CommentAware;
import com.pmease.gitplex.web.component.diff.blob.text.MarkAwareDiffBlock.Type;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;
+import com.pmease.gitplex.web.component.diff.revision.BlobMarkSupport;
+import com.pmease.gitplex.web.component.diff.revision.DiffMark;
import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;
import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
@SuppressWarnings("serial")
-public class TextDiffPanel extends Panel {
+public class TextDiffPanel extends Panel implements CommentAware {
- private static class TextDiffUrlKey extends MetaDataKey<Url> {
- };
-
- public static final TextDiffUrlKey TEXT_DIFF_URL_KEY = new TextDiffUrlKey();
-
private final IModel<Depot> depotModel;
private final IModel<PullRequest> requestModel;
@@ -74,7 +79,7 @@ public class TextDiffPanel extends Panel {
private final DiffViewMode diffMode;
- private MarkInfo markInfo;
+ private final BlobMarkSupport markSupport;
private Component symbolTooltip;
@@ -83,49 +88,31 @@ public class TextDiffPanel extends Panel {
private transient List<MarkAwareDiffBlock> diffBlocks;
public TextDiffPanel(String id, IModel<Depot> depotModel, IModel<PullRequest> requestModel,
- BlobChange change, DiffViewMode diffMode) {
+ BlobChange change, DiffViewMode diffMode, @Nullable BlobMarkSupport markSupport) {
super(id);
this.depotModel = depotModel;
this.requestModel = requestModel;
this.change = change;
this.diffMode = diffMode;
+ this.markSupport = markSupport;
}
@Override
protected void onInitialize() {
super.onInitialize();
- Url url = getPage().getMetaData(TEXT_DIFF_URL_KEY);
- if (url == null)
- url = ((CommonPage)getPage()).getRequestUrl();
- String markFile = url.getQueryParameterValue("mark-file").toString();
-
- /*
- * Initialize mark info here as we want to make sure that calculated mark aware diff
- * blocks remain unchanged after initialization of this panel as otherwise line
- * expanding may work abnormally
- */
- if (change.getPath().equals(markFile)) {
- String markPos = url.getQueryParameterValue("mark-pos").toString();
- String[] fields = StringUtils.split(markPos, "-");
- boolean old = fields[0].equals("old");
- int beginLine = Integer.parseInt(StringUtils.substringBefore(fields[1], "."))-1;
- int endLine = Integer.parseInt(StringUtils.substringBefore(fields[2], "."));
- markInfo = new MarkInfo(old, beginLine, endLine);
- }
-
add(new DiffStatBar("diffStat", change.getAdditions(), change.getDeletions(), true));
add(new BlobDiffTitle("title", change));
PullRequest request = requestModel.getObject();
if (request != null) {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.requestId = request.getId();
state.blobIdent = change.getBlobIdent();
PageParameters params = DepotFilePage.paramsOf(request.getTargetDepot(), state);
add(new BookmarkablePageLink<Void>("viewFile", DepotFilePage.class, params));
- state = new HistoryState();
+ state = new DepotFilePage.State();
state.blobIdent.revision = request.getSourceBranch();
state.blobIdent.path = change.getPath();
state.mode = Mode.EDIT;
@@ -144,7 +131,7 @@ public class TextDiffPanel extends Panel {
editFileLink.add(AttributeAppender.append("target", "_blank"));
add(editFileLink);
} else {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent = change.getBlobIdent();
PageParameters params = DepotFilePage.paramsOf(depotModel.getObject(), state);
add(new BookmarkablePageLink<Void>("viewFile", DepotFilePage.class, params));
@@ -183,9 +170,28 @@ public class TextDiffPanel extends Panel {
getMarkupId(), index, expanded);
target.appendJavaScript(script);
break;
- case "storeUrl":
- String url = params.getParameterValue("param1").toString();
- getPage().setMetaData(TEXT_DIFF_URL_KEY, Url.parse(url));
+ case "openSelectionPopup":
+ String jsonOfPosition = String.format("{left: %d, top: %d}",
+ params.getParameterValue("param1").toInt(),
+ params.getParameterValue("param2").toInt());
+ DiffMark mark = getMark(params, "param3", "param4", "param5", "param6", "param7");
+ script = String.format("gitplex.textdiff.openSelectionPopup('%s', %s, %s, '%s', %s);",
+ getMarkupId(), jsonOfPosition, mark.toJson(), markSupport.getMarkUrl(mark),
+ SecurityUtils.getAccount()!=null);
+ target.appendJavaScript(script);
+ break;
+ case "addComment":
+ Preconditions.checkNotNull(SecurityUtils.getAccount());
+ mark = getMark(params, "param1", "param2", "param3", "param4", "param5");
+ markSupport.onAddComment(target, mark);
+ break;
+ case "openComment":
+ Long commentId = params.getParameterValue("param1").toLong();
+ CodeComment comment = GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ markSupport.onOpenComment(target, comment);
+ script = String.format("gitplex.textdiff.onOpenComment($('#%s'), %s);",
+ getMarkupId(), getJsonOfComment(comment));
+ target.appendJavaScript(script);
break;
}
}
@@ -216,11 +222,20 @@ public class TextDiffPanel extends Panel {
};
add(symbolTooltip);
- add(AttributeAppender.append("data-markfile", change.getPath()));
-
setOutputMarkupId(true);
}
+ private DiffMark getMark(IRequestParameters params, String leftSideParam,
+ String beginLineParam, String beginCharParam,
+ String endLineParam, String endCharParam) {
+ boolean leftSide = params.getParameterValue(leftSideParam).toBoolean();
+ int beginLine = params.getParameterValue(beginLineParam).toInt();
+ int beginChar = params.getParameterValue(beginCharParam).toInt();
+ int endLine = params.getParameterValue(endLineParam).toInt();
+ int endChar = params.getParameterValue(endCharParam).toInt();
+ return new DiffMark(change.getPath(), leftSide, beginLine, beginChar, endLine, endChar);
+ }
+
private void appendEquals(StringBuilder builder, int index, int lastContextSize, int contextSize) {
MarkAwareDiffBlock block = getDiffBlocks().get(index);
if (index == 0) {
@@ -260,11 +275,18 @@ public class TextDiffPanel extends Panel {
appendEqual(builder, block, i, 0);
}
+ private RevCommit getOldCommit() {
+ return depotModel.getObject().getRevCommit(change.getOldBlobIdent().revision);
+ }
+
+ private RevCommit getNewCommit() {
+ return depotModel.getObject().getRevCommit(change.getNewBlobIdent().revision);
+ }
+
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- response.render(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(
new JavaScriptResourceReference(TextDiffPanel.class, "text-diff.js")));
response.render(CssHeaderItem.forReference(
@@ -272,33 +294,105 @@ public class TextDiffPanel extends Panel {
response.render(CssHeaderItem.forReference(
new CssResourceReference(TextDiffPanel.class, "text-diff.css")));
+ String jsonOfOldCommentInfos;
+ String jsonOfNewCommentInfos;
+ String jsonOfMark;
+ String jsonOfCommentInfo;
+ String dirtyContainerId;
+ if (markSupport != null) {
+ String oldCommitHash = getOldCommit().name();
+ String newCommitHash = getNewCommit().name();
+ Map<Integer, List<CommentInfo>> oldCommentInfos = new HashMap<>();
+ Map<Integer, List<CommentInfo>> newCommentInfos = new HashMap<>();
+ for (CodeComment comment: markSupport.getComments()) {
+ if (comment.getMark() != null) {
+ int line = comment.getMark().getBeginLine();
+ List<CommentInfo> commentInfosAtLine;
+ CommentInfo commentInfo = new CommentInfo();
+ commentInfo.id = comment.getId();
+ commentInfo.mark = new DiffMark(comment, oldCommitHash, newCommitHash);
+ if (commentInfo.mark.isLeftSide()) {
+ commentInfosAtLine = oldCommentInfos.get(line);
+ if (commentInfosAtLine == null) {
+ commentInfosAtLine = new ArrayList<>();
+ oldCommentInfos.put(line, commentInfosAtLine);
+ }
+ } else {
+ commentInfosAtLine = newCommentInfos.get(line);
+ if (commentInfosAtLine == null) {
+ commentInfosAtLine = new ArrayList<>();
+ newCommentInfos.put(line, commentInfosAtLine);
+ }
+ }
+ commentInfosAtLine.add(commentInfo);
+ }
+ }
+ for (List<CommentInfo> value: oldCommentInfos.values()) {
+ value.sort((o1, o2)->(int)(o1.id-o2.id));
+ }
+ for (List<CommentInfo> value: newCommentInfos.values()) {
+ value.sort((o1, o2)->(int)(o1.id-o2.id));
+ }
+
+ try {
+ jsonOfOldCommentInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(oldCommentInfos);
+ jsonOfNewCommentInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(newCommentInfos);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+
+ DiffMark mark = markSupport.getMark();
+ if (mark != null) {
+ jsonOfMark = mark.toJson();
+ } else {
+ jsonOfMark = "undefined";
+ }
+ CodeComment comment = markSupport.getOpenComment();
+ if (comment != null) {
+ jsonOfCommentInfo = getJsonOfComment(comment);
+ } else {
+ jsonOfCommentInfo = "undefined";
+ }
+ dirtyContainerId = "'" + markSupport.getDirtyContainer().getMarkupId() + "'";
+ } else {
+ jsonOfMark = "undefined";
+ jsonOfCommentInfo = "undefined";
+ jsonOfOldCommentInfos = "undefined";
+ jsonOfNewCommentInfos = "undefined";
+ dirtyContainerId = "undefined";
+ }
+
CharSequence callback = callbackBehavior.getCallbackFunction(
- explicit("action"), explicit("param1"), explicit("param2"), explicit("param3"));
- String script = String.format("gitplex.textdiff.init('%s', '%s', '%s', '%s', %s, %s);",
+ explicit("action"), explicit("param1"), explicit("param2"),
+ explicit("param3"), explicit("param4"), explicit("param5"),
+ explicit("param6"), explicit("param7"), explicit("param8"));
+ String script = String.format("gitplex.textdiff.init('%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s, %s);",
getMarkupId(), symbolTooltip.getMarkupId(),
change.getOldBlobIdent().revision, change.getNewBlobIdent().revision,
- RequestCycle.get().find(AjaxRequestTarget.class) == null, callback);
+ RequestCycle.get().find(AjaxRequestTarget.class) == null, callback,
+ markSupport!=null, jsonOfMark, jsonOfCommentInfo,
+ jsonOfOldCommentInfos, jsonOfNewCommentInfos, dirtyContainerId);
response.render(OnDomReadyHeaderItem.forScript(script));
}
-
+
private String renderDiffs() {
int contextSize = Constants.DIFF_CONTEXT_SIZE;
StringBuilder builder = new StringBuilder();
if (diffMode == DiffViewMode.UNIFIED) {
builder.append(""
+ "<colgroup>"
- + "<col width='40'></col>"
- + "<col width='40'></col>"
+ + "<col width='60'></col>"
+ + "<col width='60'></col>"
+ "<col width='15'></col>"
+ "<col></col>"
+ "</colgroup>");
} else {
builder.append(""
+ "<colgroup>"
- + "<col width='40'></col>"
+ + "<col width='60'></col>"
+ "<col width='15'></col>"
+ "<col></col>"
- + "<col width='40'></col>"
+ + "<col width='60'></col>"
+ "<col width='15'></col>"
+ "<col></col>"
+ "</colgroup>");
@@ -612,6 +706,30 @@ public class TextDiffPanel extends Panel {
private List<MarkAwareDiffBlock> getDiffBlocks() {
if (diffBlocks == null) {
diffBlocks = new ArrayList<>();
+ List<Range> oldRanges = new ArrayList<>();
+ List<Range> newRanges = new ArrayList<>();
+ if (markSupport != null) {
+ List<DiffMark> marks = new ArrayList<>();
+ DiffMark mark = markSupport.getMark();
+ if (mark != null) {
+ marks.add(mark);
+ }
+ String oldCommitHash = getOldCommit().name();
+ String newCommitHash = getNewCommit().name();
+ for (CodeComment comment: markSupport.getComments()) {
+ mark = new DiffMark(comment, oldCommitHash, newCommitHash);
+ marks.add(mark);
+ }
+ for (DiffMark each: marks) {
+ Range range = new Range(each.beginLine, each.endLine+1);
+ if (each.isLeftSide()) {
+ oldRanges.add(range);
+ } else {
+ newRanges.add(range);
+ }
+ }
+ }
+
for (DiffBlock<List<CmToken>> diffBlock: change.getDiffBlocks()) {
if (diffBlock.getOperation() == Operation.DELETE) {
diffBlocks.add(new MarkAwareDiffBlock(Type.DELETE, diffBlock.getUnits(),
@@ -620,44 +738,42 @@ public class TextDiffPanel extends Panel {
diffBlocks.add(new MarkAwareDiffBlock(Type.INSERT, diffBlock.getUnits(),
diffBlock.getOldStart(), diffBlock.getNewStart()));
} else {
- if (markInfo != null) {
- int beginMarkIndex;
- int endMarkIndex;
- if (markInfo.isOld()) {
- beginMarkIndex = markInfo.getBeginLine() - diffBlock.getOldStart();
- endMarkIndex = markInfo.getEndLine() - diffBlock.getOldStart();
- } else {
- beginMarkIndex = markInfo.getBeginLine() - diffBlock.getNewStart();
- endMarkIndex = markInfo.getEndLine() - diffBlock.getNewStart();
- }
- if (beginMarkIndex < 0)
- beginMarkIndex = 0;
- if (beginMarkIndex > diffBlock.getUnits().size())
- beginMarkIndex = diffBlock.getUnits().size();
- if (endMarkIndex < 0)
- endMarkIndex = 0;
- if (endMarkIndex > diffBlock.getUnits().size())
- endMarkIndex = diffBlock.getUnits().size();
- List<List<CmToken>> lines = diffBlock.getUnits().subList(0, beginMarkIndex);
- if (!lines.isEmpty()) {
- diffBlocks.add(new MarkAwareDiffBlock(Type.EQUAL, lines,
- diffBlock.getOldStart(), diffBlock.getNewStart()));
- }
- lines = diffBlock.getUnits().subList(beginMarkIndex, endMarkIndex);
- if (!lines.isEmpty()) {
- diffBlocks.add(new MarkAwareDiffBlock(Type.MARKED_EQUAL, lines,
- diffBlock.getOldStart()+beginMarkIndex,
- diffBlock.getNewStart()+beginMarkIndex));
- }
- lines = diffBlock.getUnits().subList(endMarkIndex, diffBlock.getUnits().size());
- if (!lines.isEmpty()) {
- diffBlocks.add(new MarkAwareDiffBlock(Type.EQUAL, lines,
- diffBlock.getOldStart()+endMarkIndex,
- diffBlock.getNewStart()+endMarkIndex));
+ List<Range> ranges = new ArrayList<>();
+ for (Range range: oldRanges) {
+ ranges.add(new Range(range.getFrom()-diffBlock.getOldStart(), range.getTo()-diffBlock.getOldStart()));
+ }
+ for (Range range: newRanges) {
+ ranges.add(new Range(range.getFrom()-diffBlock.getNewStart(), range.getTo()-diffBlock.getNewStart()));
+ }
+ ranges = RangeUtils.merge(ranges);
+
+ int lastIndex = 0;
+ for (Range range: ranges) {
+ int from = range.getFrom();
+ int to = range.getTo();
+ if (from < diffBlock.getUnits().size() && to > 0) {
+ if (from < lastIndex)
+ from = lastIndex;
+ if (to > diffBlock.getUnits().size())
+ to = diffBlock.getUnits().size();
+ if (lastIndex < from) {
+ List<List<CmToken>> lines = diffBlock.getUnits().subList(lastIndex, from);
+ diffBlocks.add(new MarkAwareDiffBlock(Type.EQUAL, lines,
+ diffBlock.getOldStart()+lastIndex, diffBlock.getNewStart()+lastIndex));
+ }
+ if (from < to) {
+ List<List<CmToken>> lines = diffBlock.getUnits().subList(from, to);
+ diffBlocks.add(new MarkAwareDiffBlock(Type.MARKED_EQUAL, lines,
+ diffBlock.getOldStart()+from, diffBlock.getNewStart()+from));
+ }
+ lastIndex = to;
}
- } else {
- diffBlocks.add(new MarkAwareDiffBlock(Type.EQUAL, diffBlock.getUnits(),
- diffBlock.getOldStart(), diffBlock.getNewStart()));
+ }
+
+ if (lastIndex < diffBlock.getUnits().size()) {
+ List<List<CmToken>> lines = diffBlock.getUnits().subList(lastIndex, diffBlock.getUnits().size());
+ diffBlocks.add(new MarkAwareDiffBlock(Type.EQUAL, lines,
+ diffBlock.getOldStart()+lastIndex, diffBlock.getNewStart()+lastIndex));
}
}
}
@@ -669,7 +785,65 @@ public class TextDiffPanel extends Panel {
protected void onDetach() {
depotModel.detach();
requestModel.detach();
+
super.onDetach();
}
+ private String getJsonOfComment(CodeComment comment) {
+ CommentInfo commentInfo = new CommentInfo();
+ commentInfo.id = comment.getId();
+ commentInfo.mark = new DiffMark(comment, getOldCommit().name(), getNewCommit().name());
+
+ String jsonOfCommentInfo;
+ try {
+ jsonOfCommentInfo = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfo);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ return jsonOfCommentInfo;
+ }
+
+ @Override
+ public void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+ String script = String.format("gitplex.textdiff.onCommentDeleted($('#%s'), %s);",
+ getMarkupId(), getJsonOfComment(comment));
+ target.appendJavaScript(script);
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target, CodeComment comment) {
+ String script = String.format("gitplex.textdiff.onCloseComment($('#%s'));", getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ @Override
+ public void onCommentAdded(AjaxRequestTarget target, CodeComment comment) {
+ String script = String.format("gitplex.textdiff.onCommentAdded($('#%s'), %s);",
+ getMarkupId(), getJsonOfComment(comment));
+ target.appendJavaScript(script);
+ }
+
+ @Override
+ public void mark(AjaxRequestTarget target, DiffMark mark) {
+ String script = String.format(""
+ + "var $container = $('#%s');"
+ + "var mark = %s;"
+ + "gitplex.textdiff.scroll($container, mark);"
+ + "gitplex.textdiff.mark($container, mark);",
+ getMarkupId(), mark.toJson());
+ target.appendJavaScript(script);
+ }
+
+ @Override
+ public void clearMark(AjaxRequestTarget target) {
+ String script = String.format("gitplex.textdiff.clearMark($('#%s'));", getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ private static class CommentInfo {
+ long id;
+
+ DiffMark mark;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
index 88292cc737..1f71b2498d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
@@ -1,7 +1,9 @@
gitplex.textdiff = {
symbolClasses: ".cm-property, .cm-variable, .cm-variable-2, .cm-variable-3, .cm-def, .cm-meta",
- init: function(containerId, symbolTooltipId, oldRev, newRev, scroll, callback) {
+ init: function(containerId, symbolTooltipId, oldRev, newRev, scroll, callback,
+ markSupport, mark, openComment, oldComments, newComments, dirtyContainerId) {
var $container = $("#" + containerId);
+ $container.data("dirtyContainer", $("#" + dirtyContainerId));
$container.data("callback", callback);
$container.data("symbolHover", function() {
var revision;
@@ -35,6 +37,10 @@ gitplex.textdiff = {
var $symbols = $container.find(gitplex.textdiff.symbolClasses);
$symbols.mouseover($container.data("symbolHover"));
$container.find("td.content").mouseover($container.data("onMouseOverContent"));
+
+ if (!markSupport)
+ return;
+
$container.on("mouseup keyup", function() {
// use a timeout to make sure selection remains stable after mouse or keyboard action
setTimeout(function() {
@@ -333,7 +339,7 @@ gitplex.textdiff = {
endRect = startRect;
}
var position = {
- left: (startRect.left + endRect.right)/2,
+ left: Math.round((startRect.left + endRect.right)/2),
top: startRect.top
};
position.left += $(window).scrollLeft();
@@ -424,43 +430,97 @@ gitplex.textdiff = {
var startCursor = getCursor($start, startOffset);
var endCursor = getCursor($end, endOffset);
- var markPos;
if (startCursor.newLine && endCursor.newLine) {
- markPos = "new-" + startCursor.newLine + "." + startCursor.newCh
- + "-" + endCursor.newLine + "." + endCursor.newCh;
+ callback("openSelectionPopup", position.left, position.top, false,
+ startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);
} else if (startCursor.oldLine && endCursor.oldLine) {
- markPos = "old-" + startCursor.oldLine + "." + startCursor.oldCh
- + "-" + endCursor.oldLine + "." + endCursor.oldCh;
+ callback("openSelectionPopup", position.left, position.top, true,
+ startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);
} else {
showInvalidSelection();
return;
}
- var permanentCallback = function($permanentLink) {
- var uri = URI(window.location.href);
- var markFile = $container.data("markfile");
- uri.removeSearch("jump-file");
- uri.removeSearch("mark-file").addSearch("mark-file", markFile);
- uri.removeSearch("mark-pos").addSearch("mark-pos", markPos);
- $permanentLink.attr("href", uri.toString());
- $permanentLink.html("<i class='fa fa-link'></i> Permanent link of this selection");
- };
- var commentCallback = function($commentLink) {
- $commentLink.removeAttr("href");
- $commentLink.html("<i class='fa fa-comment'></i> Add comment for this selection");
- };
- $("#selection-popup").data("open")(position, permanentCallback,
- commentCallback, $container[0]);
-
}, 100);
});
- var uri = URI(window.location.href);
- var search = uri.search(true);
- if ($container.data("markfile") == search["mark-file"] && search["mark-pos"]) {
- gitplex.textdiff.mark(search["mark-file"], search["mark-pos"]);
+ if (mark) {
+ $container.data("mark", mark);
+ gitplex.textdiff.mark($container, mark);
if (scroll)
- gitplex.textdiff.scroll(search["mark-file"], search["mark-pos"]);
+ gitplex.textdiff.scroll($container, mark);
+ }
+ if (openComment) {
+ $container.data("comment", openComment);
+ }
+ for (var line in oldComments) {
+ if (oldComments.hasOwnProperty(line)) {
+ gitplex.textdiff.addCommentIndicator($container, true, line, oldComments[line][1]);
+ }
+ }
+ for (var line in newComments) {
+ if (newComments.hasOwnProperty(line)) {
+ gitplex.textdiff.addCommentIndicator($container, false, line, newComments[line][1]);
+ }
+ }
+
+ gitplex.textdiff.highlightCommentTrigger($container);
+
+ function alignCommentPopovers() {
+ $container.find(".comment-popover:visible").each(function() {
+ var $popover = $(this);
+ var leftSide = $popover.hasClass("old");
+ var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, $popover.data("line")).children(".comment-indicator");
+ if ($indicator.length != 0) {
+ $popover.css({
+ "left": $indicator.offset().left + $indicator.outerWidth() - $container.offset().left,
+ "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $container.offset().top
+ });
+ }
+ });
}
+ $(window).on("resize scroll", function(e) {
+ e.preventDefault();
+ alignCommentPopovers();
+ });
+ },
+ openSelectionPopup: function(containerId, position, mark, markUrl, loggedIn) {
+ var $container = $("#" + containerId);
+ var permanentLinkCallback = function($permanentLink) {
+ $permanentLink.attr("href", markUrl);
+ $permanentLink.html("<i class='fa fa-link'></i> Permanent link of this selection");
+ };
+
+ var commentLinkCallback = function($commentLink) {
+ $commentLink.off("click");
+ if (loggedIn) {
+ $commentLink.click(function() {
+ if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ $container.removeData("openComment");
+ $container.data("mark", mark);
+
+ $("#selection-popup").hide();
+ window.getSelection().removeAllRanges();
+
+ // continue to operate DOM in a timer to give browser a chance to
+ // clear selections
+ setTimeout(function() {
+ gitplex.textdiff.mark($container, mark);
+ gitplex.textdiff.highlightCommentTrigger($container);
+ }, 100);
+
+ $container.data("callback")("addComment", mark.leftSide,
+ mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
+ });
+ } else {
+ $commentLink.html("Log in to comment on selection");
+ }
+ };
+
+ $("#selection-popup").data("open")(position, permanentLinkCallback,
+ commentLinkCallback, $container[0]);
},
expand: function(containerId, blockIndex, expandedHtml) {
var $container = $("#" + containerId);
@@ -480,12 +540,10 @@ gitplex.textdiff = {
$symbols.mouseover($container.data("symbolHover"));
$expandedTrs.find("td.content").mouseover($container.data("onMouseOverContent"));
},
- getMarkInfo: function(markFile, markPos) {
- var $container = $('*[data-markfile="' + markFile.escape() + '"]');
- var splitted = markPos.split("-");
- var oldOrNew = splitted[0];
- var startCursor = splitted[1].split(".");
- var endCursor = splitted[2].split(".");
+ getMarkInfo: function($container, mark) {
+ var oldOrNew = mark.leftSide?"old":"new";
+ var startCursor = [mark.beginLine+1, mark.beginChar];
+ var endCursor = [mark.endLine+1, mark.endChar];
var $startTd = $container.find("td.content[data-" + oldOrNew + "='" + (startCursor[0]-1) + "']");
var $endTd = $container.find("td.content[data-" + oldOrNew + "='" + (endCursor[0]-1) + "']");
if ($startTd.length == 0) {
@@ -516,8 +574,8 @@ gitplex.textdiff = {
oldOrNew: oldOrNew
};
},
- scroll: function(markFile, markPos) {
- var markInfo = gitplex.textdiff.getMarkInfo(markFile, markPos);
+ scroll: function($container, mark) {
+ var markInfo = gitplex.textdiff.getMarkInfo($container, mark);
var $startTd = markInfo.startTd;
var $endTd = markInfo.endTd;
if ($startTd && $endTd) {
@@ -532,8 +590,10 @@ gitplex.textdiff = {
}
}
},
- mark: function(markFile, markPos) {
- var markInfo = gitplex.textdiff.getMarkInfo(markFile, markPos);
+ mark: function($container, mark) {
+ gitplex.textdiff.clearMark($container);
+
+ var markInfo = gitplex.textdiff.getMarkInfo($container, mark);
var $startTd = markInfo.startTd;
var $endTd = markInfo.endTd;
if ($startTd && $endTd) {
@@ -645,8 +705,8 @@ gitplex.textdiff = {
}
}
},
- clearMarks: function() {
- $("td.content.content-mark").each(function() {
+ clearMark: function($container) {
+ $container.find("td.content.content-mark").each(function() {
var $this = $(this);
$this.html($this.data("beforemark"));
$this.removeClass("content-mark");
@@ -654,5 +714,168 @@ gitplex.textdiff = {
$container = $this.closest(".text-diff").parent();
$this.find(gitplex.textdiff.symbolClasses).mouseover($container.data("symbolHover"));
});
- }
+ },
+ restoreMark: function($container) {
+ var mark = $container.data("mark");
+ if (mark) {
+ gitplex.textdiff.mark($container, mark);
+ } else {
+ gitplex.textdiff.clearMark($container);
+ }
+ },
+ addCommentIndicator: function($container, leftSide, line, comments) {
+ var oldOrNew = leftSide?"old":"new";
+ $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "']").remove();
+
+ var callback = $container.data("callback");
+
+ var $indicator = $(document.createElement("a"));
+ $indicator.addClass("comment-indicator");
+ $indicator.data("comments", comments);
+ if (comments.length != 1) {
+ var oldOrNew = leftSide?"old":"new";
+ $indicator.append("<i class='fa fa-comments'></i>");
+ var content = "";
+ for (var i in comments) {
+ var comment = comments[i];
+ var index = parseInt(i) + 1;
+ content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + index + "</a>";
+ }
+ $indicator.popover({
+ html: true,
+ container: $container,
+ placement: "right auto",
+ template: "<div class='" + oldOrNew + "' data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
+ content: content
+ });
+ $indicator.on('shown.bs.popover', function () {
+ $("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {
+ $(this).mouseover(function() {
+ var comment = comments[$(this).index()];
+ gitplex.textdiff.mark($container, comment.mark);
+ });
+ $(this).mouseout(function() {
+ gitplex.textdiff.restoreMark($container);
+ });
+ $(this).click(function() {
+ if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ var comment = comments[$(this).index()];
+ callback("openComment", comment.id);
+ });
+ });
+ gitplex.textdiff.highlightCommentTrigger($container);
+ });
+ } else {
+ var comment = comments[0];
+ $indicator.addClass("comment-trigger").attr("title", "Click to show comment of marked text");
+ $indicator.append("<i class='fa fa-commenting'></i>");
+ $indicator.mouseover(function() {
+ gitplex.textdiff.mark($container, comment.mark);
+ });
+ $indicator.mouseout(function() {
+ gitplex.textdiff.restoreMark($container);
+ });
+ $indicator.click(function() {
+ if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ callback("openComment", comment.id);
+ });
+ }
+ var $lineNumTd = gitplex.textdiff.getLineNumTd($container, leftSide, line);
+ if ($lineNumTd) {
+ $lineNumTd.children(".comment-indicator").remove();
+ $lineNumTd.prepend($indicator);
+ }
+ },
+ getLineNumTd: function($container, leftSide, line) {
+ if (leftSide) {
+ var $lineNumTds = $container.find("td.content[data-old='" + line + "']").prevAll("td.number");
+ if ($lineNumTds.length != 0) {
+ return $lineNumTds.first();
+ }
+ } else {
+ var $lineNumTds = $container.find("td.content[data-new='" + line + "']").prevAll("td.number");
+ if ($lineNumTds.length != 0) {
+ return $lineNumTds.last();
+ }
+ }
+ return $();
+ },
+ highlightCommentTrigger: function($container) {
+ $container.find(".comment-trigger").removeClass("active");
+
+ var openComment = $container.data("openComment");
+ if (openComment) {
+ var line = parseInt(openComment.mark.beginLine);
+ var $indicator = gitplex.textdiff.getLineNumTd($container, openComment.mark.leftSide, line).children(".comment-indicator");
+ if ($indicator.length != 0) {
+ var comments = $indicator.data("comments");
+ if (comments.length == 1) {
+ $indicator.addClass("active");
+ } else {
+ var oldOrNew = leftSide?"old":"new";
+ $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {
+ var comment = comments[$(this).index()];
+ if (comment.id == openComment.id) {
+ $(this).addClass("active");
+ }
+ });
+ }
+ }
+ }
+ },
+ onCommentAdded: function($container, comment) {
+ $container.data("openComment", comment);
+ $container.data("mark", comment.mark);
+
+ var line = parseInt(comment.mark.beginLine);
+ var leftSide = comment.mark.leftSide;
+
+ var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");
+ var comments;
+ if ($indicator.length != 0) {
+ comments = $indicator.data("comments");
+ } else {
+ comments = [];
+ }
+ comments.push(comment);
+ gitplex.textdiff.addCommentIndicator($container, line, leftSide, comments);
+ gitplex.textdiff.highlightCommentTrigger($container);
+ },
+ onCommentDeleted: function($container, comment) {
+ $container.removeData("openComment");
+
+ var line = parseInt(comment.mark.beginLine);
+ var leftSide = comment.mark.leftSide;
+ var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");
+ var comments = $indicator.data("comments");
+ if (comments.length == 1) {
+ $indicator.remove();
+ } else {
+ for (var i in comments) {
+ var comment = comments[i];
+ if (comment.id == commentId) {
+ comments.splice(i, 1);
+ break;
+ }
+ }
+ gitplex.textdiff.addCommentIndicator($container, line, leftSide, comments);
+ }
+ gitplex.textdiff.highlightCommentTrigger();
+ },
+ onOpenComment: function($container, comment) {
+ $container.data("openComment", comment);
+ $container.data("mark", comment.mark);
+ gitplex.textdiff.highlightCommentTrigger($container);
+ gitplex.textdiff.mark($container, comment.mark);
+ },
+ onCloseComment: function($container) {
+ $container.removeData("openComment");
+ gitplex.textdiff.highlightCommentTrigger($container);
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobMarkSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobMarkSupport.java
new file mode 100644
index 0000000000..5dbfecfc4b
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobMarkSupport.java
@@ -0,0 +1,29 @@
+package com.pmease.gitplex.web.component.diff.revision;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+
+import com.pmease.gitplex.core.entity.CodeComment;
+
+public interface BlobMarkSupport extends Serializable {
+
+ Collection<CodeComment> getComments();
+
+ @Nullable DiffMark getMark();
+
+ String getMarkUrl(DiffMark mark);
+
+ @Nullable CodeComment getOpenComment();
+
+ void onOpenComment(AjaxRequestTarget target, CodeComment comment);
+
+ void onAddComment(AjaxRequestTarget target, DiffMark mark);
+
+ Component getDirtyContainer();
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
index f6e2c5c043..27b898b69b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
@@ -7,6 +7,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.component.Mark;
public class DiffMark extends Mark {
@@ -29,6 +30,12 @@ public class DiffMark extends Mark {
this.path = path;
this.leftSide = leftSide;
}
+
+ public DiffMark(CodeComment comment, String oldCommitHash, String newCommitHash) {
+ super(comment.getMark());
+ path = comment.getPath();
+ leftSide = comment.getCommit().equals(oldCommitHash);
+ }
public String getPath() {
return path;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/MarkSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/MarkSupport.java
new file mode 100644
index 0000000000..529ef51e81
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/MarkSupport.java
@@ -0,0 +1,29 @@
+package com.pmease.gitplex.web.component.diff.revision;
+
+import java.io.Serializable;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+
+import com.pmease.gitplex.core.entity.CodeComment;
+
+public interface MarkSupport extends Serializable {
+
+ @Nullable DiffMark getMark();
+
+ void onMark(AjaxRequestTarget target, DiffMark mark);
+
+ String getMarkUrl(DiffMark mark);
+
+ String getCommentUrl(CodeComment comment);
+
+ @Nullable CodeComment getOpenComment();
+
+ void onCommentOpened(AjaxRequestTarget target, CodeComment comment);
+
+ void onCommentClosed(AjaxRequestTarget target);
+
+ void onAddComment(AjaxRequestTarget target, DiffMark mark);
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
index 22fe2eb9e3..7fd733fcd6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
@@ -48,6 +48,7 @@
<span class="pull-left">Comment</span>
<a wicket:id="close" class="pull-right close" title="Hide comment"><i class="fa fa-times"></i></a>
<a wicket:id="locate" class="pull-right locate close" title="Locate marked text of this comment"><i class="fa fa-hand-o-right"></i></a>
+ <a wicket:id="permanent" class="pull-right permanent close" title="Permanent link of this comment"><i class="fa fa-link"></i></a>
</div>
<div wicket:id="body" class="body"></div>
</div>
@@ -60,4 +61,14 @@
</div>
</div>
</div>
+ <wicket:fragment wicket:id="newCommentFrag">
+ <form wicket:id="form" class="new-comment leave-confirm">
+ <div wicket:id="feedback" class="feedback"></div>
+ <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>
+ <div class="actions">
+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Save</button>
+ <button wicket:id="cancel" class="btn btn-sm btn-default">Cancel</button>
+ </div>
+ </form>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
index 86735c7492..0d7dacdb64 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
@@ -32,17 +32,22 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebRequest;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.eclipse.jgit.revwalk.RevCommit;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
@@ -60,7 +65,6 @@ import com.pmease.commons.util.match.WildcardUtils;
import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;
-import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import com.pmease.commons.wicket.behavior.inputassist.InputAssistBehavior;
import com.pmease.commons.wicket.component.menu.MenuItem;
import com.pmease.commons.wicket.component.menu.MenuLink;
@@ -68,11 +72,21 @@ import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.CompareContext;
+import com.pmease.gitplex.core.entity.component.Mark;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.web.Constants;
+import com.pmease.gitplex.web.component.comment.CodeCommentPanel;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;
+import com.pmease.gitplex.web.component.diff.blob.CommentAware;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
import com.pmease.gitplex.web.util.SuggestionUtils;
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
/**
* Make sure to add only one revision diff panel on a page
*
@@ -83,7 +97,11 @@ import com.pmease.gitplex.web.util.SuggestionUtils;
public abstract class RevisionDiffPanel extends Panel {
private static final String COOKIE_VIEW_MODE = "gitplex.diff.viewmode";
+
+ private static final String BODY_ID = "body";
+ private static final String DIFF_ID = "diff";
+
private final IModel<Depot> depotModel;
private final IModel<PullRequest> requestModel;
@@ -92,16 +110,14 @@ public abstract class RevisionDiffPanel extends Panel {
private final String newRev;
+ private final MarkSupport markSupport;
+
private String pathFilter;
private WhitespaceOption whitespaceOption;
private DiffViewMode diffMode;
- private Long commentId;
-
- private DiffMark mark;
-
private IModel<List<DiffEntry>> diffEntriesModel = new LoadableDetachableModel<List<DiffEntry>>() {
@Override
@@ -254,12 +270,25 @@ public abstract class RevisionDiffPanel extends Panel {
}
};
+ private final IModel<Collection<CodeComment>> commentsModel =
+ new LoadableDetachableModel<Collection<CodeComment>>() {
+
+ @Override
+ protected Collection<CodeComment> load() {
+ Depot depot = depotModel.getObject();
+ return GitPlex.getInstance(CodeCommentManager.class).query(
+ depot, depot.getRevCommit(oldRev), depot.getRevCommit(newRev));
+ }
+
+ };
+
private WebMarkupContainer commentContainer;
+ private ListView<BlobChange> diffsView;
+
public RevisionDiffPanel(String id, IModel<Depot> depotModel, IModel<PullRequest> requestModel,
String oldRev, String newRev, @Nullable String pathFilter,
- WhitespaceOption whitespaceOption, @Nullable Long commentId,
- @Nullable DiffMark mark) {
+ WhitespaceOption whitespaceOption, @Nullable MarkSupport markSupport) {
super(id);
this.depotModel = depotModel;
@@ -268,8 +297,7 @@ public abstract class RevisionDiffPanel extends Panel {
this.newRev = newRev;
this.pathFilter = pathFilter;
this.whitespaceOption = whitespaceOption;
- this.commentId = commentId;
- this.mark = mark;
+ this.markSupport = markSupport;
WebRequest request = (WebRequest) RequestCycle.get().getRequest();
Cookie cookie = request.getCookie(COOKIE_VIEW_MODE);
@@ -283,7 +311,7 @@ public abstract class RevisionDiffPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- WebMarkupContainer body = new WebMarkupContainer("body") {
+ WebMarkupContainer body = new WebMarkupContainer(BODY_ID) {
@Override
public void renderHead(IHeaderResponse response) {
@@ -484,15 +512,59 @@ public abstract class RevisionDiffPanel extends Panel {
};
commentContainer.setOutputMarkupPlaceholderTag(true);
+
body.add(commentContainer);
commentContainer.add(new AjaxLink<Void>("locate") {
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+ setOutputMarkupId(true);
+ }
+
@Override
public void onClick(AjaxRequestTarget target) {
-
+ CodeComment comment = markSupport.getOpenComment();
+ DiffMark mark;
+ if (comment != null) {
+ mark = new DiffMark(comment, getOldCommit().name(), getNewCommit().name());
+ } else {
+ mark = (DiffMark)commentContainer.getDefaultModel();
+ }
+ CommentAware commentAware = getCommentAware(mark.getPath());
+ if (commentAware != null)
+ commentAware.mark(target, mark);
+ markSupport.onMark(target, mark);
+ target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));
}
});
+
+ // use this instead of bookmarkable link as we want to get the link
+ // updated whenever we re-render the comment container
+ AttributeAppender appender = AttributeAppender.append("href", new LoadableDetachableModel<String>() {
+
+ @Override
+ protected String load() {
+ if (markSupport.getOpenComment() != null) {
+ return markSupport.getCommentUrl(markSupport.getOpenComment());
+ } else {
+ return "";
+ }
+ }
+
+ });
+
+ commentContainer.add(new WebMarkupContainer("permanent") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(markSupport.getOpenComment() != null);
+ }
+
+ }.add(appender));
+
commentContainer.add(new AjaxLink<Void>("close") {
@Override
@@ -503,13 +575,42 @@ public abstract class RevisionDiffPanel extends Panel {
@Override
public void onClick(AjaxRequestTarget target) {
- hideComment(target);
- onOpenComment(target, null);
+ clearComment(target);
+ CodeComment comment = markSupport.getOpenComment();
+ if (comment != null) {
+ CommentAware commentAware = getCommentAware(comment.getPath());
+ if (commentAware != null)
+ commentAware.onCommentClosed(target, comment);
+ markSupport.onCommentClosed(target);
+ }
+ target.appendJavaScript("$(window).resize();");
}
});
- commentContainer.add(new WebMarkupContainer("body"));
-
+ if (markSupport != null && markSupport.getOpenComment() != null) {
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return markSupport.getOpenComment();
+ }
+
+ };
+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ RevisionDiffPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+ commentContainer.add(commentPanel);
+ } else {
+ commentContainer.add(new WebMarkupContainer(BODY_ID));
+ commentContainer.setVisible(false);
+ }
+
Component totalChangedLink;
body.add(totalChangedLink = new Label("totalChanged", new AbstractReadOnlyModel<String>() {
@@ -540,7 +641,7 @@ public abstract class RevisionDiffPanel extends Panel {
totalChangedLink.add(AttributeAppender.append("class", "expanded"));
}
body.add(diffStats);
- diffStats.add(new ListView<BlobChange>("diffStats", new AbstractReadOnlyModel<List<BlobChange>>() {
+ diffStats.add(diffsView = new ListView<BlobChange>("diffStats", new AbstractReadOnlyModel<List<BlobChange>>() {
@Override
public List<BlobChange> getObject() {
@@ -604,7 +705,225 @@ public abstract class RevisionDiffPanel extends Panel {
protected void populateItem(ListItem<BlobChange> item) {
BlobChange change = item.getModelObject();
item.setMarkupId("diff-" + change.getPath());
- item.add(new BlobDiffPanel("diff", depotModel, requestModel, change, diffMode));
+ if (markSupport != null) {
+ item.add(new BlobDiffPanel(DIFF_ID, depotModel, requestModel, change, diffMode, new BlobMarkSupport() {
+
+ @Override
+ public DiffMark getMark() {
+ DiffMark mark = markSupport.getMark();
+ if (mark != null && change.getPaths().contains(mark.getPath()))
+ return mark;
+ else
+ return null;
+ }
+
+ @Override
+ public String getMarkUrl(DiffMark mark) {
+ return markSupport.getMarkUrl(mark);
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ CodeComment comment = markSupport.getOpenComment();
+ if (comment != null && change.getPaths().contains(comment.getPath()))
+ return comment;
+ else
+ return null;
+ }
+
+ @Override
+ public void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
+ Long commentId = comment.getId();
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ }
+
+ };
+
+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ RevisionDiffPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+
+ commentContainer.replace(commentPanel);
+ commentContainer.setVisible(true);
+ target.add(commentContainer);
+
+ CodeComment prevComment = markSupport.getOpenComment();
+ if (prevComment != null) {
+ CommentAware commentAware = getCommentAware(prevComment.getPath());
+ if (commentAware != null)
+ commentAware.onCommentClosed(target, prevComment);
+ }
+
+ DiffMark prevMark = markSupport.getMark();
+ if (prevMark != null) {
+ CommentAware commentAware = getCommentAware(prevMark.getPath());
+ if (commentAware != null)
+ commentAware.clearMark(target);
+ }
+
+ markSupport.onCommentOpened(target, comment);
+ target.appendJavaScript("$(window).resize();");
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, DiffMark mark) {
+ commentContainer.setDefaultModelObject(mark);
+
+ Fragment fragment = new Fragment(BODY_ID, "newCommentFrag", RevisionDiffPanel.this);
+ fragment.setOutputMarkupId(true);
+
+ Form<?> form = new Form<Void>("form");
+
+ CommentInput input;
+ form.add(input = new CommentInput("input", Model.of("")) {
+
+ @Override
+ protected DepotAttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(depotModel.getObject());
+ }
+
+ });
+ input.setRequired(true);
+
+ NotificationPanel feedback = new NotificationPanel("feedback", input);
+ feedback.setOutputMarkupPlaceholderTag(true);
+ form.add(feedback);
+
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ clearComment(target);
+ target.appendJavaScript("$(window).resize();");
+ }
+
+ });
+
+ form.add(new AjaxButton("save") {
+
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ super.onError(target, form);
+ target.add(feedback);
+ }
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ CodeComment comment = new CodeComment();
+ CompareContext compareContext = new CompareContext();
+ Depot depot = depotModel.getObject();
+ String oldCommitHash = depot.getRevCommit(oldRev).name();
+ String newCommitHash = depot.getRevCommit(newRev).name();
+ if (mark.isLeftSide()) {
+ comment.setCommit(oldCommitHash);
+ compareContext.setCompareCommit(newCommitHash);
+ compareContext.setLeftSide(false);
+ } else {
+ comment.setCommit(newCommitHash);
+ compareContext.setCompareCommit(oldCommitHash);
+ compareContext.setLeftSide(true);
+ }
+ compareContext.setPathFilter(pathFilter);
+ compareContext.setWhitespaceOption(whitespaceOption);
+ comment.setCompareContext(compareContext);
+ comment.setPath(mark.getPath());
+ comment.setContent(input.getModelObject());
+ comment.setDepot(depotModel.getObject());
+ comment.setUser(SecurityUtils.getAccount());
+ comment.setMark(new Mark(mark.getBeginLine(), mark.getBeginChar(),
+ mark.getEndLine(), mark.getEndChar()));
+ GitPlex.getInstance(CodeCommentManager.class).persist(comment);
+
+ Long commentId = comment.getId();
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ }
+
+ };
+ CodeCommentPanel commentPanel = new CodeCommentPanel(fragment.getId(), commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ RevisionDiffPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+ commentContainer.replaceWith(commentPanel);
+ target.add(commentContainer);
+
+ CommentAware commentAware = getCommentAware(comment.getPath());
+ if (commentAware != null)
+ commentAware.onCommentAdded(target, comment);
+
+ markSupport.onCommentOpened(target, comment);
+ }
+
+ });
+ fragment.add(form);
+ commentContainer.replace(fragment);
+ commentContainer.setVisible(true);
+ target.add(commentContainer);
+
+ CodeComment prevComment = markSupport.getOpenComment();
+ if (prevComment != null) {
+ CommentAware commentAware = getCommentAware(prevComment.getPath());
+ if (commentAware != null)
+ commentAware.onCommentClosed(target, prevComment);
+ }
+ DiffMark prevMark = markSupport.getMark();
+ if (prevMark != null) {
+ CommentAware commentAware = getCommentAware(prevMark.getPath());
+ if (commentAware != null)
+ commentAware.clearMark(target);
+ }
+
+ markSupport.onAddComment(target, mark);
+ target.appendJavaScript("$(window).resize();");
+ }
+
+ @Override
+ public Collection<CodeComment> getComments() {
+ Collection<CodeComment> comments = new ArrayList<>();
+ for (CodeComment comment: commentsModel.getObject()) {
+ if (comment.getPath().equals(change.getOldBlobIdent().path)
+ || comment.getPath().equals(change.getNewBlobIdent().path)) {
+ comments.add(comment);
+ }
+ }
+ return comments;
+ }
+
+ @Override
+ public Component getDirtyContainer() {
+ return RevisionDiffPanel.this;
+ }
+
+ }));
+ } else {
+ item.add(new BlobDiffPanel(DIFF_ID, depotModel, requestModel, change, diffMode, null));
+ }
}
});
@@ -612,15 +931,48 @@ public abstract class RevisionDiffPanel extends Panel {
setOutputMarkupId(true);
}
- private void hideComment(AjaxRequestTarget target) {
- commentContainer.replace(new WebMarkupContainer("body"));
+ @Nullable
+ private CommentAware getCommentAware(String path) {
+ return diffsView.visitChildren(ListItem.class, new IVisitor<ListItem<BlobChange>, CommentAware>() {
+
+ @Override
+ public void component(ListItem<BlobChange> object, IVisit<CommentAware> visit) {
+ if (object.getModelObject().getPaths().contains(path)) {
+ visit.stop((CommentAware) object.get(DIFF_ID));
+ } else {
+ visit.dontGoDeeper();
+ }
+ }
+
+ });
+ }
+
+ private RevCommit getOldCommit() {
+ return depotModel.getObject().getRevCommit(oldRev);
+ }
+
+ private RevCommit getNewCommit() {
+ return depotModel.getObject().getRevCommit(newRev);
+ }
+
+ private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+ clearComment(target);
+ CommentAware commentAware = getCommentAware(comment.getPath());
+ if (commentAware != null)
+ commentAware.onCommentDeleted(target, comment);
+ markSupport.onCommentClosed(target);
+ target.appendJavaScript("$(window).resize();");
+ }
+
+ private void clearComment(AjaxRequestTarget target) {
+ commentContainer.replace(new WebMarkupContainer(BODY_ID));
commentContainer.setVisible(false);
target.add(commentContainer);
- target.appendJavaScript("gitplex.revisionDiff.onOpenComment();");
}
@Override
protected void onDetach() {
+ commentsModel.detach();
diffEntriesModel.detach();
changesAndCountModel.detach();
depotModel.detach();
@@ -633,7 +985,6 @@ public abstract class RevisionDiffPanel extends Panel {
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(JavaScriptHeaderItem.forReference(JQueryUIResourceReference.INSTANCE));
- response.render(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(
new JavaScriptResourceReference(RevisionDiffPanel.class, "revision-diff.js")));
@@ -646,8 +997,6 @@ public abstract class RevisionDiffPanel extends Panel {
protected abstract void onWhitespaceOptionChange(AjaxRequestTarget target,
WhitespaceOption whitespaceOption);
- protected abstract void onOpenComment(AjaxRequestTarget target, @Nullable CodeComment comment);
-
private static class ChangesAndCount {
private final List<BlobChange> changes;
@@ -682,4 +1031,5 @@ public abstract class RevisionDiffPanel extends Panel {
}
}
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
index dd9fc9b676..d505eb874d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
@@ -67,6 +67,9 @@
.revision-diff>.body>.loading {
font-size: 20px;
}
+.revision-diff>.body>.detail>.diffs {
+ margin-bottom: 0;
+}
.revision-diff>.body>.detail>.diffs>.diff {
margin-bottom: 20px;
}
@@ -87,6 +90,12 @@
margin-right: 8px;
font-size: 20px;
}
+.revision-diff>.body>.detail>.comment>.content>.head .permanent {
+ margin-top: 2px;
+ margin-right: 8px;
+ font-size: 18px;
+}
+
.revision-diff>.body>.detail>.comment>.ui-resizable-handle {
position: absolute;
background: #EEE url("vgrabber.png") no-repeat scroll right center;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
index 79790918e4..d89063e26f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
@@ -38,7 +38,12 @@ gitplex.revisionDiff = {
$comment.css("top", 0);
}
var $lastDiff = $diffs.children().last();
- var commentHeight = $lastDiff.offset().top + $lastDiff.height() - scrollTop;
+ var commentHeight;
+ if ($lastDiff.length != 0) {
+ commentHeight = $lastDiff.offset().top + $lastDiff.height() - scrollTop;
+ } else {
+ commentHeight = $diffs.offset().top + $diffs.height() - scrollTop;
+ }
var windowHeight = $(window).height();
var minCommentHeight = windowHeight - 100;
if (commentHeight < minCommentHeight)
@@ -89,8 +94,5 @@ gitplex.revisionDiff = {
}
});
}
- },
- onOpenComment: function(commentInfo) {
- $(window).resize();
- }
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/hashandcode/HashAndCodePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/hashandcode/HashAndCodePanel.java
index e360e1721d..4610456508 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/hashandcode/HashAndCodePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/hashandcode/HashAndCodePanel.java
@@ -1,75 +1,74 @@
-package com.pmease.gitplex.web.component.hashandcode;
-
-import javax.annotation.Nullable;
-
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.resource.CssResourceReference;
-
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.web.component.commithash.CommitHashPanel;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
-
-@SuppressWarnings("serial")
-public class HashAndCodePanel extends Panel {
-
- private final IModel<Depot> depotModel;
-
- private final Long requestId;
-
- private final String hash;
-
- private final String path;
-
- public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash) {
- this(id, depotModel, hash, null);
- }
-
- public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash,
- @Nullable String path) {
- this(id, depotModel, hash, path, null);
- }
-
- public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash,
- @Nullable String path, @Nullable Long requestId) {
- super(id);
-
- this.depotModel = depotModel;
- this.requestId = requestId;
- this.hash = hash;
- this.path = path;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new CommitHashPanel("hash", hash));
-
- HistoryState state = new HistoryState();
- state.requestId = requestId;
- state.blobIdent.revision = hash;
- state.blobIdent.path = path;
- add(new BookmarkablePageLink<Void>("code", DepotFilePage.class,
- DepotFilePage.paramsOf(depotModel.getObject(), state)));
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new CssResourceReference(
- HashAndCodePanel.class, "hash-and-code.css")));
- }
-
- @Override
- protected void onDetach() {
- depotModel.detach();
-
- super.onDetach();
- }
-
-}
+package com.pmease.gitplex.web.component.hashandcode;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.resource.CssResourceReference;
+
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.web.component.commithash.CommitHashPanel;
+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
+
+@SuppressWarnings("serial")
+public class HashAndCodePanel extends Panel {
+
+ private final IModel<Depot> depotModel;
+
+ private final Long requestId;
+
+ private final String hash;
+
+ private final String path;
+
+ public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash) {
+ this(id, depotModel, hash, null);
+ }
+
+ public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash,
+ @Nullable String path) {
+ this(id, depotModel, hash, path, null);
+ }
+
+ public HashAndCodePanel(String id, IModel<Depot> depotModel, String hash,
+ @Nullable String path, @Nullable Long requestId) {
+ super(id);
+
+ this.depotModel = depotModel;
+ this.requestId = requestId;
+ this.hash = hash;
+ this.path = path;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new CommitHashPanel("hash", hash));
+
+ DepotFilePage.State state = new DepotFilePage.State();
+ state.requestId = requestId;
+ state.blobIdent.revision = hash;
+ state.blobIdent.path = path;
+ add(new BookmarkablePageLink<Void>("code", DepotFilePage.class,
+ DepotFilePage.paramsOf(depotModel.getObject(), state)));
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new CssResourceReference(
+ HashAndCodePanel.class, "hash-and-code.css")));
+ }
+
+ @Override
+ protected void onDetach() {
+ depotModel.detach();
+
+ super.onDetach();
+ }
+
+}
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.java
index f42e2e2a59..d7ad2cce91 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
@@ -46,7 +46,6 @@ import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.web.component.depotfile.blobsearch.result.SearchResultPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public abstract class SymbolTooltipPanel extends Panel {
@@ -237,7 +236,7 @@ public abstract class SymbolTooltipPanel extends Panel {
}
public PageParameters getQueryHitParams(QueryHit hit) {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = revision;
state.blobIdent.path = hit.getBlobPath();
state.mark = Mark.of(hit.getTokenPos());
@@ -246,7 +245,7 @@ public abstract class SymbolTooltipPanel extends Panel {
}
public PageParameters getFindOccurrencesParams() {
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = revision;
state.blobIdent.path = getBlobPath();
state.requestId = PullRequest.idOf(requestModel.getObject());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
index dbc24a2fc3..299add8230 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
@@ -73,7 +73,6 @@ import com.pmease.gitplex.web.page.depot.NoCommitsPage;
import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.pmease.gitplex.web.util.DateUtils;
@@ -418,7 +417,7 @@ public class DepotBranchesPage extends DepotPage {
Ref ref = item.getModelObject();
final String branch = GitUtils.ref2branch(ref.getName());
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = branch;
AbstractLink link = new BookmarkablePageLink<Void>("branchLink",
DepotFilePage.class, DepotFilePage.paramsOf(getDepot(), state));
@@ -445,7 +444,7 @@ public class DepotBranchesPage extends DepotPage {
});
- final AheadBehind ab = Preconditions.checkNotNull(aheadBehindsModel.getObject().get(lastCommit));
+ AheadBehind ab = Preconditions.checkNotNull(aheadBehindsModel.getObject().get(lastCommit));
item.add(new Link<Void>("behindLink") {
@@ -479,7 +478,7 @@ public class DepotBranchesPage extends DepotPage {
if (request != null) {
setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
} else {
- RevisionComparePage.HistoryState state = new RevisionComparePage.HistoryState();
+ RevisionComparePage.State state = new RevisionComparePage.State();
state.leftSide = new DepotAndBranch(getDepot(), branch);
state.rightSide = new DepotAndBranch(getDepot(), getBaseBranch());
PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
@@ -538,7 +537,7 @@ public class DepotBranchesPage extends DepotPage {
if (request != null) {
setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
} else {
- RevisionComparePage.HistoryState state = new RevisionComparePage.HistoryState();
+ RevisionComparePage.State state = new RevisionComparePage.State();
state.leftSide = new DepotAndBranch(getDepot(), getBaseBranch());
state.rightSide = new DepotAndBranch(getDepot(), branch);
PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
index bb5f132522..0e3ccf2987 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
@@ -1,9 +1,10 @@
package com.pmease.gitplex.web.page.depot.commit;
-import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
@@ -24,18 +25,15 @@ import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
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.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.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.GitUtils;
@@ -46,11 +44,13 @@ import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.manager.AuxiliaryManager;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.web.component.avatar.ContributorAvatars;
import com.pmease.gitplex.web.component.contributorpanel.ContributorPanel;
import com.pmease.gitplex.web.component.createbranch.CreateBranchLink;
import com.pmease.gitplex.web.component.createtag.CreateTagLink;
import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+import com.pmease.gitplex.web.component.diff.revision.MarkSupport;
import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
import com.pmease.gitplex.web.component.hashandcode.HashAndCodePanel;
import com.pmease.gitplex.web.page.depot.DepotPage;
@@ -59,7 +59,7 @@ import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.page.depot.tags.DepotTagsPage;
@SuppressWarnings("serial")
-public class CommitDetailPage extends DepotPage {
+public class CommitDetailPage extends DepotPage implements MarkSupport {
private static final String PARAM_REVISION = "revision";
@@ -75,45 +75,31 @@ public class CommitDetailPage extends DepotPage {
private static final String PARAM_MARK = "mark";
- protected String revision;
+ private State state;
- private HistoryState state;
+ private ObjectId resolvedRevision;
- private IModel<RevCommit> commitModel = new LoadableDetachableModel<RevCommit>() {
-
- @Override
- protected RevCommit load() {
- try(RevWalk revWalk = new RevWalk(getDepot().getRepository())) {
- ObjectId objectId;
- if (GitUtils.isHash(revision))
- objectId = ObjectId.fromString(revision);
- else
- objectId = getDepot().getRepository().resolve(revision);
- return revWalk.parseCommit(objectId);
- } catch (RevisionSyntaxException | IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- };
+ private ObjectId resolvedCompareWith;
private RevisionDiffPanel revisionDiff;
public CommitDetailPage(PageParameters params) {
super(params);
- revision = GitUtils.normalizePath(params.get(PARAM_REVISION).toString());
- state = new HistoryState(params);
+ state = new State(params);
+ resolvedRevision = getDepot().getRevCommit(state.revision).copy();
+ if (state.compareWith != null)
+ resolvedCompareWith = getDepot().getRevCommit(state.compareWith).copy();
}
private RevCommit getCommit() {
- return commitModel.getObject();
+ return getDepot().getRevCommit(state.revision);
}
- private List<String> getParents() {
- List<String> parents = new ArrayList<>();
+ private List<RevCommit> getParents() {
+ List<RevCommit> parents = new ArrayList<>();
for (RevCommit parent: getCommit().getParents())
- parents.add(parent.name());
+ parents.add(parent);
return parents;
}
@@ -125,7 +111,7 @@ public class CommitDetailPage extends DepotPage {
add(new HashAndCodePanel("hashAndCode", depotModel, getCommit().getId().name()));
- add(new CreateBranchLink("createBranch", depotModel, revision) {
+ add(new CreateBranchLink("createBranch", depotModel, state.revision) {
@Override
protected void onCreate(AjaxRequestTarget target, String branch) {
@@ -134,7 +120,7 @@ public class CommitDetailPage extends DepotPage {
});
- add(new CreateTagLink("createTag", depotModel, revision) {
+ add(new CreateTagLink("createTag", depotModel, state.revision) {
@Override
protected void onCreate(AjaxRequestTarget target, String tag) {
@@ -200,7 +186,7 @@ public class CommitDetailPage extends DepotPage {
String ref = item.getModelObject().getName();
String branch = GitUtils.ref2branch(ref);
if (branch != null) {
- DepotFilePage.HistoryState state = new DepotFilePage.HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = branch;
Link<Void> link = new BookmarkablePageLink<Void>("link", DepotFilePage.class,
DepotFilePage.paramsOf(depotModel.getObject(), state));
@@ -209,7 +195,7 @@ public class CommitDetailPage extends DepotPage {
item.add(AttributeAppender.append("class", "branch"));
} else {
String tag = Preconditions.checkNotNull(GitUtils.ref2tag(ref));
- DepotFilePage.HistoryState state = new DepotFilePage.HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = tag;
Link<Void> link = new BookmarkablePageLink<Void>("link", DepotFilePage.class,
DepotFilePage.paramsOf(depotModel.getObject(), state));
@@ -228,41 +214,60 @@ public class CommitDetailPage extends DepotPage {
add(new ContributorAvatars("contributorAvatars", getCommit().getAuthorIdent(), getCommit().getCommitterIdent()));
add(new ContributorPanel("contribution", getCommit().getAuthorIdent(), getCommit().getCommitterIdent(), true));
- final WebMarkupContainer parentsContainer = new WebMarkupContainer("parents");
+ newParentsContainer(null);
+
+ if (getCommit().getParentCount() != 0) {
+ newRevisionDiff(null);
+ } else {
+ add(new WebMarkupContainer("revisionDiff").setVisible(false));
+ }
+ }
+
+ private void newParentsContainer(@Nullable AjaxRequestTarget target) {
+ WebMarkupContainer parentsContainer = new WebMarkupContainer("parents");
parentsContainer.setOutputMarkupId(true);
- add(parentsContainer);
if (getParents().size() == 1) {
- String parent = getParents().get(0);
+ RevCommit parent = getParents().get(0);
+ State newState = new State();
+ newState.revision = parent.name();
+ newState.whitespaceOption = state.whitespaceOption;
Link<Void> link = new BookmarkablePageLink<Void>("parent", CommitDetailPage.class,
- paramsOf(depotModel.getObject(), parent));
- link.add(new Label("label", GitUtils.abbreviateSHA(parent)));
+ paramsOf(depotModel.getObject(), newState));
+ link.add(new Label("label", GitUtils.abbreviateSHA(parent.name())));
parentsContainer.add(link);
parentsContainer.add(new WebMarkupContainer("parents").setVisible(false));
} else {
parentsContainer.add(new WebMarkupContainer("parent").setVisible(false));
parentsContainer.add(new Label("count", getParents().size() + " parents"));
- parentsContainer.add(new ListView<String>("parents", new LoadableDetachableModel<List<String>>() {
+ parentsContainer.add(new ListView<RevCommit>("parents", new LoadableDetachableModel<List<RevCommit>>() {
@Override
- protected List<String> load() {
+ protected List<RevCommit> load() {
return getParents();
}
}) {
@Override
- protected void populateItem(ListItem<String> item) {
- final String parent = item.getModelObject();
+ protected void populateItem(ListItem<RevCommit> item) {
+ RevCommit parent = item.getModelObject();
+
+ State newState = new State();
+ newState.revision = parent.name();
+ newState.whitespaceOption = state.whitespaceOption;
+
Link<Void> link = new BookmarkablePageLink<Void>("link", CommitDetailPage.class,
- paramsOf(depotModel.getObject(), parent));
- link.add(new Label("label", GitUtils.abbreviateSHA(parent)));
+ paramsOf(depotModel.getObject(), newState));
+ link.add(new Label("label", GitUtils.abbreviateSHA(parent.name())));
item.add(link);
item.add(new AjaxLink<Void>("diff") {
@Override
public void onClick(AjaxRequestTarget target) {
- setCompareWith(parent);
+ state.compareWith = item.getModelObject().name();
+ resolvedCompareWith = item.getModelObject().copy();
+
target.add(parentsContainer);
newRevisionDiff(target);
pushState(target);
@@ -271,7 +276,7 @@ public class CommitDetailPage extends DepotPage {
@Override
protected void onInitialize() {
super.onInitialize();
- if (parent.equals(getCompareWith()))
+ if (item.getModelObject().equals(getCompareWith()))
add(AttributeAppender.append("class", "active"));
}
@@ -279,30 +284,31 @@ public class CommitDetailPage extends DepotPage {
}
});
- }
-
- if (getCommit().getParentCount() != 0) {
- newRevisionDiff(null);
+ }
+ if (target != null) {
+ replace(parentsContainer);
+ target.add(parentsContainer);
} else {
- add(new WebMarkupContainer("revisionDiff").setVisible(false));
+ add(parentsContainer);
}
}
- private String getCompareWith() {
- if (state.compareWith == null)
- state.compareWith = getParents().get(0);
- return state.compareWith;
- }
-
- private void setCompareWith(String compareWith) {
- state.compareWith = compareWith;
+ private ObjectId getCompareWith() {
+ List<RevCommit> parents = getParents();
+ if (resolvedCompareWith != null) {
+ if (parents.contains(resolvedCompareWith))
+ return resolvedCompareWith;
+ else
+ return parents.get(0);
+ } else {
+ return parents.get(0);
+ }
}
private void newRevisionDiff(@Nullable AjaxRequestTarget target) {
revisionDiff = new RevisionDiffPanel("revisionDiff", depotModel,
- Model.of((PullRequest)null), getCompareWith(),
- getCommit().name(), state.pathFilter, state.whitespaceOption,
- state.commentId, state.mark) {
+ Model.of((PullRequest)null), getCompareWith().name(), state.revision,
+ state.pathFilter, state.whitespaceOption, this) {
@Override
protected void onPathFilterChange(AjaxRequestTarget target, String pathFilter) {
@@ -314,12 +320,7 @@ public class CommitDetailPage extends DepotPage {
protected void onWhitespaceOptionChange(AjaxRequestTarget target,
WhitespaceOption whitespaceOption) {
state.whitespaceOption = whitespaceOption;
- pushState(target);
- }
-
- @Override
- protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
- state.commentId = CodeComment.idOf(comment);
+ newParentsContainer(target);
pushState(target);
}
@@ -343,13 +344,9 @@ public class CommitDetailPage extends DepotPage {
CommitDetailPage.class, "commit-detail.css")));
}
- public static PageParameters paramsOf(Depot depot, String revision) {
- return paramsOf(depot, revision, new HistoryState());
- }
-
- public static PageParameters paramsOf(Depot depot, String revision, HistoryState state) {
+ public static PageParameters paramsOf(Depot depot, State state) {
PageParameters params = paramsOf(depot);
- params.set(PARAM_REVISION, revision);
+ params.set(PARAM_REVISION, state.revision);
if (state.compareWith != null)
params.set(PARAM_COMPARE_WITH, state.compareWith);
if (state.whitespaceOption != WhitespaceOption.DEFAULT)
@@ -358,23 +355,24 @@ public class CommitDetailPage extends DepotPage {
params.set(PARAM_PATH_FILTER, state.pathFilter);
if (state.commentId != null)
params.set(PARAM_COMMENT, state.commentId);
+ if (state.mark != null)
+ params.set(PARAM_MARK, state.mark.toString());
return params;
}
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(DepotCommitsPage.class, paramsOf(depot));
+ public static PageParameters paramsOf(Depot depot, String revision) {
+ State state = new State();
+ state.revision = revision;
+ return paramsOf(depot, state);
}
@Override
- protected void onDetach() {
- commitModel.detach();
-
- super.onDetach();
+ protected void onSelect(AjaxRequestTarget target, Depot depot) {
+ setResponsePage(DepotCommitsPage.class, paramsOf(depot));
}
private void pushState(AjaxRequestTarget target) {
- PageParameters params = paramsOf(getDepot(), getCommit().name(), state);
+ PageParameters params = paramsOf(getDepot(), state);
CharSequence url = RequestCycle.get().urlFor(CommitDetailPage.class, params);
pushState(target, url.toString(), state);
}
@@ -383,28 +381,35 @@ public class CommitDetailPage extends DepotPage {
protected void onPopState(AjaxRequestTarget target, Serializable data) {
super.onPopState(target, data);
- state = (HistoryState) data;
+ state = (State) data;
newRevisionDiff(target);
}
- public static class HistoryState implements Serializable {
+ public static class State implements Serializable {
private static final long serialVersionUID = 1L;
+ public String revision;
+
+ @Nullable
public String compareWith;
+ @Nullable
public Long commentId;
public WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
+ @Nullable
public String pathFilter;
+ @Nullable
public DiffMark mark;
- public HistoryState() {
+ public State() {
}
- public HistoryState(PageParameters params) {
+ public State(PageParameters params) {
+ revision = GitUtils.normalizePath(params.get(PARAM_REVISION).toString());
compareWith = params.get(PARAM_COMPARE_WITH).toString();
whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
pathFilter = params.get(PARAM_PATH_FILTER).toString();
@@ -415,4 +420,85 @@ public class CommitDetailPage extends DepotPage {
}
}
+
+ @Override
+ public DiffMark getMark() {
+ return state.mark;
+ }
+
+ @Override
+ public String getMarkUrl(DiffMark mark) {
+ State markState = new State();
+ markState.mark = mark;
+ markState.whitespaceOption = state.whitespaceOption;
+ markState.compareWith = state.compareWith;
+ markState.pathFilter = state.pathFilter;
+ markState.revision = resolvedRevision.name();
+ return urlFor(CommitDetailPage.class, paramsOf(getDepot(), markState)).toString();
+ }
+
+ @Override
+ public String getCommentUrl(CodeComment comment) {
+ State commentState = new State();
+ String compareWith = getCompareWith().name();
+ commentState.mark = new DiffMark(comment, compareWith, resolvedRevision.name());
+ commentState.commentId = comment.getId();
+ commentState.whitespaceOption = state.whitespaceOption;
+ commentState.compareWith = compareWith;
+ commentState.pathFilter = state.pathFilter;
+ commentState.revision = resolvedRevision.name();
+ return urlFor(CommitDetailPage.class, paramsOf(getDepot(), commentState)).toString();
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ if (state.commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(state.commentId);
+ else
+ return null;
+ }
+
+ @Override
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ state.commentId = comment.getId();
+ state.mark = new DiffMark(comment, getCompareWith().name(), resolvedRevision.name());
+ pushState(target);
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target) {
+ state.commentId = null;
+ pushState(target);
+ }
+
+ @Override
+ public void onMark(AjaxRequestTarget target, DiffMark mark) {
+ state.mark = mark;
+ pushState(target);
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, DiffMark mark) {
+ state.commentId = null;
+ state.mark = mark;
+ pushState(target);
+ }
+
+ /*
+ * In case we are on a branch, this operation makes sure that the branch resolves
+ * to a certain commit during the life cycle of our page, unless the page is
+ * refreshed. This can avoid the issue that displayed file content and subsequent
+ * operations encounters different commit if someone commits to the branch while
+ * we are staying on the page.
+ */
+ @Override
+ protected Map<String, ObjectId> getObjectIdCache() {
+ Map<String, ObjectId> objectIdCache = new HashMap<>();
+ if (resolvedRevision != null)
+ objectIdCache.put(state.revision, resolvedRevision);
+ if (resolvedCompareWith != null)
+ objectIdCache.put(state.compareWith, resolvedCompareWith);
+ return objectIdCache;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
index 55a117bc45..3d4df2dcf4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
@@ -84,7 +84,7 @@ public class DepotCommitsPage extends DepotPage {
private static final String PARAM_STEP = "step";
- private HistoryState state = new HistoryState();
+ private State state = new State();
private boolean hasMore;
@@ -157,7 +157,7 @@ public class DepotCommitsPage extends DepotPage {
public DepotCommitsPage(PageParameters params) {
super(params);
- state = new HistoryState(params);
+ state = new State(params);
}
@SuppressWarnings("deprecation")
@@ -427,7 +427,7 @@ public class DepotCommitsPage extends DepotPage {
}
}
if (state.getCompareWith() != null) {
- RevisionComparePage.HistoryState state = new RevisionComparePage.HistoryState();
+ RevisionComparePage.State state = new RevisionComparePage.State();
state.leftSide = new DepotAndRevision(getDepot(), commit.getHash());
state.rightSide = new DepotAndRevision(getDepot(), DepotCommitsPage.this.state.getCompareWith());
state.pathFilter = path;
@@ -451,7 +451,7 @@ public class DepotCommitsPage extends DepotPage {
return item;
}
- public static PageParameters paramsOf(Depot depot, HistoryState state) {
+ public static PageParameters paramsOf(Depot depot, State state) {
PageParameters params = paramsOf(depot);
if (state.getCompareWith() != null)
params.set(PARAM_COMPARE_WITH, state.getCompareWith());
@@ -471,7 +471,7 @@ public class DepotCommitsPage extends DepotPage {
protected void onPopState(AjaxRequestTarget target, Serializable data) {
super.onPopState(target, data);
- state = (HistoryState) data;
+ state = (State) data;
target.add(queryForm);
@@ -541,7 +541,7 @@ public class DepotCommitsPage extends DepotPage {
List<Commit> current;
}
- public static class HistoryState implements Serializable {
+ public static class State implements Serializable {
private static final long serialVersionUID = 1L;
@@ -553,10 +553,10 @@ public class DepotCommitsPage extends DepotPage {
private transient Optional<QueryContext> parseTree;
- public HistoryState() {
+ public State() {
}
- public HistoryState(PageParameters params) {
+ public State(PageParameters params) {
compareWith = params.get(PARAM_COMPARE_WITH).toString();
query = params.get(PARAM_QUERY).toString();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
index 1ae72cf3da..fe83e79115 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
@@ -37,9 +37,11 @@ import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.component.DepotAndBranch;
import com.pmease.gitplex.core.entity.component.DepotAndRevision;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.web.component.commitlist.CommitListPanel;
import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+import com.pmease.gitplex.web.component.diff.revision.MarkSupport;
import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
import com.pmease.gitplex.web.component.revisionpicker.AffinalRevisionPicker;
import com.pmease.gitplex.web.page.depot.DepotPage;
@@ -49,7 +51,7 @@ import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetail
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
@SuppressWarnings("serial")
-public class RevisionComparePage extends DepotPage {
+public class RevisionComparePage extends DepotPage implements MarkSupport {
private static final String PARAM_LEFT = "left";
@@ -59,6 +61,8 @@ public class RevisionComparePage extends DepotPage {
private static final String PARAM_COMMENT = "comment";
+ private static final String PARAM_MARK = "mark";
+
private static final String PARAM_PATH_FILTER = "path-filter";
private static final String TAB_PANEL_ID = "tabPanel";
@@ -73,11 +77,11 @@ public class RevisionComparePage extends DepotPage {
private AjaxActionTab filesTab;
- private HistoryState state = new HistoryState();
+ private State state = new State();
private ObjectId resolvedRightSideRevision;
- public static PageParameters paramsOf(Depot depot, HistoryState state) {
+ public static PageParameters paramsOf(Depot depot, State state) {
PageParameters params = paramsOf(depot);
params.set(PARAM_LEFT, state.leftSide.toString());
params.set(PARAM_RIGHT, state.rightSide.toString());
@@ -87,6 +91,8 @@ public class RevisionComparePage extends DepotPage {
params.set(PARAM_PATH_FILTER, state.pathFilter);
if (state.commentId != null)
params.set(PARAM_COMMENT, state.commentId);
+ if (state.mark != null)
+ params.set(PARAM_MARK, state.mark.toString());
return params;
}
@@ -102,7 +108,7 @@ public class RevisionComparePage extends DepotPage {
} else {
state.rightSide = new DepotAndRevision(getDepot(), getDepot().getDefaultBranch());
}
- resolvedRightSideRevision = state.rightSide.getObjectId();
+ resolvedRightSideRevision = state.rightSide.getCommit().copy();
str = params.get(PARAM_LEFT).toString();
if (str != null) {
@@ -174,7 +180,7 @@ public class RevisionComparePage extends DepotPage {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot, String revision) {
- HistoryState state = new HistoryState(RevisionComparePage.this.state);
+ State state = new State(RevisionComparePage.this.state);
state.leftSide = new DepotAndRevision(depot, revision);
PageParameters params = paramsOf(depot, state);
@@ -188,7 +194,7 @@ public class RevisionComparePage extends DepotPage {
@Override
public void onClick() {
- HistoryState state = new HistoryState(RevisionComparePage.this.state);
+ State state = new State(RevisionComparePage.this.state);
state.leftSide = RevisionComparePage.this.state.rightSide;
state.rightSide = RevisionComparePage.this.state.leftSide;
setResponsePage(RevisionComparePage.class,paramsOf(getDepot(), state));
@@ -285,7 +291,7 @@ public class RevisionComparePage extends DepotPage {
@Override
public void onClick() {
- HistoryState newState = new HistoryState(state);
+ State newState = new State(state);
newState.leftSide = state.rightSide;
newState.rightSide = state.leftSide;
PageParameters params = paramsOf(getDepot(), newState);
@@ -349,7 +355,7 @@ public class RevisionComparePage extends DepotPage {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot, String revision) {
- HistoryState state = new HistoryState(RevisionComparePage.this.state);
+ State state = new State(RevisionComparePage.this.state);
state.rightSide = new DepotAndRevision(depot, revision);
PageParameters params = paramsOf(getDepot(), state);
@@ -392,7 +398,7 @@ public class RevisionComparePage extends DepotPage {
tabPanel = new RevisionDiffPanel(TAB_PANEL_ID, depotModel,
new Model<PullRequest>(null), mergeBaseModel.getObject(),
state.rightSide.getRevision(), state.pathFilter,
- state.whitespaceOption, state.commentId, state.mark) {
+ state.whitespaceOption, this) {
@Override
protected void onConfigure() {
@@ -413,16 +419,6 @@ public class RevisionComparePage extends DepotPage {
pushState(target);
}
- @Override
- protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
- state.commentId = CodeComment.idOf(comment);
- if (comment != null) {
- boolean leftSide = comment.getCommit().equals(mergeBaseModel.getObject());
- state.mark = new DiffMark(comment.getPath(), leftSide, comment.getMark());
- }
- pushState(target);
- }
-
};
commitsTab.setSelected(false);
filesTab.setSelected(true);
@@ -458,7 +454,7 @@ public class RevisionComparePage extends DepotPage {
protected void onPopState(AjaxRequestTarget target, Serializable data) {
super.onPopState(target, data);
- state = (HistoryState) data;
+ state = (State) data;
newTabPanel(target);
}
@@ -476,7 +472,7 @@ public class RevisionComparePage extends DepotPage {
setResponsePage(RevisionComparePage.class, paramsOf(depot));
}
- public static class HistoryState implements Serializable {
+ public static class State implements Serializable {
private static final long serialVersionUID = 1L;
@@ -495,10 +491,10 @@ public class RevisionComparePage extends DepotPage {
@Nullable
public DiffMark mark;
- public HistoryState() {
+ public State() {
}
- public HistoryState(HistoryState state) {
+ public State(State state) {
leftSide = state.leftSide;
rightSide = state.rightSide;
whitespaceOption = state.whitespaceOption;
@@ -508,5 +504,67 @@ public class RevisionComparePage extends DepotPage {
}
}
+
+ @Override
+ public DiffMark getMark() {
+ return state.mark;
+ }
+
+ @Override
+ public String getMarkUrl(DiffMark mark) {
+ State markState = new State();
+ markState.leftSide = new DepotAndRevision(state.rightSide.getDepot(), mergeBaseModel.getObject());
+ markState.rightSide = new DepotAndRevision(state.rightSide.getDepot(), resolvedRightSideRevision.name());
+ markState.mark = mark;
+ markState.pathFilter = state.pathFilter;
+ markState.whitespaceOption = state.whitespaceOption;
+ return urlFor(RevisionComparePage.class, paramsOf(state.rightSide.getDepot(), state)).toString();
+ }
+
+ @Override
+ public String getCommentUrl(CodeComment comment) {
+ State markState = new State();
+ markState.leftSide = new DepotAndRevision(state.rightSide.getDepot(), mergeBaseModel.getObject());
+ markState.rightSide = new DepotAndRevision(state.rightSide.getDepot(), resolvedRightSideRevision.name());
+ markState.mark = new DiffMark(comment, mergeBaseModel.getObject(), resolvedRightSideRevision.name());
+ markState.commentId = comment.getId();
+ markState.pathFilter = state.pathFilter;
+ markState.whitespaceOption = state.whitespaceOption;
+ return urlFor(RevisionComparePage.class, paramsOf(state.rightSide.getDepot(), state)).toString();
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ if (state.commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(state.commentId);
+ else
+ return null;
+ }
+
+ @Override
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ state.mark = new DiffMark(comment, mergeBaseModel.getObject(), resolvedRightSideRevision.name());
+ state.commentId = comment.getId();
+ pushState(target);
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target) {
+ state.commentId = null;
+ pushState(target);
+ }
+
+ @Override
+ public void onMark(AjaxRequestTarget target, DiffMark mark) {
+ state.mark = mark;
+ pushState(target);
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, DiffMark mark) {
+ state.commentId = null;
+ state.mark = mark;
+ pushState(target);
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java
index 2895716672..e0df6f97d2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java
@@ -87,7 +87,7 @@ class ContributionPanel extends Panel {
protected void populateItem(ListItem<NameAndEmail> item) {
NameAndEmail nameAndEmail = item.getModelObject();
PersonIdent person = new PersonIdent(nameAndEmail.getName(), nameAndEmail.getEmailAddress());
- DepotCommitsPage.HistoryState state = new DepotCommitsPage.HistoryState();
+ DepotCommitsPage.State state = new DepotCommitsPage.State();
state.setCompareWith(blobIdent.revision);
state.setQuery(String.format("path(%s) author(%s <%s>)",
blobIdent.path, nameAndEmail.getName(), nameAndEmail.getEmailAddress()));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
index f9285fabc7..e2c6004f6b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
@@ -399,7 +399,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
@Override
- public CodeComment getComment() {
+ public CodeComment getOpenComment() {
if (commentId != null)
return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
else
@@ -526,7 +526,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
for (RefListener listener: GitPlex.getExtensions(RefListener.class))
listener.onRefUpdate(depot, refName, oldCommit, newCommit);
- HistoryState state = getState();
+ State state = getState();
state.blobIdent = committed;
state.mode = null;
applyState(target, state);
@@ -570,7 +570,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
Depot depot = getDepot();
String branch = blobIdent.revision;
depot.cacheObjectId(branch, newCommit);
- resolveRevision();
+ resolvedRevision = newCommit;
try (RevWalk revWalk = new RevWalk(getDepot().getRepository())) {
RevTree revTree = getDepot().getRevCommit(newCommit).getTree();
String parentPath = StringUtils.substringBeforeLast(blobIdent.path, "/");
@@ -585,7 +585,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
for (RefListener listener: GitPlex.getExtensions(RefListener.class))
listener.onRefUpdate(depot, refName, oldCommit, newCommit);
BlobIdent parentBlobIdent = new BlobIdent(branch, parentPath, FileMode.TREE.getBits());
- HistoryState state = getState();
+ State state = getState();
state.blobIdent = parentBlobIdent;
state.mode = null;
applyState(target, state);
@@ -623,8 +623,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
pushState(target, url.toString(), getState());
}
- private HistoryState getState() {
- HistoryState state = new HistoryState();
+ private State getState() {
+ State state = new State();
state.blobIdent = new BlobIdent(blobIdent);
state.mark = mark;
state.mode = mode;
@@ -633,10 +633,16 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
return state;
}
- private void setState(HistoryState state) {
+ private void setState(State state) {
if (!blobIdent.revision.equals(state.blobIdent.revision)) {
blobIdent = new BlobIdent(state.blobIdent);
- resolveRevision();
+ /*
+ * a hack to reset resolved revision to null to disable getObjectIdCache()
+ * temporarily as otherwise getObjectId() method below will always
+ * resolved to existing value of resolvedRevision
+ */
+ resolvedRevision = null;
+ resolvedRevision = getDepot().getObjectId(blobIdent.revision);
} else {
blobIdent = new BlobIdent(state.blobIdent);
}
@@ -647,7 +653,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
private void onSelect(AjaxRequestTarget target, String revision) {
- HistoryState state = getState();
+ State state = getState();
state.blobIdent.revision = revision;
state.requestId = null;
state.commentId = null;
@@ -679,7 +685,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
@Override
protected String getRevisionUrl(String revision) {
- HistoryState state = new HistoryState();
+ State state = new State();
state.blobIdent.revision = revision;
PageParameters params = DepotFilePage.paramsOf(depotModel.getObject(), state);
return urlFor(DepotFilePage.class, params).toString();
@@ -699,7 +705,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
}
- private void applyState(AjaxRequestTarget target, HistoryState state) {
+ private void applyState(AjaxRequestTarget target, State state) {
if (!state.blobIdent.revision.equals(blobIdent.revision))
newSearchResult(target, null);
@@ -730,7 +736,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
new CssResourceReference(DepotFilePage.class, "depot-file.css")));
}
- public static PageParameters paramsOf(Depot depot, HistoryState state) {
+ public static PageParameters paramsOf(Depot depot, State state) {
PageParameters params = paramsOf(depot);
if (state.blobIdent.revision != null)
params.set(PARAM_REVISION, state.blobIdent.revision);
@@ -787,7 +793,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
protected void onPopState(AjaxRequestTarget target, Serializable data) {
super.onPopState(target, data);
- applyState(target, (HistoryState) data);
+ applyState(target, (State) data);
resizeWindow(target);
}
@@ -841,7 +847,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
@Override
public String getMarkUrl(Mark mark) {
- HistoryState state = getState();
+ State state = getState();
state.blobIdent.revision = resolvedRevision.name();
state.commentId = null;
state.mark = mark;
@@ -925,21 +931,23 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
@Override
- public void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
- commentId = CodeComment.idOf(comment);
- if (comment != null)
- mark = comment.getMark();
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ commentId = comment.getId();
+ mark = comment.getMark();
pushState(target);
}
- private void resolveRevision() {
- /*
- * a hack to reset resolved revision to null to disable getObjectIdCache()
- * temporarily as otherwise getObjectId() method below will always
- * resolved to existing value of resolvedRevision
- */
- resolvedRevision = null;
- resolvedRevision = getDepot().getObjectId(blobIdent.revision);
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target) {
+ commentId = null;
+ pushState(target);
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, Mark mark) {
+ commentId = null;
+ this.mark = mark;
+ pushState(target);
}
@Override
@@ -992,7 +1000,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
- public static class HistoryState implements Serializable {
+ public static class State implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
index 2b60767c37..91c6e091c8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
@@ -56,6 +56,7 @@ import com.pmease.gitplex.core.entity.PullRequestUpdate;
import com.pmease.gitplex.core.entity.ReviewInvitation;
import com.pmease.gitplex.core.entity.component.CloseInfo;
import com.pmease.gitplex.core.entity.component.DepotAndBranch;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.security.ObjectPermission;
import com.pmease.gitplex.web.component.BranchLink;
@@ -63,12 +64,15 @@ import com.pmease.gitplex.web.component.branchpicker.AffinalBranchPicker;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
import com.pmease.gitplex.web.component.commitlist.CommitListPanel;
+import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+import com.pmease.gitplex.web.component.diff.revision.MarkSupport;
import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
import com.pmease.gitplex.web.component.pullrequest.requestassignee.AssigneeChoice;
import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerAvatar;
import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerChoice;
import com.pmease.gitplex.web.model.ReviewersModel;
import com.pmease.gitplex.web.page.depot.NoCommitsPage;
+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
@@ -78,7 +82,7 @@ import com.pmease.gitplex.web.page.security.LoginPage;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@SuppressWarnings("serial")
-public class NewRequestPage extends PullRequestPage {
+public class NewRequestPage extends PullRequestPage implements MarkSupport {
private static final String TAB_PANEL_ID = "tabPanel";
@@ -90,6 +94,14 @@ public class NewRequestPage extends PullRequestPage {
private IModel<PullRequest> requestModel;
+ private Long commentId;
+
+ private DiffMark mark;
+
+ private String pathFilter;
+
+ private WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
+
public static PageParameters paramsOf(Depot depot, DepotAndBranch target, DepotAndBranch source) {
PageParameters params = paramsOf(depot);
params.set("target", target.toString());
@@ -331,19 +343,17 @@ public class NewRequestPage extends PullRequestPage {
*/
RevisionDiffPanel diffPanel = new RevisionDiffPanel(TAB_PANEL_ID, depotModel,
new Model<PullRequest>(null), request.getBaseCommitHash(),
- source.getRevision(), null, WhitespaceOption.DEFAULT, null, null) {
+ source.getRevision(), pathFilter, whitespaceOption, this) {
@Override
protected void onPathFilterChange(AjaxRequestTarget target, String pathFilter) {
+ NewRequestPage.this.pathFilter = pathFilter;
}
@Override
protected void onWhitespaceOptionChange(AjaxRequestTarget target,
WhitespaceOption whitespaceOption) {
- }
-
- @Override
- protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
+ NewRequestPage.this.whitespaceOption = whitespaceOption;
}
};
@@ -619,4 +629,64 @@ public class NewRequestPage extends PullRequestPage {
setResponsePage(RequestListPage.class, paramsOf(depot));
}
+ @Override
+ public DiffMark getMark() {
+ return mark;
+ }
+
+ @Override
+ public String getMarkUrl(DiffMark mark) {
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ state.mark = mark;
+ state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
+ state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getLatestUpdate().getHeadCommitHash());
+ state.pathFilter = pathFilter;
+ state.whitespaceOption = whitespaceOption;
+ return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ if (commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ else
+ return null;
+ }
+
+ @Override
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ commentId = comment.getId();
+ PullRequest request = getPullRequest();
+ mark = new DiffMark(comment, request.getBaseCommitHash(), request.getLatestUpdate().getHeadCommitHash());
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target) {
+ commentId = null;
+ }
+
+ @Override
+ public String getCommentUrl(CodeComment comment) {
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ PullRequest request = getPullRequest();
+ mark = new DiffMark(comment, request.getBaseCommitHash(), request.getLatestUpdate().getHeadCommitHash());
+ state.commentId = comment.getId();
+ state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
+ state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getLatestUpdate().getHeadCommitHash());
+ state.pathFilter = pathFilter;
+ state.whitespaceOption = whitespaceOption;
+ return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
+ }
+
+ @Override
+ public void onMark(AjaxRequestTarget target, DiffMark mark) {
+ this.mark = mark;
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, DiffMark mark) {
+ this.commentId = null;
+ this.mark = mark;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/HistoryState.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/HistoryState.java
deleted file mode 100644
index 73b9ec9b02..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/HistoryState.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare;
-
-import java.io.Serializable;
-
-import com.pmease.commons.lang.diff.WhitespaceOption;
-import com.pmease.gitplex.web.component.diff.revision.DiffMark;
-
-public class HistoryState implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public String oldRev;
-
- public String newRev;
-
- public WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
-
- public String pathFilter;
-
- public Long commentId;
-
- public DiffMark mark;
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java
index 1e726fa69e..32a0572793 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java
@@ -44,19 +44,22 @@ import com.pmease.commons.wicket.component.floating.AlignPlacement;
import com.pmease.commons.wicket.component.floating.FloatingPanel;
import com.pmease.commons.wicket.component.menu.MenuItem;
import com.pmease.commons.wicket.component.menu.MenuLink;
+import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.PullRequestUpdate;
import com.pmease.gitplex.core.entity.component.IntegrationPreview;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.web.component.diff.revision.DiffMark;
+import com.pmease.gitplex.web.component.diff.revision.MarkSupport;
import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;
import com.pmease.gitplex.web.websocket.PullRequestChanged;
@SuppressWarnings("serial")
-public class RequestComparePage extends RequestDetailPage {
+public class RequestComparePage extends RequestDetailPage implements MarkSupport {
private static final String PARAM_OLD_REV = "old-rev";
@@ -80,7 +83,7 @@ public class RequestComparePage extends RequestDetailPage {
public static final String REV_TARGET_BRANCH = "targetBranch";
- private HistoryState state = new HistoryState();
+ private State state = new State();
// below fields duplicates some members of state field, and they are serving different
// purposes and may have different values. State members reflects url parameters, while
@@ -164,7 +167,7 @@ public class RequestComparePage extends RequestDetailPage {
initFromState(state);
}
- private void initFromState(HistoryState state) {
+ private void initFromState(State state) {
oldCommitHash = getCommitHash(state.oldRev);
newCommitHash = getCommitHash(state.newRev);
whitespaceOption = state.whitespaceOption;
@@ -471,18 +474,17 @@ public class RequestComparePage extends RequestDetailPage {
@Override
public void onDetach() {
commitsModel.detach();
-
super.onDetach();
}
public static PageParameters paramsOf(PullRequest request, String oldRev, String newRev) {
- HistoryState state = new HistoryState();
+ State state = new State();
state.oldRev = oldRev;
state.newRev = newRev;
return paramsOf(request, state);
}
- public static PageParameters paramsOf(PullRequest request, HistoryState state) {
+ public static PageParameters paramsOf(PullRequest request, State state) {
PageParameters params = RequestDetailPage.paramsOf(request);
if (state.oldRev != null)
@@ -496,7 +498,7 @@ public class RequestComparePage extends RequestDetailPage {
if (state.commentId != null)
params.set(PARAM_COMMENT, state.commentId);
if (state.mark != null)
- params.set(PARAM_MARK, state.mark);
+ params.set(PARAM_MARK, state.mark.toString());
return params;
}
@@ -627,7 +629,7 @@ public class RequestComparePage extends RequestDetailPage {
protected void onPopState(AjaxRequestTarget target, Serializable data) {
super.onPopState(target, data);
- state = (HistoryState) data;
+ state = (State) data;
initFromState(state);
target.add(compareHead);
@@ -655,7 +657,7 @@ public class RequestComparePage extends RequestDetailPage {
private void newCompareResult(@Nullable IPartialPageRequestHandler partialPageRequestHandler) {
revisionDiff = new RevisionDiffPanel("revisionDiff", depotModel,
requestModel, oldCommitHash, newCommitHash, pathFilter,
- whitespaceOption, commentId, mark) {
+ whitespaceOption, this) {
@Override
protected void onPathFilterChange(AjaxRequestTarget target, String pathFilter) {
@@ -670,12 +672,6 @@ public class RequestComparePage extends RequestDetailPage {
pushState(target);
}
- @Override
- protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {
- commentId = state.commentId = CodeComment.idOf(comment);
- pushState(target);
- }
-
};
revisionDiff.setOutputMarkupId(true);
if (partialPageRequestHandler != null) {
@@ -693,4 +689,84 @@ public class RequestComparePage extends RequestDetailPage {
new CssResourceReference(RequestComparePage.class, "request-compare.css")));
}
+ @Override
+ public DiffMark getMark() {
+ return mark;
+ }
+
+ @Override
+ public String getMarkUrl(DiffMark mark) {
+ State state = new State();
+ state.mark = mark;
+ state.oldRev = oldCommitHash;
+ state.newRev = newCommitHash;
+ state.pathFilter = pathFilter;
+ state.whitespaceOption = whitespaceOption;
+ return urlFor(RequestComparePage.class, paramsOf(getPullRequest(), state)).toString();
+ }
+
+ @Override
+ public String getCommentUrl(CodeComment comment) {
+ State state = new State();
+ state.mark = new DiffMark(comment, oldCommitHash, newCommitHash);
+ state.commentId = comment.getId();
+ state.oldRev = oldCommitHash;
+ state.newRev = newCommitHash;
+ state.pathFilter = pathFilter;
+ state.whitespaceOption = whitespaceOption;
+ return urlFor(RequestComparePage.class, paramsOf(getPullRequest(), state)).toString();
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ if (commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ else
+ return null;
+ }
+
+ @Override
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ commentId = state.commentId = comment.getId();
+ mark = state.mark = new DiffMark(comment, oldCommitHash, newCommitHash);
+ pushState(target);
+ }
+
+ @Override
+ public void onCommentClosed(AjaxRequestTarget target) {
+ commentId = state.commentId = null;
+ pushState(target);
+ }
+
+ @Override
+ public void onMark(AjaxRequestTarget target, DiffMark mark) {
+ this.mark = state.mark = mark;
+ pushState(target);
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, DiffMark mark) {
+ commentId = state.commentId = null;
+ this.mark = state.mark = mark;
+ pushState(target);
+ }
+
+ public static class State implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public String oldRev;
+
+ public String newRev;
+
+ public WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
+
+ public String pathFilter;
+
+ public Long commentId;
+
+ public DiffMark mark;
+
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/SinceChangesLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/SinceChangesLink.java
index 2c36f136fd..78ebcfd508 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/SinceChangesLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/SinceChangesLink.java
@@ -13,7 +13,6 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare.HistoryState;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare.RequestComparePage;
import com.pmease.gitplex.web.websocket.PullRequestChanged;
@@ -61,7 +60,7 @@ class SinceChangesLink extends Panel {
@Override
public void onClick() {
PullRequest request = requestModel.getObject();
- HistoryState state = new HistoryState();
+ RequestComparePage.State state = new RequestComparePage.State();
state.oldRev = oldRevModel.getObject();
state.newRev = RequestComparePage.REV_LAST_UPDATE_PREFIX+1;
PageParameters params = RequestComparePage.paramsOf(request, state);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
index 2126cc76fd..b400246cc4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
@@ -57,7 +57,6 @@ import com.pmease.gitplex.web.page.depot.NoCommitsPage;
import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
import com.pmease.gitplex.web.util.DateUtils;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@@ -256,7 +255,7 @@ public class DepotTagsPage extends DepotPage {
Ref ref = item.getModelObject();
final String tagName = GitUtils.ref2tag(ref.getName());
- HistoryState state = new HistoryState();
+ DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = tagName;
AbstractLink link = new BookmarkablePageLink<Void>("tagLink",
DepotFilePage.class, DepotFilePage.paramsOf(getDepot(), state));
@@ -335,7 +334,7 @@ public class DepotTagsPage extends DepotPage {
}
DepotAndRevision source = new DepotAndRevision(getDepot(),
GitUtils.ref2tag(item.getModelObject().getName()));
- RevisionComparePage.HistoryState state = new RevisionComparePage.HistoryState();
+ RevisionComparePage.State state = new RevisionComparePage.State();
state.leftSide = target;
state.rightSide = source;
state.pathFilter = "";
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index b47194918b..94dabb85a5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,2 +1,3 @@
<wicket:extend>
+ <a wicket:id="link">link</a>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index 0ceb7952ae..865f4ef345 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -2,9 +2,15 @@ package com.pmease.gitplex.web.page.test;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.manager.DepotManager;
+import com.pmease.gitplex.web.component.diff.revision.DiffMark;
import com.pmease.gitplex.web.page.base.BasePage;
+import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
@SuppressWarnings("serial")
public class TestPage extends BasePage {
@@ -12,6 +18,14 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
+
+ Depot depot = GitPlex.getInstance(DepotManager.class).load(1L);
+
+ CommitDetailPage.State state = new CommitDetailPage.State();
+ state.mark = new DiffMark("dir a.java", false, 0, 0, 1, 1);
+ state.revision = "master";
+ add(new BookmarkablePageLink<Void>("link",
+ CommitDetailPage.class, CommitDetailPage.paramsOf(depot, state)));
}
@Override