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 |
*/
|
698678
|
16 |
package com.gitblit.wicket.panels;
|
JM |
17 |
|
|
18 |
import java.util.ArrayList;
|
|
19 |
import java.util.Collections;
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
c22722
|
24 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
1fa5e8
|
25 |
import org.apache.wicket.markup.html.panel.Fragment;
|
698678
|
26 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
27 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
28 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
29 |
import org.apache.wicket.model.StringResourceModel;
|
|
30 |
import org.eclipse.jgit.lib.Repository;
|
|
31 |
|
33d8d8
|
32 |
import com.gitblit.Constants;
|
c22722
|
33 |
import com.gitblit.SyndicationServlet;
|
1f9dae
|
34 |
import com.gitblit.models.RefModel;
|
JM |
35 |
import com.gitblit.models.RepositoryModel;
|
698678
|
36 |
import com.gitblit.utils.JGitUtils;
|
87cc1e
|
37 |
import com.gitblit.utils.StringUtils;
|
698678
|
38 |
import com.gitblit.wicket.WicketUtils;
|
JM |
39 |
import com.gitblit.wicket.pages.BranchesPage;
|
85c2e6
|
40 |
import com.gitblit.wicket.pages.CommitPage;
|
698678
|
41 |
import com.gitblit.wicket.pages.LogPage;
|
1fa5e8
|
42 |
import com.gitblit.wicket.pages.MetricsPage;
|
85c2e6
|
43 |
import com.gitblit.wicket.pages.SearchPage;
|
698678
|
44 |
import com.gitblit.wicket.pages.SummaryPage;
|
JM |
45 |
import com.gitblit.wicket.pages.TreePage;
|
|
46 |
|
bc10f9
|
47 |
public class BranchesPanel extends BasePanel {
|
698678
|
48 |
|
JM |
49 |
private static final long serialVersionUID = 1L;
|
1fa5e8
|
50 |
|
JM |
51 |
private final boolean hasBranches;
|
698678
|
52 |
|
2a7306
|
53 |
public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,
|
JM |
54 |
final int maxCount) {
|
698678
|
55 |
super(wicketId);
|
JM |
56 |
|
|
57 |
// branches
|
|
58 |
List<RefModel> branches = new ArrayList<RefModel>();
|
5cc4f2
|
59 |
branches.addAll(JGitUtils.getLocalBranches(r, false, maxCount));
|
cf9550
|
60 |
if (model.showRemoteBranches) {
|
5cc4f2
|
61 |
branches.addAll(JGitUtils.getRemoteBranches(r, false, maxCount));
|
cf9550
|
62 |
}
|
698678
|
63 |
Collections.sort(branches);
|
JM |
64 |
Collections.reverse(branches);
|
|
65 |
if (maxCount > 0 && branches.size() > maxCount) {
|
|
66 |
branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
|
|
67 |
}
|
|
68 |
|
|
69 |
if (maxCount > 0) {
|
|
70 |
// summary page
|
|
71 |
// show branches page link
|
2a7306
|
72 |
add(new LinkPanel("branches", "title", new StringResourceModel("gb.branches", this,
|
JM |
73 |
null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
74 |
} else {
|
JM |
75 |
// branches page
|
|
76 |
// show repository summary page link
|
2a7306
|
77 |
add(new LinkPanel("branches", "title", model.name, SummaryPage.class,
|
JM |
78 |
WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
79 |
}
|
155bf7
|
80 |
|
698678
|
81 |
ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
|
JM |
82 |
DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
|
|
83 |
private static final long serialVersionUID = 1L;
|
2a7306
|
84 |
int counter;
|
698678
|
85 |
|
JM |
86 |
public void populateItem(final Item<RefModel> item) {
|
|
87 |
final RefModel entry = item.getModelObject();
|
|
88 |
|
bc10f9
|
89 |
item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
|
698678
|
90 |
|
2a7306
|
91 |
item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(
|
JM |
92 |
entry.displayName, 28), LogPage.class, WicketUtils.newObjectParameter(
|
|
93 |
model.name, entry.getName())));
|
155bf7
|
94 |
|
85c2e6
|
95 |
String author = entry.getAuthorIdent().getName();
|
JM |
96 |
LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,
|
88598b
|
97 |
SearchPage.class, WicketUtils.newSearchParameter(model.name,
|
33d8d8
|
98 |
entry.getName(), author, Constants.SearchType.AUTHOR));
|
JM |
99 |
setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
|
85c2e6
|
100 |
item.add(authorLink);
|
88598b
|
101 |
|
85c2e6
|
102 |
// short message
|
JM |
103 |
String shortMessage = entry.getShortMessage();
|
|
104 |
String trimmedMessage = StringUtils.trimShortLog(shortMessage);
|
88598b
|
105 |
LinkPanel shortlog = new LinkPanel("branchLog", "list subject", trimmedMessage,
|
JM |
106 |
CommitPage.class, WicketUtils.newObjectParameter(model.name,
|
|
107 |
entry.getName()));
|
85c2e6
|
108 |
if (!shortMessage.equals(trimmedMessage)) {
|
JM |
109 |
WicketUtils.setHtmlTooltip(shortlog, shortMessage);
|
|
110 |
}
|
|
111 |
item.add(shortlog);
|
88598b
|
112 |
|
1fa5e8
|
113 |
if (maxCount <= 0) {
|
JM |
114 |
Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);
|
|
115 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
|
|
116 |
.newObjectParameter(model.name, entry.getName())));
|
|
117 |
fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
118 |
.newObjectParameter(model.name, entry.getName())));
|
|
119 |
fragment.add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
|
|
120 |
WicketUtils.newObjectParameter(model.name, entry.getName())));
|
85c2e6
|
121 |
fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(
|
JM |
122 |
getRequest().getRelativePathPrefixToContextRoot(), model.name,
|
|
123 |
entry.getName(), 0)));
|
1fa5e8
|
124 |
item.add(fragment);
|
JM |
125 |
} else {
|
|
126 |
Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);
|
|
127 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
|
|
128 |
.newObjectParameter(model.name, entry.getName())));
|
|
129 |
fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
130 |
.newObjectParameter(model.name, entry.getName())));
|
|
131 |
item.add(fragment);
|
|
132 |
}
|
698678
|
133 |
WicketUtils.setAlternatingBackground(item, counter);
|
JM |
134 |
counter++;
|
|
135 |
}
|
|
136 |
};
|
|
137 |
add(branchesView);
|
|
138 |
if (branches.size() < maxCount || maxCount <= 0) {
|
|
139 |
add(new Label("allBranches", "").setVisible(false));
|
|
140 |
} else {
|
2a7306
|
141 |
add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches",
|
JM |
142 |
this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
143 |
}
|
1fa5e8
|
144 |
// We always have 1 branch
|
a2709d
|
145 |
hasBranches = (branches.size() > 1)
|
JM |
146 |
|| ((branches.size() == 1) && !branches.get(0).displayName
|
caad17
|
147 |
.equalsIgnoreCase("master"));
|
1fa5e8
|
148 |
}
|
JM |
149 |
|
|
150 |
public BranchesPanel hideIfEmpty() {
|
|
151 |
setVisible(hasBranches);
|
|
152 |
return this;
|
698678
|
153 |
}
|
JM |
154 |
}
|