commit | author | age
|
1e1b85
|
1 |
/*
|
JM |
2 |
* Copyright 2012 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.MessageFormat;
|
|
19 |
import java.util.Map;
|
|
20 |
|
|
21 |
import org.apache.wicket.Component;
|
|
22 |
import org.apache.wicket.Localizer;
|
|
23 |
import org.apache.wicket.PageParameters;
|
|
24 |
import org.apache.wicket.markup.html.basic.Label;
|
|
25 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
|
26 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
|
27 |
import org.apache.wicket.markup.html.link.Link;
|
|
28 |
import org.apache.wicket.markup.html.panel.Fragment;
|
|
29 |
|
|
30 |
import com.gitblit.Constants.AccessRestrictionType;
|
|
31 |
import com.gitblit.GitBlit;
|
|
32 |
import com.gitblit.Keys;
|
|
33 |
import com.gitblit.SyndicationServlet;
|
|
34 |
import com.gitblit.models.RepositoryModel;
|
|
35 |
import com.gitblit.models.UserModel;
|
|
36 |
import com.gitblit.utils.ArrayUtils;
|
|
37 |
import com.gitblit.utils.StringUtils;
|
|
38 |
import com.gitblit.wicket.GitBlitWebSession;
|
|
39 |
import com.gitblit.wicket.WicketUtils;
|
|
40 |
import com.gitblit.wicket.pages.DocsPage;
|
|
41 |
import com.gitblit.wicket.pages.EditRepositoryPage;
|
|
42 |
import com.gitblit.wicket.pages.LogPage;
|
|
43 |
import com.gitblit.wicket.pages.SummaryPage;
|
|
44 |
import com.gitblit.wicket.pages.TreePage;
|
|
45 |
|
|
46 |
public class ProjectRepositoryPanel extends BasePanel {
|
|
47 |
|
|
48 |
private static final long serialVersionUID = 1L;
|
|
49 |
|
fb6bf3
|
50 |
public ProjectRepositoryPanel(String wicketId, Localizer localizer, Component parent,
|
1e1b85
|
51 |
final boolean isAdmin, final RepositoryModel entry,
|
JM |
52 |
final Map<AccessRestrictionType, String> accessRestrictions) {
|
|
53 |
super(wicketId);
|
|
54 |
|
|
55 |
final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);
|
|
56 |
final boolean showSize = GitBlit.getBoolean(Keys.web.showRepositorySizes, true);
|
|
57 |
|
|
58 |
// repository swatch
|
|
59 |
Component swatch;
|
|
60 |
if (entry.isBare) {
|
|
61 |
swatch = new Label("repositorySwatch", " ").setEscapeModelStrings(false);
|
|
62 |
} else {
|
|
63 |
swatch = new Label("repositorySwatch", "!");
|
fb6bf3
|
64 |
WicketUtils.setHtmlTooltip(swatch, localizer.getString("gb.workingCopyWarning", parent));
|
1e1b85
|
65 |
}
|
JM |
66 |
WicketUtils.setCssBackground(swatch, entry.toString());
|
|
67 |
add(swatch);
|
|
68 |
swatch.setVisible(showSwatch);
|
|
69 |
|
|
70 |
PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);
|
|
71 |
add(new LinkPanel("repositoryName", "list", StringUtils.getRelativePath(entry.projectPath,
|
|
72 |
StringUtils.stripDotGit(entry.name)), SummaryPage.class, pp));
|
|
73 |
add(new Label("repositoryDescription", entry.description).setVisible(!StringUtils
|
|
74 |
.isEmpty(entry.description)));
|
|
75 |
|
|
76 |
if (StringUtils.isEmpty(entry.originRepository)) {
|
|
77 |
add(new Label("originRepository").setVisible(false));
|
|
78 |
} else {
|
|
79 |
Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
|
5dd805
|
80 |
forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(entry.originRepository),
|
1e1b85
|
81 |
SummaryPage.class, WicketUtils.newRepositoryParameter(entry.originRepository)));
|
JM |
82 |
add(forkFrag);
|
|
83 |
}
|
|
84 |
|
e4e682
|
85 |
if (entry.isSparkleshared()) {
|
JM |
86 |
add(WicketUtils.newImage("sparkleshareIcon", "star_16x16.png", localizer.getString("gb.isSparkleshared", parent)));
|
|
87 |
} else {
|
|
88 |
add(WicketUtils.newClearPixel("sparkleshareIcon").setVisible(false));
|
|
89 |
}
|
|
90 |
|
1e1b85
|
91 |
add(new BookmarkablePageLink<Void>("docs", DocsPage.class, pp).setVisible(entry.useDocs));
|
JM |
92 |
|
|
93 |
if (entry.isFrozen) {
|
fb6bf3
|
94 |
add(WicketUtils.newImage("frozenIcon", "cold_16x16.png", localizer.getString("gb.isFrozen", parent)));
|
1e1b85
|
95 |
} else {
|
JM |
96 |
add(WicketUtils.newClearPixel("frozenIcon").setVisible(false));
|
|
97 |
}
|
|
98 |
|
|
99 |
if (entry.isFederated) {
|
fb6bf3
|
100 |
add(WicketUtils.newImage("federatedIcon", "federated_16x16.png", localizer.getString("gb.isFederated", parent)));
|
1e1b85
|
101 |
} else {
|
JM |
102 |
add(WicketUtils.newClearPixel("federatedIcon").setVisible(false));
|
|
103 |
}
|
|
104 |
|
661db6
|
105 |
if (ArrayUtils.isEmpty(entry.owners)) {
|
fb6bf3
|
106 |
add(new Label("repositoryOwner").setVisible(false));
|
JM |
107 |
} else {
|
661db6
|
108 |
String owner = "";
|
JM |
109 |
for (String username : entry.owners) {
|
|
110 |
UserModel ownerModel = GitBlit.self().getUserModel(username);
|
5dd805
|
111 |
|
661db6
|
112 |
if (ownerModel != null) {
|
JM |
113 |
owner = ownerModel.getDisplayName();
|
5dd805
|
114 |
}
|
fb6bf3
|
115 |
}
|
661db6
|
116 |
if (entry.owners.size() > 1) {
|
JM |
117 |
owner += ", ...";
|
|
118 |
}
|
|
119 |
Label ownerLabel = (new Label("repositoryOwner", owner + " (" +
|
fb6bf3
|
120 |
localizer.getString("gb.owner", parent) + ")"));
|
661db6
|
121 |
WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners));
|
JM |
122 |
add(ownerLabel);
|
fb6bf3
|
123 |
}
|
1e1b85
|
124 |
|
JM |
125 |
UserModel user = GitBlitWebSession.get().getUser();
|
ec0ce1
|
126 |
if (user == null) {
|
JM |
127 |
user = UserModel.ANONYMOUS;
|
|
128 |
}
|
1e1b85
|
129 |
Fragment repositoryLinks;
|
ec0ce1
|
130 |
boolean showOwner = entry.isOwner(user.username);
|
1e1b85
|
131 |
// owner of personal repository gets admin powers
|
JM |
132 |
boolean showAdmin = isAdmin || entry.isUsersPersonalRepository(user.username);
|
|
133 |
|
|
134 |
if (showAdmin || showOwner) {
|
|
135 |
repositoryLinks = new Fragment("repositoryLinks", showAdmin ? "repositoryAdminLinks"
|
|
136 |
: "repositoryOwnerLinks", this);
|
|
137 |
repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", EditRepositoryPage.class,
|
|
138 |
WicketUtils.newRepositoryParameter(entry.name)));
|
|
139 |
if (showAdmin) {
|
|
140 |
Link<Void> deleteLink = new Link<Void>("deleteRepository") {
|
|
141 |
|
|
142 |
private static final long serialVersionUID = 1L;
|
|
143 |
|
|
144 |
@Override
|
|
145 |
public void onClick() {
|
|
146 |
if (GitBlit.self().deleteRepositoryModel(entry)) {
|
0c7c49
|
147 |
// redirect to the owning page
|
JM |
148 |
if (entry.isPersonalRepository()) {
|
|
149 |
setResponsePage(getPage().getClass(), WicketUtils.newUsernameParameter(entry.projectPath.substring(1)));
|
|
150 |
} else {
|
|
151 |
setResponsePage(getPage().getClass(), WicketUtils.newProjectParameter(entry.projectPath));
|
|
152 |
}
|
1e1b85
|
153 |
} else {
|
JM |
154 |
error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
|
|
155 |
}
|
|
156 |
}
|
|
157 |
};
|
|
158 |
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
|
fb6bf3
|
159 |
localizer.getString("gb.deleteRepository", parent), entry)));
|
1e1b85
|
160 |
repositoryLinks.add(deleteLink);
|
JM |
161 |
}
|
|
162 |
} else {
|
|
163 |
repositoryLinks = new Fragment("repositoryLinks", "repositoryUserLinks", this);
|
|
164 |
}
|
|
165 |
|
|
166 |
repositoryLinks.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
167 |
.newRepositoryParameter(entry.name)).setEnabled(entry.hasCommits));
|
|
168 |
|
|
169 |
repositoryLinks.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
|
|
170 |
.newRepositoryParameter(entry.name)).setEnabled(entry.hasCommits));
|
|
171 |
|
|
172 |
add(repositoryLinks);
|
|
173 |
|
|
174 |
String lastChange;
|
|
175 |
if (entry.lastChange.getTime() == 0) {
|
|
176 |
lastChange = "--";
|
|
177 |
} else {
|
|
178 |
lastChange = getTimeUtils().timeAgo(entry.lastChange);
|
|
179 |
}
|
|
180 |
Label lastChangeLabel = new Label("repositoryLastChange", lastChange);
|
|
181 |
add(lastChangeLabel);
|
|
182 |
WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
|
|
183 |
|
|
184 |
if (entry.hasCommits) {
|
|
185 |
// Existing repository
|
|
186 |
add(new Label("repositorySize", entry.size).setVisible(showSize));
|
|
187 |
} else {
|
|
188 |
// New repository
|
fb6bf3
|
189 |
add(new Label("repositorySize", localizer.getString("gb.empty", parent)).setEscapeModelStrings(false));
|
1e1b85
|
190 |
}
|
JM |
191 |
|
|
192 |
add(new ExternalLink("syndication", SyndicationServlet.asLink("", entry.name, null, 0)));
|
|
193 |
}
|
|
194 |
}
|