Search in sources :

Example 1 with FilterableRepositoryList

use of com.gitblit.wicket.panels.FilterableRepositoryList in project gitblit by gitblit.

the class MyDashboardPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit");
        String message = readMarkdown(messageSource, "login.mkd");
        Component repositoriesMessage = new Label("repositoriesMessage", message);
        add(repositoriesMessage.setEscapeModelStrings(false));
        add(new Label("activity").setVisible(false));
        add(new Label("repositoryTabs").setVisible(false));
        return;
    }
    // Load the markdown welcome message
    String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit");
    String message = readMarkdown(messageSource, "welcome.mkd");
    Component repositoriesMessage = new Label("repositoriesMessage", message).setEscapeModelStrings(false).setVisible(message.length() > 0);
    add(repositoriesMessage);
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    // parameters
    int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
    int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
    if (daysBack < 1) {
        daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    }
    if (maxDaysBack > 0 && daysBack > maxDaysBack) {
        daysBack = maxDaysBack;
    }
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1 * daysBack);
    Date minimumDate = c.getTime();
    // build repo lists
    List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
    List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
    List<RepositoryModel> active = new ArrayList<RepositoryModel>();
    for (RepositoryModel model : getRepositoryModels()) {
        if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
            owned.add(model);
        }
        if (user.getPreferences().isStarredRepository(model.name)) {
            starred.add(model);
        }
        if (model.isShowActivity() && model.lastChange.after(minimumDate)) {
            active.add(model);
        }
    }
    Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            return o2.lastChange.compareTo(o1.lastChange);
        }
    };
    Collections.sort(owned, lastUpdateSort);
    Collections.sort(starred, lastUpdateSort);
    Collections.sort(active, lastUpdateSort);
    String activityTitle;
    Set<RepositoryModel> feed = new HashSet<RepositoryModel>();
    feed.addAll(starred);
    feed.addAll(owned);
    if (feed.isEmpty()) {
        // no starred or owned, go with recent activity
        activityTitle = getString("gb.recentActivity");
        feed.addAll(active);
    } else if (starred.isEmpty()) {
        // no starred, owned repos feed
        activityTitle = getString("gb.owned");
    } else if (owned.isEmpty()) {
        // no owned, starred repos feed
        activityTitle = getString("gb.starred");
    } else {
        // starred and owned repositories
        activityTitle = getString("gb.starredAndOwned");
    }
    addActivity(user, feed, activityTitle, daysBack);
    Fragment repositoryTabs;
    if (UserModel.ANONYMOUS.equals(user)) {
        repositoryTabs = new Fragment("repositoryTabs", "anonymousTabsFragment", this);
    } else {
        repositoryTabs = new Fragment("repositoryTabs", "authenticatedTabsFragment", this);
    }
    add(repositoryTabs);
    // projects list
    List<ProjectModel> projects = app().projects().getProjectModels(getRepositoryModels(), false);
    repositoryTabs.add(new FilterableProjectList("projects", projects));
    // active repository list
    if (active.isEmpty()) {
        repositoryTabs.add(new Label("active").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("active", active);
        repoList.setTitle(getString("gb.activeRepositories"), "icon-time");
        repositoryTabs.add(repoList);
    }
    // starred repository list
    if (ArrayUtils.isEmpty(starred)) {
        repositoryTabs.add(new Label("starred").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("starred", starred);
        repoList.setTitle(getString("gb.starredRepositories"), "icon-star");
        repositoryTabs.add(repoList);
    }
    // owned repository list
    if (ArrayUtils.isEmpty(owned)) {
        repositoryTabs.add(new Label("owned").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("owned", owned);
        repoList.setTitle(getString("gb.myRepositories"), "icon-user");
        repoList.setAllowCreate(user.canCreate() || user.canAdmin());
        repositoryTabs.add(repoList);
    }
}
Also used : FilterableRepositoryList(com.gitblit.wicket.panels.FilterableRepositoryList) Calendar(java.util.Calendar) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) Date(java.util.Date) Comparator(java.util.Comparator) UserModel(com.gitblit.models.UserModel) FilterableProjectList(com.gitblit.wicket.panels.FilterableProjectList) Component(org.apache.wicket.Component) ProjectModel(com.gitblit.models.ProjectModel) HashSet(java.util.HashSet)

Example 2 with FilterableRepositoryList

use of com.gitblit.wicket.panels.FilterableRepositoryList in project gitblit by gitblit.

the class ProjectPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        authenticationError("Please login");
        return;
    }
    String projectName = params == null ? null : WicketUtils.getProjectName(params);
    if (StringUtils.isEmpty(projectName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    ProjectModel project = getProjectModel(projectName);
    if (project == null) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    add(new Label("projectTitle", project.getDisplayName()));
    add(new Label("projectDescription", project.description));
    String feedLink = SyndicationServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), projectName, null, 0);
    add(new ExternalLink("syndication", feedLink));
    add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(project.getDisplayName(), null), feedLink));
    // project markdown message
    String pmessage = transformMarkdown(project.projectMarkdown);
    Component projectMessage = new Label("projectMessage", pmessage).setEscapeModelStrings(false).setVisible(pmessage.length() > 0);
    add(projectMessage);
    // markdown message above repositories list
    String rmessage = transformMarkdown(project.repositoriesMarkdown);
    Component repositoriesMessage = new Label("repositoriesMessage", rmessage).setEscapeModelStrings(false).setVisible(rmessage.length() > 0);
    add(repositoriesMessage);
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
    if (daysBack < 1) {
        daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    }
    // reflog utils.
    if (params != null) {
        params.remove("db");
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    addActivity(user, repositories, getString("gb.recentActivity"), daysBack);
    if (repositories.isEmpty()) {
        add(new Label("repositoryList").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("repositoryList", repositories);
        repoList.setAllowCreate(user.canCreate(project.name + "/"));
        add(repoList);
    }
}
Also used : FilterableRepositoryList(com.gitblit.wicket.panels.FilterableRepositoryList) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) ProjectModel(com.gitblit.models.ProjectModel) Component(org.apache.wicket.Component)

Aggregations

ProjectModel (com.gitblit.models.ProjectModel)2 RepositoryModel (com.gitblit.models.RepositoryModel)2 UserModel (com.gitblit.models.UserModel)2 FilterableRepositoryList (com.gitblit.wicket.panels.FilterableRepositoryList)2 Component (org.apache.wicket.Component)2 Label (org.apache.wicket.markup.html.basic.Label)2 GitblitRedirectException (com.gitblit.wicket.GitblitRedirectException)1 FilterableProjectList (com.gitblit.wicket.panels.FilterableProjectList)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)1