Commit c39144ca authored by Jan Wagemakers's avatar Jan Wagemakers

config front end working :-)

parent 1df35205
......@@ -13,6 +13,11 @@ public class Configuration {
protected Configuration() {}
public Configuration(String airport, float lowTemp) {
this.airport=airport;
this.lowTemp=lowTemp;
}
public int getId() {
return id;
}
......@@ -24,4 +29,16 @@ public class Configuration {
public float getLowTemp() {
return lowTemp;
}
public void setId(int id) {
this.id = id;
}
public void setAirport(String airport) {
this.airport = airport;
}
public void setLowTemp(float lowTemp) {
this.lowTemp = lowTemp;
}
}
......@@ -52,12 +52,18 @@ public class StartupRunner implements CommandLineRunner {
public void run(String... args) throws Exception {
logger.info("Control Thermostat With Bluetooth");
// ID 1 = current configuration (schema.sql)
config = configurationRepository.findById(1).get();
// Check is configuration exists (create if not)
if (configurationRepository.existsById(1)) {
// ID 1 = current configuration (schema.sql)
config = configurationRepository.findById(1).get();
} else {
config = new Configuration("EBAW", 16.0f);
config = configurationRepository.save(config);
}
System.out.println("CONFIG : " + config.getAirport() + " " + config.getLowTemp());
}
@Scheduled(initialDelay = 1 * 1000, fixedDelay = 15 * 60 * 1000)
@Scheduled(initialDelay = 5 * 1000, fixedDelay = 15 * 60 * 1000)
public void repeat15m() {
logger.info("Repeat 15M");
outside.update(config.getAirport());
......
......@@ -6,9 +6,11 @@
package be.janwagemakers.controlthermostatbluetooth.controller;
import be.janwagemakers.controlthermostatbluetooth.DataList;
import be.janwagemakers.controlthermostatbluetooth.Entity.Configuration;
import be.janwagemakers.controlthermostatbluetooth.Entity.Rule;
import be.janwagemakers.controlthermostatbluetooth.Entity.User;
import be.janwagemakers.controlthermostatbluetooth.Outside;
import be.janwagemakers.controlthermostatbluetooth.Repository.ConfigurationRepository;
import be.janwagemakers.controlthermostatbluetooth.Repository.RuleRepository;
import be.janwagemakers.controlthermostatbluetooth.Repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,6 +31,7 @@ import java.util.*;
@org.springframework.stereotype.Controller
public class HTMLController {
@Autowired private ConfigurationRepository configurationRepository;
@Autowired private UserRepository userRepository;
@Autowired private RuleRepository ruleRepository;
@Autowired private Outside outside;
......@@ -75,6 +78,12 @@ public class HTMLController {
return "users";
}
@GetMapping("/config")
public String config(Model model) {
model.addAttribute("config", configurationRepository.findAll());
return "config";
}
@GetMapping("/rules")
public String rules(Model model) {
List<Rule> rules = new ArrayList<>();
......@@ -105,6 +114,12 @@ public class HTMLController {
return users(model);
}
@PostMapping("/config")
public String config(@ModelAttribute Configuration newConfig, Model model ) {
newConfig = configurationRepository.save(newConfig);
return config(model);
}
@PostMapping("/rule")
public String rule(@ModelAttribute Rule newRule, @RequestParam String action, @RequestParam String line, Model model ) {
if (action.equals("ADD")) {
......
drop table configuration if exists;
-- drop table configuration if exists;
-- drop table rule if exists;
-- drop table user if exists;
--
......@@ -40,4 +40,4 @@ create table if not exists user (
alter table rule add constraint if not exists FK55ew2b76r531nnmw97mm96yt2 foreign key (user_id) references user;
-- Hard coded at the moment until Front end works
INSERT INTO configuration (airport, low_temp) VALUES ('EBAW', '16.0');
-- INSERT INTO configuration (airport, low_temp) VALUES ('EBAW', '16.0');
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--meta http-equiv="refresh" content="30"-->
<!-- Main JS (navbar.js, katex_init.js and masonry_init.js)-->
<script defer=true src="./assets/js/main.min.js"></script>
<!-- CSS -->
<link rel="stylesheet" href="./assets/css/main.css">
<!-- Font Awesome -->
<!-- <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
<link rel="stylesheet" type="text/css" href="./assets/css/vendor/font-awesome.min.css">
<!-- Google Fonts -->
<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,700italic,400italic" rel="stylesheet"
type="text/css">
<title>Thermostat - Jan Wagemakers -</title>
</head>
<body>
<div th:replace="./includes/menu :: menu"></div>
<div class="content">
<article class="feature-image">
<header id="main" style="background-image: url('./assets/img/pexels/darkCloud.jpeg')">
<h1 id="About" class="title">
Configuration
</h1>
</header>
<section class="post-content">
<h2>Configuration</h2>
<hr>
<form th:each="cfg : ${config}" action="#" th:action="@{/config}" method="post">
<input type="hidden" name="id" th:value="${cfg.id}" readonly/>
Airport:<br>
<p><input type="text" name="airport" th:value="${cfg.airport}"></p>
Low Temperature:<br>
<p><input type="number" min="0" max="30" step="0.1" name="lowTemp" th:value="${cfg.lowTemp}"></p>
<input type="submit" name="action" value="Save"/>
<hr>
</form>
</section>
</article>
</div>
</body>
</html>
......@@ -33,6 +33,13 @@
</a>
</li>
<li class="separator"> |</li>
<li>
<a class="clear" href="/config">
Configuration
</a>
</li>
<li class="separator"> |</li>
<li>
<a class="clear" href="/log">
......
......@@ -51,12 +51,12 @@
<h2>Add a new user</h2>
<hr>
<form action="#" th:action="@{/users}" th:object="${newUser}" method="post">
<td><input type="hidden" th:field="*{id}" readonly/></td>
<input type="hidden" th:field="*{id}" readonly/>
Name:<br>
<p><input type="text" th:field="*{name}"/></p>
Smartphone&apos;s bluetooth:<br>
<p><input type="text" th:field="*{bluetooth}"/></p>
<input type="submit" name="action" value="Add"/></td>
<input type="submit" name="action" value="Add"/>
</form>
<hr>
</section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment