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 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
45c0d6
|
18 |
import java.awt.Color;
|
fc8426
|
19 |
import java.awt.Dimension;
|
45c0d6
|
20 |
import java.text.MessageFormat;
|
a1ea87
|
21 |
import java.text.ParseException;
|
8a2e9c
|
22 |
import java.util.ArrayList;
|
5fe7df
|
23 |
import java.util.List;
|
8a2e9c
|
24 |
|
5fe7df
|
25 |
import org.apache.wicket.PageParameters;
|
JM |
26 |
import org.apache.wicket.markup.html.basic.Label;
|
1fa5e8
|
27 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
5fe7df
|
28 |
import org.eclipse.jgit.lib.Repository;
|
a1ea87
|
29 |
import org.eclipse.jgit.revwalk.RevCommit;
|
531cd2
|
30 |
import org.wicketstuff.googlecharts.Chart;
|
JM |
31 |
import org.wicketstuff.googlecharts.ChartAxis;
|
|
32 |
import org.wicketstuff.googlecharts.ChartAxisType;
|
|
33 |
import org.wicketstuff.googlecharts.ChartProvider;
|
|
34 |
import org.wicketstuff.googlecharts.ChartType;
|
|
35 |
import org.wicketstuff.googlecharts.IChartData;
|
|
36 |
import org.wicketstuff.googlecharts.LineStyle;
|
|
37 |
import org.wicketstuff.googlecharts.MarkerType;
|
|
38 |
import org.wicketstuff.googlecharts.ShapeMarker;
|
f5d0ad
|
39 |
|
8a2e9c
|
40 |
import com.gitblit.Constants;
|
f98825
|
41 |
import com.gitblit.Constants.AccessRestrictionType;
|
87cc1e
|
42 |
import com.gitblit.GitBlit;
|
155bf7
|
43 |
import com.gitblit.Keys;
|
1f9dae
|
44 |
import com.gitblit.models.Metric;
|
a1ea87
|
45 |
import com.gitblit.models.PathModel;
|
5fe7df
|
46 |
import com.gitblit.utils.JGitUtils;
|
a1ea87
|
47 |
import com.gitblit.utils.MarkdownUtils;
|
424fe1
|
48 |
import com.gitblit.utils.MetricUtils;
|
8a2e9c
|
49 |
import com.gitblit.utils.StringUtils;
|
45c0d6
|
50 |
import com.gitblit.utils.TimeUtils;
|
bc10f9
|
51 |
import com.gitblit.wicket.WicketUtils;
|
698678
|
52 |
import com.gitblit.wicket.panels.BranchesPanel;
|
JM |
53 |
import com.gitblit.wicket.panels.LogPanel;
|
|
54 |
import com.gitblit.wicket.panels.TagsPanel;
|
5fe7df
|
55 |
|
JM |
56 |
public class SummaryPage extends RepositoryPage {
|
|
57 |
|
|
58 |
public SummaryPage(PageParameters params) {
|
cebf45
|
59 |
super(params);
|
155bf7
|
60 |
|
85c2e6
|
61 |
int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
|
fb01c9
|
62 |
if (numberCommits <= 0) {
|
85c2e6
|
63 |
numberCommits = 20;
|
fb01c9
|
64 |
}
|
85c2e6
|
65 |
int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
|
155bf7
|
66 |
|
JM |
67 |
Repository r = getRepository();
|
45c0d6
|
68 |
List<Metric> metrics = null;
|
JM |
69 |
Metric metricsTotal = null;
|
2a7306
|
70 |
if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
|
1fa5e8
|
71 |
metrics = MetricUtils.getDateMetrics(r, null, true, null);
|
45c0d6
|
72 |
metricsTotal = metrics.remove(0);
|
ef5c58
|
73 |
}
|
85c2e6
|
74 |
|
8c9a20
|
75 |
addSyndicationDiscoveryLink();
|
5fe7df
|
76 |
|
JM |
77 |
// repository description
|
f97bf0
|
78 |
add(new Label("repositoryDescription", getRepositoryModel().description));
|
JM |
79 |
add(new Label("repositoryOwner", getRepositoryModel().owner));
|
155bf7
|
80 |
|
88598b
|
81 |
add(WicketUtils.createTimestampLabel("repositoryLastChange",
|
JM |
82 |
JGitUtils.getLastChange(r, null), getTimeZone()));
|
45c0d6
|
83 |
if (metricsTotal == null) {
|
008322
|
84 |
add(new Label("branchStats", ""));
|
45c0d6
|
85 |
} else {
|
008322
|
86 |
add(new Label("branchStats",
|
JM |
87 |
MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count,
|
|
88 |
metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));
|
45c0d6
|
89 |
}
|
008322
|
90 |
add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
|
JM |
91 |
WicketUtils.newRepositoryParameter(repositoryName)));
|
8a2e9c
|
92 |
|
JM |
93 |
List<String> repositoryUrls = new ArrayList<String>();
|
|
94 |
|
2a7306
|
95 |
if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
|
8a2e9c
|
96 |
AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
|
JM |
97 |
switch (accessRestriction) {
|
|
98 |
case NONE:
|
|
99 |
add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
|
100 |
break;
|
|
101 |
case PUSH:
|
2a7306
|
102 |
add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
|
JM |
103 |
getAccessRestrictions().get(accessRestriction)));
|
8a2e9c
|
104 |
break;
|
JM |
105 |
case CLONE:
|
2a7306
|
106 |
add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
|
JM |
107 |
getAccessRestrictions().get(accessRestriction)));
|
8a2e9c
|
108 |
break;
|
JM |
109 |
case VIEW:
|
2a7306
|
110 |
add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
|
JM |
111 |
getAccessRestrictions().get(accessRestriction)));
|
8a2e9c
|
112 |
break;
|
JM |
113 |
default:
|
|
114 |
add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
|
115 |
}
|
|
116 |
StringBuilder sb = new StringBuilder();
|
2179fb
|
117 |
sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest()));
|
5450d0
|
118 |
sb.append(Constants.GIT_PATH);
|
8a2e9c
|
119 |
sb.append(repositoryName);
|
JM |
120 |
repositoryUrls.add(sb.toString());
|
|
121 |
} else {
|
f98825
|
122 |
add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
JM |
123 |
}
|
8a2e9c
|
124 |
repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));
|
JM |
125 |
|
2a7306
|
126 |
add(new Label("repositoryCloneUrl", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
|
JM |
127 |
.setEscapeModelStrings(false));
|
5fe7df
|
128 |
|
ef5c58
|
129 |
add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0));
|
1fa5e8
|
130 |
add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
|
JM |
131 |
add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());
|
155bf7
|
132 |
|
a1ea87
|
133 |
if (getRepositoryModel().showReadme) {
|
JM |
134 |
String htmlText = null;
|
|
135 |
try {
|
|
136 |
RevCommit head = JGitUtils.getCommit(r, null);
|
|
137 |
List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
|
|
138 |
List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
|
|
139 |
String readme = null;
|
|
140 |
for (PathModel path : paths) {
|
|
141 |
if (!path.isTree()) {
|
|
142 |
String name = path.name.toLowerCase();
|
|
143 |
|
|
144 |
if (name.startsWith("readme")) {
|
|
145 |
if (name.indexOf('.') > -1) {
|
|
146 |
String ext = name.substring(name.lastIndexOf('.') + 1);
|
|
147 |
if (markdownExtensions.contains(ext)) {
|
|
148 |
readme = path.name;
|
|
149 |
break;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
}
|
|
153 |
}
|
|
154 |
}
|
|
155 |
if (!StringUtils.isEmpty(readme)) {
|
4ab184
|
156 |
String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme);
|
a1ea87
|
157 |
htmlText = MarkdownUtils.transformMarkdown(markdownText);
|
JM |
158 |
}
|
|
159 |
} catch (ParseException p) {
|
|
160 |
error(p.getMessage());
|
|
161 |
}
|
|
162 |
// Add the html to the page
|
|
163 |
add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible(
|
|
164 |
!StringUtils.isEmpty(htmlText)));
|
|
165 |
} else {
|
|
166 |
add(new Label("readme").setVisible(false));
|
|
167 |
}
|
|
168 |
|
fc8426
|
169 |
// Display an activity line graph
|
ef5c58
|
170 |
insertActivityGraph(metrics);
|
5fe7df
|
171 |
}
|
155bf7
|
172 |
|
cebf45
|
173 |
@Override
|
JM |
174 |
protected String getPageName() {
|
1e47ab
|
175 |
return getString("gb.summary");
|
cebf45
|
176 |
}
|
fc8426
|
177 |
|
ef5c58
|
178 |
private void insertActivityGraph(List<Metric> metrics) {
|
2a7306
|
179 |
if ((metrics != null) && (metrics.size() > 0)
|
JM |
180 |
&& GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
|
f1720c
|
181 |
IChartData data = WicketUtils.getChartData(metrics);
|
fc8426
|
182 |
|
2a7306
|
183 |
ChartProvider provider = new ChartProvider(new Dimension(400, 100), ChartType.LINE,
|
JM |
184 |
data);
|
fc8426
|
185 |
ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
|
2a7306
|
186 |
dateAxis.setLabels(new String[] { metrics.get(0).name,
|
JM |
187 |
metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
|
fc8426
|
188 |
provider.addAxis(dateAxis);
|
JM |
189 |
|
008322
|
190 |
ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
|
a1ea87
|
191 |
commitAxis.setLabels(new String[] { "",
|
JM |
192 |
String.valueOf((int) WicketUtils.maxValue(metrics)) });
|
fc8426
|
193 |
provider.addAxis(commitAxis);
|
8a2e9c
|
194 |
provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });
|
f5d0ad
|
195 |
provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5));
|
8a2e9c
|
196 |
|
fc8426
|
197 |
add(new Chart("commitsChart", provider));
|
JM |
198 |
} else {
|
1e8390
|
199 |
add(WicketUtils.newBlankImage("commitsChart"));
|
fc8426
|
200 |
}
|
JM |
201 |
}
|
5fe7df
|
202 |
}
|