Commit ee4f1db3 authored by Jan Wagemakers's avatar Jan Wagemakers

possible to edit users and rules now

parent c39144ca
...@@ -86,6 +86,5 @@ public class Rule { ...@@ -86,6 +86,5 @@ public class Rule {
public void setUser(User user) { public void setUser(User user) {
this.user = user; this.user = user;
} }
} }
...@@ -102,6 +102,7 @@ public class HTMLController { ...@@ -102,6 +102,7 @@ public class HTMLController {
public String user(@ModelAttribute User newUser, @RequestParam String action, @RequestParam String id, Model model ) { public String user(@ModelAttribute User newUser, @RequestParam String action, @RequestParam String id, Model model ) {
switch (action) { switch (action) {
case "Add" : case "Add" :
case "Save" :
newUser = userRepository.save(newUser); newUser = userRepository.save(newUser);
break; break;
case "Del" : case "Del" :
...@@ -122,10 +123,14 @@ public class HTMLController { ...@@ -122,10 +123,14 @@ public class HTMLController {
@PostMapping("/rule") @PostMapping("/rule")
public String rule(@ModelAttribute Rule newRule, @RequestParam String action, @RequestParam String line, Model model ) { public String rule(@ModelAttribute Rule newRule, @RequestParam String action, @RequestParam String line, Model model ) {
if (action.equals("ADD")) { switch (action) {
newRule = ruleRepository.save(newRule); case "Add" :
} else { case "Save" :
ruleRepository.deleteById(Integer.parseInt(line)); newRule = ruleRepository.save(newRule);
break;
case "Del" :
ruleRepository.deleteById(Integer.parseInt(line));
break;
} }
return rules(model); return rules(model);
} }
......
...@@ -34,83 +34,72 @@ ...@@ -34,83 +34,72 @@
</header> </header>
<section class="post-content"> <section class="post-content">
<div id="refresh">
<h2 th:text="'Rules : ' + ${user}"></h2>
<hr>
<form th:each="rule : ${rules}" action="#" th:action="@{/rule}" method="post">
<input type="hidden" name="line" th:value="${rule.line}" readonly />
<p> <h2 th:text="'Rules : ' + ${user}"></h2>
<select disabled > <hr>
<option th:value="0" th:selected="${0==rule.day}" th:text="'Every Day'"></option> <form th:each="rule : ${rules}" action="#" th:action="@{/rule}" method="post">
<option th:value="1" th:selected="${1==rule.day}" th:text="Sunday"></option> <input type="hidden" name="line" th:value="${rule.line}" readonly/>
<option th:value="2" th:selected="${2==rule.day}" th:text="Monday"></option> <p>
<option th:value="3" th:selected="${3==rule.day}" th:text="Tuesday"></option> <select name="day">
<option th:value="4" th:selected="${4==rule.day}" th:text="Wednesday"></option> <option th:value="0" th:selected="${0==rule.day}" th:text="'Every Day'"></option>
<option th:value="5" th:selected="${5==rule.day}" th:text="Thursday"></option> <option th:value="1" th:selected="${1==rule.day}" th:text="Sunday"></option>
<option th:value="6" th:selected="${6==rule.day}" th:text="Friday"></option> <option th:value="2" th:selected="${2==rule.day}" th:text="Monday"></option>
<option th:value="7" th:selected="${7==rule.day}" th:text="Saturday"></option> <option th:value="3" th:selected="${3==rule.day}" th:text="Tuesday"></option>
</select> <option th:value="4" th:selected="${4==rule.day}" th:text="Wednesday"></option>
<input type="hidden" name="day" th:value="${rule.day}" readonly /> <option th:value="5" th:selected="${5==rule.day}" th:text="Thursday"></option>
</p> <option th:value="6" th:selected="${6==rule.day}" th:text="Friday"></option>
<p> <option th:value="7" th:selected="${7==rule.day}" th:text="Saturday"></option>
<input style="width: 10%" type="number" min="0" max="23" name="hour" th:value="${rule.hour}" readonly /> </select>
h&nbsp;:&nbsp; <!-- <input type="hidden" name="day" th:value="${rule.day}" > -->
<input style="width: 10%" type="number" min="0" max="59" name="min" th:value="${rule.min}" readonly /> </p>
m&nbsp;=&nbsp; <p>
<input style="width: 10%" type="number" min="0" max="30" step="0.1" name="temp" th:value="${rule.temp}" readonly /> <input style="width: 10%" type="number" min="0" max="23" name="hour" th:value="${rule.hour}">
°C h&nbsp;:&nbsp;
</p> <input style="width: 10%" type="number" min="0" max="59" name="min" th:value="${rule.min}">
<p><input type="hidden" name="userId" th:value="${rule.user.id}" readonly /></p> m&nbsp;=&nbsp;
<p><input type="submit" name="action" value="DEL" /></p> <input style="width: 10%" type="number" min="0" max="30" step="0.1" name="temp" th:value="${rule.temp}">
<hr> °C
</form> </p>
<h2>Add a new rule</h2> <p><input type="hidden" name="user" th:value="${rule.user.id}" readonly/></p>
<hr> <p>
<form action="#" th:action="@{/rule}" th:object="${newRule}" method="post"> <input type="submit" name="action" value="Save"/>
<input type="hidden" th:field="*{line}" readonly/> <input type="submit" name="action" value="Del"/>
<p> </p>
<select th:field="*{day}">
<option th:value="0" th:text="'Every Day'"></option>
<option th:value="1" th:text="Sunday"></option>
<option th:value="2" th:text="Monday"></option>
<option th:value="3" th:text="Tuesday"></option>
<option th:value="4" th:text="Wednesday"></option>
<option th:value="5" th:text="Thursday"></option>
<option th:value="6" th:text="Friday"></option>
<option th:value="7" th:text="Saturday"></option>
</select>
</p>
<!--p><input type="text" th:field="*{day}"/></p-->
<p>
<input style="width: 10%" type="number" min="0" max="23" th:field="*{hour}"/>
h&nbsp;:&nbsp;
<input style="width: 10%" type="number" min="0" max="59" th:field="*{min}"/>
m&nbsp;=&nbsp;
<input style="width: 10%" type="number" min="0" max="30" step="0.1" th:field="*{temp}"/>
°C
</p>
<p><input type="hidden" th:field="*{user.id}" readonly/></p>
<p><input type="submit" name="action" value="ADD"/></p>
</form>
<hr> <hr>
</div> </form>
<h2>Add a new rule</h2>
<hr>
<form action="#" th:action="@{/rule}" th:object="${newRule}" method="post">
<input type="hidden" th:field="*{line}" readonly/>
<p>
<select th:field="*{day}">
<option th:value="0" th:text="'Every Day'"></option>
<option th:value="1" th:text="Sunday"></option>
<option th:value="2" th:text="Monday"></option>
<option th:value="3" th:text="Tuesday"></option>
<option th:value="4" th:text="Wednesday"></option>
<option th:value="5" th:text="Thursday"></option>
<option th:value="6" th:text="Friday"></option>
<option th:value="7" th:text="Saturday"></option>
</select>
</p>
<!--p><input type="text" th:field="*{day}"/></p-->
<p>
<input style="width: 10%" type="number" min="0" max="23" th:field="*{hour}"/>
h&nbsp;:&nbsp;
<input style="width: 10%" type="number" min="0" max="59" th:field="*{min}"/>
m&nbsp;=&nbsp;
<input style="width: 10%" type="number" min="0" max="30" step="0.1" th:field="*{temp}"/>
°C
</p>
<p><input type="hidden" th:field="*{user.id}" readonly/></p>
<p><input type="submit" name="action" value="Add"/></p>
</form>
<hr>
</section> </section>
</article> </article>
</div> </div>
<!--
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js">
</script>
<script>
$(document).ready(
function() {
setInterval(function() {
$('#refresh').load('./rules #refresh');
}, 1000);
});
</script>
-->
</body> </body>
</html> </html>
...@@ -34,20 +34,19 @@ ...@@ -34,20 +34,19 @@
</header> </header>
<section class="post-content"> <section class="post-content">
<div id="refresh"> <h2>Current users</h2>
<h2>Current users</h2> <hr>
<form th:each="user : ${users}" action="#" th:action="@{/users}" method="post">
<input type="hidden" name="id" th:value="${user.id}" readonly/>
Name:<br>
<p><input type="text" name="name" th:value="${user.name}" ></p>
Smartphone&apos;s bluetooth:<br>
<p><input type="text" name="bluetooth" th:value="${user.bluetooth}" ></p>
<input type="submit" name="action" value="Save"/>
<input type="submit" name="action" value="Del"/>
<input type="submit" name="action" value="Rules"/>
<hr> <hr>
<form th:each="user : ${users}" action="#" th:action="@{/users}" method="post"> </form>
<input type="hidden" name="id" th:value="${user.id}" readonly/>
Name:<br>
<p><input type="text" name="name" th:value="${user.name}" readonly/></p>
Smartphone&apos;s bluetooth:<br>
<p><input type="text" name="bluetooth" th:value="${user.bluetooth}" readonly/></p>
<input type="submit" name="action" value="Del"/>
<input type="submit" name="action" value="Rules"/>
<hr>
</form>
</div>
<h2>Add a new user</h2> <h2>Add a new user</h2>
<hr> <hr>
<form action="#" th:action="@{/users}" th:object="${newUser}" method="post"> <form action="#" th:action="@{/users}" th:object="${newUser}" method="post">
...@@ -63,17 +62,5 @@ ...@@ -63,17 +62,5 @@
</article> </article>
</div> </div>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js">
</script>
<script>
$(document).ready(
function() {
setInterval(function() {
$('#refresh').load('./users #refresh');
}, 1000);
});
</script>
</body> </body>
</html> </html>
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