commit | author | age
|
698678
|
1 |
package com.gitblit.wicket.panels;
|
JM |
2 |
|
|
3 |
import java.util.Date;
|
|
4 |
import java.util.List;
|
|
5 |
import java.util.Map;
|
|
6 |
|
|
7 |
import org.apache.wicket.markup.html.basic.Label;
|
a645ba
|
8 |
import org.apache.wicket.markup.html.image.ContextImage;
|
698678
|
9 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
JM |
10 |
import org.apache.wicket.markup.repeater.Item;
|
|
11 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
12 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
13 |
import org.apache.wicket.model.StringResourceModel;
|
|
14 |
import org.eclipse.jgit.lib.ObjectId;
|
|
15 |
import org.eclipse.jgit.lib.Repository;
|
|
16 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
17 |
|
87cc1e
|
18 |
import com.gitblit.GitBlit;
|
155bf7
|
19 |
import com.gitblit.Keys;
|
698678
|
20 |
import com.gitblit.utils.JGitUtils;
|
98ce17
|
21 |
import com.gitblit.utils.JGitUtils.SearchType;
|
87cc1e
|
22 |
import com.gitblit.utils.StringUtils;
|
698678
|
23 |
import com.gitblit.wicket.LinkPanel;
|
JM |
24 |
import com.gitblit.wicket.WicketUtils;
|
608ece
|
25 |
import com.gitblit.wicket.pages.CommitDiffPage;
|
155bf7
|
26 |
import com.gitblit.wicket.pages.CommitPage;
|
698678
|
27 |
import com.gitblit.wicket.pages.LogPage;
|
98ce17
|
28 |
import com.gitblit.wicket.pages.SearchPage;
|
698678
|
29 |
import com.gitblit.wicket.pages.SummaryPage;
|
JM |
30 |
import com.gitblit.wicket.pages.TreePage;
|
|
31 |
|
bc10f9
|
32 |
public class LogPanel extends BasePanel {
|
698678
|
33 |
|
JM |
34 |
private static final long serialVersionUID = 1L;
|
f602a2
|
35 |
|
JM |
36 |
private boolean hasMore = false;
|
698678
|
37 |
|
98ce17
|
38 |
public LogPanel(String wicketId, final String repositoryName, final String objectId, Repository r, int limit, int pageOffset) {
|
698678
|
39 |
super(wicketId);
|
50984c
|
40 |
boolean pageResults = limit <= 0;
|
87cc1e
|
41 |
int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50);
|
66c29a
|
42 |
if (itemsPerPage <= 1) {
|
JM |
43 |
itemsPerPage = 50;
|
|
44 |
}
|
bc10f9
|
45 |
|
698678
|
46 |
final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);
|
ef5c58
|
47 |
List<RevCommit> commits;
|
JM |
48 |
if (pageResults) {
|
|
49 |
// Paging result set
|
50984c
|
50 |
commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
|
ef5c58
|
51 |
} else {
|
JM |
52 |
// Fixed size result set
|
|
53 |
commits = JGitUtils.getRevLog(r, objectId, 0, limit);
|
|
54 |
}
|
f602a2
|
55 |
|
JM |
56 |
// inaccurate way to determine if there are more commits.
|
|
57 |
// works unless commits.size() represents the exact end.
|
|
58 |
hasMore = commits.size() >= itemsPerPage;
|
698678
|
59 |
|
JM |
60 |
// header
|
ef5c58
|
61 |
if (pageResults) {
|
698678
|
62 |
// shortlog page
|
JM |
63 |
// show repository summary page link
|
ef5c58
|
64 |
add(new LinkPanel("header", "title", repositoryName, SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
698678
|
65 |
} else {
|
JM |
66 |
// summary page
|
|
67 |
// show shortlog page link
|
|
68 |
add(new LinkPanel("header", "title", new StringResourceModel("gb.log", this, null), LogPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
|
69 |
}
|
|
70 |
|
|
71 |
ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
|
|
72 |
DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
|
|
73 |
private static final long serialVersionUID = 1L;
|
|
74 |
int counter = 0;
|
|
75 |
|
|
76 |
public void populateItem(final Item<RevCommit> item) {
|
|
77 |
final RevCommit entry = item.getModelObject();
|
|
78 |
final Date date = JGitUtils.getCommitDate(entry);
|
|
79 |
|
bc10f9
|
80 |
item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));
|
698678
|
81 |
|
98ce17
|
82 |
// author search link
|
698678
|
83 |
String author = entry.getAuthorIdent().getName();
|
98ce17
|
84 |
LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author, SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, author, SearchType.AUTHOR));
|
JM |
85 |
setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
|
|
86 |
item.add(authorLink);
|
698678
|
87 |
|
a645ba
|
88 |
// merge icon
|
JM |
89 |
if (entry.getParentCount() > 1) {
|
|
90 |
item.add(new ContextImage("commitIcon", "/com/gitblit/wicket/resources/commit_merge_16x16.png"));
|
|
91 |
} else {
|
|
92 |
item.add(new ContextImage("commitIcon", "/com/gitblit/wicket/resources/blank.png"));
|
|
93 |
}
|
|
94 |
|
|
95 |
// short message
|
698678
|
96 |
String shortMessage = entry.getShortMessage();
|
87cc1e
|
97 |
String trimmedMessage = StringUtils.trimShortLog(shortMessage);
|
ef5c58
|
98 |
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()));
|
698678
|
99 |
if (!shortMessage.equals(trimmedMessage)) {
|
JM |
100 |
WicketUtils.setHtmlTitle(shortlog, shortMessage);
|
|
101 |
}
|
|
102 |
item.add(shortlog);
|
|
103 |
|
7d35e2
|
104 |
item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
|
698678
|
105 |
|
ef5c58
|
106 |
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
608ece
|
107 |
item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
ef5c58
|
108 |
item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
698678
|
109 |
|
JM |
110 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
111 |
counter++;
|
|
112 |
}
|
|
113 |
};
|
50984c
|
114 |
add(logView);
|
698678
|
115 |
|
JM |
116 |
// determine to show pager, more, or neither
|
ef5c58
|
117 |
if (limit <= 0) {
|
698678
|
118 |
// no display limit
|
JM |
119 |
add(new Label("moreLogs", "").setVisible(false));
|
50984c
|
120 |
} else {
|
ef5c58
|
121 |
if (pageResults) {
|
698678
|
122 |
// paging
|
JM |
123 |
add(new Label("moreLogs", "").setVisible(false));
|
|
124 |
} else {
|
|
125 |
// more
|
ef5c58
|
126 |
if (commits.size() == limit) {
|
698678
|
127 |
// show more
|
JM |
128 |
add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs", this, null), LogPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
|
129 |
} else {
|
|
130 |
// no more
|
|
131 |
add(new Label("moreLogs", "").setVisible(false));
|
|
132 |
}
|
|
133 |
}
|
|
134 |
}
|
|
135 |
}
|
f602a2
|
136 |
|
JM |
137 |
public boolean hasMore() {
|
|
138 |
return hasMore;
|
|
139 |
}
|
698678
|
140 |
}
|