From: Martin Spielmann Date: Sat, 4 Nov 2017 12:19:08 +0000 (+0100) Subject: Merge remote-tracking branch 'collapsible/ticket/527' into 725_nested_repos X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6c061651fb95212ae242dbca06c8d9ef80146201;p=gitblit.git Merge remote-tracking branch 'collapsible/ticket/527' into 725_nested_repos --- 6c061651fb95212ae242dbca06c8d9ef80146201 diff --cc src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java index 804fb299,aab602e5..6d680229 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java @@@ -59,406 -57,419 +59,444 @@@ import com.gitblit.wicket.pages.UserPag public class RepositoriesPanel extends BasePanel { - private static final long serialVersionUID = 1L; - - private enum CollapsibleRepositorySetting { - DISABLED, - - EXPANDED, - - COLLAPSED; - - public static CollapsibleRepositorySetting get(String name) { - CollapsibleRepositorySetting returnVal = CollapsibleRepositorySetting.DISABLED; - for (CollapsibleRepositorySetting setting : values()) { - if (setting.name().equalsIgnoreCase(name)) { - returnVal = setting; - break; - } - } - return returnVal; - } - } - - public RepositoriesPanel(String wicketId, final boolean showAdmin, final boolean showManagement, - List models, boolean enableLinks, - final Map accessRestrictionTranslations) { - super(wicketId); - - final boolean linksActive = enableLinks; - final boolean showSize = app().settings().getBoolean(Keys.web.showRepositorySizes, true); - final String collapsibleRespositorySetting = app().settings().getString(Keys.web.collapsibleRepositoryGroups, null); - final CollapsibleRepositorySetting collapsibleRepoGroups = CollapsibleRepositorySetting.get(collapsibleRespositorySetting); - - final UserModel user = GitBlitWebSession.get().getUser(); - - final IDataProvider dp; - - Fragment managementLinks; - if (showAdmin) { - // user is admin - managementLinks = new Fragment("managementPanel", "adminLinks", this); - managementLinks.add(new Link("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("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("newRepository", app().getNewRepositoryPage())); - 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 rootRepositories = new ArrayList(); - Map> groups = new HashMap>(); - 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()); - } - groups.get(rootPath).add(model); - } - } - List roots = new ArrayList(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 groupedModels = new ArrayList(); - for (String root : roots) { - List 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 ListDataProvider(groupedModels); - } else { - dp = new SortableRepositoriesProvider(models); - } - - final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true); - - DataView dataView = new DataView("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 item) { - final RepositoryModel entry = item.getModelObject(); - if (entry instanceof GroupRepositoryModel) { - GroupRepositoryModel groupRow = (GroupRepositoryModel) entry; - currGroupName = entry.name; - Fragment row = new Fragment("rowContent", "groupRepositoryRow", this); - if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED) { - Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupMinusCollapsible", this); - row.add(groupCollapsible); - } else if(collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { - Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupPlusCollapsible", this); - row.add(groupCollapsible); - } else { - Fragment groupCollapsible = new Fragment("groupCollapsible", "emptyFragment", this); - row.add(groupCollapsible); - } - 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 collapsible"); - // reset counter so that first row is light background - counter = 0; - return; - } - 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); - } - - if (linksActive) { - Class 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, - 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", "(" + getString("gb.empty") + ")") - .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 && 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)); - } - - 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 = app().users().getUserModel(username); - if (ownerModel != null) { - owner = ownerModel.getDisplayName(); - break; - } - } - if (entry.owners.size() > 1) { - owner += ", ..."; - } - } - Label ownerLabel = new Label("repositoryOwner", owner); - WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners)); - row.add(ownerLabel); - - String lastChange; - if (entry.lastChange.getTime() == 0) { - lastChange = "--"; - } else { - lastChange = getTimeUtils().timeAgo(entry.lastChange); - } - Label lastChangeLabel = new Label("repositoryLastChange", lastChange); - row.add(lastChangeLabel); - WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange)); - if (!StringUtils.isEmpty(entry.lastChangeAuthor)) { - WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor); - } - - WicketUtils.setAlternatingBackground(item, counter); - counter++; - } - }; - add(dataView); - - if (dp instanceof SortableDataProvider) { - // add sortable header - SortableDataProvider sdp = (SortableDataProvider) dp; - Fragment fragment = new Fragment("headerContent", "flatRepositoryHeader", this); - fragment.add(newSort("orderByRepository", SortBy.repository, sdp, dataView)); - fragment.add(newSort("orderByDescription", SortBy.description, sdp, dataView)); - fragment.add(newSort("orderByOwner", SortBy.owner, sdp, dataView)); - fragment.add(newSort("orderByDate", SortBy.date, sdp, dataView)); - add(fragment); - } else { - // not sortable - Fragment fragment = new Fragment("headerContent", "groupRepositoryHeader", this); - if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED || - collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { - Fragment allCollapsible = new Fragment("allCollapsible", "tableAllCollapsible", this); - fragment.add(allCollapsible); - } else { - Fragment allCollapsible = new Fragment("allCollapsible", "emptyFragment", this); - fragment.add(allCollapsible); - } - add(fragment); - } - } - - private static class GroupRepositoryModel extends RepositoryModel { - - private static final long serialVersionUID = 1L; - - int count; - String title; - - GroupRepositoryModel(String name, int count) { - super(name, "", "", new Date(0)); - this.count = count; - } - - @Override - public String toString() { - return (StringUtils.isEmpty(title) ? name : title) + " (" + count + ")"; - } - } - - protected enum SortBy { - repository, description, owner, date; - } - - 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; - - @Override - protected void onSortChanged() { - dataView.setCurrentPage(0); - } - }; - } - - private static class SortableRepositoriesProvider extends SortableDataProvider { - - private static final long serialVersionUID = 1L; - - private List list; - - protected SortableRepositoriesProvider(List list) { - this.list = list; - setSort(SortBy.date.name(), false); - } - - @Override - public int size() { - if (list == null) { - return 0; - } - return list.size(); - } - - @Override - public IModel model(RepositoryModel header) { - return new Model(header); - } - - @Override - public Iterator iterator(int first, int count) { - SortParam sp = getSort(); - String prop = sp.getProperty(); - final boolean asc = sp.isAscending(); - - if (prop == null || prop.equals(SortBy.date.name())) { - Collections.sort(list, new Comparator() { - @Override - public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) { - return o1.lastChange.compareTo(o2.lastChange); - } - return o2.lastChange.compareTo(o1.lastChange); - } - }); - } else if (prop.equals(SortBy.repository.name())) { - Collections.sort(list, new Comparator() { - @Override - public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) { - return o1.name.compareTo(o2.name); - } - return o2.name.compareTo(o1.name); - } - }); - } else if (prop.equals(SortBy.owner.name())) { - Collections.sort(list, new Comparator() { - @Override - public int compare(RepositoryModel o1, RepositoryModel o2) { - String own1 = ArrayUtils.toString(o1.owners); - String own2 = ArrayUtils.toString(o2.owners); - if (asc) { - return own1.compareTo(own2); - } - return own2.compareTo(own1); - } - }); - } else if (prop.equals(SortBy.description.name())) { - Collections.sort(list, new Comparator() { - @Override - public int compare(RepositoryModel o1, RepositoryModel o2) { - if (asc) { - return o1.description.compareTo(o2.description); - } - return o2.description.compareTo(o1.description); - } - }); - } - return list.subList(first, first + count).iterator(); - } - } + private static final long serialVersionUID = 1L; + ++ private enum CollapsibleRepositorySetting { ++ DISABLED, ++ ++ EXPANDED, ++ ++ COLLAPSED; ++ ++ public static CollapsibleRepositorySetting get(String name) { ++ CollapsibleRepositorySetting returnVal = CollapsibleRepositorySetting.DISABLED; ++ for (CollapsibleRepositorySetting setting : values()) { ++ if (setting.name().equalsIgnoreCase(name)) { ++ returnVal = setting; ++ break; ++ } ++ } ++ return returnVal; ++ } ++ } + public RepositoriesPanel(String wicketId, final boolean showAdmin, final boolean showManagement, List models, boolean enableLinks, + final Map accessRestrictionTranslations) { + super(wicketId); + + final boolean linksActive = enableLinks; + final boolean showSize = app().settings().getBoolean(Keys.web.showRepositorySizes, true); ++ final String collapsibleRespositorySetting = app().settings().getString(Keys.web.collapsibleRepositoryGroups, null); ++ final CollapsibleRepositorySetting collapsibleRepoGroups = CollapsibleRepositorySetting.get(collapsibleRespositorySetting); + + final UserModel user = GitBlitWebSession.get().getUser(); + + IDataProvider dp = null; + + Fragment managementLinks; + if (showAdmin) { + // user is admin + managementLinks = new Fragment("managementPanel", "adminLinks", this); + managementLinks.add(new Link("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("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("newRepository", app().getNewRepositoryPage())); + add(managementLinks); + } else { + // user has no management permissions + add(new Label("managementPanel").setVisible(false)); + } + + if (true) { + // if (app().settings().getString(Keys.web.repositoryListType, + // "flat").equalsIgnoreCase("tree")) { + TreeNodeModel tree = new TreeNodeModel(); + for (RepositoryModel model : models) { + String rootPath = StringUtils.getRootPath(model.name); + if (StringUtils.isEmpty(rootPath)) { + // root repository + // rootRepositories.add(model); + tree.add(model); + } else { + // create folder structure + tree.add(rootPath, model); + // non-root, grouped repository + // if (!groups.containsKey(rootPath)) { + // groups.put(rootPath, new ArrayList()); + // } + // groups.get(rootPath).add(model); + } + } + + WebMarkupContainer row = new WebMarkupContainer("row"); + add(row); + row.add(new MultiLineLabel("rowContent", tree.toString())); + + + Fragment fragment = new Fragment("headerContent", "groupRepositoryHeader", this); + add(fragment); + + + + + } else if (app().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) { + List rootRepositories = new ArrayList(); + Map> groups = new HashMap>(); + 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()); + } + groups.get(rootPath).add(model); + } + } + List roots = new ArrayList(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 groupedModels = new ArrayList(); + for (String root : roots) { + List 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 ListDataProvider(groupedModels); + } else { + dp = new SortableRepositoriesProvider(models); + } + + if (dp != null) { + final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true); + + DataView dataView = new DataView("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 item) { + final RepositoryModel entry = item.getModelObject(); + if (entry instanceof GroupRepositoryModel) { + GroupRepositoryModel groupRow = (GroupRepositoryModel) entry; + currGroupName = entry.name; + Fragment row = new Fragment("rowContent", "groupRepositoryRow", this); ++ if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED) { ++ Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupMinusCollapsible", this); ++ row.add(groupCollapsible); ++ } else if(collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { ++ Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupPlusCollapsible", this); ++ row.add(groupCollapsible); ++ } else { ++ Fragment groupCollapsible = new Fragment("groupCollapsible", "emptyFragment", this); ++ row.add(groupCollapsible); ++ } + 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"); ++ WicketUtils.setCssClass(item, "group collapsible"); + // reset counter so that first row is light background + counter = 0; + return; + } + 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); + } + + if (linksActive) { + Class 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, 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", "(" + getString("gb.empty") + ")").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 && 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)); + } + + 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 = app().users().getUserModel(username); + if (ownerModel != null) { + owner = ownerModel.getDisplayName(); + break; + } + } + if (entry.owners.size() > 1) { + owner += ", ..."; + } + } + Label ownerLabel = new Label("repositoryOwner", owner); + WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners)); + row.add(ownerLabel); + + String lastChange; + if (entry.lastChange.getTime() == 0) { + lastChange = "--"; + } else { + lastChange = getTimeUtils().timeAgo(entry.lastChange); + } + Label lastChangeLabel = new Label("repositoryLastChange", lastChange); + row.add(lastChangeLabel); + WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange)); + if (!StringUtils.isEmpty(entry.lastChangeAuthor)) { + WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor); + } + + WicketUtils.setAlternatingBackground(item, counter); + counter++; + } + }; + add(dataView); + + if (dp instanceof SortableDataProvider) { + // add sortable header + SortableDataProvider sdp = (SortableDataProvider) dp; + Fragment fragment = new Fragment("headerContent", "flatRepositoryHeader", this); + fragment.add(newSort("orderByRepository", SortBy.repository, sdp, dataView)); + fragment.add(newSort("orderByDescription", SortBy.description, sdp, dataView)); + fragment.add(newSort("orderByOwner", SortBy.owner, sdp, dataView)); + fragment.add(newSort("orderByDate", SortBy.date, sdp, dataView)); + add(fragment); + } else { + // not sortable + Fragment fragment = new Fragment("headerContent", "groupRepositoryHeader", this); ++ if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED || ++ collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { ++ Fragment allCollapsible = new Fragment("allCollapsible", "tableAllCollapsible", this); ++ fragment.add(allCollapsible); ++ } else { ++ Fragment allCollapsible = new Fragment("allCollapsible", "emptyFragment", this); ++ fragment.add(allCollapsible); ++ } + add(fragment); + } + } + + + } + + private static class GroupRepositoryModel extends RepositoryModel { + + private static final long serialVersionUID = 1L; + + int count; + String title; + + GroupRepositoryModel(String name, int count) { + super(name, "", "", new Date(0)); + this.count = count; + } + + @Override + public String toString() { + return (StringUtils.isEmpty(title) ? name : title) + " (" + count + ")"; + } + } + + protected enum SortBy { + repository, description, owner, date; + } + + 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; + + @Override + protected void onSortChanged() { + dataView.setCurrentPage(0); + } + }; + } + + private static class SortableRepositoriesProvider extends SortableDataProvider { + + private static final long serialVersionUID = 1L; + + private List list; + + protected SortableRepositoriesProvider(List list) { + this.list = list; + setSort(SortBy.date.name(), false); + } + + @Override + public int size() { + if (list == null) { + return 0; + } + return list.size(); + } + + @Override + public IModel model(RepositoryModel header) { + return new Model(header); + } + + @Override + public Iterator iterator(int first, int count) { + SortParam sp = getSort(); + String prop = sp.getProperty(); + final boolean asc = sp.isAscending(); + + if (prop == null || prop.equals(SortBy.date.name())) { + Collections.sort(list, new Comparator() { + @Override + public int compare(RepositoryModel o1, RepositoryModel o2) { + if (asc) { + return o1.lastChange.compareTo(o2.lastChange); + } + return o2.lastChange.compareTo(o1.lastChange); + } + }); + } else if (prop.equals(SortBy.repository.name())) { + Collections.sort(list, new Comparator() { + @Override + public int compare(RepositoryModel o1, RepositoryModel o2) { + if (asc) { + return o1.name.compareTo(o2.name); + } + return o2.name.compareTo(o1.name); + } + }); + } else if (prop.equals(SortBy.owner.name())) { + Collections.sort(list, new Comparator() { + @Override + public int compare(RepositoryModel o1, RepositoryModel o2) { + String own1 = ArrayUtils.toString(o1.owners); + String own2 = ArrayUtils.toString(o2.owners); + if (asc) { + return own1.compareTo(own2); + } + return own2.compareTo(own1); + } + }); + } else if (prop.equals(SortBy.description.name())) { + Collections.sort(list, new Comparator() { + @Override + public int compare(RepositoryModel o1, RepositoryModel o2) { + if (asc) { + return o1.description.compareTo(o2.description); + } + return o2.description.compareTo(o1.description); + } + }); + } + return list.subList(first, first + count).iterator(); + } + } } diff --cc src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java index 00000000,00000000..4887c65a new file mode 100644 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java @@@ -1,0 -1,0 +1,142 @@@ ++package com.gitblit.wicket.panels; ++ ++import java.io.Serializable; ++import java.util.ArrayList; ++import java.util.List; ++ ++import com.gitblit.models.RepositoryModel; ++import com.gitblit.utils.StringUtils; ++ ++public class TreeNodeModel implements Serializable { ++ ++ private static final long serialVersionUID = 1L; ++ final TreeNodeModel parent; ++ final String name; ++ private final List subFolders = new ArrayList<>(); ++ private final List repositories = new ArrayList<>(); ++ ++ /** ++ * Create a new tree root ++ */ ++ public TreeNodeModel() { ++ this.name = ""; ++ this.parent = null; ++ } ++ ++ protected TreeNodeModel(String name, TreeNodeModel parent) { ++ this.name = name; ++ this.parent = parent; ++ } ++ ++ public int getDepth() { ++ if(parent == null) { ++ return 0; ++ }else { ++ return parent.getDepth() +1; ++ } ++ } ++ ++ /** ++ * Add a new sub folder to the current folder ++ * ++ * @param subFolder the subFolder to create ++ * @return the newly created folder to allow chaining ++ */ ++ public TreeNodeModel add(String subFolder) { ++ TreeNodeModel n = new TreeNodeModel(subFolder, this); ++ subFolders.add(n); ++ return n; ++ } ++ ++ /** ++ * Add the given repo to the current folder ++ * ++ * @param repo ++ */ ++ public void add(RepositoryModel repo) { ++ repositories.add(repo); ++ } ++ ++ /** ++ * Adds the given repository model within the given path. Creates parent folders if they do not exist ++ * ++ * @param path ++ * @param model ++ */ ++ public void add(String path, RepositoryModel model) { ++ TreeNodeModel folder = getSubTreeNode(this, path, true); ++ folder.add(model); ++ } ++ ++ @Override ++ public String toString() { ++ String string = name + "\n"; ++ for(TreeNodeModel n : subFolders) { ++ string += "f"; ++ for(int i = 0; i < n.getDepth(); i++) { ++ string += "-"; ++ } ++ string += n.toString(); ++ } ++ ++ for(RepositoryModel n : repositories) { ++ string += "r"; ++ for(int i = 0; i < getDepth()+1; i++) { ++ string += "-"; ++ } ++ string += n.toString() + "\n"; ++ } ++ ++ return string; ++ } ++ ++ public boolean containsSubFolder(String path) { ++ return containsSubFolder(this, path); ++ } ++ ++ public TreeNodeModel getSubFolder(String path) { ++ return getSubTreeNode(this, path, false); ++ } ++ ++ ++ ++ ++ private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boolean create) { ++ if(!StringUtils.isEmpty(path)) { ++ boolean isPathInCurrentHierarchyLevel = path.lastIndexOf('/') < 0; ++ if(isPathInCurrentHierarchyLevel) { ++ for(TreeNodeModel t : node.subFolders) { ++ if(t.name.equals(path) ) { ++ return t; ++ } ++ } ++ ++ if(create) { ++ node.add(path); ++ return getSubTreeNode(node, path, true); ++ } ++ }else { ++ //traverse into subFolder ++ String folderInCurrentHierarchyLevel = path.substring(0, path.indexOf('/')); ++ ++ for(TreeNodeModel t : node.subFolders) { ++ if(t.name.equals(folderInCurrentHierarchyLevel) ) { ++ String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); ++ return getSubTreeNode(t, folderInNextHierarchyLevel, create); ++ } ++ } ++ ++ if(create) { ++ String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); ++ return getSubTreeNode(node.add(folderInCurrentHierarchyLevel), folderInNextHierarchyLevel, true); ++ } ++ } ++ } ++ ++ return null; ++ } ++ ++ private static boolean containsSubFolder(TreeNodeModel node, String path) { ++ return getSubTreeNode(node, path, false) != null; ++ } ++} diff --cc src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java index 00000000,00000000..57051dd4 new file mode 100644 --- /dev/null +++ b/src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java @@@ -1,0 -1,0 +1,48 @@@ ++package com.gitblit.wicket.panels; ++ ++import static org.junit.Assert.assertEquals; ++import static org.junit.Assert.assertFalse; ++import static org.junit.Assert.assertTrue; ++ ++import org.junit.Test; ++ ++import com.gitblit.models.RepositoryModel; ++ ++public class TreeNodeModelTest { ++ ++ @Test ++ public void testContainsSubFolder() { ++ TreeNodeModel tree = new TreeNodeModel(); ++ tree.add("foo").add("bar").add("baz"); ++ ++ assertTrue(tree.containsSubFolder("foo/bar/baz")); ++ assertTrue(tree.containsSubFolder("foo/bar")); ++ assertFalse(tree.containsSubFolder("foo/bar/blub")); ++ } ++ ++ @Test ++ public void testAddInHierarchy() { ++ TreeNodeModel tree = new TreeNodeModel(); ++ tree.add("foo").add("bar"); ++ ++ RepositoryModel model = new RepositoryModel("test","","",null); ++ ++ // add model to non-existing folder. should be created automatically ++ tree.add("foo/bar/baz", model); ++ tree.add("another/non/existing/folder", model); ++ ++ assertTrue(tree.containsSubFolder("foo/bar/baz")); ++ assertTrue(tree.containsSubFolder("another/non/existing/folder")); ++ } ++ ++ @Test ++ public void testGetDepth() { ++ TreeNodeModel tree = new TreeNodeModel(); ++ TreeNodeModel bar = tree.add("foo").add("bar").add("baz"); ++ ++ assertEquals(0, tree.getDepth()); ++ assertEquals(3, bar.getDepth()); ++ } ++ ++ ++}