| | |
| | | */
|
| | | package com.gitblit.wicket.panels;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.wicket.Component;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByBorder;
|
| | | import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
|
| | | import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.markup.html.link.ExternalLink;
|
| | | import org.apache.wicket.markup.html.link.Link;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.markup.repeater.Item;
|
| | |
| | | import org.apache.wicket.model.Model;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.models.ProjectModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.ModelUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.pages.BasePage;
|
| | | import com.gitblit.wicket.pages.EditRepositoryPage;
|
| | | import com.gitblit.wicket.pages.EmptyRepositoryPage;
|
| | | import com.gitblit.wicket.pages.ProjectPage;
|
| | | import com.gitblit.wicket.pages.RepositoriesPage;
|
| | | import com.gitblit.wicket.pages.SummaryPage;
|
| | |
| | | super(wicketId);
|
| | |
|
| | | final boolean linksActive = enableLinks;
|
| | | final boolean showSize = GitBlit.getBoolean(Keys.web.showRepositorySizes, true);
|
| | | final boolean showSize = app().settings().getBoolean(Keys.web.showRepositorySizes, true);
|
| | |
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | |
|
| | |
| | |
|
| | | @Override
|
| | | public void onClick() {
|
| | | GitBlit.self().resetRepositoryListCache();
|
| | | app().repositories().resetRepositoryListCache();
|
| | | setResponsePage(RepositoriesPage.class);
|
| | | }
|
| | | }.setVisible(GitBlit.getBoolean(Keys.git.cacheRepositoryList, true)));
|
| | | managementLinks.add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class));
|
| | | }.setVisible(app().settings().getBoolean(Keys.git.cacheRepositoryList, true)));
|
| | | managementLinks.add(new BookmarkablePageLink<Void>("newRepository", app().getNewRepositoryPage()));
|
| | | 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));
|
| | | managementLinks.add(new BookmarkablePageLink<Void>("newRepository", app().getNewRepositoryPage()));
|
| | | add(managementLinks);
|
| | | } else {
|
| | | // user has no management permissions
|
| | | add (new Label("managementPanel").setVisible(false));
|
| | | }
|
| | |
|
| | | if (GitBlit.getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) {
|
| | | 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) {
|
| | |
| | | roots.add(0, "");
|
| | | groups.put("", rootRepositories);
|
| | | }
|
| | | |
| | |
|
| | | List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();
|
| | | for (String root : roots) {
|
| | | List<RepositoryModel> subModels = groups.get(root);
|
| | | ProjectModel project = GitBlit.self().getProjectModel(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;
|
| | |
| | | Collections.sort(subModels);
|
| | | groupedModels.addAll(subModels);
|
| | | }
|
| | | dp = new RepositoriesProvider(groupedModels);
|
| | | dp = new ListDataProvider<RepositoryModel>(groupedModels);
|
| | | } else {
|
| | | dp = new SortableRepositoriesProvider(models);
|
| | | }
|
| | |
|
| | | final String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
| | | final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);
|
| | | |
| | | 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;
|
| | |
| | | counter = 0;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void populateItem(final Item<RepositoryModel> item) {
|
| | | final RepositoryModel entry = item.getModelObject();
|
| | | if (entry instanceof GroupRepositoryModel) {
|
| | |
| | | currGroupName = entry.name;
|
| | | Fragment row = new Fragment("rowContent", "groupRepositoryRow", this);
|
| | | item.add(row);
|
| | | |
| | |
|
| | | String name = groupRow.name;
|
| | | if (name.charAt(0) == '~') {
|
| | | if (name.startsWith(ModelUtils.getUserRepoPrefix())) {
|
| | | // user page
|
| | | String username = name.substring(1);
|
| | | UserModel user = GitBlit.self().getUserModel(username);
|
| | | 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 {
|
| | |
| | | Fragment row = new Fragment("rowContent", "repositoryRow", this);
|
| | | item.add(row);
|
| | |
|
| | | // show colored repository type icon
|
| | | Fragment iconFragment;
|
| | | if (entry.isMirror) {
|
| | | iconFragment = new Fragment("repoIcon", "mirrorIconFragment", this);
|
| | | } else if (entry.isFork()) {
|
| | | iconFragment = new Fragment("repoIcon", "forkIconFragment", this);
|
| | | } else if (entry.isBare) {
|
| | | iconFragment = new Fragment("repoIcon", "repoIconFragment", this);
|
| | | } else {
|
| | | iconFragment = new Fragment("repoIcon", "cloneIconFragment", this);
|
| | | }
|
| | | if (showSwatch) {
|
| | | WicketUtils.setCssStyle(iconFragment, "color:" + StringUtils.getColor(entry.toString()));
|
| | | }
|
| | | row.add(iconFragment);
|
| | |
|
| | | // 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;
|
| | | }
|
| | |
|
| | | Class<? extends BasePage> linkPage = SummaryPage.class;
|
| | | PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);
|
| | | row.add(new LinkPanel("repositoryName", "list", repoName, linkPage, pp));
|
| | | row.add(new LinkPanel("repositoryDescription", "list", entry.description,
|
| | |
| | | } else {
|
| | | row.add(WicketUtils.newClearPixel("sparkleshareIcon").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.useTickets) {
|
| | | 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")));
|
| | | } else {
|
| | | row.add(WicketUtils.newBlankImage("docsIcon"));
|
| | | }
|
| | |
|
| | | if (entry.isFrozen) {
|
| | | if (!entry.isMirror && entry.isFrozen) {
|
| | | row.add(WicketUtils.newImage("frozenIcon", "cold_16x16.png",
|
| | | getString("gb.isFrozen")));
|
| | | } else {
|
| | |
| | | } 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"));
|
| | |
|
| | | if (entry.isMirror) {
|
| | | row.add(WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png",
|
| | | getString("gb.isMirror")));
|
| | | } else {
|
| | | 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 = GitBlit.self().getUserModel(username);
|
| | | UserModel ownerModel = app().users().getUserModel(username);
|
| | | if (ownerModel != null) {
|
| | | owner = ownerModel.getDisplayName();
|
| | | break;
|
| | |
| | | Label lastChangeLabel = new Label("repositoryLastChange", lastChange);
|
| | | row.add(lastChangeLabel);
|
| | | WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
|
| | |
|
| | | boolean showOwner = user != null && entry.isOwner(user.username);
|
| | | boolean myPersonalRepository = showOwner && entry.isUsersPersonalRepository(user.username);
|
| | | if (showAdmin || myPersonalRepository) {
|
| | | 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;
|
| | |
|
| | | @Override
|
| | | public void onClick() {
|
| | | if (GitBlit.self().deleteRepositoryModel(entry)) {
|
| | | if (dp instanceof SortableRepositoriesProvider) {
|
| | | info(MessageFormat.format(getString("gb.repositoryDeleted"), entry));
|
| | | ((SortableRepositoriesProvider) dp).remove(entry);
|
| | | } else {
|
| | | setResponsePage(getPage().getClass(), getPage().getPageParameters());
|
| | | }
|
| | | } else {
|
| | | error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
|
| | | }
|
| | | }
|
| | | };
|
| | | deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
|
| | | getString("gb.deleteRepository"), 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)));
|
| | | row.add(repositoryLinks);
|
| | | } else {
|
| | | row.add(new Label("repositoryLinks"));
|
| | | if (!StringUtils.isEmpty(entry.lastChangeAuthor)) {
|
| | | WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor);
|
| | | }
|
| | | row.add(new ExternalLink("syndication", SyndicationServlet.asLink(baseUrl,
|
| | | entry.name, null, 0)).setVisible(linksActive));
|
| | |
|
| | | WicketUtils.setAlternatingBackground(item, counter);
|
| | | counter++;
|
| | | }
|
| | |
| | | };
|
| | | }
|
| | |
|
| | | private static class RepositoriesProvider extends ListDataProvider<RepositoryModel> {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public RepositoriesProvider(List<RepositoryModel> list) {
|
| | | super(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<RepositoryModel> getData() {
|
| | | return super.getData();
|
| | | }
|
| | |
|
| | | public void remove(RepositoryModel model) {
|
| | | int index = getData().indexOf(model);
|
| | | RepositoryModel groupModel = null;
|
| | | if (index == (getData().size() - 1)) {
|
| | | // last element
|
| | | if (index > 0) {
|
| | | // previous element is group header, then this is last
|
| | | // repository in group. remove group too.
|
| | | if (getData().get(index - 1) instanceof GroupRepositoryModel) {
|
| | | groupModel = getData().get(index - 1);
|
| | | }
|
| | | }
|
| | | } 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) {
|
| | | // repository is sandwiched by group headers so this
|
| | | // repository is the only element in the group. remove
|
| | | // group.
|
| | | groupModel = getData().get(index - 1);
|
| | | }
|
| | | }
|
| | |
|
| | | if (groupModel == null) {
|
| | | // Find the group and decrement the count
|
| | | for (int i = index; i >= 0; i--) {
|
| | | if (getData().get(i) instanceof GroupRepositoryModel) {
|
| | | ((GroupRepositoryModel) getData().get(i)).count--;
|
| | | break;
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // Remove the group header
|
| | | getData().remove(groupModel);
|
| | | }
|
| | |
|
| | | getData().remove(model);
|
| | | }
|
| | | }
|
| | |
|
| | | private static class SortableRepositoriesProvider extends SortableDataProvider<RepositoryModel> {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | | protected SortableRepositoriesProvider(List<RepositoryModel> list) {
|
| | | this.list = list;
|
| | | setSort(SortBy.date.name(), false);
|
| | | }
|
| | |
|
| | | public void remove(RepositoryModel model) {
|
| | | list.remove(model);
|
| | | }
|
| | |
|
| | | @Override
|