commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
98ce17
|
16 |
package com.gitblit.wicket.panels;
|
JM |
17 |
|
|
18 |
import java.util.Date;
|
|
19 |
import java.util.List;
|
|
20 |
import java.util.Map;
|
|
21 |
|
5450d0
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
98ce17
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
JM |
24 |
import org.apache.wicket.markup.repeater.Item;
|
|
25 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
26 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
27 |
import org.eclipse.jgit.lib.ObjectId;
|
|
28 |
import org.eclipse.jgit.lib.Repository;
|
|
29 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
30 |
|
33d8d8
|
31 |
import com.gitblit.Constants;
|
98ce17
|
32 |
import com.gitblit.GitBlit;
|
JM |
33 |
import com.gitblit.Keys;
|
4ab184
|
34 |
import com.gitblit.models.RefModel;
|
98ce17
|
35 |
import com.gitblit.utils.JGitUtils;
|
f5d0ad
|
36 |
import com.gitblit.utils.StringUtils;
|
98ce17
|
37 |
import com.gitblit.wicket.WicketUtils;
|
JM |
38 |
import com.gitblit.wicket.pages.CommitDiffPage;
|
|
39 |
import com.gitblit.wicket.pages.CommitPage;
|
4e1930
|
40 |
import com.gitblit.wicket.pages.GitSearchPage;
|
98ce17
|
41 |
import com.gitblit.wicket.pages.TreePage;
|
JM |
42 |
|
|
43 |
public class SearchPanel extends BasePanel {
|
|
44 |
|
|
45 |
private static final long serialVersionUID = 1L;
|
|
46 |
|
2a7306
|
47 |
private boolean hasMore;
|
98ce17
|
48 |
|
2a7306
|
49 |
public SearchPanel(String wicketId, final String repositoryName, final String objectId,
|
1e1b85
|
50 |
final String value, Constants.SearchType searchType, Repository r, int limit, int pageOffset,
|
JM |
51 |
boolean showRemoteRefs) {
|
98ce17
|
52 |
super(wicketId);
|
JM |
53 |
boolean pageResults = limit <= 0;
|
2a7306
|
54 |
int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
|
98ce17
|
55 |
if (itemsPerPage <= 1) {
|
JM |
56 |
itemsPerPage = 50;
|
|
57 |
}
|
|
58 |
|
|
59 |
RevCommit commit = JGitUtils.getCommit(r, objectId);
|
|
60 |
|
1e1b85
|
61 |
final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
|
98ce17
|
62 |
List<RevCommit> commits;
|
JM |
63 |
if (pageResults) {
|
|
64 |
// Paging result set
|
2a7306
|
65 |
commits = JGitUtils.searchRevlogs(r, objectId, value, searchType, pageOffset
|
JM |
66 |
* itemsPerPage, itemsPerPage);
|
98ce17
|
67 |
} else {
|
JM |
68 |
// Fixed size result set
|
|
69 |
commits = JGitUtils.searchRevlogs(r, objectId, value, searchType, 0, limit);
|
|
70 |
}
|
|
71 |
|
|
72 |
// inaccurate way to determine if there are more commits.
|
|
73 |
// works unless commits.size() represents the exact end.
|
|
74 |
hasMore = commits.size() >= itemsPerPage;
|
|
75 |
|
|
76 |
// header
|
5450d0
|
77 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
85c2e6
|
78 |
|
5450d0
|
79 |
add(new Label("searchString", value));
|
JM |
80 |
add(new Label("searchType", searchType.toString()));
|
98ce17
|
81 |
|
JM |
82 |
ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
|
|
83 |
DataView<RevCommit> searchView = new DataView<RevCommit>("commit", dp) {
|
|
84 |
private static final long serialVersionUID = 1L;
|
2a7306
|
85 |
int counter;
|
98ce17
|
86 |
|
JM |
87 |
public void populateItem(final Item<RevCommit> item) {
|
|
88 |
final RevCommit entry = item.getModelObject();
|
|
89 |
final Date date = JGitUtils.getCommitDate(entry);
|
|
90 |
|
9adf62
|
91 |
item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));
|
98ce17
|
92 |
|
JM |
93 |
// author search link
|
|
94 |
String author = entry.getAuthorIdent().getName();
|
2a7306
|
95 |
LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
|
4e1930
|
96 |
GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
33d8d8
|
97 |
author, Constants.SearchType.AUTHOR));
|
JM |
98 |
setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
|
98ce17
|
99 |
item.add(authorLink);
|
JM |
100 |
|
a645ba
|
101 |
// merge icon
|
JM |
102 |
if (entry.getParentCount() > 1) {
|
1e8390
|
103 |
item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
|
a645ba
|
104 |
} else {
|
1e8390
|
105 |
item.add(WicketUtils.newBlankImage("commitIcon"));
|
a645ba
|
106 |
}
|
JM |
107 |
|
98ce17
|
108 |
String shortMessage = entry.getShortMessage();
|
a45caa
|
109 |
String trimmedMessage = shortMessage;
|
JM |
110 |
if (allRefs.containsKey(entry.getId())) {
|
|
111 |
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
|
|
112 |
} else {
|
|
113 |
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
|
|
114 |
}
|
2a7306
|
115 |
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
|
JM |
116 |
trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
|
|
117 |
repositoryName, entry.getName()));
|
98ce17
|
118 |
if (!shortMessage.equals(trimmedMessage)) {
|
1e8390
|
119 |
WicketUtils.setHtmlTooltip(shortlog, shortMessage);
|
98ce17
|
120 |
}
|
JM |
121 |
item.add(shortlog);
|
|
122 |
|
|
123 |
item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
|
|
124 |
|
2a7306
|
125 |
item.add(new BookmarkablePageLink<Void>("commit", CommitPage.class, WicketUtils
|
JM |
126 |
.newObjectParameter(repositoryName, entry.getName())));
|
|
127 |
item.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,
|
|
128 |
WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
129 |
item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
130 |
.newObjectParameter(repositoryName, entry.getName())));
|
98ce17
|
131 |
|
JM |
132 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
133 |
counter++;
|
|
134 |
}
|
|
135 |
};
|
|
136 |
add(searchView);
|
|
137 |
}
|
|
138 |
|
|
139 |
public boolean hasMore() {
|
|
140 |
return hasMore;
|
|
141 |
}
|
|
142 |
}
|