summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java
blob: 2c57a051f0de103beccf38ab5abcee31661b1f9e (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.gitblit.wicket.pages;

import java.util.List;

import org.apache.wicket.Component;
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 com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel;
import com.gitblit.models.UserModel;
import com.gitblit.models.TicketModel.Status;
import com.gitblit.models.TicketModel.Type;
import com.gitblit.tickets.ITicketService;
import com.gitblit.tickets.QueryBuilder;
import com.gitblit.tickets.QueryResult;
import com.gitblit.tickets.TicketIndexer.Lucene;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebApp;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.GravatarImage;
import com.gitblit.wicket.panels.LinkPanel;

public class MyTicketsPage extends RootPage {
	
	public MyTicketsPage()
	{
		this(null);	
	}
	
	public MyTicketsPage(PageParameters params)
	{
		super();
		setupPage("", getString("gb.mytickets"));
		
		UserModel currentUser = GitBlitWebSession.get().getUser();
		if (currentUser == null) {
			currentUser = UserModel.ANONYMOUS;
		}
		String username = currentUser.getName();
		
		QueryBuilder qb = QueryBuilder
			.q(Lucene.createdby.matches(username))
			.or(Lucene.responsible.matches(username))
			.or(Lucene.watchedby.matches(username));
		
		ITicketService tickets = GitBlitWebApp.get().tickets();
		List<QueryResult> results = tickets.queryFor(qb.build(), 0, 0, Lucene.updated.name(), true);
		
		final ListDataProvider<QueryResult> dp = new ListDataProvider<QueryResult>(results);
		
		DataView<QueryResult> dataView = new DataView<QueryResult>("row", dp) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(Item<QueryResult> item) {
				QueryResult ticket = item.getModelObject();
				RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
				
				Component swatch = new Label("repositorySwatch", "&nbsp;").setEscapeModelStrings(false);
				WicketUtils.setCssBackground(swatch, repository.toString());
				item.add(swatch);
				
				PageParameters rp = WicketUtils.newRepositoryParameter(ticket.repository);
				PageParameters tp = WicketUtils.newObjectParameter(ticket.repository, "" + ticket.number);
				item.add(new LinkPanel("repositoryName", "list", StringUtils.stripDotGit(ticket.repository), SummaryPage.class, rp));
				
				item.add(getStateIcon("ticketIcon", ticket.type, ticket.status));
				item.add(new Label("ticketNumber", "" + ticket.number));
				item.add(new LinkPanel("ticketTitle", "list", ticket.title, TicketsPage.class, tp));

				// votes indicator
				Label v = new Label("ticketVotes", "" + ticket.votesCount);
				WicketUtils.setHtmlTooltip(v, getString("gb.votes"));
				item.add(v.setVisible(ticket.votesCount > 0));

				Label ticketStatus = new Label("ticketStatus", ticket.status.toString());
				String statusClass = getStatusClass(ticket.status);
				WicketUtils.setCssClass(ticketStatus, statusClass);
				item.add(ticketStatus);
				
				UserModel responsible = app().users().getUserModel(ticket.responsible);
				if (responsible == null) {
					if (ticket.responsible == null) {
						item.add(new Label("ticketResponsibleImg").setVisible(false));
					} else {
						item.add(new GravatarImage("ticketResponsibleImg", ticket.responsible, ticket.responsible, null, 16, true));
					}
					item.add(new Label("ticketResponsible", ticket.responsible));
				} else {
					item.add(new GravatarImage("ticketResponsibleImg", responsible, null, 16, true));
					item.add(new LinkPanel("ticketResponsible", null, responsible.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(ticket.responsible)));
				}
			}
		};
		
		add(dataView);
	}
	
	protected Label getStateIcon(String wicketId, TicketModel ticket) {
		return getStateIcon(wicketId, ticket.type, ticket.status);
	}

	protected Label getStateIcon(String wicketId, Type type, Status state) {
		Label label = new Label(wicketId);
		if (type == null) {
			type = Type.defaultType;
		}
		switch (type) {
		case Proposal:
			WicketUtils.setCssClass(label, "fa fa-code-fork");
			break;
		case Bug:
			WicketUtils.setCssClass(label, "fa fa-bug");
			break;
		case Enhancement:
			WicketUtils.setCssClass(label, "fa fa-magic");
			break;
		case Question:
			WicketUtils.setCssClass(label, "fa fa-question");
			break;
		default:
			// standard ticket
			WicketUtils.setCssClass(label, "fa fa-ticket");
		}
		WicketUtils.setHtmlTooltip(label, getTypeState(type, state));
		return label;
	}

	protected String getTypeState(Type type, Status state) {
		return state.toString() + " " + type.toString();
	}

	protected String getLozengeClass(Status status, boolean subtle) {
		if (status == null) {
			status = Status.New;
		}
		String css = "";
		switch (status) {
		case Declined:
		case Duplicate:
		case Invalid:
		case Wontfix:
		case Abandoned:
			css = "aui-lozenge-error";
			break;
		case Fixed:
		case Merged:
		case Resolved:
			css = "aui-lozenge-success";
			break;
		case New:
			css = "aui-lozenge-complete";
			break;
		case On_Hold:
			css = "aui-lozenge-current";
			break;
		default:
			css = "";
			break;
		}

		return "aui-lozenge" + (subtle ? " aui-lozenge-subtle": "") + (css.isEmpty() ? "" : " ") + css;
	}

	protected String getStatusClass(Status status) {
		String css = "";
		switch (status) {
		case Declined:
		case Duplicate:
		case Invalid:
		case Wontfix:
		case Abandoned:
			css = "resolution-error";
			break;
		case Fixed:
		case Merged:
		case Resolved:
			css = "resolution-success";
			break;
		case New:
			css = "resolution-complete";
			break;
		case On_Hold:
			css = "resolution-current";
			break;
		default:
			css = "";
			break;
		}

		return "resolution" + (css.isEmpty() ? "" : " ") + css;
	}
}