use vue.js for the UI

This commit is contained in:
2018-04-02 09:18:41 +02:00
parent 22c99f8517
commit 5e53e667fe
9 changed files with 11607 additions and 159 deletions

View File

@@ -1,7 +1,6 @@
package org.lucares.pdbui;
import java.text.Collator;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
@@ -12,6 +11,7 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.lang3.StringUtils;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.plot.api.PlotSettings;
import org.lucares.pdbui.domain.AutocompleteProposal;
@@ -28,6 +28,7 @@ import org.lucares.recommind.logs.Plotter;
import org.lucares.utils.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@@ -51,9 +52,12 @@ public class PdbController implements HardcodedValues {
private final Plotter plotter;
private final PerformanceDb db;
private final ReentrantLock plotterLock = new ReentrantLock();
@Value("${mode.production:true}")
private boolean modeProduction;
public PdbController(final PerformanceDb db, final Plotter plotter) {
this.db = db;
this.plotter = plotter;
@@ -63,8 +67,10 @@ public class PdbController implements HardcodedValues {
public ModelAndView index() {
final String view = "main";
final Map<String, Object> model = new HashMap<>();
model.put("oldestValue", LocalDateTime.now().minusDays(7).format(DATE_FORMAT_BEGIN));
model.put("latestValue", LocalDateTime.now().format(DATE_FORMAT_END));
// model.put("oldestValue",
// LocalDateTime.now().minusDays(7).format(DATE_FORMAT_BEGIN));
// model.put("latestValue", LocalDateTime.now().format(DATE_FORMAT_END));
model.put("isProduction", modeProduction);
return new ModelAndView(view, model);
}
@@ -77,20 +83,21 @@ public class PdbController implements HardcodedValues {
PlotResponse createPlot(@RequestBody final PlotRequest request)
throws InternalPlottingException, InterruptedException {
final PlotSettings plotSettings = PlotSettingsTransformer
.toSettings(request);
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
if (StringUtils.isBlank(plotSettings.getQuery())) {
throw new BadRequest("The query must not be empty!");
}
// TODO the UI should cancel requests that are in flight before sending a plot request
// TODO the UI should cancel requests that are in flight before sending a plot
// request
if (plotterLock.tryLock()) {
try {
final PlotResult result = plotter.plot(plotSettings);
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/"
+ result.getImageName();
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + result.getImageName();
LOGGER.trace("image url: {}", imageUrl);
return new PlotResponse(
DataSeries.toMap(result.getDataSeries()), imageUrl);
return new PlotResponse(DataSeries.toMap(result.getDataSeries()), imageUrl);
} catch (final NoDataPointsException e) {
throw new NotFoundException(e);
} finally {
@@ -115,7 +122,7 @@ public class PdbController implements HardcodedValues {
final int zeroBasedCaretIndex = caretIndex - 1;
final List<Proposal> proposals = db.autocomplete(query, zeroBasedCaretIndex);
final List<Proposal> nonEmptyProposals = CollectionUtils.filter(proposals, p -> p.hasResults() );
final List<Proposal> nonEmptyProposals = CollectionUtils.filter(proposals, p -> p.hasResults());
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(nonEmptyProposals);
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());