summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/wicket/pages/BranchesPage.java
blob: 30fac1a832950dafdeb1cce1658c37bdb9b6a97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.gitblit.wicket.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;

import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.Utils;
import com.gitblit.wicket.LinkPanel;
import com.gitblit.wicket.RepositoryPage;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.models.RefModel;
import com.gitblit.wicket.panels.BranchLinksPanel;


public class BranchesPage extends RepositoryPage {

	public BranchesPage(PageParameters params) {
		super(params);

		Repository r = getRepository();
		List<RefModel> branches = new ArrayList<RefModel>();
		branches.addAll(JGitUtils.getLocalBranches(r, -1));
		branches.addAll(JGitUtils.getRemoteBranches(r, -1));

		// shortlog
		add(new LinkPanel("summary", "title", repositoryName, SummaryPage.class, newRepositoryParameter()));

		ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
		DataView<RefModel> branchView = new DataView<RefModel>("branch", branchesDp) {
			private static final long serialVersionUID = 1L;
			int counter = 0;

			public void populateItem(final Item<RefModel> item) {
				final RefModel entry = item.getModelObject();
				String date;
				if (entry.getDate() != null) {
					date = Utils.timeAgo(entry.getDate());
				} else {
					date = "";
				}
				Label branchDateLabel = new Label("branchDate", date);
				item.add(branchDateLabel);
				WicketUtils.setCssClass(branchDateLabel, Utils.timeAgoCss(entry.getDate()));

				item.add(new LinkPanel("branchName", "list name", entry.getDisplayName(), ShortLogPage.class, newCommitParameter(entry.getName())));

				boolean remote = entry.getName().startsWith(Constants.R_REMOTES);
				item.add(new Label("branchType", remote ? getString("gb.remote"):getString("gb.local")));
				
				item.add(new BranchLinksPanel("branchLinks", repositoryName, entry));
				
				String clazz = counter % 2 == 0 ? "dark" : "light";
				WicketUtils.setCssClass(item, clazz);
				counter++;
			}
		};
		add(branchView);
	}
	
	@Override
	protected String getPageName() {
		return getString("gb.branches");
	}
}