Search in sources :

Example 1 with ToggleMenuItem

use of com.gitblit.models.Menu.ToggleMenuItem in project gitblit by gitblit.

the class RootPage method getRepositoryFilterItems.

protected List<com.gitblit.models.Menu.MenuItem> getRepositoryFilterItems(PageParameters params) {
    final UserModel user = GitBlitWebSession.get().getUser();
    Set<MenuItem> filters = new LinkedHashSet<MenuItem>();
    List<RepositoryModel> repositories = getRepositoryModels();
    // accessible repositories by federation set
    Map<String, AtomicInteger> setMap = new HashMap<String, AtomicInteger>();
    for (RepositoryModel repository : repositories) {
        for (String set : repository.federationSets) {
            String key = set.toLowerCase();
            if (setMap.containsKey(key)) {
                setMap.get(key).incrementAndGet();
            } else {
                setMap.put(key, new AtomicInteger(1));
            }
        }
    }
    if (setMap.size() > 0) {
        List<String> sets = new ArrayList<String>(setMap.keySet());
        Collections.sort(sets);
        for (String set : sets) {
            filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", set, setMap.get(set).get()), "set", set, params));
        }
        // divider
        filters.add(new MenuDivider());
    }
    // user's team memberships
    if (user != null && user.teams.size() > 0) {
        List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);
        Collections.sort(teams);
        for (TeamModel team : teams) {
            filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", team.name, team.repositories.size()), "team", team.name, params));
        }
        // divider
        filters.add(new MenuDivider());
    }
    // custom filters
    String customFilters = app().settings().getString(Keys.web.customFilters, null);
    if (!StringUtils.isEmpty(customFilters)) {
        boolean addedExpression = false;
        List<String> expressions = StringUtils.getStringsFromValue(customFilters, "!!!");
        for (String expression : expressions) {
            if (!StringUtils.isEmpty(expression)) {
                addedExpression = true;
                filters.add(new ToggleMenuItem(null, "x", expression, params));
            }
        }
        // if we added any custom expressions, add a divider
        if (addedExpression) {
            filters.add(new MenuDivider());
        }
    }
    return new ArrayList<MenuItem>(filters);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ToggleMenuItem(com.gitblit.models.Menu.ToggleMenuItem) MenuDivider(com.gitblit.models.Menu.MenuDivider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PageLinkMenuItem(com.gitblit.models.Menu.PageLinkMenuItem) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) ExternalLinkMenuItem(com.gitblit.models.Menu.ExternalLinkMenuItem) MenuItem(com.gitblit.models.Menu.MenuItem) ToggleMenuItem(com.gitblit.models.Menu.ToggleMenuItem) RepositoryModel(com.gitblit.models.RepositoryModel) UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ExternalLinkMenuItem (com.gitblit.models.Menu.ExternalLinkMenuItem)1 MenuDivider (com.gitblit.models.Menu.MenuDivider)1 MenuItem (com.gitblit.models.Menu.MenuItem)1 PageLinkMenuItem (com.gitblit.models.Menu.PageLinkMenuItem)1 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)1 ToggleMenuItem (com.gitblit.models.Menu.ToggleMenuItem)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 TeamModel (com.gitblit.models.TeamModel)1 UserModel (com.gitblit.models.UserModel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1