From a1ea877042b93949ef244b96e8affd65cc3f89c1 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Wed, 01 Jun 2011 20:19:51 -0400 Subject: [PATCH] Readme markdown on summary page per-repository. --- src/com/gitblit/wicket/panels/RepositoriesPanel.java | 111 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 76 insertions(+), 35 deletions(-) diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/com/gitblit/wicket/panels/RepositoriesPanel.java index c141379..a0c9e13 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.gitblit.wicket.panels; import java.text.MessageFormat; @@ -28,13 +43,12 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; import com.gitblit.wicket.GitBlitWebSession; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.UserModel; import com.gitblit.wicket.pages.EditRepositoryPage; import com.gitblit.wicket.pages.SummaryPage; @@ -42,7 +56,8 @@ private static final long serialVersionUID = 1L; - public RepositoriesPanel(String wicketId, final boolean showAdmin, final Map<AccessRestrictionType, String> accessRestrictionTranslations) { + public RepositoriesPanel(String wicketId, final boolean showAdmin, + final Map<AccessRestrictionType, String> accessRestrictionTranslations) { super(wicketId); final UserModel user = GitBlitWebSession.get().getUser(); @@ -53,12 +68,12 @@ adminLinks.add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class)); add(adminLinks.setVisible(showAdmin)); - if (GitBlit.self().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) { + if (GitBlit.getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) { Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>(); for (RepositoryModel model : models) { String rootPath = StringUtils.getRootPath(model.name); if (StringUtils.isEmpty(rootPath)) { - rootPath = GitBlit.self().settings().getString(Keys.web.repositoryRootGroupName, " "); + rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " "); } if (!groups.containsKey(rootPath)) { groups.put(rootPath, new ArrayList<RepositoryModel>()); @@ -80,7 +95,7 @@ DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("row", dp) { private static final long serialVersionUID = 1L; - int counter = 0; + int counter; @Override protected void onBeforeRender() { @@ -102,28 +117,34 @@ if (entry.hasCommits) { // Existing repository PageParameters pp = WicketUtils.newRepositoryParameter(entry.name); - row.add(new LinkPanel("repositoryName", "list", entry.name, SummaryPage.class, pp)); - row.add(new LinkPanel("repositoryDescription", "list", entry.description, SummaryPage.class, pp)); + row.add(new LinkPanel("repositoryName", "list", entry.name, SummaryPage.class, + pp)); + row.add(new LinkPanel("repositoryDescription", "list", entry.description, + SummaryPage.class, pp)); } else { // New repository - row.add(new Label("repositoryName", entry.name + "<span class='empty'>(empty)</span>").setEscapeModelStrings(false)); + row.add(new Label("repositoryName", entry.name + + "<span class='empty'>(empty)</span>").setEscapeModelStrings(false)); row.add(new Label("repositoryDescription", entry.description)); } if (entry.useTickets) { - row.add(WicketUtils.newImage("ticketsIcon", "bug_16x16.png", getString("gb.tickets"))); + row.add(WicketUtils.newImage("ticketsIcon", "bug_16x16.png", + getString("gb.tickets"))); } else { row.add(WicketUtils.newBlankImage("ticketsIcon")); } if (entry.useDocs) { - row.add(WicketUtils.newImage("docsIcon", "book_16x16.png", getString("gb.docs"))); + row.add(WicketUtils + .newImage("docsIcon", "book_16x16.png", getString("gb.docs"))); } else { row.add(WicketUtils.newBlankImage("docsIcon")); } if (entry.isFrozen) { - row.add(WicketUtils.newImage("frozenIcon", "cold_16x16.png", getString("gb.isFrozen"))); + row.add(WicketUtils.newImage("frozenIcon", "cold_16x16.png", + getString("gb.isFrozen"))); } else { row.add(WicketUtils.newClearPixel("frozenIcon").setVisible(false)); } @@ -132,13 +153,16 @@ row.add(WicketUtils.newBlankImage("accessRestrictionIcon")); break; case PUSH: - row.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png", accessRestrictionTranslations.get(entry.accessRestriction))); + 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))); + 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))); + row.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png", + accessRestrictionTranslations.get(entry.accessRestriction))); break; default: row.add(WicketUtils.newBlankImage("accessRestrictionIcon")); @@ -151,10 +175,13 @@ row.add(lastChangeLabel); WicketUtils.setCssClass(lastChangeLabel, TimeUtils.timeAgoCss(entry.lastChange)); - boolean showOwner = user != null && user.getUsername().equalsIgnoreCase(entry.owner); + boolean showOwner = user != null && user.username.equalsIgnoreCase(entry.owner); if (showAdmin) { - Fragment repositoryLinks = new Fragment("repositoryLinks", "repositoryAdminLinks", this); - repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", EditRepositoryPage.class, WicketUtils.newRepositoryParameter(entry.name))); + Fragment repositoryLinks = new Fragment("repositoryLinks", + "repositoryAdminLinks", this); + repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", + EditRepositoryPage.class, WicketUtils + .newRepositoryParameter(entry.name))); Link<Void> deleteLink = new Link<Void>("deleteRepository") { private static final long serialVersionUID = 1L; @@ -169,16 +196,21 @@ ((RepositoriesProvider) dp).remove(entry); } } else { - error(MessageFormat.format("Failed to delete repository ''{0}''!", entry)); + error(MessageFormat.format("Failed to delete repository ''{0}''!", + entry)); } } }; - deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format("Delete repository \"{0}\"?", entry))); + deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format( + "Delete repository \"{0}\"?", entry))); repositoryLinks.add(deleteLink); row.add(repositoryLinks); } else if (showOwner) { - Fragment repositoryLinks = new Fragment("repositoryLinks", "repositoryOwnerLinks", this); - repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", EditRepositoryPage.class, WicketUtils.newRepositoryParameter(entry.name))); + Fragment repositoryLinks = new Fragment("repositoryLinks", + "repositoryOwnerLinks", this); + repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", + EditRepositoryPage.class, WicketUtils + .newRepositoryParameter(entry.name))); row.add(repositoryLinks); } else { row.add(new Label("repositoryLinks")); @@ -205,11 +237,11 @@ } } - private class GroupRepositoryModel extends RepositoryModel { + private static class GroupRepositoryModel extends RepositoryModel { private static final long serialVersionUID = 1L; - int count = 0; + int count; GroupRepositoryModel(String name, int count) { super(name, "", "", new Date(0)); @@ -226,7 +258,8 @@ repository, description, owner, date; } - protected OrderByBorder newSort(String wicketId, SortBy field, SortableDataProvider<?> dp, final DataView<?> dataView) { + protected OrderByBorder newSort(String wicketId, SortBy field, SortableDataProvider<?> dp, + final DataView<?> dataView) { return new OrderByBorder(wicketId, field.name(), dp) { private static final long serialVersionUID = 1L; @@ -237,7 +270,7 @@ }; } - private class RepositoriesProvider extends ListDataProvider<RepositoryModel> { + private static class RepositoriesProvider extends ListDataProvider<RepositoryModel> { private static final long serialVersionUID = 1L; @@ -264,7 +297,8 @@ } } else if (index < (getData().size() - 1)) { // not last element. check next element for group match. - if (getData().get(index - 1) instanceof GroupRepositoryModel && getData().get(index + 1) instanceof GroupRepositoryModel) { + if (getData().get(index - 1) instanceof GroupRepositoryModel + && getData().get(index + 1) instanceof GroupRepositoryModel) { // repository is sandwiched by group headers so this // repository is the only element in the group. remove // group. @@ -289,9 +323,11 @@ } } - private class SortableRepositoriesProvider extends SortableDataProvider<RepositoryModel> { + private static class SortableRepositoriesProvider extends SortableDataProvider<RepositoryModel> { + private static final long serialVersionUID = 1L; - private List<RepositoryModel> list = null; + + private List<RepositoryModel> list; protected SortableRepositoriesProvider(List<RepositoryModel> list) { this.list = list; @@ -304,8 +340,9 @@ @Override public int size() { - if (list == null) + if (list == null) { return 0; + } return list.size(); } @@ -324,8 +361,9 @@ Collections.sort(list, new Comparator<RepositoryModel>() { @Override public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) + if (asc) { return o1.lastChange.compareTo(o2.lastChange); + } return o2.lastChange.compareTo(o1.lastChange); } }); @@ -333,8 +371,9 @@ Collections.sort(list, new Comparator<RepositoryModel>() { @Override public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) + if (asc) { return o1.name.compareTo(o2.name); + } return o2.name.compareTo(o1.name); } }); @@ -342,8 +381,9 @@ Collections.sort(list, new Comparator<RepositoryModel>() { @Override public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) + if (asc) { return o1.owner.compareTo(o2.owner); + } return o2.owner.compareTo(o1.owner); } }); @@ -351,8 +391,9 @@ Collections.sort(list, new Comparator<RepositoryModel>() { @Override public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) + if (asc) { return o1.description.compareTo(o2.description); + } return o2.description.compareTo(o1.description); } }); -- Gitblit v1.9.1