| | |
| | | package com.gitblit.wicket.panels;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | |
| | | 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.Link;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.markup.repeater.Item;
|
| | | import org.apache.wicket.markup.repeater.data.DataView;
|
| | |
| | | import com.gitblit.wicket.pages.EditRepositoryPage;
|
| | | import com.gitblit.wicket.pages.SummaryPage;
|
| | |
|
| | |
|
| | | public class RepositoriesPanel extends BasePanel {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | |
| | |
|
| | | public RepositoriesPanel(String wicketId, final boolean showAdmin, final Map<AccessRestrictionType, String> accessRestrictionTranslations) {
|
| | | super(wicketId);
|
| | | |
| | |
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
|
| | | IDataProvider<RepositoryModel> dp;
|
| | | |
| | | final IDataProvider<RepositoryModel> dp;
|
| | |
|
| | | Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this);
|
| | | adminLinks.add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class));
|
| | | add(adminLinks.setVisible(showAdmin));
|
| | | |
| | |
|
| | | if (GitBlit.self().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) {
|
| | | Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>();
|
| | | for (RepositoryModel model : models) {
|
| | |
| | | List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();
|
| | | for (String root : roots) {
|
| | | List<RepositoryModel> subModels = groups.get(root);
|
| | | groupedModels.add(new GroupRepositoryModel(root + " (" + subModels.size() + ")"));
|
| | | groupedModels.add(new GroupRepositoryModel(root, subModels.size()));
|
| | | groupedModels.addAll(subModels);
|
| | | }
|
| | | dp = new ListDataProvider<RepositoryModel>(groupedModels);
|
| | | dp = new RepositoriesProvider(groupedModels);
|
| | | } else {
|
| | | dp = new DataProvider(models);
|
| | | dp = new SortableRepositoriesProvider(models);
|
| | | }
|
| | |
|
| | | DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("row", dp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | | int counter = 0;
|
| | |
|
| | | @Override
|
| | | protected void onBeforeRender() {
|
| | | super.onBeforeRender();
|
| | | counter = 0;
|
| | | }
|
| | |
|
| | | public void populateItem(final Item<RepositoryModel> item) {
|
| | | final RepositoryModel entry = item.getModelObject();
|
| | | if (entry instanceof GroupRepositoryModel) {
|
| | | Fragment row = new Fragment("rowContent", "groupRepositoryRow", this);
|
| | | item.add(row);
|
| | | row.add(new Label("groupName", entry.name));
|
| | | row.add(new Label("groupName", entry.toString()));
|
| | | WicketUtils.setCssClass(item, "group");
|
| | | return;
|
| | | }
|
| | |
| | | row.add(lastChangeLabel);
|
| | | WicketUtils.setCssClass(lastChangeLabel, TimeUtils.timeAgoCss(entry.lastChange));
|
| | |
|
| | | boolean showOwner = user != null && user.getUsername().equalsIgnoreCase(entry.owner); |
| | | boolean showOwner = user != null && user.getUsername().equalsIgnoreCase(entry.owner);
|
| | | if (showAdmin) {
|
| | | Fragment repositoryLinks = new Fragment("repositoryLinks", "repositoryAdminLinks", this);
|
| | | repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", EditRepositoryPage.class, WicketUtils.newRepositoryParameter(entry.name)));
|
| | | repositoryLinks.add(new BookmarkablePageLink<Void>("renameRepository", EditRepositoryPage.class, WicketUtils.newRepositoryParameter(entry.name)).setEnabled(false));
|
| | | repositoryLinks.add(new BookmarkablePageLink<Void>("deleteRepository", EditRepositoryPage.class, WicketUtils.newRepositoryParameter(entry.name)).setEnabled(false));
|
| | | Link<Void> deleteLink = new Link<Void>("deleteRepository") {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | public void onClick() {
|
| | | if (GitBlit.self().deleteRepositoryModel(entry)) {
|
| | | info(MessageFormat.format("Repository ''{0}'' deleted.", entry));
|
| | | if (dp instanceof SortableRepositoriesProvider) {
|
| | | ((SortableRepositoriesProvider) dp).remove(entry);
|
| | | } else {
|
| | | ((RepositoriesProvider) dp).remove(entry);
|
| | | }
|
| | | } else {
|
| | | error(MessageFormat.format("Failed to 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);
|
| | |
| | | add(fragment);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | private class GroupRepositoryModel extends RepositoryModel {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | GroupRepositoryModel(String name) {
|
| | | int count = 0;
|
| | |
|
| | | GroupRepositoryModel(String name, int count) {
|
| | | super(name, "", "", new Date(0));
|
| | | this.count = count;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return name + " (" + count + ")";
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | protected enum SortBy {
|
| | | repository, description, owner, date;
|
| | | }
|
| | |
| | | };
|
| | | }
|
| | |
|
| | | private class DataProvider extends SortableDataProvider<RepositoryModel> {
|
| | | private 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 class SortableRepositoriesProvider extends SortableDataProvider<RepositoryModel> {
|
| | | private static final long serialVersionUID = 1L;
|
| | | private List<RepositoryModel> list = null;
|
| | |
|
| | | protected DataProvider(List<RepositoryModel> list) {
|
| | | protected SortableRepositoriesProvider(List<RepositoryModel> list) {
|
| | | this.list = list;
|
| | | setSort(SortBy.date.name(), false);
|
| | | }
|
| | |
|
| | | public void remove(RepositoryModel model) {
|
| | | list.remove(model);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int size() {
|
| | | if (list == null)
|