use of com.gitblit.models.ProjectModel 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);
}
}
use of com.gitblit.models.ProjectModel in project gitblit by gitblit.
the class BasePage method getProjectModels.
protected List<ProjectModel> getProjectModels() {
final UserModel user = GitBlitWebSession.get().getUser();
List<ProjectModel> projects = app().projects().getProjectModels(user, true);
return projects;
}
use of com.gitblit.models.ProjectModel in project gitblit by gitblit.
the class ProjectPage method getProjectsMenu.
protected List<MenuItem> getProjectsMenu() {
List<MenuItem> menu = new ArrayList<MenuItem>();
List<ProjectModel> projects = new ArrayList<ProjectModel>();
for (ProjectModel model : getProjectModels()) {
if (!model.isUserProject()) {
projects.add(model);
}
}
int maxProjects = 15;
boolean showAllProjects = projects.size() > maxProjects;
if (showAllProjects) {
// sort by last changed
Collections.sort(projects, new Comparator<ProjectModel>() {
@Override
public int compare(ProjectModel o1, ProjectModel o2) {
return o2.lastChange.compareTo(o1.lastChange);
}
});
// take most recent subset
projects = projects.subList(0, maxProjects);
// sort those by name
Collections.sort(projects);
}
for (ProjectModel project : projects) {
menu.add(new ParameterMenuItem(project.getDisplayName(), "p", project.name));
}
if (showAllProjects) {
menu.add(new MenuDivider());
menu.add(new ParameterMenuItem("all projects"));
}
return menu;
}
use of com.gitblit.models.ProjectModel 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);
}
}
use of com.gitblit.models.ProjectModel in project gitblit by gitblit.
the class ProjectsPage 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()) {
add(new Label("projectsPanel"));
return;
}
List<ProjectModel> projects = getProjects(params);
Collections.sort(projects);
ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
protected void onBeforeRender() {
super.onBeforeRender();
counter = 0;
}
@Override
public void populateItem(final Item<ProjectModel> item) {
final ProjectModel entry = item.getModelObject();
PageParameters pp = WicketUtils.newProjectParameter(entry.name);
item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
String lastChange;
if (entry.lastChange.getTime() == 0) {
lastChange = "--";
} else {
lastChange = getTimeUtils().timeAgo(entry.lastChange);
}
Label lastChangeLabel = new Label("projectLastChange", lastChange);
item.add(lastChangeLabel);
WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
add(dataView);
}
Aggregations