moved templates to resource directory

This commit is contained in:
s5260822 2025-03-18 20:36:18 +01:00
parent 62beaba05a
commit 32a3823e79
17 changed files with 139 additions and 133 deletions

View file

@ -1,67 +1,68 @@
package org.texttechnologylab.project.gruppe_05_1.rest;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;
import io.javalin.openapi.plugin.OpenApiPlugin;
import io.javalin.openapi.plugin.redoc.ReDocPlugin;
import io.javalin.rendering.template.JavalinFreemarker;
import org.texttechnologylab.project.gruppe_05_1.util.Logger;
import java.io.File;
import java.io.IOException;
public class RESTHandler {
public static final String TEMPLATE_DIR = "src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates";
public void startJavalin() {
// Javalin Konfiguration (z.B. port)
JavalinConfig jlConfig = new JavalinConfig();
int port = jlConfig.getPort();
// FreeMarker Konfiguration
Configuration fmConfig = new Configuration(Configuration.VERSION_2_3_33);
fmConfig.setDefaultEncoding("UTF-8");
try {
fmConfig.setDirectoryForTemplateLoading(new File(TEMPLATE_DIR));
} catch (IOException e) {
throw new RuntimeException(e);
}
fmConfig.setLogTemplateExceptions(true);
fmConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// Erzeuge die Javalin app
Javalin app = Javalin.create(config -> {
config.staticFiles.add("src/main/resources/public", Location.EXTERNAL); // momentan nicht benutzt
config.fileRenderer(new JavalinFreemarker(fmConfig));
config.registerPlugin(new OpenApiPlugin(pluginConfig -> {
// Define OpenAPI spec configuration
pluginConfig.withDefinitionConfiguration((version, definition) -> {
definition.withOpenApiInfo(info -> info.setTitle("Javalin OpenAPI Documentation"));
});
}));
config.registerPlugin(new ReDocPlugin());
})
.start(port);
Logger.info("Javalin app started on http://localhost:" + port);
// Routes
// ======
// Parlamentarier
app.get("/", ParlamentarierController::getAllParlamentarier);
app.get("/portfolio/{id}", ParlamentarierController::getParlamentarierDetails);
app.delete("/deleteParlamentarier", ParlamentarierController::deleteAllParlamentarier);
// Reden
app.get("/reden/{id}", SpeechController::listSpeeches); // zeige Reden eines Parlamentariers an
app.get("/reden/{id}/{redeId}", SpeechController::showSpeech); // zeige eine bestimmte Rede des Parlamentariers an
}
}
package org.texttechnologylab.project.gruppe_05_1.rest;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;
import io.javalin.openapi.plugin.OpenApiPlugin;
import io.javalin.openapi.plugin.redoc.ReDocPlugin;
import io.javalin.rendering.template.JavalinFreemarker;
import org.texttechnologylab.project.gruppe_05_1.util.Logger;
import java.io.File;
import java.io.IOException;
import static org.texttechnologylab.project.gruppe_05_1.Main.JAVALIN_STATIC_FILES_DIR;
import static org.texttechnologylab.project.gruppe_05_1.Main.JAVALIN_TEMPLATE_DIR;
public class RESTHandler {
public void startJavalin() {
// Javalin Konfiguration (z.B. port)
JavalinConfig jlConfig = new JavalinConfig();
int port = jlConfig.getPort();
// FreeMarker Konfiguration
Configuration fmConfig = new Configuration(Configuration.VERSION_2_3_33);
fmConfig.setDefaultEncoding("UTF-8");
try {
fmConfig.setDirectoryForTemplateLoading(new File(JAVALIN_TEMPLATE_DIR));
} catch (IOException e) {
throw new RuntimeException(e);
}
fmConfig.setLogTemplateExceptions(true);
fmConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// Erzeuge die Javalin app
Javalin app = Javalin.create(config -> {
config.staticFiles.add(JAVALIN_STATIC_FILES_DIR, Location.EXTERNAL); // momentan nicht benutzt
config.fileRenderer(new JavalinFreemarker(fmConfig));
config.registerPlugin(new OpenApiPlugin(pluginConfig -> {
// Define OpenAPI spec configuration
pluginConfig.withDefinitionConfiguration((version, definition) -> {
definition.withOpenApiInfo(info -> info.setTitle("Javalin OpenAPI Documentation"));
});
}));
config.registerPlugin(new ReDocPlugin());
})
.start(port);
Logger.info("Javalin app started on http://localhost:" + port);
// Routes
// ======
// Parlamentarier
app.get("/", FrontEndController::getHomepage);
app.get("/members", FrontEndController::getAllParlamentarier);
app.get("/portfolio/{id}", FrontEndController::getParlamentarierDetails);
app.delete("/deleteParlamentarier", ParlamentarierController::deleteAllParlamentarier);
// Reden
app.get("/reden/{id}", FrontEndController::listSpeeches); // zeige Reden eines Parlamentariers an
app.get("/reden/{id}/{redeId}", FrontEndController::showSpeech); // zeige eine bestimmte Rede des Parlamentariers an
}
}

View file

@ -1,4 +0,0 @@
<form name="searchForm" action="/" method="get">
Name : <input type="text" name="filter" value="${filter!' '}" />
<input type="submit" value="Suche" />
</form>

View file

@ -1,52 +0,0 @@
<svg id="topicsBubblechart"></svg>
<script>
var topicsData = [
<#list condenseTopicInformation as topicTuple>
{ topic: "${topicTuple.topic}", score: "${topicTuple.score?string?replace(',', '.')}"} <#sep>,
</#list>
];
const topics_bc_width = 1000;
const topics_bc_height = 800;
fillOpacity = 0.5;
var svg = d3.select("#topicsBubblechart")
.attr("width", topics_bc_width)
.attr("height", topics_bc_height)
var topics_bc_color = d3.scaleOrdinal(d3.schemeCategory10);
var topics_bc_size = d3.scaleLinear().domain([1, 10]).range([30, 100]);
var bubbles = svg.selectAll("circle")
.data(topicsData)
.enter().append("circle")
.attr("r", d => topics_bc_size(d.score))
.attr("fill", d => topics_bc_color(d.topic))
.attr("fill-opacity", fillOpacity);
var topics_labels = svg.selectAll("text")
.data(topicsData)
.enter().append("text")
.attr("text-anchor", "middle")
.attr("font-size", d => (10 * d.score) + "px")
.attr("fill", "#000")
.text(d => d.topic);
var topics_bc_simulation = d3.forceSimulation(topicsData)
.force("charge", d3.forceManyBody().strength(5))
.force("center", d3.forceCenter(topics_bc_width / 2, topics_bc_height / 2))
.force("collision", d3.forceCollide(d => topics_bc_size(d.score) + 25))
.force("x", d3.forceX(topics_bc_width / 2).strength(0.1))
.force("y", d3.forceY(topics_bc_height / 2).strength(0.1));
topics_bc_simulation.on("tick", () => {
bubbles.attr("cx", d => d.x).attr("cy", d => d.y);
topics_labels.attr("x", d => d.x).attr("y", d => d.y);
});
</script>

Before

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,4 @@
<form name="searchForm" action="/members" method="get">
Name : <input type="text" name="filter" value="${filter!' '}" />
<input id="search-button" type="submit" value="Suche" />
</form>

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="de">
<head>
<link rel="stylesheet" href="index.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Abgeordnete Übersicht</title>
@ -13,10 +14,9 @@
}
</style>
</head>
<#include "header.ftl">
<body>
<header>
<h1>Abgeordnete (alphabetisch sortiert)</h1>
</header>
<h2>Abgeordnete (alphabetisch sortiert)</h2>
<main>
<#include "filterForm.ftl">
@ -41,9 +41,10 @@
</#list>
</tbody>
</table>
<a href="/" class="back-link">Zurück zum Anfang</a>
<a href="/members" class="back-link">Zurück zum Anfang</a>
</main>
</body>
<#include "footer.ftl">
</html>

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="de">
<head>
<link rel="stylesheet" href="index.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${p.vorname} ${p.nachname} (${p.partei})</title>
@ -12,6 +13,7 @@
}
</style>
</head>
<#include "header.ftl">
<body>
<header>
<h1>${p.vorname} ${p.nachname} (${p.partei})</h1>
@ -100,4 +102,5 @@
</main>
</body>
<#include "footer.ftl">
</html>

View file

@ -1,4 +1,3 @@
<svg id="posBarchart"></svg>
<script>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before After
Before After

View file

@ -12,6 +12,7 @@
}
</style>
</head>
<#include "header.ftl">
<body>
<header>
<h1>Reden von ${p.vorname} ${p.nachname} (${p.partei})</h1>
@ -40,4 +41,6 @@
</table>
</section>
</main>
<body>
<body>
<#include "footer.ftl">
</html>

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="de">
<head>
<link rel="stylesheet" href="index.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction}) </#if></title>
@ -12,13 +13,10 @@
}
</style>
</head>
<#include "header.ftl">
<body>
<script src="https://d3js.org/d3.v7.min.js"></script>
<header>
<h1>Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction}) </#if> </h1>
</header>
<br>
@ -40,4 +38,5 @@
</body>
<#include "footer.ftl">
</html>

View file

@ -0,0 +1,52 @@
<svg id="topicsBubblechart"></svg>
<script>
var topicsData = [
<#list condenseTopicInformation as topicTuple>
{ topic: "${topicTuple.topic}", score: "${topicTuple.score?string?replace(',', '.')}"} <#sep>,
</#list>
];
const topics_bc_width = 1000;
const topics_bc_height = 800;
fillOpacity = 0.5;
var svg = d3.select("#topicsBubblechart")
.attr("width", topics_bc_width)
.attr("height", topics_bc_height)
var topics_bc_color = d3.scaleOrdinal(d3.schemeCategory10);
var topics_bc_size = d3.scaleLinear().domain([1, 10]).range([30, 100]);
var bubbles = svg.selectAll("circle")
.data(topicsData)
.enter().append("circle")
.attr("r", d => topics_bc_size(d.score))
.attr("fill", d => topics_bc_color(d.topic))
.attr("fill-opacity", fillOpacity);
var topics_labels = svg.selectAll("text")
.data(topicsData)
.enter().append("text")
.attr("text-anchor", "middle")
.attr("font-size", d => (10 * d.score) + "px")
.attr("fill", "#000")
.text(d => d.topic);
var topics_bc_simulation = d3.forceSimulation(topicsData)
.force("charge", d3.forceManyBody().strength(5))
.force("center", d3.forceCenter(topics_bc_width / 2, topics_bc_height / 2))
.force("collision", d3.forceCollide(d => topics_bc_size(d.score) + 25))
.force("x", d3.forceX(topics_bc_width / 2).strength(0.1))
.force("y", d3.forceY(topics_bc_height / 2).strength(0.1));
topics_bc_simulation.on("tick", () => {
bubbles.attr("cx", d => d.x).attr("cy", d => d.y);
topics_labels.attr("x", d => d.x).attr("y", d => d.y);
});
</script>

After

Width:  |  Height:  |  Size: 1.6 KiB