super(wicketId);
final boolean linksActive = enableLinks;
final boolean showSize = app().settings().getBoolean(Keys.web.showRepositorySizes, true);
final UserModel user = GitBlitWebSession.get().getUser();
final IDataProvider<RepositoryModel> dp;
Fragment managementLinks;
if (showAdmin) {
// user is admin
managementLinks = new Fragment("managementPanel", "adminLinks", this);
managementLinks.add(new Link<Void>("clearCache") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
app().repositories().resetRepositoryListCache();
setResponsePage(RepositoriesPage.class);
}
}.setVisible(app().settings().getBoolean(Keys.git.cacheRepositoryList, true)));
managementLinks.add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class));
add(managementLinks);
} else if (showManagement && user != null && user.canCreate()) {
// user can create personal repositories
managementLinks = new Fragment("managementPanel", "personalLinks", this);
managementLinks.add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class));
add(managementLinks);
} else {
// user has no management permissions
add (new Label("managementPanel").setVisible(false));
}
if (app().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) {
List<RepositoryModel> rootRepositories = new ArrayList<RepositoryModel>();
Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>();
for (RepositoryModel model : models) {
String rootPath = StringUtils.getRootPath(model.name);
if (StringUtils.isEmpty(rootPath)) {
// root repository
rootRepositories.add(model);
} else {
// non-root, grouped repository
if (!groups.containsKey(rootPath)) {
groups.put(rootPath, new ArrayList<RepositoryModel>());
}
groups.get(rootPath).add(model);
}
}
List<String> roots = new ArrayList<String>(groups.keySet());
Collections.sort(roots);
if (rootRepositories.size() > 0) {
// inject the root repositories at the top of the page
roots.add(0, "");
groups.put("", rootRepositories);
}
List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();
for (String root : roots) {
List<RepositoryModel> subModels = groups.get(root);
ProjectModel project = app().projects().getProjectModel(root);
GroupRepositoryModel group = new GroupRepositoryModel(project == null ? root : project.name, subModels.size());
if (project != null) {
group.title = project.title;
group.description = project.description;
}
groupedModels.add(group);
Collections.sort(subModels);
groupedModels.addAll(subModels);
}
dp = new RepositoriesProvider(groupedModels);
} else {
dp = new SortableRepositoriesProvider(models);
}
final String baseUrl = WicketUtils.getGitblitURL(getRequest());
final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true);
DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("row", dp) {
private static final long serialVersionUID = 1L;
int counter;
String currGroupName;
@Override
protected void onBeforeRender() {
super.onBeforeRender();
counter = 0;
}
@Override
public void populateItem(final Item<RepositoryModel> item) {
final RepositoryModel entry = item.getModelObject();
if (entry instanceof GroupRepositoryModel) {
GroupRepositoryModel groupRow = (GroupRepositoryModel) entry;
currGroupName = entry.name;
Fragment row = new Fragment("rowContent", "groupRepositoryRow", this);
item.add(row);
String name = groupRow.name;
if (name.startsWith(ModelUtils.getUserRepoPrefix())) {
// user page
String username = ModelUtils.getUserNameFromRepoPath(name);
UserModel user = app().users().getUserModel(username);
row.add(new LinkPanel("groupName", null, (user == null ? username : user.getDisplayName()) + " (" + groupRow.count + ")", UserPage.class, WicketUtils.newUsernameParameter(username)));
row.add(new Label("groupDescription", getString("gb.personalRepositories")));
} else {
// project page
row.add(new LinkPanel("groupName", null, groupRow.toString(), ProjectPage.class, WicketUtils.newProjectParameter(entry.name)));
row.add(new Label("groupDescription", entry.description == null ? "":entry.description));
}
WicketUtils.setCssClass(item, "group");
// reset counter so that first row is light background
counter = 0;
return;
}
Fragment row = new Fragment("rowContent", "repositoryRow", this);
item.add(row);
// try to strip group name for less cluttered list
String repoName = entry.toString();
if (!StringUtils.isEmpty(currGroupName) && (repoName.indexOf('/') > -1)) {
repoName = repoName.substring(currGroupName.length() + 1);
}
// repository swatch
Component swatch;
if (entry.isBare){
swatch = new Label("repositorySwatch", " ").setEscapeModelStrings(false);
} else {
swatch = new Label("repositorySwatch", "!");
WicketUtils.setHtmlTooltip(swatch, getString("gb.workingCopyWarning"));
}
WicketUtils.setCssBackground(swatch, entry.toString());
row.add(swatch);
swatch.setVisible(showSwatch);
if (linksActive) {
Class<? extends BasePage> linkPage;
if (entry.hasCommits) {
// repository has content
linkPage = SummaryPage.class;
} else {
// new/empty repository OR proposed repository
linkPage = EmptyRepositoryPage.class;
}
PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);
row.add(new LinkPanel("repositoryName", "list", repoName, linkPage, pp));
row.add(new LinkPanel("repositoryDescription", "list", entry.description,
linkPage, pp));
} else {
// no links like on a federation page
row.add(new Label("repositoryName", repoName));
row.add(new Label("repositoryDescription", entry.description));
}
if (entry.hasCommits) {
// Existing repository
row.add(new Label("repositorySize", entry.size).setVisible(showSize));
} else {
// New repository
row.add(new Label("repositorySize", "<span class='empty'>(" + getString("gb.empty") + ")</span>")
.setEscapeModelStrings(false));
}
if (entry.isSparkleshared()) {
row.add(WicketUtils.newImage("sparkleshareIcon", "star_16x16.png",
getString("gb.isSparkleshared")));
} else {
row.add(WicketUtils.newClearPixel("sparkleshareIcon").setVisible(false));
}
if (entry.isMirror) {
row.add(WicketUtils.newImage("mirrorIcon", "mirror_16x16.png",
getString("gb.isMirror")));
} else {
row.add(WicketUtils.newClearPixel("mirrorIcon").setVisible(false));
}
if (entry.isFork()) {
row.add(WicketUtils.newImage("forkIcon", "commit_divide_16x16.png",
getString("gb.isFork")));
} else {
row.add(WicketUtils.newClearPixel("forkIcon").setVisible(false));
}
if (entry.isFrozen) {
row.add(WicketUtils.newImage("frozenIcon", "cold_16x16.png",
getString("gb.isFrozen")));
} else {
row.add(WicketUtils.newClearPixel("frozenIcon").setVisible(false));
}
if (entry.isFederated) {
row.add(WicketUtils.newImage("federatedIcon", "federated_16x16.png",
getString("gb.isFederated")));
} else {
row.add(WicketUtils.newClearPixel("federatedIcon").setVisible(false));
}
switch (entry.accessRestriction) {
case NONE:
row.add(WicketUtils.newBlankImage("accessRestrictionIcon"));
break;
case PUSH:
row.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
accessRestrictionTranslations.get(entry.accessRestriction)));
break;
case CLONE:
row.add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
accessRestrictionTranslations.get(entry.accessRestriction)));
break;
case VIEW:
row.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
accessRestrictionTranslations.get(entry.accessRestriction)));
break;
default:
row.add(WicketUtils.newBlankImage("accessRestrictionIcon"));
}
String owner = "";
if (!ArrayUtils.isEmpty(entry.owners)) {
// display first owner
for (String username : entry.owners) {
UserModel ownerModel = app().users().getUserModel(username);
if (ownerModel != null) {
owner = ownerModel.getDisplayName();
break;
}
}
if (entry.owners.size() > 1) {
owner += ", ...";