Skip to content

Commit 7c29a83

Browse files
tulinkryVladimir Kotal
authored andcommitted
Templating projects and repositories on the main page (#2719)
reusing project and repository templates - using JSTL tags for implementing reusable templating - reusing the tags on appropriate places so the code is not duplicated fixes #2685
1 parent af8b92a commit 7c29a83

File tree

8 files changed

+279
-277
lines changed

8 files changed

+279
-277
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/nbproject/configs/*.properties
44
tags
55
TAGS
6+
!opengrok-web/src/main/webapp/WEB-INF/tags
67
build
78
dist
89
coverage

opengrok-indexer/src/main/java/org/opengrok/indexer/web/ProjectHelper.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
23+
* Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
2324
*/
2425
package org.opengrok.indexer.web;
2526

27+
import static org.opengrok.indexer.web.PageConfig.OPEN_GROK_PROJECT;
28+
2629
import java.util.ArrayList;
30+
import java.util.Comparator;
2731
import java.util.List;
2832
import java.util.Locale;
2933
import java.util.Map;
3034
import java.util.Set;
3135
import java.util.TreeMap;
3236
import java.util.TreeSet;
3337
import java.util.function.Predicate;
38+
import java.util.stream.Collectors;
3439
import org.opengrok.indexer.configuration.Group;
3540
import org.opengrok.indexer.configuration.Project;
3641
import org.opengrok.indexer.history.RepositoryInfo;
3742

38-
import static org.opengrok.indexer.web.PageConfig.OPEN_GROK_PROJECT;
39-
4043
/**
4144
* Preprocessing of projects, repositories and groups for the UI
4245
*
@@ -57,6 +60,8 @@ public final class ProjectHelper {
5760
private static final String PROJECT_HELPER_SUBGROUPS_OF = "project_helper_subgroups_of_";
5861
private static final String PROJECT_HELPER_FAVOURITE_GROUP = "project_helper_favourite_group";
5962

63+
private static final Comparator<RepositoryInfo> REPOSITORY_NAME_COMPARATOR = Comparator.comparing(RepositoryInfo::getDirectoryName);
64+
6065
private PageConfig cfg;
6166
/**
6267
* Set of groups
@@ -123,6 +128,23 @@ public List<RepositoryInfo> getRepositoryInfo(Project p) {
123128
return info == null ? new ArrayList<>() : new ArrayList<>(info);
124129
}
125130

131+
/**
132+
* Get repository info list for particular project. A copy of the list is
133+
* returned always to allow concurrent modifications of the list in the
134+
* caller. The items in the list shall not be modified concurrently, though.
135+
* This list is sorted with respect {@link #REPOSITORY_NAME_COMPARATOR}.
136+
*
137+
* @param p the project for which we find the repository info list
138+
* @return Copy of a list of repository info or empty list if no info is
139+
* found
140+
*/
141+
public List<RepositoryInfo> getSortedRepositoryInfo(Project p) {
142+
return getRepositoryInfo(p)
143+
.stream()
144+
.sorted(REPOSITORY_NAME_COMPARATOR)
145+
.collect(Collectors.toList());
146+
}
147+
126148
/**
127149
* Generates ungrouped projects and repositories.
128150
*/

opengrok-web/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
5858
<groupId>javax.servlet</groupId>
5959
<artifactId>javax.servlet-api</artifactId>
6060
</dependency>
61+
<dependency>
62+
<groupId>javax.servlet</groupId>
63+
<artifactId>jsp-api</artifactId>
64+
<version>2.0</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>javax.servlet</groupId>
68+
<artifactId>jstl</artifactId>
69+
<version>1.2</version>
70+
</dependency>
6171
<dependency>
6272
<groupId>org.glassfish.jersey.containers</groupId>
6373
<artifactId>jersey-container-servlet</artifactId>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<%--
2+
CDDL HEADER START
3+
4+
The contents of this file are subject to the terms of the
5+
Common Development and Distribution License (the "License").
6+
You may not use this file except in compliance with the License.
7+
8+
See LICENSE.txt included in this distribution for the specific
9+
language governing permissions and limitations under the License.
10+
11+
When distributing Covered Code, include this CDDL HEADER in each
12+
file and include the License file at LICENSE.txt.
13+
If applicable, add the following below this CDDL HEADER, with the
14+
fields enclosed by brackets "[]" replaced with your own identifying
15+
information: Portions Copyright [yyyy] [name of copyright owner]
16+
17+
CDDL HEADER END
18+
19+
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
20+
Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
21+
--%>
22+
<%@ tag import="org.opengrok.indexer.web.Prefix" %>
23+
<%@ tag import="org.opengrok.indexer.web.Util" %>
24+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
25+
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
26+
<%@ taglib prefix="opengrok" tagdir="/WEB-INF/tags" %>
27+
28+
<%@ attribute name="project" required="true" type="org.opengrok.indexer.configuration.Project" %>
29+
30+
<tr>
31+
<td colspan="3" class="name repository">
32+
<a href="${request.getContextPath}${Prefix.XREF_P.toString()}/${project.name}"
33+
title="Xref for project ${Util.htmlize(project.name)}">
34+
${Util.htmlize(project.name)}
35+
</a>
36+
</td>
37+
</tr>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<%--
2+
CDDL HEADER START
3+
4+
The contents of this file are subject to the terms of the
5+
Common Development and Distribution License (the "License").
6+
You may not use this file except in compliance with the License.
7+
8+
See LICENSE.txt included in this distribution for the specific
9+
language governing permissions and limitations under the License.
10+
11+
When distributing Covered Code, include this CDDL HEADER in each
12+
file and include the License file at LICENSE.txt.
13+
If applicable, add the following below this CDDL HEADER, with the
14+
fields enclosed by brackets "[]" replaced with your own identifying
15+
information: Portions Copyright [yyyy] [name of copyright owner]
16+
17+
CDDL HEADER END
18+
19+
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
20+
Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
21+
--%>
22+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
23+
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
24+
<%@ taglib prefix="opengrok" tagdir="/WEB-INF/tags" %>
25+
26+
<%@ attribute name="projects" required="true" type="java.util.Set<org.opengrok.indexer.configuration.Project>" %>
27+
28+
<c:if test="${projects.size() > 0}">
29+
<thead>
30+
<tr>
31+
<td colspan="3"><b>Project</b></td>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
<c:forEach var="project" items="${projects}">
36+
<c:if test="${project.indexed}">
37+
<opengrok:project
38+
project="${project}"
39+
/>
40+
</c:if>
41+
</c:forEach>
42+
</tbody>
43+
</c:if>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<%--
2+
CDDL HEADER START
3+
4+
The contents of this file are subject to the terms of the
5+
Common Development and Distribution License (the "License").
6+
You may not use this file except in compliance with the License.
7+
8+
See LICENSE.txt included in this distribution for the specific
9+
language governing permissions and limitations under the License.
10+
11+
When distributing Covered Code, include this CDDL HEADER in each
12+
file and include the License file at LICENSE.txt.
13+
If applicable, add the following below this CDDL HEADER, with the
14+
fields enclosed by brackets "[]" replaced with your own identifying
15+
information: Portions Copyright [yyyy] [name of copyright owner]
16+
17+
CDDL HEADER END
18+
19+
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
20+
Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
21+
--%>
22+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
23+
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
24+
<%@ taglib prefix="opengrok" tagdir="/WEB-INF/tags" %>
25+
26+
<%@ attribute name="pageConfig" required="true" type="org.opengrok.indexer.web.PageConfig" %>
27+
<%@ attribute name="repositories" required="true" type="java.util.Set<org.opengrok.indexer.configuration.Project>" %>
28+
29+
<c:if test="${repositories.size() > 0}">
30+
<thead>
31+
<tr>
32+
<td><b>Repository</b></td>
33+
<td><b>SCM Type: Parent (branch)</b></td>
34+
<td><b>Current version</b></td>
35+
</tr>
36+
</thead>
37+
<tbody>
38+
<c:forEach var="project" items="${repositories}">
39+
<c:if test="${project.indexed}">
40+
<c:forEach var="repositoryInfo"
41+
items="${pageConfig.projectHelper.getSortedRepositoryInfo(project)}"
42+
varStatus="iterator">
43+
<c:if test="${iterator.first || repositoryInfo.parent != null}">
44+
<opengrok:repository
45+
pageConfig="${pageConfig}"
46+
project="${project}"
47+
repositoryInfo="${repositoryInfo}"
48+
isFirst="${iterator.first}"
49+
/>
50+
</c:if>
51+
</c:forEach>
52+
</c:if>
53+
</c:forEach>
54+
</tbody>
55+
</c:if>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<%--
2+
CDDL HEADER START
3+
4+
The contents of this file are subject to the terms of the
5+
Common Development and Distribution License (the "License").
6+
You may not use this file except in compliance with the License.
7+
8+
See LICENSE.txt included in this distribution for the specific
9+
language governing permissions and limitations under the License.
10+
11+
When distributing Covered Code, include this CDDL HEADER in each
12+
file and include the License file at LICENSE.txt.
13+
If applicable, add the following below this CDDL HEADER, with the
14+
fields enclosed by brackets "[]" replaced with your own identifying
15+
information: Portions Copyright [yyyy] [name of copyright owner]
16+
17+
CDDL HEADER END
18+
19+
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
20+
Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
21+
--%>
22+
<%@ tag import="java.nio.file.Paths" %>
23+
<%@ tag import="org.apache.commons.lang3.ObjectUtils" %>
24+
<%@ tag import="org.opengrok.indexer.web.Prefix" %>
25+
<%@ tag import="org.opengrok.indexer.web.Util" %>
26+
<%@ tag import="org.opengrok.indexer.web.messages.MessagesUtils" %>
27+
28+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
29+
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
30+
31+
<%@ attribute name="pageConfig" required="true" type="org.opengrok.indexer.web.PageConfig" %>
32+
<%@ attribute name="project" required="true" type="org.opengrok.indexer.configuration.Project" %>
33+
<%@ attribute name="repositoryInfo" required="true" type="org.opengrok.indexer.history.RepositoryInfo" %>
34+
<%@ attribute name="isFirst" required="true" type="java.lang.Boolean" %>
35+
36+
<c:set var="isSubrepository" value="${!repositoryInfo.getDirectoryNameRelative().equals(project.getPath())}"/>
37+
<c:set var="name" value="${project.name}"/>
38+
<c:set var="defaultLength" value="${Integer.valueOf(10)}"/>
39+
<c:set var="summary" value="${ObjectUtils.defaultIfNull(repositoryInfo.currentVersion, \"N/A\")}"/>
40+
<c:set var="maxLength" value="${Math.max(defaultLength, pageConfig.currentIndexedCollapseThreshold)}"/>
41+
42+
<c:if test="${isSubrepository}">
43+
<c:set var="name"
44+
value="${Paths.get(pageConfig.sourceRootPath).relativize(Paths.get(repositoryInfo.directoryName))}"/>
45+
</c:if>
46+
47+
<c:if test="${isSubrepository && isFirst}">
48+
<tr>
49+
<td class="name repository" colspan="3">
50+
<a href="${request.getContextPath()}${Prefix.XREF_P.toString()}/${project.name}"
51+
title="Xref for project ${Util.htmlize(project.name)}">
52+
${Util.htmlize(project.name)}
53+
</a>
54+
</td>
55+
</tr>
56+
</c:if>
57+
58+
<tr>
59+
<td class="name ${isSubrepository ? "subrepository" : "repository"}">
60+
<a href="${request.getContextPath()}${Prefix.XREF_P.toString()}/${project.name}"
61+
title="Xref for project ${Util.htmlize(name)}">
62+
${Util.htmlize(name)}
63+
</a>
64+
65+
<c:set var="messages" value="${MessagesUtils.messagesToJson(project)}"/>
66+
<c:if test="${not empty messages}">
67+
<span class="important-note important-note-rounded"
68+
data-messages='${messages}'>!</span>
69+
</c:if>
70+
</td>
71+
<td>${Util.htmlize(ObjectUtils.defaultIfNull(repositoryInfo.type, "N/A"))}:
72+
${Util.linkify(ObjectUtils.defaultIfNull(Util.redactUrl(repositoryInfo.parent), "N/A"))}
73+
(${Util.htmlize(ObjectUtils.defaultIfNull(repositoryInfo.branch, "N/A"))})
74+
</td>
75+
<td>
76+
<c:choose>
77+
<c:when test="${summary.length() > maxLength}">
78+
<span class="rev-message-summary">${Util.htmlize(summary.substring(0, maxLength))}</span>
79+
<span class="rev-message-full rev-message-hidden">${Util.htmlize(summary)}</span>
80+
<span data-toggle-state="less"><a class="rev-toggle-a rev-message-toggle"
81+
href="#">show more ... </a></span>
82+
</c:when>
83+
<c:otherwise>
84+
<span class="rev-message-full">${Util.htmlize(summary)}</span>
85+
</c:otherwise>
86+
</c:choose>
87+
</td>
88+
</tr>

0 commit comments

Comments
 (0)