create web application

This commit is contained in:
2016-12-21 17:48:36 +01:00
parent 35054b00b8
commit d1e39513f3
65 changed files with 805 additions and 43 deletions

View File

@@ -0,0 +1,12 @@
package org.lucares.pdbui;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("org.lucares.pdbui")
// @PropertySource("classpath:/config.system.properties")
// @PropertySource("classpath:/config.user.properties")
public class MySpringConfiguration {
}

View File

@@ -0,0 +1,14 @@
package org.lucares.pdbui;
import java.nio.file.Paths;
import org.springframework.boot.SpringApplication;
public class MyWebapp {
public static final String IMAGE_DIR = Paths.get("/tmp/images").toFile().getAbsolutePath() + "/";
public static void main(final String[] args) throws Exception {
SpringApplication.run(MySpringConfiguration.class, args);
}
}

View File

@@ -0,0 +1,34 @@
package org.lucares.pdbui;
import org.lucares.pdbui.domain.PlotRequest;
import org.lucares.pdbui.domain.PlotResponse;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class PdbController {
private final PdbRepository pdbRepository;
public PdbController(final PdbRepository pdbRepository) {
this.pdbRepository = pdbRepository;
}
@RequestMapping(path = "/plots", //
method = RequestMethod.POST, //
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
)
@ResponseBody
PlotResponse createPlot(@RequestBody final PlotRequest request) {
System.out.println(request.getQuery());
return new PlotResponse("img/abc.png");
}
}

View File

@@ -0,0 +1,19 @@
package org.lucares.pdbui;
import org.lucares.performance.db.PerformanceDb;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Repository;
@Repository
public class PdbRepository implements DisposableBean {
private final PerformanceDb db;
public PdbRepository(final PerformanceDb db) {
this.db = db;
}
@Override
public void destroy() {
db.close();
}
}

View File

@@ -0,0 +1,14 @@
package org.lucares.pdbui;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/**").addResourceLocations("file:" + MyWebapp.IMAGE_DIR);
}
}

View File

@@ -0,0 +1,18 @@
package org.lucares.pdbui.domain;
public class PlotRequest {
private String query;
public String getQuery() {
return query;
}
public void setQuery(final String query) {
this.query = query;
}
@Override
public String toString() {
return query;
}
}

View File

@@ -0,0 +1,31 @@
package org.lucares.pdbui.domain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PlotResponse {
private List<String> imageUrls = new ArrayList<>();
public PlotResponse() {
super();
}
public PlotResponse(final String... imageUrls) {
this.imageUrls.addAll(Arrays.asList(imageUrls));
}
public List<String> getImageUrls() {
return imageUrls;
}
public void setImageUrls(final List<String> imageUrls) {
this.imageUrls = imageUrls;
}
@Override
public String toString() {
return String.valueOf(imageUrls);
}
}

View File

@@ -0,0 +1 @@
db.base=/tmp/db

View File

@@ -0,0 +1 @@
db.base=/home/andi/ws/performanceDb/db

View File

@@ -0,0 +1,55 @@
body {
margin:0;
padding:0;
}
@font-face {
font-family: 'FontAwesome';
src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');
src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
#top-menu-bar {
background-color: black;
color: white;
padding: 3px;
}
#logo {
font-weight: bold;
}
#search-bar {
background-color: #aaa;
text-align: right;
padding-bottom:3px;
}
#search-bar #search-query {
width:100%;
padding:2;
border:0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#search-bar #search-submit {
margin-right:3px;
}
#result-view {
background: red;
font-size: 32px;
}
#result-view i {
background: white;
display:inline;
font-style:normal;
line-height: 1.2em;
}

View File

@@ -0,0 +1,34 @@
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* makes the font 33% larger relative to the icon container */
.fa-lg {
font-size: 1.33333333em;
line-height: 0.75em;
vertical-align: -15%;
}
.fa-2x {
font-size: 2em;
}
.fa-3x {
font-size: 3em;
}
.fa-4x {
font-size: 4em;
}
.fa-5x {
font-size: 5em;
}
.fa-search:before {
content: "\f002";
}
.fa-icons:before {
content: "\f002";
}

View File

@@ -0,0 +1,8 @@
body, p, td, th, textarea
{
font-family: sans-serif;
}
textarea {
font-size:1.2em;
}

View File

@@ -0,0 +1,2 @@
/font-awesome-4.7.0/
/font-awesome-4.7.0.zip

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/search.js"></script>
<link rel="stylesheet" type="text/css" href="css/typography.css">
<link rel="stylesheet" type="text/css" href="css/design.css">
<link rel="stylesheet" type="text/css" href="css/icons.css">
</head>
<body>
<div id="top-menu-bar">
<div id="logo">LOGO</div>
</div>
<div id="search-bar">
<textarea id="search-query"></textarea>
<button id="search-submit"><i class="fa fa-search"> Search</i></button>
</div>
<div id="result-view">
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,39 @@
$(document).ready(function(){
$('#search-submit').click(function(event){
event.preventDefault(); // prevent submit of form which would reload the page
var request = {};
request['query'] = $('#search-query').val();
var success = function(response){
$('#result-view').text("SUCCESS: "+response.imageUrls);
};
var error = function(e) {
//var response = JSON.parse(e.responseText);
$('#result-view').text("FAILED: " + JSON.stringify(e));
};
postJson("plots", request, success, error);
});
});
function postJson(url, requestData, successCallback, errorCallback) {
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(requestData),
contentType: 'application/json'
})
.done(successCallback)
.fail(errorCallback);
}

View File

@@ -0,0 +1,11 @@
package org.lucares.pdbui;
import org.lucares.pdbui.MySpringConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
@SpringBootTest
@Import(MySpringConfiguration.class)
public class MySpringTestConfiguration {
}

View File

@@ -0,0 +1,24 @@
package org.lucares.pdbui;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MySpringTestConfiguration.class)
public class TimeTest {
// @Autowired
// private PdbController timeController;
//
// @Test
// public void testReturnedTimeIsNow() throws Exception {
// final Date before = new Date();
//
// final Date now = timeController.time();
// final Date after = new Date();
//
// Assert.assertTrue(before.compareTo(now) <= 0);
// Assert.assertTrue(now.compareTo(after) <= 0);
// }
}