commit | author | age
|
98ce17
|
1 |
package com.gitblit.wicket.panels;
|
JM |
2 |
|
|
3 |
import java.util.Date;
|
|
4 |
import java.util.List;
|
|
5 |
import java.util.Map;
|
|
6 |
|
a645ba
|
7 |
import org.apache.wicket.markup.html.image.ContextImage;
|
98ce17
|
8 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
JM |
9 |
import org.apache.wicket.markup.repeater.Item;
|
|
10 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
11 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
12 |
import org.eclipse.jgit.lib.ObjectId;
|
|
13 |
import org.eclipse.jgit.lib.Repository;
|
|
14 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
15 |
|
|
16 |
import com.gitblit.GitBlit;
|
|
17 |
import com.gitblit.Keys;
|
|
18 |
import com.gitblit.utils.JGitUtils;
|
|
19 |
import com.gitblit.utils.StringUtils;
|
|
20 |
import com.gitblit.utils.JGitUtils.SearchType;
|
|
21 |
import com.gitblit.wicket.LinkPanel;
|
|
22 |
import com.gitblit.wicket.WicketUtils;
|
|
23 |
import com.gitblit.wicket.pages.CommitDiffPage;
|
|
24 |
import com.gitblit.wicket.pages.CommitPage;
|
|
25 |
import com.gitblit.wicket.pages.SearchPage;
|
|
26 |
import com.gitblit.wicket.pages.TreePage;
|
|
27 |
|
|
28 |
public class SearchPanel extends BasePanel {
|
|
29 |
|
|
30 |
private static final long serialVersionUID = 1L;
|
|
31 |
|
|
32 |
private boolean hasMore = false;
|
|
33 |
|
|
34 |
public SearchPanel(String wicketId, final String repositoryName, final String objectId, final String value, SearchType searchType, Repository r, int limit, int pageOffset) {
|
|
35 |
super(wicketId);
|
|
36 |
boolean pageResults = limit <= 0;
|
|
37 |
int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50);
|
|
38 |
if (itemsPerPage <= 1) {
|
|
39 |
itemsPerPage = 50;
|
|
40 |
}
|
|
41 |
|
|
42 |
RevCommit commit = JGitUtils.getCommit(r, objectId);
|
|
43 |
|
|
44 |
final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);
|
|
45 |
List<RevCommit> commits;
|
|
46 |
if (pageResults) {
|
|
47 |
// Paging result set
|
|
48 |
commits = JGitUtils.searchRevlogs(r, objectId, value, searchType, pageOffset * itemsPerPage, itemsPerPage);
|
|
49 |
} else {
|
|
50 |
// Fixed size result set
|
|
51 |
commits = JGitUtils.searchRevlogs(r, objectId, value, searchType, 0, limit);
|
|
52 |
}
|
|
53 |
|
|
54 |
// inaccurate way to determine if there are more commits.
|
|
55 |
// works unless commits.size() represents the exact end.
|
|
56 |
hasMore = commits.size() >= itemsPerPage;
|
|
57 |
|
|
58 |
// header
|
|
59 |
add(new LinkPanel("header", "title", commit.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName())));
|
|
60 |
|
|
61 |
ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
|
|
62 |
DataView<RevCommit> searchView = new DataView<RevCommit>("commit", dp) {
|
|
63 |
private static final long serialVersionUID = 1L;
|
|
64 |
int counter = 0;
|
|
65 |
|
|
66 |
public void populateItem(final Item<RevCommit> item) {
|
|
67 |
final RevCommit entry = item.getModelObject();
|
|
68 |
final Date date = JGitUtils.getCommitDate(entry);
|
|
69 |
|
|
70 |
item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));
|
|
71 |
|
|
72 |
// author search link
|
|
73 |
String author = entry.getAuthorIdent().getName();
|
|
74 |
LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author, SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, author, SearchType.AUTHOR));
|
|
75 |
setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
|
|
76 |
item.add(authorLink);
|
|
77 |
|
a645ba
|
78 |
// merge icon
|
JM |
79 |
if (entry.getParentCount() > 1) {
|
|
80 |
item.add(new ContextImage("commitIcon", "/com/gitblit/wicket/resources/commit_merge_16x16.png"));
|
|
81 |
} else {
|
|
82 |
item.add(new ContextImage("commitIcon", "/com/gitblit/wicket/resources/blank.png"));
|
|
83 |
}
|
|
84 |
|
98ce17
|
85 |
String shortMessage = entry.getShortMessage();
|
JM |
86 |
String trimmedMessage = StringUtils.trimShortLog(shortMessage);
|
|
87 |
// TODO highlight matches
|
|
88 |
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()));
|
|
89 |
if (!shortMessage.equals(trimmedMessage)) {
|
|
90 |
WicketUtils.setHtmlTitle(shortlog, shortMessage);
|
|
91 |
}
|
|
92 |
item.add(shortlog);
|
|
93 |
|
|
94 |
item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
|
|
95 |
|
|
96 |
item.add(new BookmarkablePageLink<Void>("commit", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
97 |
item.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
98 |
item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
99 |
|
|
100 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
101 |
counter++;
|
|
102 |
}
|
|
103 |
};
|
|
104 |
add(searchView);
|
|
105 |
}
|
|
106 |
|
|
107 |
public boolean hasMore() {
|
|
108 |
return hasMore;
|
|
109 |
}
|
|
110 |
}
|