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.pages;
|
|
17 |
|
e94078
|
18 |
import java.io.Serializable;
|
1e1b85
|
19 |
import java.util.ArrayList;
|
JM |
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.apache.wicket.Component;
|
|
23 |
import org.apache.wicket.PageParameters;
|
|
24 |
import org.apache.wicket.markup.html.basic.Label;
|
|
25 |
import org.apache.wicket.markup.repeater.Item;
|
|
26 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
27 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
28 |
import org.eclipse.jgit.lib.PersonIdent;
|
|
29 |
|
|
30 |
import com.gitblit.Keys;
|
e94078
|
31 |
import com.gitblit.models.ForkModel;
|
1e1b85
|
32 |
import com.gitblit.models.RepositoryModel;
|
JM |
33 |
import com.gitblit.models.UserModel;
|
|
34 |
import com.gitblit.utils.StringUtils;
|
|
35 |
import com.gitblit.wicket.GitBlitWebSession;
|
|
36 |
import com.gitblit.wicket.WicketUtils;
|
b57b9e
|
37 |
import com.gitblit.wicket.panels.AvatarImage;
|
1e1b85
|
38 |
import com.gitblit.wicket.panels.LinkPanel;
|
JM |
39 |
|
|
40 |
public class ForksPage extends RepositoryPage {
|
|
41 |
|
|
42 |
public ForksPage(PageParameters params) {
|
|
43 |
super(params);
|
699e71
|
44 |
|
e94078
|
45 |
final RepositoryModel pageRepository = getRepositoryModel();
|
699e71
|
46 |
|
99d0d4
|
47 |
ForkModel root = app().repositories().getForkNetwork(pageRepository.name);
|
e94078
|
48 |
List<FlatFork> network = flatten(root);
|
699e71
|
49 |
|
e94078
|
50 |
ListDataProvider<FlatFork> forksDp = new ListDataProvider<FlatFork>(network);
|
JM |
51 |
DataView<FlatFork> forksList = new DataView<FlatFork>("fork", forksDp) {
|
1e1b85
|
52 |
private static final long serialVersionUID = 1L;
|
JM |
53 |
|
699e71
|
54 |
@Override
|
e94078
|
55 |
public void populateItem(final Item<FlatFork> item) {
|
JM |
56 |
FlatFork fork = item.getModelObject();
|
|
57 |
RepositoryModel repository = fork.repository;
|
699e71
|
58 |
|
e94078
|
59 |
if (repository.isPersonalRepository()) {
|
99d0d4
|
60 |
UserModel user = app().users().getUserModel(repository.projectPath.substring(1));
|
89e54f
|
61 |
if (user == null) {
|
JM |
62 |
// user account no longer exists
|
|
63 |
user = new UserModel(repository.projectPath.substring(1));
|
|
64 |
}
|
b461a4
|
65 |
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
|
b57b9e
|
66 |
item.add(new AvatarImage("anAvatar", ident, 20));
|
e94078
|
67 |
if (pageRepository.equals(repository)) {
|
JM |
68 |
// do not link to self
|
|
69 |
item.add(new Label("aProject", user.getDisplayName()));
|
|
70 |
} else {
|
|
71 |
item.add(new LinkPanel("aProject", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(user.username)));
|
|
72 |
}
|
1e1b85
|
73 |
} else {
|
e94078
|
74 |
Component swatch;
|
JM |
75 |
if (repository.isBare){
|
|
76 |
swatch = new Label("anAvatar", " ").setEscapeModelStrings(false);
|
|
77 |
} else {
|
|
78 |
swatch = new Label("anAvatar", "!");
|
|
79 |
WicketUtils.setHtmlTooltip(swatch, getString("gb.workingCopyWarning"));
|
|
80 |
}
|
|
81 |
WicketUtils.setCssClass(swatch, "repositorySwatch");
|
|
82 |
WicketUtils.setCssBackground(swatch, repository.toString());
|
|
83 |
item.add(swatch);
|
|
84 |
String projectName = repository.projectPath;
|
|
85 |
if (StringUtils.isEmpty(projectName)) {
|
99d0d4
|
86 |
projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main");
|
e94078
|
87 |
}
|
JM |
88 |
if (pageRepository.equals(repository)) {
|
|
89 |
// do not link to self
|
|
90 |
item.add(new Label("aProject", projectName));
|
|
91 |
} else {
|
|
92 |
item.add(new LinkPanel("aProject", null, projectName, ProjectPage.class, WicketUtils.newProjectParameter(projectName)));
|
|
93 |
}
|
1e1b85
|
94 |
}
|
699e71
|
95 |
|
e94078
|
96 |
String repo = StringUtils.getLastPathElement(repository.name);
|
JM |
97 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
98 |
if (user == null) {
|
|
99 |
user = UserModel.ANONYMOUS;
|
|
100 |
}
|
20714a
|
101 |
if (user.canView(repository)) {
|
e94078
|
102 |
if (pageRepository.equals(repository)) {
|
JM |
103 |
// do not link to self
|
|
104 |
item.add(new Label("aFork", StringUtils.stripDotGit(repo)));
|
|
105 |
} else {
|
|
106 |
item.add(new LinkPanel("aFork", null, StringUtils.stripDotGit(repo), SummaryPage.class, WicketUtils.newRepositoryParameter(repository.name)));
|
|
107 |
}
|
|
108 |
item.add(WicketUtils.createDateLabel("lastChange", repository.lastChange, getTimeZone(), getTimeUtils()));
|
d683dd
|
109 |
} else {
|
e94078
|
110 |
item.add(new Label("aFork", repo));
|
JM |
111 |
item.add(new Label("lastChange").setVisible(false));
|
|
112 |
}
|
699e71
|
113 |
|
e94078
|
114 |
WicketUtils.setCssStyle(item, "margin-left:" + (32*fork.level) + "px;");
|
JM |
115 |
if (fork.level == 0) {
|
|
116 |
WicketUtils.setCssClass(item, "forkSource");
|
|
117 |
} else {
|
|
118 |
WicketUtils.setCssClass(item, "forkEntry");
|
d683dd
|
119 |
}
|
1e1b85
|
120 |
}
|
JM |
121 |
};
|
699e71
|
122 |
|
1e1b85
|
123 |
add(forksList);
|
JM |
124 |
}
|
|
125 |
|
|
126 |
@Override
|
|
127 |
protected String getPageName() {
|
|
128 |
return getString("gb.forks");
|
|
129 |
}
|
699e71
|
130 |
|
e94078
|
131 |
protected List<FlatFork> flatten(ForkModel root) {
|
JM |
132 |
List<FlatFork> list = new ArrayList<FlatFork>();
|
|
133 |
list.addAll(flatten(root, 0));
|
|
134 |
return list;
|
|
135 |
}
|
699e71
|
136 |
|
e94078
|
137 |
protected List<FlatFork> flatten(ForkModel node, int level) {
|
JM |
138 |
List<FlatFork> list = new ArrayList<FlatFork>();
|
def01d
|
139 |
if (node == null) {
|
JM |
140 |
return list;
|
|
141 |
}
|
e94078
|
142 |
list.add(new FlatFork(node.repository, level));
|
JM |
143 |
if (!node.isLeaf()) {
|
|
144 |
for (ForkModel fork : node.forks) {
|
|
145 |
list.addAll(flatten(fork, level + 1));
|
|
146 |
}
|
|
147 |
}
|
|
148 |
return list;
|
|
149 |
}
|
699e71
|
150 |
|
e94078
|
151 |
private class FlatFork implements Serializable {
|
699e71
|
152 |
|
e94078
|
153 |
private static final long serialVersionUID = 1L;
|
JM |
154 |
|
|
155 |
public final RepositoryModel repository;
|
|
156 |
public final int level;
|
699e71
|
157 |
|
e94078
|
158 |
public FlatFork(RepositoryModel repository, int level) {
|
JM |
159 |
this.repository = repository;
|
|
160 |
this.level = level;
|
|
161 |
}
|
|
162 |
}
|
1e1b85
|
163 |
}
|