Skip to content

Commit b08a983

Browse files
committed
fix /timetable/create
1 parent bb5a3ea commit b08a983

6 files changed

Lines changed: 83 additions & 8 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package de.kaleidox.workbench.controller;
22

3+
import de.kaleidox.workbench.model.jpa.representant.Customer;
34
import de.kaleidox.workbench.model.jpa.timetable.TimetableEntry;
45
import de.kaleidox.workbench.repo.CustomerRepository;
56
import de.kaleidox.workbench.repo.TimetableEntryRepository;
67
import de.kaleidox.workbench.repo.UserRepository;
78
import org.jetbrains.annotations.Nullable;
89
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.data.repository.query.Param;
911
import org.springframework.security.core.Authentication;
1012
import org.springframework.stereotype.Controller;
1113
import org.springframework.ui.Model;
1214
import org.springframework.web.bind.annotation.GetMapping;
1315
import org.springframework.web.bind.annotation.ModelAttribute;
16+
import org.springframework.web.bind.annotation.PathVariable;
1417
import org.springframework.web.bind.annotation.RequestMapping;
1518
import org.springframework.web.bind.annotation.RequestParam;
1619

@@ -67,4 +70,20 @@ public String index(
6770
public String create() {
6871
return "timetable/create_entry";
6972
}
73+
74+
@GetMapping("/{customerName}/{departmentName}/{startTime}")
75+
public String view(
76+
Model model, @PathVariable @Param("customerName") String customerName,
77+
@PathVariable @Param("departmentName") String departmentName,
78+
@PathVariable @Param("startTime") LocalDateTime startTime
79+
) {
80+
var cKey = new Customer.CompositeKey(customerName, departmentName);
81+
var customer = customers.findById(cKey).orElseThrow();
82+
83+
var eKey = new TimetableEntry.CompositeKey(customer, startTime);
84+
var entry = entries.findById(eKey).orElseThrow();
85+
86+
model.addAttribute("entry", entry);
87+
return "timetable/view_entry";
88+
}
7089
}

src/main/java/de/kaleidox/workbench/model/jpa/timetable/TimetableEntry.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class TimetableEntry {
3737
@ElementCollection Collection<Interruption> interruptions = new ArrayList<>();
3838
@ElementCollection Collection<Assignment> assignments = new ArrayList<>();
3939

40+
@JsonIgnore
41+
public String getViewUrlPath() {
42+
return "";
43+
}
44+
4045
@JsonIgnore
4146
public String getDayText() {
4247
return startTime.format(DATE_FORMATTER);
101 KB
Binary file not shown.

src/main/resources/static/timetable.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ function init() {
2020
}
2121

2222
function populateCustomerNames() {
23-
populateSelection($('#input-customerName')[0], '/api/customers/names')
23+
populateSelection($('#input-customerName')[0], `${window.location.origin}/api/customers/names`)
2424
}
2525

2626
function populateDepartmentNames() {
2727
let customer = $('#input-customerName')[0].value
2828
if (customer === undefined || customer === '') return
29-
populateSelection($('#input-departmentName')[0], '/api/customers/' + customer + '/departments')
29+
populateSelection($('#input-departmentName')[0], `${window.location.origin}/api/customers/${customer}/departments`)
3030
}
3131

3232
async function populateSelection(selectTag, optionsUrl) {
@@ -51,11 +51,27 @@ function toLocalISOString(date) {
5151
}
5252

5353
function submitCreateEntry() {
54-
var data = $('form').serializeArray()
54+
let data = {
55+
'customerInfo': {
56+
'name': $('#input-customerName')[0].value,
57+
'department': $('#input-departmentName')[0].value
58+
},
59+
'startTime': $('#input-startTime')[0].value,
60+
'endTime': $('#input-endTime')[0].value,
61+
'notes': $('#input-notes')[0].value
62+
}
5563

56-
fetch({
57-
method: 'POST', url: 'api/timetableEntries/create', headers: {
64+
fetch(`${window.location.origin}/api/timetableEntries/create`, {
65+
method: 'POST',
66+
headers: {
5867
'Content-Type': 'application/json'
59-
}, body: JSON.stringify(data)
68+
},
69+
body: JSON.stringify(data)
70+
}).then(response => {
71+
if (Math.floor(response.status / 100) === 2) {
72+
window.location.href = `${window.location.origin}/timetable/${data.customerInfo.name}/${data.customerInfo.department}/${data.startTime}`
73+
return
74+
}
75+
response.text().then(alert)
6076
})
6177
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<script th:src="@{/static/timetable.js}" type="text/javascript"></script>
55
<body onload="init()">
66
<div class="ui-menubar" th:insert="~{/layout/menubar}"></div>
7-
<form class="ui-panel-1">
7+
<div class="ui-panel-1">
88
<div class="ui-panel-2">
99
<label for="input-customerName">Kunde</label> & <label for="input-departmentName">Abteilung</label>
1010
<br/>
@@ -29,7 +29,7 @@
2929
<textarea cols="80" id="input-notes" name="notes" rows="5"></textarea>
3030
</div>
3131
<input onclick="submitCreateEntry()" type="submit">
32-
</form>
32+
</div>
3333
<div class="ui-footer" th:insert="~{/layout/footer}"></div>
3434
</body>
3535
</html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head th:insert="~{/layout/head}"></head>
4+
<script th:src="@{/static/timetable.js}" type="text/javascript"></script>
5+
<body onload="init()">
6+
<div class="ui-menubar" th:insert="~{/layout/menubar}"></div>
7+
<form class="ui-panel-1">
8+
<div class="ui-panel-2">
9+
<label for="input-customerName">Kunde</label> & <label for="input-departmentName">Abteilung</label>
10+
<br/>
11+
<select class="ui-select-big" id="input-customerName" name="customerName" onchange="populateDepartmentNames()" required size="8">
12+
<option>- wird geladen -</option>
13+
</select>
14+
<select class="ui-select-big" id="input-departmentName" name="departmentName" required size="8">
15+
<option>- bitte Kunde wählen -</option>
16+
</select>
17+
</div>
18+
<div class="ui-panel-2">
19+
<label for="input-startTime">Anfang</label>
20+
<input class="input-datetime" id="input-startTime" name="startTime" required type="datetime-local" value="now">
21+
</div>
22+
<div class="ui-panel-2">
23+
<label for="input-endTime">Ende</label>
24+
<input class="input-datetime" id="input-endTime" name="endTime" required type="datetime-local" value="now">
25+
</div>
26+
<div class="ui-panel-2">
27+
<label for="input-notes">Beschreibung</label>
28+
<br/>
29+
<textarea cols="80" id="input-notes" name="notes" rows="5"></textarea>
30+
</div>
31+
<input onclick="submitCreateEntry()" type="submit">
32+
</form>
33+
<div class="ui-footer" th:insert="~{/layout/footer}"></div>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)