James Moger
2012-10-22 eba89539a29deba954035056437279088c3e047b
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  */
698678 16 package com.gitblit.wicket.panels;
JM 17
18 import java.util.Date;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.wicket.markup.html.basic.Label;
23 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
24 import org.apache.wicket.markup.repeater.Item;
25 import org.apache.wicket.markup.repeater.data.DataView;
26 import org.apache.wicket.markup.repeater.data.ListDataProvider;
27 import org.apache.wicket.model.StringResourceModel;
28 import org.eclipse.jgit.lib.ObjectId;
29 import org.eclipse.jgit.lib.Repository;
30 import org.eclipse.jgit.revwalk.RevCommit;
31
33d8d8 32 import com.gitblit.Constants;
87cc1e 33 import com.gitblit.GitBlit;
155bf7 34 import com.gitblit.Keys;
4ab184 35 import com.gitblit.models.RefModel;
698678 36 import com.gitblit.utils.JGitUtils;
87cc1e 37 import com.gitblit.utils.StringUtils;
698678 38 import com.gitblit.wicket.WicketUtils;
608ece 39 import com.gitblit.wicket.pages.CommitDiffPage;
155bf7 40 import com.gitblit.wicket.pages.CommitPage;
698678 41 import com.gitblit.wicket.pages.LogPage;
4e1930 42 import com.gitblit.wicket.pages.GitSearchPage;
698678 43 import com.gitblit.wicket.pages.TreePage;
JM 44
bc10f9 45 public class LogPanel extends BasePanel {
698678 46
JM 47     private static final long serialVersionUID = 1L;
48
2a7306 49     private boolean hasMore;
JM 50
51     public LogPanel(String wicketId, final String repositoryName, final String objectId,
1e1b85 52             Repository r, int limit, int pageOffset, boolean showRemoteRefs) {
698678 53         super(wicketId);
50984c 54         boolean pageResults = limit <= 0;
2a7306 55         int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
66c29a 56         if (itemsPerPage <= 1) {
JM 57             itemsPerPage = 50;
58         }
bc10f9 59
1e1b85 60         final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
ef5c58 61         List<RevCommit> commits;
JM 62         if (pageResults) {
63             // Paging result set
50984c 64             commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
ef5c58 65         } else {
JM 66             // Fixed size result set
67             commits = JGitUtils.getRevLog(r, objectId, 0, limit);
68         }
f602a2 69
JM 70         // inaccurate way to determine if there are more commits.
2a7306 71         // works unless commits.size() represents the exact end.
f602a2 72         hasMore = commits.size() >= itemsPerPage;
698678 73
JM 74         // header
ef5c58 75         if (pageResults) {
698678 76             // shortlog page
a45caa 77             add(new Label("header", objectId));
698678 78         } else {
JM 79             // summary page
80             // show shortlog page link
9c4725 81             add(new LinkPanel("header", "title", objectId, LogPage.class,
JM 82                     WicketUtils.newRepositoryParameter(repositoryName)));
698678 83         }
JM 84
85         ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
86         DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
87             private static final long serialVersionUID = 1L;
2a7306 88             int counter;
698678 89
JM 90             public void populateItem(final Item<RevCommit> item) {
91                 final RevCommit entry = item.getModelObject();
92                 final Date date = JGitUtils.getCommitDate(entry);
93
9adf62 94                 item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));
698678 95
98ce17 96                 // author search link
698678 97                 String author = entry.getAuthorIdent().getName();
2a7306 98                 LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
4e1930 99                         GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName,
JM 100                                 objectId, author, Constants.SearchType.AUTHOR));
33d8d8 101                 setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
98ce17 102                 item.add(authorLink);
698678 103
a645ba 104                 // merge icon
JM 105                 if (entry.getParentCount() > 1) {
1e8390 106                     item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
a645ba 107                 } else {
1e8390 108                     item.add(WicketUtils.newBlankImage("commitIcon"));
a645ba 109                 }
2a7306 110
a645ba 111                 // short message
698678 112                 String shortMessage = entry.getShortMessage();
a45caa 113                 String trimmedMessage = shortMessage;
JM 114                 if (allRefs.containsKey(entry.getId())) {
115                     trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
116                 } else {
117                     trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
118                 }
2a7306 119                 LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
JM 120                         trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
121                                 repositoryName, entry.getName()));
698678 122                 if (!shortMessage.equals(trimmedMessage)) {
1e8390 123                     WicketUtils.setHtmlTooltip(shortlog, shortMessage);
698678 124                 }
JM 125                 item.add(shortlog);
126
7d35e2 127                 item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
698678 128
2a7306 129                 item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
JM 130                         .newObjectParameter(repositoryName, entry.getName())));
131                 item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
008322 132                         .newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
JM 133                         .getParentCount() > 0));
2a7306 134                 item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
JM 135                         .newObjectParameter(repositoryName, entry.getName())));
698678 136
JM 137                 WicketUtils.setAlternatingBackground(item, counter);
138                 counter++;
139             }
140         };
50984c 141         add(logView);
698678 142
JM 143         // determine to show pager, more, or neither
ef5c58 144         if (limit <= 0) {
698678 145             // no display limit
JM 146             add(new Label("moreLogs", "").setVisible(false));
50984c 147         } else {
ef5c58 148             if (pageResults) {
698678 149                 // paging
JM 150                 add(new Label("moreLogs", "").setVisible(false));
151             } else {
152                 // more
ef5c58 153                 if (commits.size() == limit) {
698678 154                     // show more
2a7306 155                     add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
JM 156                             this, null), LogPage.class,
157                             WicketUtils.newRepositoryParameter(repositoryName)));
698678 158                 } else {
JM 159                     // no more
160                     add(new Label("moreLogs", "").setVisible(false));
161                 }
162             }
163         }
164     }
2a7306 165
f602a2 166     public boolean hasMore() {
JM 167         return hasMore;
168     }
698678 169 }