commit | author | age
|
5e3521
|
1 |
/* |
JM |
2 |
* Copyright 2013 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 |
*/ |
|
16 |
package com.gitblit.wicket.panels; |
|
17 |
|
|
18 |
import java.text.DateFormat; |
|
19 |
import java.text.MessageFormat; |
|
20 |
import java.text.SimpleDateFormat; |
|
21 |
import java.util.ArrayList; |
|
22 |
import java.util.Date; |
|
23 |
import java.util.List; |
|
24 |
import java.util.TimeZone; |
|
25 |
|
|
26 |
import org.apache.wicket.markup.html.basic.Label; |
|
27 |
import org.apache.wicket.markup.repeater.Item; |
|
28 |
import org.apache.wicket.markup.repeater.data.DataView; |
|
29 |
import org.apache.wicket.markup.repeater.data.ListDataProvider; |
|
30 |
import org.eclipse.jgit.lib.PersonIdent; |
|
31 |
|
|
32 |
import com.gitblit.Constants; |
|
33 |
import com.gitblit.Keys; |
|
34 |
import com.gitblit.models.DailyLogEntry; |
|
35 |
import com.gitblit.models.RepositoryCommit; |
|
36 |
import com.gitblit.utils.StringUtils; |
|
37 |
import com.gitblit.utils.TimeUtils; |
|
38 |
import com.gitblit.wicket.WicketUtils; |
|
39 |
import com.gitblit.wicket.pages.CommitPage; |
|
40 |
import com.gitblit.wicket.pages.ComparePage; |
|
41 |
import com.gitblit.wicket.pages.SummaryPage; |
|
42 |
import com.gitblit.wicket.pages.TagPage; |
|
43 |
import com.gitblit.wicket.pages.TicketsPage; |
|
44 |
import com.gitblit.wicket.pages.TreePage; |
|
45 |
|
|
46 |
public class DigestsPanel extends BasePanel { |
|
47 |
|
|
48 |
private static final long serialVersionUID = 1L; |
|
49 |
|
|
50 |
private final boolean hasChanges; |
|
51 |
|
|
52 |
private boolean hasMore; |
|
53 |
|
|
54 |
public DigestsPanel(String wicketId, List<DailyLogEntry> digests) { |
|
55 |
super(wicketId); |
|
56 |
hasChanges = digests.size() > 0; |
|
57 |
|
|
58 |
ListDataProvider<DailyLogEntry> dp = new ListDataProvider<DailyLogEntry>(digests); |
|
59 |
DataView<DailyLogEntry> pushView = new DataView<DailyLogEntry>("change", dp) { |
|
60 |
private static final long serialVersionUID = 1L; |
|
61 |
|
|
62 |
@Override |
|
63 |
public void populateItem(final Item<DailyLogEntry> logItem) { |
|
64 |
final DailyLogEntry change = logItem.getModelObject(); |
|
65 |
|
|
66 |
String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy"); |
|
67 |
TimeZone timezone = getTimeZone(); |
|
68 |
DateFormat df = new SimpleDateFormat(dateFormat); |
|
69 |
df.setTimeZone(timezone); |
|
70 |
|
|
71 |
String fullRefName = change.getChangedRefs().get(0); |
|
72 |
String shortRefName = fullRefName; |
|
73 |
String ticketId = ""; |
|
74 |
boolean isTag = false; |
|
75 |
boolean isTicket = false; |
|
76 |
if (shortRefName.startsWith(Constants.R_TICKET)) { |
|
77 |
ticketId = shortRefName = shortRefName.substring(Constants.R_TICKET.length()); |
|
78 |
shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId); |
|
79 |
isTicket = true; |
|
80 |
} else if (shortRefName.startsWith(Constants.R_HEADS)) { |
|
81 |
shortRefName = shortRefName.substring(Constants.R_HEADS.length()); |
|
82 |
} else if (shortRefName.startsWith(Constants.R_TAGS)) { |
|
83 |
shortRefName = shortRefName.substring(Constants.R_TAGS.length()); |
|
84 |
isTag = true; |
|
85 |
} |
|
86 |
|
|
87 |
String fuzzydate; |
|
88 |
TimeUtils tu = getTimeUtils(); |
|
89 |
Date pushDate = change.date; |
|
90 |
if (TimeUtils.isToday(pushDate, timezone)) { |
|
91 |
fuzzydate = tu.today(); |
|
92 |
} else if (TimeUtils.isYesterday(pushDate, timezone)) { |
|
93 |
fuzzydate = tu.yesterday(); |
|
94 |
} else { |
|
95 |
fuzzydate = getTimeUtils().timeAgo(pushDate); |
|
96 |
} |
|
97 |
logItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(pushDate))); |
|
98 |
|
|
99 |
Label changeIcon = new Label("changeIcon"); |
|
100 |
// use the repository hash color to differentiate the icon. |
|
101 |
String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository)); |
|
102 |
WicketUtils.setCssStyle(changeIcon, "color: " + color); |
|
103 |
|
|
104 |
if (isTag) { |
|
105 |
WicketUtils.setCssClass(changeIcon, "iconic-tag"); |
|
106 |
} else if (isTicket) { |
|
107 |
WicketUtils.setCssClass(changeIcon, "fa fa-ticket"); |
|
108 |
} else { |
|
109 |
WicketUtils.setCssClass(changeIcon, "iconic-loop"); |
|
110 |
} |
|
111 |
logItem.add(changeIcon); |
|
112 |
|
|
113 |
if (isTag) { |
|
114 |
// tags are special |
|
115 |
PersonIdent ident = change.getCommits().get(0).getAuthorIdent(); |
|
116 |
if (!StringUtils.isEmpty(ident.getName())) { |
|
117 |
logItem.add(new Label("whoChanged", ident.getName())); |
|
118 |
} else { |
|
119 |
logItem.add(new Label("whoChanged", ident.getEmailAddress())); |
|
120 |
} |
|
121 |
} else { |
|
122 |
logItem.add(new Label("whoChanged").setVisible(false)); |
|
123 |
} |
|
124 |
|
|
125 |
String preposition = "gb.of"; |
|
126 |
boolean isDelete = false; |
|
127 |
String what; |
|
128 |
String by = null; |
|
129 |
switch(change.getChangeType(fullRefName)) { |
|
130 |
case CREATE: |
|
131 |
if (isTag) { |
|
132 |
// new tag |
|
133 |
what = getString("gb.createdNewTag"); |
|
134 |
preposition = "gb.in"; |
|
135 |
} else { |
|
136 |
// new branch |
|
137 |
what = getString("gb.createdNewBranch"); |
|
138 |
preposition = "gb.in"; |
|
139 |
} |
|
140 |
break; |
|
141 |
case DELETE: |
|
142 |
isDelete = true; |
|
143 |
if (isTag) { |
|
144 |
what = getString("gb.deletedTag"); |
|
145 |
} else { |
|
146 |
what = getString("gb.deletedBranch"); |
|
147 |
} |
|
148 |
preposition = "gb.from"; |
|
149 |
break; |
|
150 |
default: |
|
151 |
what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.commitsTo") : getString("gb.oneCommitTo"), change.getCommitCount()); |
|
152 |
|
|
153 |
if (change.getAuthorCount() == 1) { |
|
154 |
by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName()); |
|
155 |
} else { |
|
156 |
by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount()); |
|
157 |
} |
|
158 |
break; |
|
159 |
} |
|
160 |
logItem.add(new Label("whatChanged", what)); |
|
161 |
logItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by))); |
|
162 |
|
|
163 |
if (isDelete) { |
|
164 |
// can't link to deleted ref |
|
165 |
logItem.add(new Label("refChanged", shortRefName)); |
|
166 |
} else if (isTag) { |
|
167 |
// link to tag |
|
168 |
logItem.add(new LinkPanel("refChanged", null, shortRefName, |
e4dd82
|
169 |
TagPage.class, WicketUtils.newObjectParameter(change.repository, shortRefName))); |
5e3521
|
170 |
} else if (isTicket) { |
JM |
171 |
// link to ticket |
|
172 |
logItem.add(new LinkPanel("refChanged", null, shortRefName, |
|
173 |
TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId))); |
|
174 |
} else { |
|
175 |
// link to tree |
|
176 |
logItem.add(new LinkPanel("refChanged", null, shortRefName, |
e4dd82
|
177 |
TreePage.class, WicketUtils.newObjectParameter(change.repository, shortRefName))); |
5e3521
|
178 |
} |
JM |
179 |
|
|
180 |
// to/from/etc |
|
181 |
logItem.add(new Label("repoPreposition", getString(preposition))); |
|
182 |
String repoName = StringUtils.stripDotGit(change.repository); |
|
183 |
logItem.add(new LinkPanel("repoChanged", null, repoName, |
|
184 |
SummaryPage.class, WicketUtils.newRepositoryParameter(change.repository))); |
|
185 |
|
|
186 |
int maxCommitCount = 5; |
|
187 |
List<RepositoryCommit> commits = change.getCommits(); |
|
188 |
if (commits.size() > maxCommitCount) { |
|
189 |
commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount)); |
|
190 |
} |
|
191 |
|
|
192 |
// compare link |
|
193 |
String compareLinkText = null; |
|
194 |
if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) { |
|
195 |
compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size()); |
|
196 |
} else if (change.getCommitCount() > maxCommitCount) { |
|
197 |
int diff = change.getCommitCount() - maxCommitCount; |
|
198 |
compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff); |
|
199 |
} |
|
200 |
if (StringUtils.isEmpty(compareLinkText)) { |
|
201 |
logItem.add(new Label("compareLink").setVisible(false)); |
|
202 |
} else { |
|
203 |
String endRangeId = change.getNewId(fullRefName); |
|
204 |
String startRangeId = change.getOldId(fullRefName); |
|
205 |
logItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId))); |
|
206 |
} |
|
207 |
|
|
208 |
final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true); |
|
209 |
|
|
210 |
ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits); |
|
211 |
DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) { |
|
212 |
private static final long serialVersionUID = 1L; |
|
213 |
|
|
214 |
@Override |
|
215 |
public void populateItem(final Item<RepositoryCommit> commitItem) { |
|
216 |
final RepositoryCommit commit = commitItem.getModelObject(); |
|
217 |
|
|
218 |
// author gravatar |
b57b9e
|
219 |
commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false)); |
5e3521
|
220 |
|
JM |
221 |
// merge icon |
|
222 |
if (commit.getParentCount() > 1) { |
|
223 |
commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png")); |
|
224 |
} else { |
|
225 |
commitItem.add(WicketUtils.newBlankImage("commitIcon")); |
|
226 |
} |
|
227 |
|
|
228 |
// short message |
|
229 |
String shortMessage = commit.getShortMessage(); |
|
230 |
String trimmedMessage = shortMessage; |
|
231 |
if (commit.getRefs() != null && commit.getRefs().size() > 0) { |
|
232 |
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS); |
|
233 |
} else { |
|
234 |
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG); |
|
235 |
} |
|
236 |
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list", |
|
237 |
trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter( |
|
238 |
change.repository, commit.getName())); |
|
239 |
if (!shortMessage.equals(trimmedMessage)) { |
|
240 |
WicketUtils.setHtmlTooltip(shortlog, shortMessage); |
|
241 |
} |
|
242 |
commitItem.add(shortlog); |
|
243 |
|
|
244 |
// commit hash link |
|
245 |
int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6); |
|
246 |
LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen), |
|
247 |
CommitPage.class, WicketUtils.newObjectParameter( |
|
248 |
change.repository, commit.getName())); |
|
249 |
WicketUtils.setCssClass(commitHash, "shortsha1"); |
|
250 |
WicketUtils.setHtmlTooltip(commitHash, commit.getName()); |
|
251 |
commitItem.add(commitHash); |
|
252 |
|
|
253 |
if (showSwatch) { |
|
254 |
// set repository color |
|
255 |
String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository)); |
|
256 |
WicketUtils.setCssStyle(commitItem, MessageFormat.format("border-left: 2px solid {0};", color)); |
|
257 |
} |
|
258 |
} |
|
259 |
}; |
|
260 |
|
|
261 |
logItem.add(commitsView); |
|
262 |
} |
|
263 |
}; |
|
264 |
|
|
265 |
add(pushView); |
|
266 |
} |
|
267 |
|
|
268 |
public boolean hasMore() { |
|
269 |
return hasMore; |
|
270 |
} |
|
271 |
|
|
272 |
public boolean hideIfEmpty() { |
|
273 |
setVisible(hasChanges); |
|
274 |
return hasChanges; |
|
275 |
} |
|
276 |
} |