Skip to content

The Unified and Autonomous Development Platform

Use ACE to render source code in wiki text

steve962b904c8618
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
index 5ca270cf86..0aa59fbaca 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
@@ -418,7 +418,7 @@ table.table-blob { width: 100%; }
.code-highlight code {
background: white; border-radius: 0; padding: 0; margin: 0; border: none;
white-space: pre; word-break: normal; word-wrap: normal;
- font-size: 12px; line-height: 18px;
+ font-size: 12px; line-height: 18px;
}
.code-highlight pre {
@@ -435,6 +435,7 @@ table.table-blob { width: 100%; }
.wiki > *:first-child { margin-top: 0; }
.wiki > *:last-child { margin-bottom: 0; }
.wiki pre { }
+.wiki pre code .ace-xcode { background: #f5f5f5; }
.code-highlight .ace_line { padding-left: 12px; }
.code-highlight .ace_line.selected { background: #ffffaa; }
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/js/vendor/ace-noconflict/ext-static_highlight.js b/gitop.web/src/main/java/com/pmease/gitop/web/assets/js/vendor/ace-noconflict/ext-static_highlight.js
index 9f26f1852d..5d7864e21e 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/js/vendor/ace-noconflict/ext-static_highlight.js
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/js/vendor/ace-noconflict/ext-static_highlight.js
@@ -84,7 +84,8 @@ var highlight = function(el, opts, callback) {
data = data.trim();
}
- highlight.render(data, mode, theme, opts.firstLineNumber, !opts.showGutter, function (highlighted) {
+ var hasLineId = opts.hasLineId || true;
+ highlight.render(data, mode, theme, opts.firstLineNumber, !opts.showGutter, hasLineId, function (highlighted) {
dom.importCssString(highlighted.css, "ace_highlight");
el.innerHTML = highlighted.html;
var container = el.firstChild.firstChild;
@@ -98,7 +99,7 @@ var highlight = function(el, opts, callback) {
});
};
-highlight.render = function(input, mode, theme, lineStart, disableGutter, callback) {
+highlight.render = function(input, mode, theme, lineStart, disableGutter, hasLineId, callback) {
var waiting = 0;
var modeCache = EditSession.prototype.$modes;
if (typeof theme == "string") {
@@ -118,13 +119,13 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba
});
}
function done() {
- var result = highlight.renderSync(input, mode, theme, lineStart, disableGutter);
+ var result = highlight.renderSync(input, mode, theme, lineStart, disableGutter, hasLineId);
return callback ? callback(result) : result;
}
return waiting || done();
};
-highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
+highlight.renderSync = function(input, mode, theme, lineStart, disableGutter, hasLineId) {
lineStart = parseInt(lineStart || 1, 10);
var session = new EditSession("");
@@ -144,7 +145,10 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
var length = session.getLength();
for(var ix = 0; ix < length; ix++) {
- stringBuilder.push("<div class='ace_line' id='LC" + (ix + 1) + "'>");
+ stringBuilder.push("<div class='ace_line'");
+ if (hasLineId)
+ stringBuilder.push(" id='LC" + (ix + 1) + "'");
+ stringBuilder.push(">");
if (!disableGutter)
stringBuilder.push("<span class='ace_gutter ace_gutter-cell' unselectable='on'>" + (ix + lineStart) + "</span>");
textLayer.$renderLine(stringBuilder, ix, true, false);
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/component/wiki/WikiTextPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/component/wiki/WikiTextPanel.java
index 8070f6607b..e5d007c613 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/component/wiki/WikiTextPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/component/wiki/WikiTextPanel.java
@@ -1,8 +1,6 @@
package com.pmease.gitop.web.component.wiki;
import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
@@ -11,7 +9,7 @@ import org.apache.wicket.model.Model;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
-import com.pmease.gitop.web.page.project.source.blob.renderer.highlighter.HighlightJsResourceReference;
+import com.pmease.gitop.web.page.project.source.blob.renderer.highlighter.AceHighlighter;
import com.pmease.gitop.web.util.MarkdownUtils;
public class WikiTextPanel extends Panel {
@@ -58,6 +56,10 @@ public class WikiTextPanel extends Panel {
}
}
}).setEscapeModelStrings(false));
+
+ if (isEnableHighlightJs()) {
+ add(new AceHighlighter().withSelector("#" + getMarkupId() + " pre code").hasLineId(false));
+ }
}
private String getOriginalContent() {
@@ -69,9 +71,9 @@ public class WikiTextPanel extends Panel {
super.renderHead(response);
if (isEnableHighlightJs()) {
- response.render(JavaScriptHeaderItem.forReference(HighlightJsResourceReference.getInstance()));
- response.render(OnDomReadyHeaderItem.forScript(
- ("$('#" + getMarkupId(true) + " .wiki pre code').each(function(i, e) { hljs.highlightBlock(e)});")));
+// response.render(JavaScriptHeaderItem.forReference(HighlightJsResourceReference.getInstance()));
+// response.render(OnDomReadyHeaderItem.forScript(
+// ("$('#" + getMarkupId(true) + " .wiki pre code').each(function(i, e) { hljs.highlightBlock(e)});")));
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java
index 3a54fe914c..7242653e55 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java
@@ -61,34 +61,24 @@ public class TextBlobPanel extends Panel {
@Override
public String getObject() {
Language lang = Languages.INSTANCE.findByMediaType(getBlob().getMediaType());
+ StringBuffer sb = new StringBuffer();
if (lang == null) {
if (MediaTypeUtils.isXMLType(getBlob().getMediaType())) {
- return "xml";
+ sb.append("xml lang-xml");
} else {
- return "no-highlight";
+ sb.append("no-highlight lang-text");
}
} else {
- return lang.getMode();
+ sb.append(lang.getMode()).append(" ").append("lang-" + lang.getAceMode());
}
+
+ return sb.toString();
}
};
code.add(AttributeAppender.append("class", cssModel));
-
- IModel<String> modeModel = new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- Language language = getBlob().getLanguage();
- return language == null ? "text" : language.getAceMode();
- }
-
- };
-
- code.add(new AceHighlighter(modeModel));
-
+ code.add(new AceHighlighter());
add(code);
-
}
private FileBlob getBlob() {
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/AceHighlighter.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/AceHighlighter.java
index 609c2a338b..8f79072f43 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/AceHighlighter.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/AceHighlighter.java
@@ -1,37 +1,28 @@
package com.pmease.gitop.web.page.project.source.blob.renderer.highlighter;
import org.apache.wicket.Component;
-import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
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.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import com.google.common.base.Strings;
+
public class AceHighlighter extends Behavior {
private static final long serialVersionUID = 1L;
- private final IModel<String> modeModel;
+ private IModel<Boolean> hasLineId = Model.of(Boolean.TRUE);
+ private IModel<String> selector = Model.of("");
- public AceHighlighter(IModel<String> mode) {
- this.modeModel = mode;
+ public AceHighlighter() {
}
- @SuppressWarnings("serial")
@Override
public void bind(Component component) {
super.bind(component);
- component.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- String mode = modeModel.getObject();
- return "language-" + (mode == null ? "text" : mode);
- }
-
- }));
}
@Override
@@ -41,15 +32,30 @@ public class AceHighlighter extends Behavior {
response.render(JavaScriptHeaderItem.forUrl("assets/js/vendor/ace-noconflict/ace.js"));
response.render(JavaScriptHeaderItem.forUrl("assets/js/vendor/ace-noconflict/ext-static_highlight.js"));
response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(AceHighlighter.class, "acehighlighter.js")));
- response.render(OnDomReadyHeaderItem.forScript("SourceHighlighter.highlight('#" + component.getMarkupId(true) + "');"));
+ response.render(OnDomReadyHeaderItem.forScript(String.format(
+ "SourceHighlighter.highlight('%s', %s)",
+ Strings.isNullOrEmpty(selector.getObject()) ? "#" + component.getMarkupId(true) : selector.getObject(),
+ String.valueOf(hasLineId.getObject()))));
+ }
+
+ public AceHighlighter hasLineId(boolean hasLineId) {
+ this.hasLineId.setObject(hasLineId);
+ return this;
+ }
+
+ public AceHighlighter withSelector(String selector) {
+ this.selector.setObject(selector);
+ return this;
}
@Override
public void detach(Component component) {
- super.detach(component);
-
- if (modeModel != null) {
- modeModel.detach();
+ if (hasLineId != null) {
+ hasLineId.detach();
}
+ if (selector != null) {
+ selector.detach();
+ }
+ super.detach(component);
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/acehighlighter.js b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/acehighlighter.js
index e5ada0f60c..94185ea81b 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/acehighlighter.js
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/highlighter/acehighlighter.js
@@ -1,13 +1,18 @@
var SourceHighlighter = SourceHighlighter || {};
-SourceHighlighter.highlight = function(element) {
- var el = $(element)[0];
-
- var highlighter = ace.require("ace/ext/static_highlight")
- var m = el.className.match(/language-(\w+)|(text)/);
- if (!m) return
- var mode = "ace/mode/" + (m[1] || m[2]);
- highlighter.highlight(el, {mode: mode, theme: "ace/theme/textmate"});
+SourceHighlighter.highlight = function(element, hasLineId) {
+ var highlighter = ace.require("ace/ext/static_highlight");
+ var dom = ace.require("ace/lib/dom")
+ function qsa(sel) {
+ return [].slice.call(document.querySelectorAll(sel));
+ }
+
+ qsa(element).forEach(function(el) {
+ var m = el.className.match(/lang-(\w+)|(text)/);
+ if (!m) return
+ var mode = "ace/mode/" + (m[1] || m[2]);
+ highlighter.highlight(el, {mode: mode, theme: "ace/theme/xcode", hasLineId: hasLineId});
+ });
$(function() {
//This emulates a click on the correct button on page load
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html
index 405da33a6b..14ccd022ad 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html
@@ -31,6 +31,8 @@
</div>
<div wicket:id="diffs"></div>
+
+ <div wicket:id="comments"></div>
</div>
<wicket:fragment wicket:id="refsFrag">
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java
index dc8feeb411..297c68152c 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java
@@ -17,9 +17,13 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.hibernate.criterion.Restrictions;
import com.google.common.collect.Iterables;
import com.pmease.commons.git.Commit;
+import com.pmease.gitop.core.Gitop;
+import com.pmease.gitop.core.manager.CommitCommentManager;
+import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.common.wicket.bootstrap.Icon;
import com.pmease.gitop.web.component.commit.CommitMetaPanel;
@@ -31,11 +35,13 @@ import com.pmease.gitop.web.git.command.CommitInCommand.RefType;
import com.pmease.gitop.web.page.PageSpec;
import com.pmease.gitop.web.page.project.ProjectCategoryPage;
import com.pmease.gitop.web.page.project.api.GitPerson;
+import com.pmease.gitop.web.page.project.source.commit.diff.CommentListPanel;
+import com.pmease.gitop.web.page.project.source.commit.diff.CommitCommentsAware;
import com.pmease.gitop.web.page.project.source.commit.diff.DiffViewPanel;
import com.pmease.gitop.web.page.project.source.tree.SourceTreePage;
@SuppressWarnings("serial")
-public class SourceCommitPage extends ProjectCategoryPage {
+public class SourceCommitPage extends ProjectCategoryPage implements CommitCommentsAware {
public static PageParameters newParams(Project project, String revision) {
PageParameters params = PageSpec.forProject(project);
@@ -44,6 +50,7 @@ public class SourceCommitPage extends ProjectCategoryPage {
}
private final IModel<Commit> commitModel;
+ private final IModel<List<CommitComment>> commentsModel;
public SourceCommitPage(PageParameters params) {
super(params);
@@ -57,8 +64,23 @@ public class SourceCommitPage extends ProjectCategoryPage {
return project.code().showRevision(revision);
}
};
+
+ this.commentsModel = new LoadableDetachableModel<List<CommitComment>>() {
+
+ @Override
+ protected List<CommitComment> load() {
+ return loadComments();
+ }
+
+ };
}
+ private List<CommitComment> loadComments() {
+ return Gitop.getInstance(CommitCommentManager.class)
+ .query(Restrictions.eq("project", getProject()),
+ Restrictions.eq("commit", getUntil()));
+ }
+
private String getSince() {
Commit commit = getCommit();
return Iterables.getFirst(commit.getParentHashes(), null);
@@ -142,6 +164,15 @@ public class SourceCommitPage extends ProjectCategoryPage {
add(createInRefListView("branches", RefType.BRANCH));
add(createInRefListView("tags", RefType.TAG));
add(new DiffViewPanel("diffs", projectModel, Model.of(getSince()), Model.of(getUntil())));
+
+ add(new CommentListPanel("comments", projectModel, new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getCommit().getHash();
+ }
+
+ }));
}
private Component createInRefListView(String id, final RefType type) {
@@ -206,6 +237,21 @@ public class SourceCommitPage extends ProjectCategoryPage {
return false;
}
+ @Override
+ public List<CommitComment> getCommitComments() {
+ return commentsModel.getObject();
+ }
+
+ @Override
+ public boolean isShowInlineComments() {
+ return true;
+ }
+
+ @Override
+ public boolean canAddComments() {
+ return true;
+ }
+
@Override
public void onDetach() {
if (commitModel != null) {
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.html
index 20e6f826bc..b45553384a 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.html
@@ -1,6 +1,6 @@
<html xmlns:wicket>
<wicket:panel>
- <div class="comment-list-header clearfix">
+ <div class="comment-list-header clearfix" wicket:id="commentsHeader">
<h2 class="left"><span wicket:id="count"></span> notes on commit
<small><span class="sha" wicket:id="sha"></span></small>
<small class="text-muted">(<span wicket:id="inlinecount"></span> line notes)</small>
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.java
index acf2395548..55c3f201e6 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommentListPanel.java
@@ -6,6 +6,7 @@ import javax.annotation.Nullable;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.event.IEvent;
@@ -26,6 +27,7 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
+import org.parboiled.common.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
@@ -56,9 +58,8 @@ public class CommentListPanel extends Panel {
public CommentListPanel(String id,
IModel<Project> projectModel,
- IModel<String> commitModel,
- IModel<List<CommitComment>> commentsModel) {
- super(id, commentsModel);
+ IModel<String> commitModel) {
+ super(id);
this.projectModel = projectModel;
this.commitModel = commitModel;
@@ -73,6 +74,48 @@ public class CommentListPanel extends Panel {
final WebMarkupContainer commentsHolder = new WebMarkupContainer("commentlist");
commentsHolder.setOutputMarkupId(true);
add(commentsHolder);
+
+ WebMarkupContainer commentsHeader = new WebMarkupContainer("commentsHeader");
+ commentsHeader.setOutputMarkupId(true);
+ add(commentsHeader);
+ commentsHeader.add(new Label("count", new AbstractReadOnlyModel<Integer>() {
+
+ @Override
+ public Integer getObject() {
+ return getCommentsOnCommit().size();
+ }
+
+ }));
+
+ commentsHeader.add(new Label("inlinecount", new AbstractReadOnlyModel<Integer>() {
+
+ @Override
+ public Integer getObject() {
+ return getCommentsOnLine().size();
+ }
+
+ }));
+
+ commentsHeader.add(new Label("sha", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return GitUtils.abbreviateSHA(getCommit(), 6);
+ }
+
+ }));
+
+ CheckBox check = new CheckBox("showAllTrigger", new PropertyModel<Boolean>(this, "showAllNotes"));
+ commentsHeader.add(check);
+
+ check.add(new AjaxFormComponentUpdatingBehavior("change") {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ target.add(commentsHolder);
+ }
+ });
+
IModel<List<CommitComment>> commentsModel = new LoadableDetachableModel<List<CommitComment>>() {
@Override
@@ -183,46 +226,14 @@ public class CommentListPanel extends Panel {
formHolder.add(new WebMarkupContainer("author").setVisibilityAllowed(false));
formHolder.add(new WebMarkupContainer("form").setVisibilityAllowed(false));
}
-
- add(new Label("count", new AbstractReadOnlyModel<Integer>() {
-
- @Override
- public Integer getObject() {
- return getCommentsOnCommit().size();
- }
-
- }));
-
- add(new Label("inlinecount", new AbstractReadOnlyModel<Integer>() {
-
- @Override
- public Integer getObject() {
- return getCommentsOnLine().size();
- }
-
- }));
-
- add(new Label("sha", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return GitUtils.abbreviateSHA(getCommit(), 6);
- }
-
- }));
-
- CheckBox check = new CheckBox("showAllTrigger", new PropertyModel<Boolean>(this, "showAllNotes"));
- add(check);
-
- check.add(new AjaxFormComponentUpdatingBehavior("change") {
-
- @Override
- protected void onUpdate(AjaxRequestTarget target) {
- target.add(commentsHolder);
- }
- });
}
+ private List<CommitComment> getCommitComments() {
+ Page page = getPage();
+ Preconditions.checkState(page instanceof CommitCommentsAware);
+ return ((CommitCommentsAware) page).getCommitComments();
+ }
+
private List<CommitComment> getCommentsOnCommit() {
return Lists.newArrayList(Iterables.filter(getCommitComments(), new Predicate<CommitComment>() {
@@ -245,11 +256,6 @@ public class CommentListPanel extends Panel {
}));
}
- @SuppressWarnings("unchecked")
- private List<CommitComment> getCommitComments() {
- return (List<CommitComment>) getDefaultModelObject();
- }
-
public @Nullable String getShortLineId(String line) {
if (Strings.isNullOrEmpty(line)) {
return null;
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommitCommentsAware.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommitCommentsAware.java
new file mode 100644
index 0000000000..190b84fdc5
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/CommitCommentsAware.java
@@ -0,0 +1,19 @@
+package com.pmease.gitop.web.page.project.source.commit.diff;
+
+import java.util.List;
+
+import com.pmease.gitop.model.CommitComment;
+
+/**
+ * Whether or this page is commit comments aware
+ *
+ */
+public interface CommitCommentsAware {
+
+ List<CommitComment> getCommitComments();
+
+ boolean isShowInlineComments();
+
+ boolean canAddComments();
+
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.html
index 387d06a049..9e7532024a 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.html
@@ -35,7 +35,5 @@
<wicket:container wicket:id="file"></wicket:container>
</div>
- <div wicket:id="comments"></div>
-
</wicket:panel>
</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.java
index 0557b22d0a..642fe33b83 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/DiffViewPanel.java
@@ -19,14 +19,11 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
-import org.hibernate.criterion.Restrictions;
import org.parboiled.common.Preconditions;
import com.google.common.base.Strings;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitop.core.Gitop;
-import com.pmease.gitop.core.manager.CommitCommentManager;
-import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.Constants;
import com.pmease.gitop.web.common.wicket.bootstrap.Alert;
@@ -49,10 +46,6 @@ public class DiffViewPanel extends Panel {
private final IModel<Patch> patchModel;
private final IModel<String> sinceModel;
private final IModel<String> untilModel;
- private final IModel<List<CommitComment>> commentsModel;
-
- private IModel<Boolean> showInlineComments = Model.of(true);
- private IModel<Boolean> enableAddComments = Model.of(true);
public DiffViewPanel(String id,
IModel<Project> projectModel,
@@ -73,24 +66,8 @@ public class DiffViewPanel extends Panel {
}
};
-
- this.commentsModel = new LoadableDetachableModel<List<CommitComment>>() {
-
- @Override
- protected List<CommitComment> load() {
- return loadComments();
- }
-
- };
}
- protected List<CommitComment> loadComments() {
- CommitCommentManager ccm = Gitop.getInstance(CommitCommentManager.class);
- return ccm.query(
- Restrictions.eq("project", getProject()),
- Restrictions.eq("commit", getUntil()));
- }
-
private Patch loadPatch() {
String since = getSince();
String until = getUntil();
@@ -159,12 +136,6 @@ public class DiffViewPanel extends Panel {
add(createAlert("largecommitwarning"));
createDiffToc();
add(createFileList("filelist"));
-
- add(createCommentsPanel("comments"));
- }
-
- protected Component createCommentsPanel(String id) {
- return new CommentListPanel(id, projectModel, untilModel, commentsModel);
}
protected Component createFileList(String id) {
@@ -189,7 +160,7 @@ public class DiffViewPanel extends Panel {
}
private Component newMessagePanel(String id, int index, IModel<FileHeader> model, IModel<String> messageModel) {
- return new BlobMessagePanel(id, index, model, projectModel, sinceModel, untilModel, commentsModel, messageModel);
+ return new BlobMessagePanel(id, index, model, projectModel, sinceModel, untilModel, messageModel);
}
protected Component createFileDiffPanel(String id, IModel<FileHeader> model, int index) {
@@ -223,7 +194,7 @@ public class DiffViewPanel extends Panel {
MediaType mediaType = types.getMediaType(path, new byte[0]);
if (MediaTypeUtils.isImageType(mediaType)
&& types.isSafeInline(mediaType)) {
- return new ImageDiffPanel(id, index, model, projectModel, sinceModel, untilModel, commentsModel);
+ return new ImageDiffPanel(id, index, model, projectModel, sinceModel, untilModel);
} else {
// other binary diffs
return newMessagePanel(id, index, model, Model.of("File is a binary file"));
@@ -267,7 +238,7 @@ public class DiffViewPanel extends Panel {
}
}
- return new TextDiffPanel(id, index, model, projectModel, sinceModel, untilModel, commentsModel, showInlineComments, enableAddComments);
+ return new TextDiffPanel(id, index, model, projectModel, sinceModel, untilModel);
}
@@ -355,16 +326,6 @@ public class DiffViewPanel extends Panel {
throw new IllegalArgumentException("change type " + changeType);
}
- public DiffViewPanel showInlineComments(IModel<Boolean> b) {
- showInlineComments = Preconditions.checkNotNull(b);
- return this;
- }
-
- public DiffViewPanel enableAddComments(IModel<Boolean> b) {
- enableAddComments = Preconditions.checkNotNull(b);
- return this;
- }
-
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
@@ -389,18 +350,6 @@ public class DiffViewPanel extends Panel {
untilModel.detach();
}
- if (commentsModel != null) {
- commentsModel.detach();
- }
-
- if (showInlineComments != null) {
- showInlineComments.detach();
- }
-
- if (enableAddComments != null) {
- enableAddComments.detach();
- }
-
super.onDetach();
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobDiffPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobDiffPanel.java
index b084003f3d..d976ac30eb 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobDiffPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobDiffPanel.java
@@ -16,7 +16,6 @@ import org.eclipse.jgit.diff.DiffEntry.Side;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
-import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.page.project.source.blob.SourceBlobPage;
import com.pmease.gitop.web.page.project.source.commit.diff.DiffStatBar;
@@ -28,7 +27,7 @@ public abstract class BlobDiffPanel extends Panel {
protected final IModel<Project> projectModel;
protected final IModel<String> sinceModel;
protected final IModel<String> untilModel;
- protected final IModel<List<CommitComment>> commentsModel;
+// protected final IModel<List<CommitComment>> commentsModel;
protected final int index;
@@ -42,8 +41,7 @@ public abstract class BlobDiffPanel extends Panel {
IModel<FileHeader> fileModel,
IModel<Project> projectModel,
IModel<String> sinceModel,
- IModel<String> untilModel,
- IModel<List<CommitComment>> commentsModel) {
+ IModel<String> untilModel) {
super(id, fileModel);
this.index = index;
@@ -51,7 +49,7 @@ public abstract class BlobDiffPanel extends Panel {
this.projectModel = projectModel;
this.sinceModel = sinceModel;
this.untilModel = untilModel;
- this.commentsModel = commentsModel;
+// this.commentsModel = commentsModel;
}
@SuppressWarnings("unchecked")
@@ -141,9 +139,9 @@ public abstract class BlobDiffPanel extends Panel {
untilModel.detach();
}
- if (commentsModel != null) {
- commentsModel.detach();
- }
+// if (commentsModel != null) {
+// commentsModel.detach();
+// }
super.onDetach();
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobMessagePanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobMessagePanel.java
index 9e5d0e7289..d777f0bd0d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobMessagePanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/BlobMessagePanel.java
@@ -1,12 +1,9 @@
package com.pmease.gitop.web.page.project.source.commit.diff.renderer;
-import java.util.List;
-
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
-import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.common.wicket.bootstrap.Alert;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.FileHeader;
@@ -22,9 +19,8 @@ public class BlobMessagePanel extends BlobDiffPanel {
IModel<Project> projectModel,
IModel<String> sinceModel,
IModel<String> untilModel,
- IModel<List<CommitComment>> commentsModel,
IModel<String> messageModel) {
- super(id, index, fileModel, projectModel, sinceModel, untilModel, commentsModel);
+ super(id, index, fileModel, projectModel, sinceModel, untilModel);
this.messageModel = messageModel;
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/image/ImageDiffPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/image/ImageDiffPanel.java
index 0bd13987f7..9de3d3dbb0 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/image/ImageDiffPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/image/ImageDiffPanel.java
@@ -1,12 +1,9 @@
package com.pmease.gitop.web.page.project.source.commit.diff.renderer.image;
-import java.util.List;
-
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
-import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.FileHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.renderer.BlobDiffPanel;
@@ -18,10 +15,9 @@ public class ImageDiffPanel extends BlobDiffPanel {
IModel<FileHeader> fileModel,
IModel<Project> projectModel,
IModel<String> sinceModel,
- IModel<String> untilModel,
- IModel<List<CommitComment>> commentsModel) {
+ IModel<String> untilModel) {
- super(id, index, fileModel, projectModel, sinceModel, untilModel, commentsModel);
+ super(id, index, fileModel, projectModel, sinceModel, untilModel);
}
@Override
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
index 6d851e2ac4..3580ffb863 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
@@ -4,6 +4,7 @@ import java.util.Collections;
import java.util.List;
import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
@@ -45,6 +46,7 @@ import com.pmease.gitop.web.component.comment.event.CommitCommentEvent;
import com.pmease.gitop.web.component.comment.event.CommitCommentRemoved;
import com.pmease.gitop.web.component.comment.event.OpenLineCommentForm;
import com.pmease.gitop.web.model.CommitCommentModel;
+import com.pmease.gitop.web.page.project.source.commit.diff.CommitCommentsAware;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.FileHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.HunkHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.HunkLine;
@@ -70,18 +72,12 @@ public class HunkPanel extends Panel {
final static String INSERT_AFTER_ROW = "var item = document.createElement('tr'); item.id='%s'; $(item).insertAfter($('#%s'));";
final static String INSERT_BEFORE_ROW = "var item = document.createElement('tr'); item.id='%s'; $(item).insertBefore($('#%s'));";
- private final IModel<Boolean> showInlineComments;
- private final IModel<Boolean> enableAddComments;
-
public HunkPanel(String id,
IModel<Project> projectModel,
IModel<String> commitModel,
IModel<Integer> indexModel,
IModel<FileHeader> fileModel,
- IModel<List<String>> blobLinesModel,
- final IModel<List<CommitComment>> commentsModel,
- final IModel<Boolean> showInlineComments,
- final IModel<Boolean> enableAddComments) {
+ IModel<List<String>> blobLinesModel) {
super(id, indexModel);
@@ -90,14 +86,11 @@ public class HunkPanel extends Panel {
this.fileModel = fileModel;
this.blobLinesModel = blobLinesModel;
- this.showInlineComments = showInlineComments;
- this.enableAddComments = enableAddComments;
-
this.commentsModel = new LoadableDetachableModel<Multimap<String, Long>>() {
@Override
protected Multimap<String, Long> load() {
- List<CommitComment> comments = commentsModel.getObject();
+ List<CommitComment> comments = getCommentsAware().getCommitComments();
Multimap<String, Long> map = LinkedListMultimap.<String, Long>create();
String fileId = TextDiffPanel.getFileId(getFile());
@@ -113,6 +106,12 @@ public class HunkPanel extends Panel {
};
}
+ private CommitCommentsAware getCommentsAware() {
+ Page page = getPage();
+ Preconditions.checkState(page instanceof CommitCommentsAware);
+ return (CommitCommentsAware) page;
+ }
+
@Override
protected void onInitialize() {
super.onInitialize();
@@ -316,7 +315,7 @@ public class HunkPanel extends Panel {
Multimap<String, Long> inlineComments = getInlineComments();
- boolean showComments = this.showInlineComments.getObject();
+ boolean showComments = getCommentsAware().isShowInlineComments();
for (int i = 0; i < lines.size(); i++) {
HunkLine line = lines.get(i);
@@ -425,7 +424,7 @@ public class HunkPanel extends Panel {
if (position < 0
|| !GitopSession.getCurrentUser().isPresent()
- || !enableAddComments.getObject()) {
+ || !getCommentsAware().canAddComments()) {
add(new WebMarkupContainer("commentlink").setVisibilityAllowed(false));
} else {
add(new AjaxLink<Void>("commentlink") {
@@ -530,7 +529,7 @@ public class HunkPanel extends Panel {
result.setVisible(
GitopSession.getCurrentUser().isPresent()
- && enableAddComments.getObject()
+ && getCommentsAware().canAddComments()
&& !(commentForm instanceof CommitCommentEditor)
&& !getCommentIds().isEmpty());
@@ -796,14 +795,6 @@ public class HunkPanel extends Panel {
if (commentsModel != null) {
commentsModel.detach();
}
-
- if (showInlineComments != null) {
- showInlineComments.detach();
- }
-
- if (enableAddComments != null) {
- enableAddComments.detach();
- }
super.onDetach();
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/TextDiffPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/TextDiffPanel.java
index 9efb2fb305..f085e2e74d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/TextDiffPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/TextDiffPanel.java
@@ -3,6 +3,7 @@ package com.pmease.gitop.web.page.project.source.commit.diff.renderer.text;
import java.util.List;
import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.event.IEvent;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
@@ -14,6 +15,7 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.parboiled.common.Preconditions;
import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.model.CommitComment;
@@ -21,6 +23,7 @@ import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.component.comment.event.CommitCommentAdded;
import com.pmease.gitop.web.component.comment.event.CommitCommentRemoved;
import com.pmease.gitop.web.git.GitUtils;
+import com.pmease.gitop.web.page.project.source.commit.diff.CommitCommentsAware;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.FileHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.HunkHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.renderer.BlobDiffPanel;
@@ -30,8 +33,8 @@ import com.pmease.gitop.web.service.FileBlobService;
@SuppressWarnings("serial")
public class TextDiffPanel extends BlobDiffPanel {
- private IModel<Boolean> showInlineComments = Model.of(true);
- private IModel<Boolean> enableAddComments = Model.of(true);
+// private IModel<Boolean> showInlineComments = Model.of(true);
+// private IModel<Boolean> enableAddComments = Model.of(true);
private final IModel<FileBlob> newFileModel;
private final IModel<FileBlob> oldFileModel;
@@ -41,17 +44,10 @@ public class TextDiffPanel extends BlobDiffPanel {
IModel<FileHeader> fileModel,
IModel<Project> projectModel,
IModel<String> sinceModel,
- IModel<String> untilModel,
- IModel<List<CommitComment>> commentsModel,
- IModel<Boolean> showInlineComments,
- IModel<Boolean> enableAddComments) {
+ IModel<String> untilModel) {
- super(id, index, fileModel, projectModel, sinceModel, untilModel, commentsModel);
+ super(id, index, fileModel, projectModel, sinceModel, untilModel);
- this.showInlineComments = showInlineComments;
- this.enableAddComments = enableAddComments;
-
-
this.newFileModel = new LoadableDetachableModel<FileBlob>() {
@Override
@@ -87,8 +83,14 @@ public class TextDiffPanel extends BlobDiffPanel {
}
}
+ private CommitCommentsAware getCommentsAware() {
+ Page page = getPage();
+ Preconditions.checkState(page instanceof CommitCommentsAware);
+ return (CommitCommentsAware) page;
+ }
+
private boolean hasInlineComments() {
- List<CommitComment> comments = commentsModel.getObject();
+ List<CommitComment> comments = getCommentsAware().getCommitComments();
String fileId = getFileId(getFile());
for (CommitComment each : comments) {
if (each.isLineComment() && each.getLine().startsWith(fileId)) {
@@ -180,10 +182,7 @@ public class TextDiffPanel extends BlobDiffPanel {
return newFileModel.getObject().getLines();
}
}
- },
- commentsModel,
- showInlineComments,
- enableAddComments));
+ }));
}
});
@@ -198,14 +197,6 @@ public class TextDiffPanel extends BlobDiffPanel {
@Override
public void onDetach() {
- if (showInlineComments != null) {
- showInlineComments.detach();
- }
-
- if (enableAddComments != null) {
- enableAddComments.detach();
- }
-
if (newFileModel != null) {
newFileModel.detach();
}