Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
allow custom stylesheets on templated html pages
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyajohnson committed Jun 19, 2018
1 parent 74d9b9e commit 2e47930
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,30 @@ public Map<String, Object> getDatasetViewContext(Dataset ds, HttpServletRequest
}

private void addBaseContext(Map<String, Object> model) {

String googleTrackingCode = htmlConfig.getGoogleTrackingCode();
if (googleTrackingCode.isEmpty()) googleTrackingCode = null;
model.put("googleTracking", googleTrackingCode);

model.put("serverName", serverInfo.getName());
model.put("logoUrl", serverInfo.getLogoUrl());
model.put("logoAlt", serverInfo.getLogoAltText());

model.put("installName", htmlConfig.getInstallName());
model.put("installUrl", htmlConfig.getInstallUrl());

model.put("webappName", htmlConfig.getWebappName());
model.put("webappUrl", htmlConfig.getWebappUrl());
model.put("webappVersion", htmlConfig.getWebappVersion());
model.put("webappBuildTimestamp", htmlConfig.getWebappVersionBuildDate());
model.put("webbappDocsUrl", htmlConfig.getWebappDocsUrl());

model.put("hostInst", htmlConfig.getHostInstName());
model.put("hostInstUrl", htmlConfig.getHostInstUrl());

model.put("standardCSS", htmlConfig.getPageCssUrl());
model.put("catalogCSS", htmlConfig.getCatalogCssUrl());
model.put("datasetCSS", htmlConfig.getDatasetCssUrl());
}

