summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket/panels
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/wicket/panels')
-rw-r--r--src/main/java/com/gitblit/wicket/panels/CommentPanel.html29
-rw-r--r--src/main/java/com/gitblit/wicket/panels/CommentPanel.java110
-rw-r--r--src/main/java/com/gitblit/wicket/panels/DigestsPanel.java539
-rw-r--r--src/main/java/com/gitblit/wicket/panels/GravatarImage.java142
-rw-r--r--src/main/java/com/gitblit/wicket/panels/MarkdownTextArea.java118
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ReflogPanel.html4
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ReflogPanel.java638
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RefsPanel.java27
8 files changed, 956 insertions, 651 deletions
diff --git a/src/main/java/com/gitblit/wicket/panels/CommentPanel.html b/src/main/java/com/gitblit/wicket/panels/CommentPanel.html
new file mode 100644
index 00000000..1fdfb168
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/CommentPanel.html
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
+<wicket:panel>
+ <div style="border: 1px solid #ccc;">
+
+ <ul class="nav nav-pills" style="margin: 2px 5px !important">
+ <li class="active"><a href="#write" data-toggle="tab"><wicket:message key="gb.write">[write]</wicket:message></a></li>
+ <li><a href="#preview" data-toggle="tab"><wicket:message key="gb.preview">[preview]</wicket:message></a></li>
+ </ul>
+ <div class="tab-content">
+ <div class="tab-pane active" id="write">
+ <textarea class="span7" style="height:7em;border-color:#ccc;border-right:0px;border-left:0px;border-radius:0px;box-shadow: none;" wicket:id="markdownEditor"></textarea>
+ </div>
+ <div class="tab-pane" id="preview">
+ <div class="preview" style="height:7em;border:1px solid #ccc;border-right:0px;border-left:0px;margin-bottom:9px;padding:4px;background-color:#ffffff;">
+ <div class="markdown" wicket:id="markdownPreview"></div>
+ </div>
+ </div>
+ </div>
+
+ <div style="text-align:right;padding-right:5px;">
+ <form style="margin-bottom:9px;" wicket:id="editorForm" action="">
+ <input class="btn btn-appmenu" type="submit" wicket:id="submit" value="comment"></input>
+ </form>
+ </div>
+
+ </div>
+</wicket:panel>
+</html> \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/CommentPanel.java b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java
new file mode 100644
index 00000000..1d49ff0f
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.TicketModel;
+import com.gitblit.models.TicketModel.Change;
+import com.gitblit.models.UserModel;
+import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.pages.BasePage;
+
+public class CommentPanel extends BasePanel {
+ private static final long serialVersionUID = 1L;
+
+ final UserModel user;
+
+ final TicketModel ticket;
+
+ final Change change;
+
+ final Class<? extends BasePage> pageClass;
+
+ private MarkdownTextArea markdownEditor;
+
+ private Label markdownPreview;
+
+ private String repositoryName;
+
+ public CommentPanel(String id, final UserModel user, final TicketModel ticket,
+ final Change change, final Class<? extends BasePage> pageClass) {
+ super(id);
+ this.user = user;
+ this.ticket = ticket;
+ this.change = change;
+ this.pageClass = pageClass;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ Form<String> form = new Form<String>("editorForm");
+ add(form);
+
+ form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ String txt = markdownEditor.getText();
+ if (change == null) {
+ // new comment
+ Change newComment = new Change(user.username);
+ newComment.comment(txt);
+ if (!ticket.isWatching(user.username)) {
+ newComment.watch(user.username);
+ }
+ RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
+ TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
+ if (updatedTicket != null) {
+ app().tickets().createNotifier().sendMailing(updatedTicket);
+ setResponsePage(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
+ } else {
+ error("Failed to add comment!");
+ }
+ } else {
+ // TODO update comment
+ }
+ }
+ }.setVisible(ticket != null && ticket.number > 0));
+
+ final IModel<String> markdownPreviewModel = new Model<String>();
+ markdownPreview = new Label("markdownPreview", markdownPreviewModel);
+ markdownPreview.setEscapeModelStrings(false);
+ markdownPreview.setOutputMarkupId(true);
+ add(markdownPreview);
+
+ markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
+ markdownEditor.setRepository(repositoryName);
+ WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
+ add(markdownEditor);
+ }
+
+ public void setRepository(String repositoryName) {
+ this.repositoryName = repositoryName;
+ if (markdownEditor != null) {
+ markdownEditor.setRepository(repositoryName);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
index de09aa95..decfda50 100644
--- a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
@@ -1,263 +1,276 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.data.DataView;
-import org.apache.wicket.markup.repeater.data.ListDataProvider;
-import org.eclipse.jgit.lib.PersonIdent;
-
-import com.gitblit.Constants;
-import com.gitblit.Keys;
-import com.gitblit.models.DailyLogEntry;
-import com.gitblit.models.RepositoryCommit;
-import com.gitblit.utils.StringUtils;
-import com.gitblit.utils.TimeUtils;
-import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.pages.CommitPage;
-import com.gitblit.wicket.pages.ComparePage;
-import com.gitblit.wicket.pages.SummaryPage;
-import com.gitblit.wicket.pages.TagPage;
-import com.gitblit.wicket.pages.TreePage;
-
-public class DigestsPanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- private final boolean hasChanges;
-
- private boolean hasMore;
-
- public DigestsPanel(String wicketId, List<DailyLogEntry> digests) {
- super(wicketId);
- hasChanges = digests.size() > 0;
-
- ListDataProvider<DailyLogEntry> dp = new ListDataProvider<DailyLogEntry>(digests);
- DataView<DailyLogEntry> pushView = new DataView<DailyLogEntry>("change", dp) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void populateItem(final Item<DailyLogEntry> logItem) {
- final DailyLogEntry change = logItem.getModelObject();
-
- String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
- TimeZone timezone = getTimeZone();
- DateFormat df = new SimpleDateFormat(dateFormat);
- df.setTimeZone(timezone);
-
- String fullRefName = change.getChangedRefs().get(0);
- String shortRefName = fullRefName;
- boolean isTag = false;
- if (shortRefName.startsWith(Constants.R_HEADS)) {
- shortRefName = shortRefName.substring(Constants.R_HEADS.length());
- } else if (shortRefName.startsWith(Constants.R_TAGS)) {
- shortRefName = shortRefName.substring(Constants.R_TAGS.length());
- isTag = true;
- }
-
- String fuzzydate;
- TimeUtils tu = getTimeUtils();
- Date pushDate = change.date;
- if (TimeUtils.isToday(pushDate, timezone)) {
- fuzzydate = tu.today();
- } else if (TimeUtils.isYesterday(pushDate, timezone)) {
- fuzzydate = tu.yesterday();
- } else {
- fuzzydate = getTimeUtils().timeAgo(pushDate);
- }
- logItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(pushDate)));
-
- Label changeIcon = new Label("changeIcon");
- // use the repository hash color to differentiate the icon.
- String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
- WicketUtils.setCssStyle(changeIcon, "color: " + color);
-
- if (isTag) {
- WicketUtils.setCssClass(changeIcon, "iconic-tag");
- } else {
- WicketUtils.setCssClass(changeIcon, "iconic-loop");
- }
- logItem.add(changeIcon);
-
- if (isTag) {
- // tags are special
- PersonIdent ident = change.getCommits().get(0).getAuthorIdent();
- if (!StringUtils.isEmpty(ident.getName())) {
- logItem.add(new Label("whoChanged", ident.getName()));
- } else {
- logItem.add(new Label("whoChanged", ident.getEmailAddress()));
- }
- } else {
- logItem.add(new Label("whoChanged").setVisible(false));
- }
-
- String preposition = "gb.of";
- boolean isDelete = false;
- String what;
- String by = null;
- switch(change.getChangeType(fullRefName)) {
- case CREATE:
- if (isTag) {
- // new tag
- what = getString("gb.createdNewTag");
- preposition = "gb.in";
- } else {
- // new branch
- what = getString("gb.createdNewBranch");
- preposition = "gb.in";
- }
- break;
- case DELETE:
- isDelete = true;
- if (isTag) {
- what = getString("gb.deletedTag");
- } else {
- what = getString("gb.deletedBranch");
- }
- preposition = "gb.from";
- break;
- default:
- what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.commitsTo") : getString("gb.oneCommitTo"), change.getCommitCount());
-
- if (change.getAuthorCount() == 1) {
- by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
- } else {
- by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
- }
- break;
- }
- logItem.add(new Label("whatChanged", what));
- logItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
-
- if (isDelete) {
- // can't link to deleted ref
- logItem.add(new Label("refChanged", shortRefName));
- } else if (isTag) {
- // link to tag
- logItem.add(new LinkPanel("refChanged", null, shortRefName,
- TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
- } else {
- // link to tree
- logItem.add(new LinkPanel("refChanged", null, shortRefName,
- TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
- }
-
- // to/from/etc
- logItem.add(new Label("repoPreposition", getString(preposition)));
- String repoName = StringUtils.stripDotGit(change.repository);
- logItem.add(new LinkPanel("repoChanged", null, repoName,
- SummaryPage.class, WicketUtils.newRepositoryParameter(change.repository)));
-
- int maxCommitCount = 5;
- List<RepositoryCommit> commits = change.getCommits();
- if (commits.size() > maxCommitCount) {
- commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
- }
-
- // compare link
- String compareLinkText = null;
- if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
- compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
- } else if (change.getCommitCount() > maxCommitCount) {
- int diff = change.getCommitCount() - maxCommitCount;
- compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
- }
- if (StringUtils.isEmpty(compareLinkText)) {
- logItem.add(new Label("compareLink").setVisible(false));
- } else {
- String endRangeId = change.getNewId(fullRefName);
- String startRangeId = change.getOldId(fullRefName);
- logItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
- }
-
- final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true);
-
- ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
- DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void populateItem(final Item<RepositoryCommit> commitItem) {
- final RepositoryCommit commit = commitItem.getModelObject();
-
- // author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
-
- // merge icon
- if (commit.getParentCount() > 1) {
- commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
- } else {
- commitItem.add(WicketUtils.newBlankImage("commitIcon"));
- }
-
- // short message
- String shortMessage = commit.getShortMessage();
- String trimmedMessage = shortMessage;
- if (commit.getRefs() != null && commit.getRefs().size() > 0) {
- trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
- } else {
- trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
- }
- LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
- trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
- change.repository, commit.getName()));
- if (!shortMessage.equals(trimmedMessage)) {
- WicketUtils.setHtmlTooltip(shortlog, shortMessage);
- }
- commitItem.add(shortlog);
-
- // commit hash link
- int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
- LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
- CommitPage.class, WicketUtils.newObjectParameter(
- change.repository, commit.getName()));
- WicketUtils.setCssClass(commitHash, "shortsha1");
- WicketUtils.setHtmlTooltip(commitHash, commit.getName());
- commitItem.add(commitHash);
-
- if (showSwatch) {
- // set repository color
- String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
- WicketUtils.setCssStyle(commitItem, MessageFormat.format("border-left: 2px solid {0};", color));
- }
- }
- };
-
- logItem.add(commitsView);
- }
- };
-
- add(pushView);
- }
-
- public boolean hasMore() {
- return hasMore;
- }
-
- public boolean hideIfEmpty() {
- setVisible(hasChanges);
- return hasChanges;
- }
-}
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.DataView;
+import org.apache.wicket.markup.repeater.data.ListDataProvider;
+import org.eclipse.jgit.lib.PersonIdent;
+
+import com.gitblit.Constants;
+import com.gitblit.Keys;
+import com.gitblit.models.DailyLogEntry;
+import com.gitblit.models.RepositoryCommit;
+import com.gitblit.utils.StringUtils;
+import com.gitblit.utils.TimeUtils;
+import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.pages.CommitPage;
+import com.gitblit.wicket.pages.ComparePage;
+import com.gitblit.wicket.pages.SummaryPage;
+import com.gitblit.wicket.pages.TagPage;
+import com.gitblit.wicket.pages.TicketsPage;
+import com.gitblit.wicket.pages.TreePage;
+
+public class DigestsPanel extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean hasChanges;
+
+ private boolean hasMore;
+
+ public DigestsPanel(String wicketId, List<DailyLogEntry> digests) {
+ super(wicketId);
+ hasChanges = digests.size() > 0;
+
+ ListDataProvider<DailyLogEntry> dp = new ListDataProvider<DailyLogEntry>(digests);
+ DataView<DailyLogEntry> pushView = new DataView<DailyLogEntry>("change", dp) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void populateItem(final Item<DailyLogEntry> logItem) {
+ final DailyLogEntry change = logItem.getModelObject();
+
+ String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
+ TimeZone timezone = getTimeZone();
+ DateFormat df = new SimpleDateFormat(dateFormat);
+ df.setTimeZone(timezone);
+
+ String fullRefName = change.getChangedRefs().get(0);
+ String shortRefName = fullRefName;
+ String ticketId = "";
+ boolean isTag = false;
+ boolean isTicket = false;
+ if (shortRefName.startsWith(Constants.R_TICKET)) {
+ ticketId = shortRefName = shortRefName.substring(Constants.R_TICKET.length());
+ shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
+ isTicket = true;
+ } else if (shortRefName.startsWith(Constants.R_HEADS)) {
+ shortRefName = shortRefName.substring(Constants.R_HEADS.length());
+ } else if (shortRefName.startsWith(Constants.R_TAGS)) {
+ shortRefName = shortRefName.substring(Constants.R_TAGS.length());
+ isTag = true;
+ }
+
+ String fuzzydate;
+ TimeUtils tu = getTimeUtils();
+ Date pushDate = change.date;
+ if (TimeUtils.isToday(pushDate, timezone)) {
+ fuzzydate = tu.today();
+ } else if (TimeUtils.isYesterday(pushDate, timezone)) {
+ fuzzydate = tu.yesterday();
+ } else {
+ fuzzydate = getTimeUtils().timeAgo(pushDate);
+ }
+ logItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(pushDate)));
+
+ Label changeIcon = new Label("changeIcon");
+ // use the repository hash color to differentiate the icon.
+ String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
+ WicketUtils.setCssStyle(changeIcon, "color: " + color);
+
+ if (isTag) {
+ WicketUtils.setCssClass(changeIcon, "iconic-tag");
+ } else if (isTicket) {
+ WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
+ } else {
+ WicketUtils.setCssClass(changeIcon, "iconic-loop");
+ }
+ logItem.add(changeIcon);
+
+ if (isTag) {
+ // tags are special
+ PersonIdent ident = change.getCommits().get(0).getAuthorIdent();
+ if (!StringUtils.isEmpty(ident.getName())) {
+ logItem.add(new Label("whoChanged", ident.getName()));
+ } else {
+ logItem.add(new Label("whoChanged", ident.getEmailAddress()));
+ }
+ } else {
+ logItem.add(new Label("whoChanged").setVisible(false));
+ }
+
+ String preposition = "gb.of";
+ boolean isDelete = false;
+ String what;
+ String by = null;
+ switch(change.getChangeType(fullRefName)) {
+ case CREATE:
+ if (isTag) {
+ // new tag
+ what = getString("gb.createdNewTag");
+ preposition = "gb.in";
+ } else {
+ // new branch
+ what = getString("gb.createdNewBranch");
+ preposition = "gb.in";
+ }
+ break;
+ case DELETE:
+ isDelete = true;
+ if (isTag) {
+ what = getString("gb.deletedTag");
+ } else {
+ what = getString("gb.deletedBranch");
+ }
+ preposition = "gb.from";
+ break;
+ default:
+ what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.commitsTo") : getString("gb.oneCommitTo"), change.getCommitCount());
+
+ if (change.getAuthorCount() == 1) {
+ by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
+ } else {
+ by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
+ }
+ break;
+ }
+ logItem.add(new Label("whatChanged", what));
+ logItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
+
+ if (isDelete) {
+ // can't link to deleted ref
+ logItem.add(new Label("refChanged", shortRefName));
+ } else if (isTag) {
+ // link to tag
+ logItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
+ } else if (isTicket) {
+ // link to ticket
+ logItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
+ } else {
+ // link to tree
+ logItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
+ }
+
+ // to/from/etc
+ logItem.add(new Label("repoPreposition", getString(preposition)));
+ String repoName = StringUtils.stripDotGit(change.repository);
+ logItem.add(new LinkPanel("repoChanged", null, repoName,
+ SummaryPage.class, WicketUtils.newRepositoryParameter(change.repository)));
+
+ int maxCommitCount = 5;
+ List<RepositoryCommit> commits = change.getCommits();
+ if (commits.size() > maxCommitCount) {
+ commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
+ }
+
+ // compare link
+ String compareLinkText = null;
+ if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
+ compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
+ } else if (change.getCommitCount() > maxCommitCount) {
+ int diff = change.getCommitCount() - maxCommitCount;
+ compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
+ }
+ if (StringUtils.isEmpty(compareLinkText)) {
+ logItem.add(new Label("compareLink").setVisible(false));
+ } else {
+ String endRangeId = change.getNewId(fullRefName);
+ String startRangeId = change.getOldId(fullRefName);
+ logItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
+ }
+
+ final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true);
+
+ ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
+ DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void populateItem(final Item<RepositoryCommit> commitItem) {
+ final RepositoryCommit commit = commitItem.getModelObject();
+
+ // author gravatar
+ commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+
+ // merge icon
+ if (commit.getParentCount() > 1) {
+ commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
+ } else {
+ commitItem.add(WicketUtils.newBlankImage("commitIcon"));
+ }
+
+ // short message
+ String shortMessage = commit.getShortMessage();
+ String trimmedMessage = shortMessage;
+ if (commit.getRefs() != null && commit.getRefs().size() > 0) {
+ trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
+ } else {
+ trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
+ }
+ LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
+ trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
+ change.repository, commit.getName()));
+ if (!shortMessage.equals(trimmedMessage)) {
+ WicketUtils.setHtmlTooltip(shortlog, shortMessage);
+ }
+ commitItem.add(shortlog);
+
+ // commit hash link
+ int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
+ LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
+ CommitPage.class, WicketUtils.newObjectParameter(
+ change.repository, commit.getName()));
+ WicketUtils.setCssClass(commitHash, "shortsha1");
+ WicketUtils.setHtmlTooltip(commitHash, commit.getName());
+ commitItem.add(commitHash);
+
+ if (showSwatch) {
+ // set repository color
+ String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
+ WicketUtils.setCssStyle(commitItem, MessageFormat.format("border-left: 2px solid {0};", color));
+ }
+ }
+ };
+
+ logItem.add(commitsView);
+ }
+ };
+
+ add(pushView);
+ }
+
+ public boolean hasMore() {
+ return hasMore;
+ }
+
+ public boolean hideIfEmpty() {
+ setVisible(hasChanges);
+ return hasChanges;
+ }
+}
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java b/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
index 9507a25e..e4157577 100644
--- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
+++ b/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
@@ -1,70 +1,74 @@
-/*
- * Copyright 2011 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import org.eclipse.jgit.lib.PersonIdent;
-
-import com.gitblit.Keys;
-import com.gitblit.models.UserModel;
-import com.gitblit.utils.ActivityUtils;
-import com.gitblit.wicket.ExternalImage;
-import com.gitblit.wicket.WicketUtils;
-
-/**
- * Represents a Gravatar image.
- *
- * @author James Moger
- *
- */
-public class GravatarImage extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- public GravatarImage(String id, PersonIdent person) {
- this(id, person, 0);
- }
-
- public GravatarImage(String id, PersonIdent person, int width) {
- this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
- }
-
- public GravatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
- this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
- }
-
- public GravatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
- this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
- }
-
- public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
- super(id);
-
- String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
- String url;
- if (identicon) {
- url = ActivityUtils.getGravatarIdenticonUrl(email, width);
- } else {
- url = ActivityUtils.getGravatarThumbnailUrl(email, width);
- }
- ExternalImage image = new ExternalImage("image", url);
- if (cssClass != null) {
- WicketUtils.setCssClass(image, cssClass);
- }
- add(image);
- WicketUtils.setHtmlTooltip(image, username);
- setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
- }
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import org.eclipse.jgit.lib.PersonIdent;
+
+import com.gitblit.Keys;
+import com.gitblit.models.UserModel;
+import com.gitblit.utils.ActivityUtils;
+import com.gitblit.wicket.ExternalImage;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Represents a Gravatar image.
+ *
+ * @author James Moger
+ *
+ */
+public class GravatarImage extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ public GravatarImage(String id, PersonIdent person) {
+ this(id, person, 0);
+ }
+
+ public GravatarImage(String id, PersonIdent person, int width) {
+ this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
+ }
+
+ public GravatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
+ this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
+ }
+
+ public GravatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
+ this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
+ }
+
+ public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
+ super(id);
+
+ String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
+ String url;
+ if (identicon) {
+ url = ActivityUtils.getGravatarIdenticonUrl(email, width);
+ } else {
+ url = ActivityUtils.getGravatarThumbnailUrl(email, width);
+ }
+ ExternalImage image = new ExternalImage("image", url);
+ if (cssClass != null) {
+ WicketUtils.setCssClass(image, cssClass);
+ }
+ add(image);
+ WicketUtils.setHtmlTooltip(image, username);
+ setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
+ }
+
+ public void setTooltip(String tooltip) {
+ WicketUtils.setHtmlTooltip(get("image"), tooltip);
+ }
} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/MarkdownTextArea.java b/src/main/java/com/gitblit/wicket/panels/MarkdownTextArea.java
new file mode 100644
index 00000000..fbce7892
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/MarkdownTextArea.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.TextArea;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.util.time.Duration;
+
+import com.gitblit.utils.MarkdownUtils;
+import com.gitblit.wicket.GitBlitWebApp;
+
+public class MarkdownTextArea extends TextArea {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String repositoryName;
+
+ protected String text = "";
+
+ public MarkdownTextArea(String id, final IModel<String> previewModel, final Label previewLabel) {
+ super(id);
+ this.repositoryName = repositoryName;
+ setModel(new PropertyModel(this, "text"));
+ add(new AjaxFormComponentUpdatingBehavior("onblur") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ renderPreview(previewModel);
+ if (target != null) {
+ target.addComponent(previewLabel);
+ }
+ }
+ });
+ add(new AjaxFormComponentUpdatingBehavior("onchange") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ renderPreview(previewModel);
+ if (target != null) {
+ target.addComponent(previewLabel);
+ }
+ }
+ });
+
+ add(new KeepAliveBehavior());
+ setOutputMarkupId(true);
+ }
+
+ protected void renderPreview(IModel<String> previewModel) {
+ if (text == null) {
+ return;
+ }
+ String html = MarkdownUtils.transformGFM(GitBlitWebApp.get().settings(), text, repositoryName);
+ previewModel.setObject(html);
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setRepository(String repositoryName) {
+ this.repositoryName = repositoryName;
+ }
+
+// @Override
+// protected void onBeforeRender() {
+// super.onBeforeRender();
+// add(new RichTextSetActiveTextFieldAttributeModifier(this.getMarkupId()));
+// }
+//
+// private class RichTextSetActiveTextFieldAttributeModifier extends AttributeModifier {
+//
+// private static final long serialVersionUID = 1L;
+//
+// public RichTextSetActiveTextFieldAttributeModifier(String markupId) {
+// super("onClick", true, new Model("richTextSetActiveTextField('" + markupId + "');"));
+// }
+// }
+
+ private class KeepAliveBehavior extends AbstractAjaxTimerBehavior {
+
+ private static final long serialVersionUID = 1L;
+
+ public KeepAliveBehavior() {
+ super(Duration.minutes(5));
+ }
+
+ @Override
+ protected void onTimer(AjaxRequestTarget target) {
+ // prevent wicket changing focus
+ target.focusComponent(null);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.html b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.html
index 8df28494..3a0b0b8c 100644
--- a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.html
+++ b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.html
@@ -12,7 +12,7 @@
<td class="icon hidden-phone"><i wicket:id="changeIcon"></i></td>
<td style="padding-left: 7px;vertical-align:middle;">
<div>
- <span class="when" wicket:id="whenChanged"></span> <span wicket:id="refRewind" class="alert alert-error" style="padding: 1px 5px;font-size: 10px;font-weight: bold;margin-left: 10px;">[rewind]</span>
+ <span class="when" wicket:id="whenChanged"></span> <span wicket:id="refRewind" class="aui-lozenge aui-lozenge-error">[rewind]</span>
</div>
<div style="font-weight:bold;"><span wicket:id="whoChanged">[change author]</span> <span wicket:id="whatChanged"></span> <span wicket:id="refChanged"></span> <span wicket:id="byAuthors"></span></div>
</td>
@@ -26,7 +26,7 @@
<td class="hidden-phone hidden-tablet" style="vertical-align:top;padding-left:7px;"><span wicket:id="commitAuthor"></span></td>
<td style="vertical-align:top;"><span wicket:id="hashLink" style="padding-left: 5px;">[hash link]</span></td>
<td style="vertical-align:top;padding-left:5px;"><img wicket:id="commitIcon" /></td>
- <td style="vertical-align:top;">
+ <td style="vertical-align:top;">
<span wicket:id="commitShortMessage">[commit short message]</span>
</td>
</tr>
diff --git a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
index c1db726a..baefc6bd 100644
--- a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
@@ -1,313 +1,325 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.data.DataView;
-import org.apache.wicket.markup.repeater.data.ListDataProvider;
-import org.apache.wicket.model.StringResourceModel;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.transport.ReceiveCommand.Type;
-
-import com.gitblit.Constants;
-import com.gitblit.Keys;
-import com.gitblit.models.RefLogEntry;
-import com.gitblit.models.RepositoryCommit;
-import com.gitblit.models.RepositoryModel;
-import com.gitblit.models.UserModel;
-import com.gitblit.utils.RefLogUtils;
-import com.gitblit.utils.StringUtils;
-import com.gitblit.utils.TimeUtils;
-import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.pages.CommitPage;
-import com.gitblit.wicket.pages.ComparePage;
-import com.gitblit.wicket.pages.ReflogPage;
-import com.gitblit.wicket.pages.TagPage;
-import com.gitblit.wicket.pages.TreePage;
-import com.gitblit.wicket.pages.UserPage;
-
-public class ReflogPanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- private final boolean hasChanges;
-
- private boolean hasMore;
-
- public ReflogPanel(String wicketId, final RepositoryModel model, Repository r, int limit, int pageOffset) {
- super(wicketId);
- boolean pageResults = limit <= 0;
- int changesPerPage = app().settings().getInteger(Keys.web.reflogChangesPerPage, 10);
- if (changesPerPage <= 1) {
- changesPerPage = 10;
- }
-
- List<RefLogEntry> changes;
- if (pageResults) {
- changes = RefLogUtils.getLogByRef(model.name, r, pageOffset * changesPerPage, changesPerPage);
- } else {
- changes = RefLogUtils.getLogByRef(model.name, r, limit);
- }
-
- // inaccurate way to determine if there are more commits.
- // works unless commits.size() represents the exact end.
- hasMore = changes.size() >= changesPerPage;
- hasChanges = changes.size() > 0;
-
- setup(changes);
-
- // determine to show pager, more, or neither
- if (limit <= 0) {
- // no display limit
- add(new Label("moreChanges").setVisible(false));
- } else {
- if (pageResults) {
- // paging
- add(new Label("moreChanges").setVisible(false));
- } else {
- // more
- if (changes.size() == limit) {
- // show more
- add(new LinkPanel("moreChanges", "link", new StringResourceModel("gb.moreChanges",
- this, null), ReflogPage.class,
- WicketUtils.newRepositoryParameter(model.name)));
- } else {
- // no more
- add(new Label("moreChanges").setVisible(false));
- }
- }
- }
- }
-
- public ReflogPanel(String wicketId, List<RefLogEntry> changes) {
- super(wicketId);
- hasChanges = changes.size() > 0;
- setup(changes);
- add(new Label("moreChanges").setVisible(false));
- }
-
- protected void setup(List<RefLogEntry> changes) {
-
- ListDataProvider<RefLogEntry> dp = new ListDataProvider<RefLogEntry>(changes);
- DataView<RefLogEntry> changeView = new DataView<RefLogEntry>("change", dp) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void populateItem(final Item<RefLogEntry> changeItem) {
- final RefLogEntry change = changeItem.getModelObject();
-
- String dateFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z");
- TimeZone timezone = getTimeZone();
- DateFormat df = new SimpleDateFormat(dateFormat);
- df.setTimeZone(timezone);
- Calendar cal = Calendar.getInstance(timezone);
-
- String fullRefName = change.getChangedRefs().get(0);
- String shortRefName = fullRefName;
- boolean isTag = false;
- if (shortRefName.startsWith(Constants.R_HEADS)) {
- shortRefName = shortRefName.substring(Constants.R_HEADS.length());
- } else if (shortRefName.startsWith(Constants.R_TAGS)) {
- shortRefName = shortRefName.substring(Constants.R_TAGS.length());
- isTag = true;
- }
-
- String fuzzydate;
- TimeUtils tu = getTimeUtils();
- Date changeDate = change.date;
- if (TimeUtils.isToday(changeDate, timezone)) {
- fuzzydate = tu.today();
- } else if (TimeUtils.isYesterday(changeDate, timezone)) {
- fuzzydate = tu.yesterday();
- } else {
- // calculate a fuzzy time ago date
- cal.setTime(changeDate);
- cal.set(Calendar.HOUR_OF_DAY, 0);
- cal.set(Calendar.MINUTE, 0);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- Date date = cal.getTime();
- fuzzydate = getTimeUtils().timeAgo(date);
- }
- changeItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(changeDate)));
-
- Label changeIcon = new Label("changeIcon");
- if (Type.DELETE.equals(change.getChangeType(fullRefName))) {
- WicketUtils.setCssClass(changeIcon, "iconic-trash-stroke");
- } else if (isTag) {
- WicketUtils.setCssClass(changeIcon, "iconic-tag");
- } else {
- WicketUtils.setCssClass(changeIcon, "iconic-upload");
- }
- changeItem.add(changeIcon);
-
- if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
- // username is an email address - 1.2.1 push log bug
- changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
- } else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
- // anonymous change
- changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
- } else {
- // link to user account page
- changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(),
- UserPage.class, WicketUtils.newUsernameParameter(change.user.username)));
- }
-
- boolean isDelete = false;
- boolean isRewind = false;
- String what;
- String by = null;
- switch(change.getChangeType(fullRefName)) {
- case CREATE:
- if (isTag) {
- // new tag
- what = getString("gb.pushedNewTag");
- } else {
- // new branch
- what = getString("gb.pushedNewBranch");
- }
- break;
- case DELETE:
- isDelete = true;
- if (isTag) {
- what = getString("gb.deletedTag");
- } else {
- what = getString("gb.deletedBranch");
- }
- break;
- case UPDATE_NONFASTFORWARD:
- isRewind = true;
- default:
- what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo") , change.getCommitCount());
-
- if (change.getAuthorCount() == 1) {
- by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
- } else {
- by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
- }
- break;
- }
- changeItem.add(new Label("whatChanged", what));
- changeItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
-
- changeItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
-
- if (isDelete) {
- // can't link to deleted ref
- changeItem.add(new Label("refChanged", shortRefName));
- } else if (isTag) {
- // link to tag
- changeItem.add(new LinkPanel("refChanged", null, shortRefName,
- TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
- } else {
- // link to tree
- changeItem.add(new LinkPanel("refChanged", null, shortRefName,
- TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
- }
-
- int maxCommitCount = 5;
- List<RepositoryCommit> commits = change.getCommits();
- if (commits.size() > maxCommitCount) {
- commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
- }
-
- // compare link
- String compareLinkText = null;
- if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
- compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
- } else if (change.getCommitCount() > maxCommitCount) {
- int diff = change.getCommitCount() - maxCommitCount;
- compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
- }
- if (StringUtils.isEmpty(compareLinkText)) {
- changeItem.add(new Label("compareLink").setVisible(false));
- } else {
- String endRangeId = change.getNewId(fullRefName);
- String startRangeId = change.getOldId(fullRefName);
- changeItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
- }
-
- ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
- DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void populateItem(final Item<RepositoryCommit> commitItem) {
- final RepositoryCommit commit = commitItem.getModelObject();
-
- // author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
-
- // merge icon
- if (commit.getParentCount() > 1) {
- commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
- } else {
- commitItem.add(WicketUtils.newBlankImage("commitIcon"));
- }
-
- // short message
- String shortMessage = commit.getShortMessage();
- String trimmedMessage = shortMessage;
- if (commit.getRefs() != null && commit.getRefs().size() > 0) {
- trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
- } else {
- trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
- }
- LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
- trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
- change.repository, commit.getName()));
- if (!shortMessage.equals(trimmedMessage)) {
- WicketUtils.setHtmlTooltip(shortlog, shortMessage);
- }
- commitItem.add(shortlog);
-
- // commit hash link
- int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
- LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
- CommitPage.class, WicketUtils.newObjectParameter(
- change.repository, commit.getName()));
- WicketUtils.setCssClass(commitHash, "shortsha1");
- WicketUtils.setHtmlTooltip(commitHash, commit.getName());
- commitItem.add(commitHash);
- }
- };
-
- changeItem.add(commitsView);
- }
- };
-
- add(changeView);
- }
-
- public boolean hasMore() {
- return hasMore;
- }
-
- public boolean hideIfEmpty() {
- setVisible(hasChanges);
- return hasChanges;
- }
-}
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.DataView;
+import org.apache.wicket.markup.repeater.data.ListDataProvider;
+import org.apache.wicket.model.StringResourceModel;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.ReceiveCommand.Type;
+
+import com.gitblit.Constants;
+import com.gitblit.Keys;
+import com.gitblit.models.RefLogEntry;
+import com.gitblit.models.RepositoryCommit;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+import com.gitblit.utils.RefLogUtils;
+import com.gitblit.utils.StringUtils;
+import com.gitblit.utils.TimeUtils;
+import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.pages.CommitPage;
+import com.gitblit.wicket.pages.ComparePage;
+import com.gitblit.wicket.pages.ReflogPage;
+import com.gitblit.wicket.pages.TagPage;
+import com.gitblit.wicket.pages.TicketsPage;
+import com.gitblit.wicket.pages.TreePage;
+import com.gitblit.wicket.pages.UserPage;
+
+public class ReflogPanel extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean hasChanges;
+
+ private boolean hasMore;
+
+ public ReflogPanel(String wicketId, final RepositoryModel model, Repository r, int limit, int pageOffset) {
+ super(wicketId);
+ boolean pageResults = limit <= 0;
+ int changesPerPage = app().settings().getInteger(Keys.web.reflogChangesPerPage, 10);
+ if (changesPerPage <= 1) {
+ changesPerPage = 10;
+ }
+
+ List<RefLogEntry> changes;
+ if (pageResults) {
+ changes = RefLogUtils.getLogByRef(model.name, r, pageOffset * changesPerPage, changesPerPage);
+ } else {
+ changes = RefLogUtils.getLogByRef(model.name, r, limit);
+ }
+
+ // inaccurate way to determine if there are more commits.
+ // works unless commits.size() represents the exact end.
+ hasMore = changes.size() >= changesPerPage;
+ hasChanges = changes.size() > 0;
+
+ setup(changes);
+
+ // determine to show pager, more, or neither
+ if (limit <= 0) {
+ // no display limit
+ add(new Label("moreChanges").setVisible(false));
+ } else {
+ if (pageResults) {
+ // paging
+ add(new Label("moreChanges").setVisible(false));
+ } else {
+ // more
+ if (changes.size() == limit) {
+ // show more
+ add(new LinkPanel("moreChanges", "link", new StringResourceModel("gb.moreChanges",
+ this, null), ReflogPage.class,
+ WicketUtils.newRepositoryParameter(model.name)));
+ } else {
+ // no more
+ add(new Label("moreChanges").setVisible(false));
+ }
+ }
+ }
+ }
+
+ public ReflogPanel(String wicketId, List<RefLogEntry> changes) {
+ super(wicketId);
+ hasChanges = changes.size() > 0;
+ setup(changes);
+ add(new Label("moreChanges").setVisible(false));
+ }
+
+ protected void setup(List<RefLogEntry> changes) {
+
+ ListDataProvider<RefLogEntry> dp = new ListDataProvider<RefLogEntry>(changes);
+ DataView<RefLogEntry> changeView = new DataView<RefLogEntry>("change", dp) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void populateItem(final Item<RefLogEntry> changeItem) {
+ final RefLogEntry change = changeItem.getModelObject();
+
+ String dateFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z");
+ TimeZone timezone = getTimeZone();
+ DateFormat df = new SimpleDateFormat(dateFormat);
+ df.setTimeZone(timezone);
+ Calendar cal = Calendar.getInstance(timezone);
+
+ String fullRefName = change.getChangedRefs().get(0);
+ String shortRefName = fullRefName;
+ String ticketId = null;
+ boolean isTag = false;
+ boolean isTicket = false;
+ if (shortRefName.startsWith(Constants.R_TICKET)) {
+ ticketId = fullRefName.substring(Constants.R_TICKET.length());
+ shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
+ isTicket = true;
+ } else if (shortRefName.startsWith(Constants.R_HEADS)) {
+ shortRefName = shortRefName.substring(Constants.R_HEADS.length());
+ } else if (shortRefName.startsWith(Constants.R_TAGS)) {
+ shortRefName = shortRefName.substring(Constants.R_TAGS.length());
+ isTag = true;
+ }
+
+ String fuzzydate;
+ TimeUtils tu = getTimeUtils();
+ Date changeDate = change.date;
+ if (TimeUtils.isToday(changeDate, timezone)) {
+ fuzzydate = tu.today();
+ } else if (TimeUtils.isYesterday(changeDate, timezone)) {
+ fuzzydate = tu.yesterday();
+ } else {
+ // calculate a fuzzy time ago date
+ cal.setTime(changeDate);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ fuzzydate = getTimeUtils().timeAgo(date);
+ }
+ changeItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(changeDate)));
+
+ Label changeIcon = new Label("changeIcon");
+ if (Type.DELETE.equals(change.getChangeType(fullRefName))) {
+ WicketUtils.setCssClass(changeIcon, "iconic-trash-stroke");
+ } else if (isTag) {
+ WicketUtils.setCssClass(changeIcon, "iconic-tag");
+ } else if (isTicket) {
+ WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
+ } else {
+ WicketUtils.setCssClass(changeIcon, "iconic-upload");
+ }
+ changeItem.add(changeIcon);
+
+ if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
+ // username is an email address - 1.2.1 push log bug
+ changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
+ } else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
+ // anonymous change
+ changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
+ } else {
+ // link to user account page
+ changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(),
+ UserPage.class, WicketUtils.newUsernameParameter(change.user.username)));
+ }
+
+ boolean isDelete = false;
+ boolean isRewind = false;
+ String what;
+ String by = null;
+ switch(change.getChangeType(fullRefName)) {
+ case CREATE:
+ if (isTag) {
+ // new tag
+ what = getString("gb.pushedNewTag");
+ } else {
+ // new branch
+ what = getString("gb.pushedNewBranch");
+ }
+ break;
+ case DELETE:
+ isDelete = true;
+ if (isTag) {
+ what = getString("gb.deletedTag");
+ } else {
+ what = getString("gb.deletedBranch");
+ }
+ break;
+ case UPDATE_NONFASTFORWARD:
+ isRewind = true;
+ default:
+ what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo"), change.getCommitCount());
+
+ if (change.getAuthorCount() == 1) {
+ by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
+ } else {
+ by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
+ }
+ break;
+ }
+ changeItem.add(new Label("whatChanged", what));
+ changeItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
+ changeItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
+
+ if (isDelete) {
+ // can't link to deleted ref
+ changeItem.add(new Label("refChanged", shortRefName));
+ } else if (isTag) {
+ // link to tag
+ changeItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
+ } else if (isTicket) {
+ // link to ticket
+ changeItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
+ } else {
+ // link to tree
+ changeItem.add(new LinkPanel("refChanged", null, shortRefName,
+ TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
+ }
+
+ int maxCommitCount = 5;
+ List<RepositoryCommit> commits = change.getCommits();
+ if (commits.size() > maxCommitCount) {
+ commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
+ }
+
+ // compare link
+ String compareLinkText = null;
+ if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
+ compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
+ } else if (change.getCommitCount() > maxCommitCount) {
+ int diff = change.getCommitCount() - maxCommitCount;
+ compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
+ }
+ if (StringUtils.isEmpty(compareLinkText)) {
+ changeItem.add(new Label("compareLink").setVisible(false));
+ } else {
+ String endRangeId = change.getNewId(fullRefName);
+ String startRangeId = change.getOldId(fullRefName);
+ changeItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
+ }
+
+ ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
+ DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void populateItem(final Item<RepositoryCommit> commitItem) {
+ final RepositoryCommit commit = commitItem.getModelObject();
+
+ // author gravatar
+ commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+
+ // merge icon
+ if (commit.getParentCount() > 1) {
+ commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
+ } else {
+ commitItem.add(WicketUtils.newBlankImage("commitIcon"));
+ }
+
+ // short message
+ String shortMessage = commit.getShortMessage();
+ String trimmedMessage = shortMessage;
+ if (commit.getRefs() != null && commit.getRefs().size() > 0) {
+ trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
+ } else {
+ trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
+ }
+ LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
+ trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
+ change.repository, commit.getName()));
+ if (!shortMessage.equals(trimmedMessage)) {
+ WicketUtils.setHtmlTooltip(shortlog, shortMessage);
+ }
+ commitItem.add(shortlog);
+
+ // commit hash link
+ int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
+ LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
+ CommitPage.class, WicketUtils.newObjectParameter(
+ change.repository, commit.getName()));
+ WicketUtils.setCssClass(commitHash, "shortsha1");
+ WicketUtils.setHtmlTooltip(commitHash, commit.getName());
+ commitItem.add(commitHash);
+ }
+ };
+
+ changeItem.add(commitsView);
+ }
+ };
+
+ add(changeView);
+ }
+
+ public boolean hasMore() {
+ return hasMore;
+ }
+
+ public boolean hideIfEmpty() {
+ setVisible(hasChanges);
+ return hasChanges;
+ }
+}
diff --git a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
index 7a16f4a2..6e9e866e 100644
--- a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
@@ -25,7 +25,6 @@ import java.util.Map;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
@@ -34,13 +33,15 @@ import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.Constants;
import com.gitblit.models.RefModel;
+import com.gitblit.models.RepositoryModel;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.pages.CommitPage;
import com.gitblit.wicket.pages.LogPage;
import com.gitblit.wicket.pages.TagPage;
+import com.gitblit.wicket.pages.TicketsPage;
-public class RefsPanel extends Panel {
+public class RefsPanel extends BasePanel {
private static final long serialVersionUID = 1L;
@@ -88,6 +89,8 @@ public class RefsPanel extends Panel {
}
}
final boolean shouldBreak = remoteCount < refs.size();
+ RepositoryModel repository = app().repositories().getRepositoryModel(repositoryName);
+ final boolean hasTickets = app().tickets().hasTickets(repository);
ListDataProvider<RefModel> refsDp = new ListDataProvider<RefModel>(refs);
DataView<RefModel> refsView = new DataView<RefModel>("ref", refsDp) {
@@ -103,7 +106,13 @@ public class RefsPanel extends Panel {
Class<? extends WebPage> linkClass = CommitPage.class;
String cssClass = "";
String tooltip = "";
- if (name.startsWith(Constants.R_HEADS)) {
+ if (name.startsWith(Constants.R_TICKET)) {
+ // Gitblit ticket ref
+ objectid = name.substring(Constants.R_TICKET.length());
+ name = name.substring(Constants.R_HEADS.length());
+ linkClass = TicketsPage.class;
+ cssClass = "localBranch";
+ } else if (name.startsWith(Constants.R_HEADS)) {
// local branch
linkClass = LogPage.class;
name = name.substring(Constants.R_HEADS.length());
@@ -113,13 +122,23 @@ public class RefsPanel extends Panel {
linkClass = LogPage.class;
cssClass = "headRef";
} else if (name.startsWith(Constants.R_CHANGES)) {
- // Gerrit change ref
+ // Gitblit change ref
name = name.substring(Constants.R_CHANGES.length());
// strip leading nn/ from nn/#####nn/ps = #####nn-ps
name = name.substring(name.indexOf('/') + 1).replace('/', '-');
String [] values = name.split("-");
+ // Gerrit change
tooltip = MessageFormat.format(getString("gb.reviewPatchset"), values[0], values[1]);
cssClass = "otherRef";
+ } else if (name.startsWith(Constants.R_TICKETS_PATCHSETS)) {
+ // Gitblit patchset ref
+ name = name.substring(Constants.R_TICKETS_PATCHSETS.length());
+ // strip leading nn/ from nn/#####nn/ps = #####nn-ps
+ name = name.substring(name.indexOf('/') + 1).replace('/', '-');
+ String [] values = name.split("-");
+ tooltip = MessageFormat.format(getString("gb.ticketPatchset"), values[0], values[1]);
+ linkClass = LogPage.class;
+ cssClass = "otherRef";
} else if (name.startsWith(Constants.R_PULL)) {
// Pull Request ref
String num = name.substring(Constants.R_PULL.length());