Skip to content

Commit

Permalink
Merge pull request #42 from Acrotrend/master
Browse files Browse the repository at this point in the history
Template functionality added
  • Loading branch information
fmichielssen committed Jan 5, 2018
2 parents 01af813 + 4be1ab2 commit e12ddcf
Show file tree
Hide file tree
Showing 38 changed files with 1,109 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -407,6 +407,7 @@
<exclude>**/*.json</exclude>
<exclude>.gitignore</exclude>
<exclude>src/deb/**</exclude>
<exclude>templates/**</exclude>
</excludes>
</configuration>
<executions>
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/eu/openanalytics/StaticResourceConfig.java
@@ -0,0 +1,45 @@
/**
* ShinyProxy
*
* Copyright (C) 2016-2017 Open Analytics
*
* ===========================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Apache License as published by
* The Apache Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Apache License for more details.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/>
*/
package eu.openanalytics;

import org.springframework.core.env.Environment;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.inject.Inject;

@Configuration
public class StaticResourceConfig extends WebMvcConfigurerAdapter {

@Inject
Environment environment;

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/thumbnail/**")
.addResourceLocations("file:../thumbnail/");

// External templates static dir
registry.addResourceHandler("/assets/**")
.addResourceLocations("file:"+environment.getProperty("shiny.proxy.template_path")+"/assets/");
}
}
53 changes: 53 additions & 0 deletions src/main/java/eu/openanalytics/TemplateResolverConfig.java
@@ -0,0 +1,53 @@
/**
* ShinyProxy
*
* Copyright (C) 2016-2017 Open Analytics
*
* ===========================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Apache License as published by
* The Apache Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Apache License for more details.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/>
*/

package eu.openanalytics;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.templateresolver.FileTemplateResolver;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

@Configuration
public class TemplateResolverConfig {

@Inject
Environment environment;

@Autowired
private SpringTemplateEngine templateEngine;

@PostConstruct
public void extension() {
FileTemplateResolver resolver = new FileTemplateResolver();
resolver.setPrefix(environment.getProperty("shiny.proxy.template_path")+"/");
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML5");
resolver.setOrder(templateEngine.getTemplateResolvers().size());
resolver.setCacheable(false);
templateEngine.addTemplateResolver(resolver);
}

}
1 change: 1 addition & 0 deletions src/main/java/eu/openanalytics/WebSecurityConfig.java
Expand Up @@ -64,6 +64,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring().antMatchers("/assets/**").and()
.ignoring().antMatchers("/css/**").and()
.ignoring().antMatchers("/webjars/**");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/eu/openanalytics/services/AppService.java
Expand Up @@ -56,6 +56,7 @@ public static class ShinyApp {
private String name;
private String displayName;
private String description;
private String thumbImage;
private String logoUrl;
private String[] dockerCmd;
private String dockerImage;
Expand All @@ -82,6 +83,13 @@ public String getDisplayName() {
public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public String getThumbImage() {
return thumbImage;
}
public void setThumbImage(String thumbImage) {
this.thumbImage = thumbImage;
}

public String getDescription() {
return description;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application-demo.yml
Expand Up @@ -7,6 +7,8 @@ shiny:
heartbeat-timeout: 60000
port: 8080
authentication: ldap
# Custom template setting: if you want enable a custom template please uncomment this field
#template_path: ../templates/1col
admin-groups: scientists
# Example: 'simple' authentication configuration
users:
Expand Down Expand Up @@ -36,10 +38,14 @@ shiny:
docker-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
docker-image: openanalytics/shinyproxy-demo
groups: scientists, mathematicians
# when you want add a thumbnail please add inside /thumbnail/ directory
thumb-image: 01_hello.png
- name: 06_tabsets
docker-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
docker-image: openanalytics/shinyproxy-demo
groups: scientists
# when you want add a thumbnail please add inside /thumbnail/ directory
thumb-image: 06_tabsets.png

logging:
file:
Expand Down
61 changes: 61 additions & 0 deletions templates/1col/admin.html
@@ -0,0 +1,61 @@
<!--
ShinyProxy
Copyright (C) 2016-2017 Open Analytics
===========================================================================
This program is free software: you can redistribute it and/or modify
it under the terms of the Apache License as published by
The Apache Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Apache License for more details.
You should have received a copy of the Apache License
along with this program. If not, see <http://www.apache.org/licenses/>
-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head lang="en">
<title th:text="${title}"></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" media="screen" th:href="@{/assets/css/bootstrap.min.css}"/>
<link rel="stylesheet" media="screen" th:href="@{/assets/css/default.css}"/>
<script th:src="@{/assets/js/jquery.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
</head>
<body>
<!-- navigation bar -->
<div th:replace="../fragments/navbar :: navbar"></div>

<!-- content -->
<div id="admin">
<h3>Container Activity</h3>
<table border="1">
<tr>
<th>Name</th>
<th>Port</th>
<th>Username</th>
<th>Appname</th>
<th>Container Id</th>
<th>Uptime</th>
</tr>
<tr th:each="proxy: ${proxies}">
<td th:text="${proxy.name}"></td>
<td th:text="${proxy.port}"></td>
<td th:text="${proxy.userName}"></td>
<td th:text="${proxy.appName}"></td>
<td th:text="${proxy.containerId}"></td>
<td th:text="${proxy.uptime()}"></td>
</tr>
</table>
</div>
</body>
</html>
74 changes: 74 additions & 0 deletions templates/1col/app.html
@@ -0,0 +1,74 @@
<!--
ShinyProxy
Copyright (C) 2016-2017 Open Analytics
===========================================================================
This program is free software: you can redistribute it and/or modify
it under the terms of the Apache License as published by
The Apache Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Apache License for more details.
You should have received a copy of the Apache License
along with this program. If not, see <http://www.apache.org/licenses/>
-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head lang="en">
<title th:text="${title}"></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" media="screen" th:href="@{/assets/css/bootstrap.min.css}"/>
<link rel="stylesheet" media="screen" th:href="@{/assets/css/default.css}"/>
<script th:src="@{/assets/js/jquery.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
</head>
<body>
<!-- navigation bar -->
<div th:replace="../fragments/navbar :: navbar"></div>

<!-- content -->
<iframe id="shinyframe" th:src="${container}" width="100%"></iframe>
<div class="loading"><div class="loading-txt">Launching <span th:text="${appTitle}"></span>...</div></div>

<script type="text/javascript" th:inline="javascript">
function setShinyframeHeight() {
$('#shinyframe').css('height', ($(window).height()-6)+'px');
}
window.addEventListener("load", setShinyframeHeight);
window.addEventListener("resize", setShinyframeHeight);

function heartbeat() {
setTimeout(function() {
$.ajax([[${heartbeatPath}]] + window.location.pathname).success(function(data) {
heartbeat();
});
}, [[${heartbeatRate}]]);
};
heartbeat();

$(window).load(function() {
var source = $("#shinyframe").attr("src");
if (source == "") {
$(".loading").show();
$.post(window.location.pathname, function(containerPath) {
$("#shinyframe").attr("src", containerPath);
$(".loading").fadeOut("slow");
}).fail(function(request) {
var newDoc = document.open("text/html", "replace");
newDoc.write(request.responseText);
newDoc.close();
});
}
});
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions templates/1col/assets/css/1-col-portfolio.css
@@ -0,0 +1,31 @@
/**
* ShinyProxy
*
* Copyright (C) 2016-2017 Open Analytics
*
* ===========================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Apache License as published by
* The Apache Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Apache License for more details.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/>
*/

body {
padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
}

footer {
margin: 50px 0;
}
.img-responsive {
max-height: 300px;
}
6 changes: 6 additions & 0 deletions templates/1col/assets/css/bootstrap.min.css

Large diffs are not rendered by default.

0 comments on commit e12ddcf

Please sign in to comment.