Added startup page

This commit is contained in:
Ziver Koc 2021-09-15 22:21:21 +02:00
parent bfd895112d
commit d7605da60f
6 changed files with 66 additions and 3 deletions

0
gradlew vendored Executable file → Normal file
View file

View file

@ -32,7 +32,7 @@
<div class="navbar-header">
<!-- Title and Icon -->
<a class="navbar-brand" href="/">
<span class="glyphicon glyphicon-record" style="color:red"></span>
<span class="glyphicon glyphicon-record" style="color: red; top: 15px;"></span>
<b>HAL</b>
</a>
<!-- Hamburger button for smaller screens -->

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="3">
<title>HAL is initializing...</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/hal.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center" style="margin-top: 10%;">
<span style="font-size: 8em">
<span class="glyphicon glyphicon-record" style="color:red; top: 15px;"></span>
<b>HAL</b>
</span>
<span style="font-size: 2em">is initializing...</span>
</div>
</div>
</div>
</body>
</html>

View file

@ -4,6 +4,7 @@ package se.hal;
import se.hal.daemon.HalExternalWebDaemon;
import se.hal.intf.*;
import se.hal.page.HalAlertManager;
import se.hal.page.StartupWebPage;
import se.hal.struct.PluginConfig;
import zutil.db.DBConnection;
import zutil.io.file.FileUtil;
@ -50,11 +51,13 @@ public class HalServer {
// init logging
LogUtil.readConfiguration("logging.properties");
http = new HttpServer(HalContext.getIntegerProperty(HalContext.CONFIG_HTTP_PORT));
http.setDefaultPage(new StartupWebPage());
http.start();
// init variables
pluginManager = new PluginManager();
daemonExecutor = Executors.newScheduledThreadPool(1); // We set only one thread for easier troubleshooting for now
http = new HttpServer(HalContext.getIntegerProperty(HalContext.CONFIG_HTTP_PORT));
http.start();
// Upgrade database
HalDatabaseUpgradeManager.initialize(pluginManager);
@ -125,6 +128,7 @@ public class HalServer {
http.setDefaultPage(new HttpFilePage(FileUtil.find(HalContext.RESOURCE_WEB_ROOT)));
http.setPage("/", new HttpRedirectPage("/map"));
http.setPage(HalAlertManager.getInstance().getUrl(), HalAlertManager.getInstance());
for (Iterator<HalWebPage> it = pluginManager.getSingletonIterator(HalJsonPage.class); it.hasNext(); )
registerPage(it.next());
for (Iterator<HalWebPage> it = pluginManager.getSingletonIterator(HalWebPage.class); it.hasNext(); )

View file

@ -0,0 +1,34 @@
package se.hal.page;
import se.hal.HalContext;
import zutil.io.file.FileUtil;
import zutil.net.http.HttpHeader;
import zutil.net.http.HttpPage;
import zutil.net.http.HttpPrintStream;
import zutil.parser.Templator;
import java.io.IOException;
import java.util.Map;
public class StartupWebPage implements HttpPage {
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/startup.tmpl";
@Override
public void respond(HttpPrintStream out, HttpHeader headers, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) throws IOException {
if (headers.getRequestURL().endsWith("bootstrap.min.css")) {
printFileContents(HalContext.RESOURCE_WEB_ROOT + "/css/bootstrap.min.css", out);
} else if (headers.getRequestURL().endsWith("hal.css")) {
printFileContents(HalContext.RESOURCE_WEB_ROOT + "/css/hal.css", out);
} else {
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
out.print(tmpl.compile());
}
}
private void printFileContents(String path, HttpPrintStream out) throws IOException {
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, "text/css");
out.print(FileUtil.getContent(HalContext.RESOURCE_WEB_ROOT + path));
}
}

0
run.sh Executable file → Normal file
View file