Skip to content

Commit ad392c7

Browse files
committed
update customer selection
1 parent 41c7c62 commit ad392c7

4 files changed

Lines changed: 65 additions & 11 deletions

File tree

src/main/java/de/kaleidox/workbench/controller/TimetableController.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.kaleidox.workbench.controller;
22

33
import de.kaleidox.workbench.model.jpa.timetable.TimetableEntry;
4+
import de.kaleidox.workbench.repo.CustomerRepository;
45
import de.kaleidox.workbench.repo.TimetableEntryRepository;
56
import de.kaleidox.workbench.repo.UserRepository;
67
import org.jetbrains.annotations.Nullable;
@@ -9,6 +10,7 @@
910
import org.springframework.stereotype.Controller;
1011
import org.springframework.ui.Model;
1112
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.ModelAttribute;
1214
import org.springframework.web.bind.annotation.RequestMapping;
1315
import org.springframework.web.bind.annotation.RequestParam;
1416

@@ -19,8 +21,19 @@
1921
@RequestMapping("/timetable")
2022
public class TimetableController {
2123
@Autowired UserRepository users;
24+
@Autowired CustomerRepository customers;
2225
@Autowired TimetableEntryRepository entries;
2326

27+
@ModelAttribute("users")
28+
public UserRepository users() {
29+
return users;
30+
}
31+
32+
@ModelAttribute("customers")
33+
public CustomerRepository customers() {
34+
return customers;
35+
}
36+
2437
@GetMapping
2538
public String index(
2639
Model model, Authentication auth, @RequestParam(required = false) @Nullable Short year,
@@ -44,7 +57,6 @@ public String index(
4457
display = entries.findThisWeekByUser(user.getUsername());
4558
}
4659

47-
model.addAttribute("user", user);
4860
model.addAttribute("entries", display);
4961
model.addAttribute("displayInfoText", displayInfoText);
5062

src/main/resources/static/style.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ body {
175175
}
176176

177177
.ui-panel-2 {
178-
border: 2.5px groove grey;
178+
border: 3px groove grey;
179179
padding: 0 10px 10px;
180180
margin-bottom: 7px;
181181
}
182182

183+
.ui-panel-3 {
184+
border: 1.5px groove lightgrey;
185+
padding: 0 5px 5px;
186+
margin-bottom: 5px;
187+
}
188+
183189
/* utility components */
184190
.null-text {
185191
font-style: italic;

src/main/resources/static/timetable.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@ function init() {
1414
for (let input of $('.input-datetime')) {
1515
input.value = toLocalISOString(date)
1616
}
17+
18+
populateCustomerNames()
19+
populateDepartmentNames()
20+
}
21+
22+
function populateCustomerNames() {
23+
populateSelection($('#input-customerName')[0], '/api/customers/names')
24+
}
25+
26+
function populateDepartmentNames() {
27+
let customer = $('#input-customerName')[0].value
28+
if (customer === undefined || customer === '') return
29+
populateSelection($('#input-departmentName')[0], '/api/customers/' + customer + '/departments')
30+
}
31+
32+
async function populateSelection(selectTag, optionsUrl) {
33+
selectTag.innerHTML = ''
34+
35+
let elements = await fetch(optionsUrl).then(response => response.json())
36+
for (let element of elements) {
37+
let option = document.createElement('option')
38+
option.innerText = element
39+
option.value = element
40+
selectTag.appendChild(option)
41+
}
1742
}
1843

1944
function toLocalISOString(date) {
@@ -29,11 +54,8 @@ function submitCreateEntry() {
2954
var data = $('form').serializeArray()
3055

3156
fetch({
32-
method: 'POST',
33-
url: 'api/timetableEntries/create',
34-
headers: {
57+
method: 'POST', url: 'api/timetableEntries/create', headers: {
3558
'Content-Type': 'application/json'
36-
},
37-
body: JSON.stringify(data)
59+
}, body: JSON.stringify(data)
3860
})
3961
}

src/main/resources/templates/timetable/create_entry.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
<body onload="init()">
66
<div class="ui-menubar" th:insert="~{/layout/menubar}"></div>
77
<form class="ui-panel-1">
8-
<label for="input-customerName">Kunde</label><input id="input-customerName" name="customerName" required type="text">
9-
<label for="input-startTime">Anfang</label><input class="input-datetime" id="input-startTime" name="startTime" required type="datetime-local" value="now">
10-
<label for="input-endTime">Ende</label><input class="input-datetime" id="input-endTime" name="endTime" required type="datetime-local" value="now">
11-
<label for="input-notes">Beschreibung</label><input id="input-notes" name="notes" type="text">
8+
<div class="ui-panel-2">
9+
<label for="input-customerName">Kunde</label>
10+
<select id="input-customerName" name="customerName" onchange="populateDepartmentNames()" required size="8"></select>
11+
<label for="input-departmentName">Abteilung</label>
12+
<select id="input-departmentName" name="departmentName" required size="8"></select>
13+
</div>
14+
<div class="ui-panel-2">
15+
<label for="input-startTime">Anfang</label>
16+
<input class="input-datetime" id="input-startTime" name="startTime" required type="datetime-local" value="now">
17+
</div>
18+
<div class="ui-panel-2">
19+
<label for="input-endTime">Ende</label>
20+
<input class="input-datetime" id="input-endTime" name="endTime" required type="datetime-local" value="now">
21+
</div>
22+
<div class="ui-panel-2">
23+
<label for="input-notes">Beschreibung</label>
24+
<input id="input-notes" name="notes" type="text">
25+
</div>
1226
<input onclick="submitCreateEntry()" type="submit">
1327
</form>
1428
<div class="ui-footer" th:insert="~{/layout/footer}"></div>

0 commit comments

Comments
 (0)