diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java index 9ce3a12..476e04d 100644 --- a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java @@ -1,14 +1,17 @@ package org.lucares.pdb.plot.api; import java.time.Instant; -import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.OffsetDateTime; -import java.time.OffsetTime; import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import org.apache.commons.lang3.StringUtils; public class PlotSettings { + + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private String query; private int height; @@ -95,7 +98,7 @@ public class PlotSettings { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC); } else { - return LocalDate.parse(dateFrom).atTime(OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC)); + return LocalDateTime.parse(dateFrom, DATE_FORMAT).atOffset(ZoneOffset.UTC); } } @@ -103,7 +106,7 @@ public class PlotSettings { if (StringUtils.isEmpty(dateTo)) { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC); } else { - return LocalDate.parse(dateTo).atTime(OffsetTime.of(23, 59, 59, 999_999_999, ZoneOffset.UTC)); + return LocalDateTime.parse(dateTo, DATE_FORMAT).atOffset(ZoneOffset.UTC); } } } diff --git a/pdb-ui/build.gradle b/pdb-ui/build.gradle index 02e4ac5..e520d04 100644 --- a/pdb-ui/build.gradle +++ b/pdb-ui/build.gradle @@ -13,6 +13,9 @@ dependencies { compile project(':performanceDb') compile project(':pdb-plotting') + compile('org.springframework.boot:spring-boot-starter-mustache:1.5.2.RELEASE') { + exclude module: 'spring-boot-starter-logging' + } compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE"){ exclude module: 'spring-boot-starter-logging' } diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java b/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java index 94e14bd..c01f1ed 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java @@ -2,9 +2,13 @@ package org.lucares.pdbui; import java.io.File; import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.lucares.ludb.FieldNotExistsException; import org.lucares.ludb.Proposal; @@ -23,12 +27,14 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; @Controller @EnableAutoConfiguration @@ -36,6 +42,9 @@ public class PdbController implements HardcodedValues, CollectionUtils { private static final Logger LOGGER = LoggerFactory.getLogger(PdbController.class); + private static final DateTimeFormatter DATE_FORMAT_BEGIN = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00"); + private static final DateTimeFormatter DATE_FORMAT_END = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59"); + private final Plotter plotter; private final PdbRepository db; @@ -44,6 +53,15 @@ public class PdbController implements HardcodedValues, CollectionUtils { this.plotter = plotter; } + @GetMapping("/") + public ModelAndView index() { + final String view = "main"; + final Map model = new HashMap<>(); + model.put("oldestValue", LocalDateTime.now().minusYears(1).format(DATE_FORMAT_BEGIN)); + model.put("latestValue", LocalDateTime.now().format(DATE_FORMAT_END)); + return new ModelAndView(view, model); + } + @RequestMapping(path = "/plots", // method = RequestMethod.POST, // consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, // diff --git a/pdb-ui/src/main/resources/resources/js/search.js b/pdb-ui/src/main/resources/resources/js/search.js index 1ef5c75..682e18b 100644 --- a/pdb-ui/src/main/resources/resources/js/search.js +++ b/pdb-ui/src/main/resources/resources/js/search.js @@ -66,7 +66,7 @@ function renderGroupBy() }; var error = function(e) { - $('#result-view').text("FAILED: " + JSON.stringify(e)); + $('#result-view').text("FAILED: " + JSON.parse(e.responseText).message); }; @@ -78,7 +78,6 @@ function showLoadingIcon() $('#result-view').html("
"); } - function plot(event){ event.preventDefault(); // prevent submit of form which would reload the page @@ -104,11 +103,10 @@ function plot(event){ $('#result-view').text("No data points found."); } else{ - $('#result-view').text("FAILED: " + JSON.stringify(e)); + $('#result-view').text("FAILED: " + JSON.parse(e.responseText).message); } }; - postJson("plots", request, success, error); } diff --git a/pdb-ui/src/main/resources/resources/index.html b/pdb-ui/src/main/resources/templates/main.html similarity index 89% rename from pdb-ui/src/main/resources/resources/index.html rename to pdb-ui/src/main/resources/templates/main.html index 2613289..ca6badf 100644 --- a/pdb-ui/src/main/resources/resources/index.html +++ b/pdb-ui/src/main/resources/templates/main.html @@ -30,10 +30,10 @@ - + - +