protected void addCatalogItems(DatasetNode cat, List<CatalogItemContext> catalogItems, boolean isLocalCatalog, int level)
Expand Down
35 changes: 35 additions & 0 deletions tds/src/main/java/thredds/server/config/HtmlConfigBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class HtmlConfigBean {

private String pageCssUrl;
private String catalogCssUrl;
private String datasetCssUrl;
private String openDapCssUrl;
private String googleTrackingCode;

private String folderIconUrl;
Expand Down Expand Up @@ -150,6 +152,22 @@ public void setPageCssUrl(String pageCssUrl) {
this.pageCssUrl = pageCssUrl;
}

/**
* Return the URL to the CSS file used for the OPeNDAP access pages.
* <p/>
* <p>Note: A relative URL is considered relative to the webapp context path.
* That is, it is relative to "http://server:port/thredds/".
*
* @return the URL to the CSS file used for the OPeNDAP access pages.
*/
public String getOpenDapCssUrl() {
return openDapCssUrl;
}

public void setOpenDapCssUrl(String openDapCssUrl) {
this.openDapCssUrl = openDapCssUrl;
}

/**
* Return the URL to the CSS file used for catalog HTML pages.
* <p/>
Expand All @@ -166,6 +184,22 @@ public void setCatalogCssUrl(String catalogCssUrl) {
this.catalogCssUrl = catalogCssUrl;
}

/**
* Return the URL to the CSS file used for catalog HTML pages.
* <p/>
* <p>Note: A relative URL is considered relative to the webapp context path.
* That is, it is relative to "http://server:port/thredds/".
*
* @return the URL to the CSS file used for catalog HTML pages.
*/
public String getDatasetCssUrl() {
return datasetCssUrl;
}

public void setDatasetCssUrl(String datasetCssUrl) {
this.datasetCssUrl = datasetCssUrl;
}

/**
* Return the google tracking code for google analytics.
*
Expand Down Expand Up @@ -389,6 +423,7 @@ public String prepareUrlStringForHtml(String url) {
public void addHtmlConfigInfoToModel(Map<String, Object> model) {
model.put("catalogCssUrl", this.getCatalogCssUrl());
model.put("standardCssUrl", this.getPageCssUrl());
model.put("openDapCssUrl", this.getOpenDapCssUrl());
model.put("googleTrackingCode", this.getGoogleTrackingCode());
model.put("datasetIconAlt", this.getDatasetIconAlt());
model.put("datasetIconUrl", this.getDatasetIconUrl());
Expand Down
8 changes: 6 additions & 2 deletions tds/src/main/java/thredds/server/config/TdsConfigMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ static void load(TdsServerInfoBean info) {


enum HtmlConfigMappings {
HTML_STANDARD_CSS_URL("htmlSetup.standardCssUrl", null, "tds.css"),
HTML_CATALOG_CSS_URL("htmlSetup.catalogCssUrl", null, "tdsCat.css"),
HTML_STANDARD_CSS_URL("htmlSetup.standardCssUrl", null, ""),
HTML_CATALOG_CSS_URL("htmlSetup.catalogCssUrl", null, ""),
HTML_DATASET_CSS_URL("htmlSetip.datasetCssUrl", null, ""),
HTML_OPENDAP_CSS_URL("htmlSetup.openDapCssUrl", null, "tdsDap.css"),
GOOGLE_TRACKING_CODE("htmlSetup.googleTrackingCode", null, ""),

HTML_FOLDER_ICON_URL("htmlSetup.folderIconUrl", null, "folder.gif"),
Expand Down Expand Up @@ -136,6 +138,8 @@ static void load(HtmlConfigBean htmlConfig, TdsContext tdsContext, TdsServerInfo

htmlConfig.setPageCssUrl(HTML_STANDARD_CSS_URL.getValueFromThreddsConfig());
htmlConfig.setCatalogCssUrl(HTML_CATALOG_CSS_URL.getValueFromThreddsConfig());
htmlConfig.setDatasetCssUrl(HTML_DATASET_CSS_URL.getValueFromThreddsConfig());
htmlConfig.setOpenDapCssUrl(HTML_OPENDAP_CSS_URL.getValueFromThreddsConfig());
htmlConfig.setGoogleTrackingCode(GOOGLE_TRACKING_CODE.getValueFromThreddsConfig());

htmlConfig.setFolderIconUrl(HTML_FOLDER_ICON_URL.getValueFromThreddsConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<standardCssUrl>tds.css</standardCssUrl>
<catalogCssUrl>tdsCat.css</catalogCssUrl>
<datasetCssUrl>tdsDst.css</datasetCssUrl>
<openDapCssUrl>tdsDap.css</openDapCssUrl>
* -->

Expand Down
6 changes: 4 additions & 2 deletions tds/src/main/webapp/WEB-INF/templates/catalog.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<head th:replace="templates/commonFragments :: head(~{::title}, ~{::script}, ~{::link})">
<title>TDS Catalog</title>
<link rel="stylesheet" href="/thredds/tds.css" type="text/css">
<link rel="stylesheet" th:if="${!#strings.isEmpty(standardCSS)}" th:href="'/thredds/' + ${standardCSS}" type="text/css">
<link rel="stylesheet" th:if="${!#strings.isEmpty(catalogCSS)}" th:href="'/thredds/' + ${catalogCSS}" type="text/css">
<!-- Google Analytics -->
<script th:if="${googleTracking != null}" type="text/javascript" th:inline="javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand All @@ -20,7 +22,7 @@

<body>

<div th:replace="~{templates/datasetFragments :: catalogHeader}"/>
<div th:replace="~{templates/commonFragments :: header}"/>

<table width="100%" cellspacing="0" cellpadding="5" align="center">
<tbody>
Expand All @@ -46,7 +48,7 @@
</tbody>
</table>

<div th:replace="~{templates/datasetFragments :: catalogFooter}"/>
<div th:replace="~{templates/commonFragments :: footer}"/>

</body>
</html>
20 changes: 0 additions & 20 deletions tds/src/main/webapp/WEB-INF/templates/commonFragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@

<body>

<div class="header" th:fragment="header(titleText, switchLinks)">
<div class="pageTitle">
<h1 th:text="${titleText}">NetCDF Subset Service</h1>
<h4 th:replace="${switchLinks}">Switch to alternate request type.</h4>
</div>

<div class="unidata">
<div class="appTitle">
<img src="https://www.unidata.ucar.edu/img/v3/logos/uniTitle.png">
<div>
<span class="bold">THREDDS Data Server</span>
<span class="service">NetCDF Subset Service</span>
</div>
</div>

<img src="https://www.unidata.ucar.edu/img/v3/logos/uniLogo.png">
</div>
</div>


<div th:fragment="header">
<div class="header">
<div class="header-logo"><img th:src="${logoUrl}" th:alt="${logoAlt}"></div>
Expand Down
6 changes: 4 additions & 2 deletions tds/src/main/webapp/WEB-INF/templates/dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<head th:replace="templates/commonFragments :: head(~{::title}, ~{::script}, ~{::link})">
<title>Catalog Services</title>
<link rel="stylesheet" href="/thredds/tds.css" type="text/css">
<link rel="stylesheet" th:if="${!#strings.isEmpty(standardCSS)}" th:href="'/thredds/' + ${standardCSS}" type="text/css">
<link rel="stylesheet" th:if="${!#strings.isEmpty(datasetCSS)}" th:href="'/thredds/' + ${datasetCSS}" type="text/css">
<script type="text/javascript" th:inline="javascript">
</script>
</head>

<body>


<div th:replace="~{templates/datasetFragments :: catalogHeader}"/>
<div th:replace="~{templates/commonFragments :: header}"/>

<h2 th:text="'Catalog ' + ${dataset.getCatUrl()}"></h2>
<h2 th:text="'Dataset: ' + ${dataset.getName()}"></h2>
Expand Down Expand Up @@ -46,7 +48,7 @@ <h2 th:text="'Dataset: ' + ${dataset.getName()}"></h2>

<div th:replace="${dataset.getViewerLinks().size() > 0} ? ~{templates/datasetFragments :: viewers} : ~{}"/>

<div th:replace="~{templates/datasetFragments :: catalogFooter}"/>
<div th:replace="~{templates/commonFragments :: footer}"/>

</body>
</html>

0 comments on commit 2e47930

Please sign in to comment.