James Moger
2012-09-10 fabe060d3a435f116128851f828e35c2af5fde67
commit | author | age
f13c4c 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
232890 16 package com.gitblit.wicket.pages;
JM 17
18 import org.apache.wicket.PageParameters;
19 import org.apache.wicket.markup.html.basic.Label;
20 import org.apache.wicket.markup.repeater.Item;
21 import org.apache.wicket.markup.repeater.data.DataView;
22 import org.apache.wicket.markup.repeater.data.ListDataProvider;
23 import org.eclipse.jgit.lib.Repository;
24
1f9dae 25 import com.gitblit.models.TicketModel;
JM 26 import com.gitblit.models.TicketModel.Comment;
87cc1e 27 import com.gitblit.utils.StringUtils;
793f76 28 import com.gitblit.utils.TicgitUtils;
232890 29 import com.gitblit.wicket.GitBlitWebSession;
JM 30 import com.gitblit.wicket.WicketUtils;
31
9802a7 32 public class TicketPage extends RepositoryPage {
232890 33
9802a7 34     public TicketPage(PageParameters params) {
cebf45 35         super(params);
232890 36
3cc6e2 37         final String ticketFolder = WicketUtils.getPath(params);
232890 38
JM 39         Repository r = getRepository();
793f76 40         TicketModel t = TicgitUtils.getTicket(r, ticketFolder);
232890 41
JM 42         add(new Label("ticketTitle", t.title));
43         add(new Label("ticketId", t.id));
61b094 44         add(new Label("ticketHandler", t.handler.toLowerCase()));
9adf62 45         add(WicketUtils.createTimestampLabel("ticketOpenDate", t.date, getTimeZone(), getTimeUtils()));
7ba0ec 46         Label stateLabel = new Label("ticketState", t.state);
1e47ab 47         WicketUtils.setTicketCssClass(stateLabel, t.state);
7ba0ec 48         add(stateLabel);
87cc1e 49         add(new Label("ticketTags", StringUtils.flattenStrings(t.tags)));
232890 50
JM 51         ListDataProvider<Comment> commentsDp = new ListDataProvider<Comment>(t.comments);
52         DataView<Comment> commentsView = new DataView<Comment>("comment", commentsDp) {
53             private static final long serialVersionUID = 1L;
2a7306 54             int counter;
232890 55
JM 56             public void populateItem(final Item<Comment> item) {
57                 final Comment entry = item.getModelObject();
2a7306 58                 item.add(WicketUtils.createDateLabel("commentDate", entry.date, GitBlitWebSession
9adf62 59                         .get().getTimezone(), getTimeUtils()));
61b094 60                 item.add(new Label("commentAuthor", entry.author.toLowerCase()));
2a7306 61                 item.add(new Label("commentText", prepareComment(entry.text))
JM 62                         .setEscapeModelStrings(false));
698678 63                 WicketUtils.setAlternatingBackground(item, counter);
232890 64                 counter++;
JM 65             }
66         };
67         add(commentsView);
68     }
155bf7 69
cebf45 70     @Override
JM 71     protected String getPageName() {
1e47ab 72         return getString("gb.ticket");
cebf45 73     }
232890 74
JM 75     private String prepareComment(String comment) {
87cc1e 76         String html = StringUtils.escapeForHtml(comment, false);
JM 77         html = StringUtils.breakLinesForHtml(comment).trim();
2a7306 78         return html.replaceAll("\\bcommit\\s*([A-Za-z0-9]*)\\b", "<a href=\"/commit/"
JM 79                 + repositoryName + "/$1\">commit $1</a>");
232890 80     }
JM 81 }