starting point for new form

master
Josha von Gizycki 5 days ago
parent 6235e5ca60
commit ae0a87b53d

@ -36,6 +36,10 @@
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId> <artifactId>kotlin-stdlib</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- FRONTEND --> <!-- FRONTEND -->
<dependency> <dependency>

@ -29,4 +29,5 @@ interface DocumentTaggingDao : Repository<DocumentTagging, Long> {
interface TagDao: Repository<Tag, Long> { interface TagDao: Repository<Tag, Long> {
fun save(tag: Tag): Tag fun save(tag: Tag): Tag
fun findByName(name: String): Tag? fun findByName(name: String): Tag?
fun findAll(): List<Tag>
} }

@ -0,0 +1,43 @@
package wanijo.wanijo2.http.controller
import jakarta.validation.Valid
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.validation.BindingResult
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import wanijo.wanijo2.domain.TagDao
import wanijo.wanijo2.http.form.NewForm
@Controller
@RequestMapping("/document")
class NewController(
private val tagDao: TagDao
) {
@GetMapping("/new")
fun newDocument(
model: Model
): String {
model["tags"] = tagDao.findAll()
model["form"] = NewForm()
return "new"
}
@PostMapping("/new")
fun saveNewDocument(
model: Model,
@Valid
newForm: NewForm,
bindingResult: BindingResult
): String {
if (bindingResult.hasErrors()) {
return newDocument(model)
}
return "redirect:/"
}
}

@ -0,0 +1,10 @@
package wanijo.wanijo2.http.form
import jakarta.validation.constraints.NotEmpty
data class NewForm (
@NotEmpty
val name: String = "",
val description: String = "",
val tagIds: List<Long> = emptyList()
)

@ -1,14 +1,5 @@
body { body {
margin: 0 5rem; margin: 0 5rem;
}
main {
.show__meta {
display: flex;
justify-content: space-evenly;
font-size: 90%;
}
a:link, a:visited { a:link, a:visited {
text-decoration: none; text-decoration: none;
@ -18,6 +9,25 @@ main {
a:hover, a:active { a:hover, a:active {
text-decoration: underline; text-decoration: underline;
} }
}
nav {
display: flex;
flex-direction: row;
align-items: baseline;
* {
margin-right: 1rem;
}
}
main {
.show__meta {
display: flex;
justify-content: space-evenly;
font-size: 90%;
}
fieldset { fieldset {
border: 1px solid AccentColor; border: 1px solid AccentColor;
@ -41,3 +51,22 @@ table {
} }
} }
} }
form {
display: grid;
grid-template-columns: 30% 70%;
grid-auto-flow: row;
row-gap: .5rem;
label {
grid-column: 1;
}
input, textarea, select, button {
grid-column: 2;
}
textarea {
min-height: 10rem;
}
}

@ -11,6 +11,9 @@
<body> <body>
<nav> <nav>
<h1>Wanijo2</h1> <h1>Wanijo2</h1>
<a th:href="@{/}">liste</a>
<a th:href="@{/document/new}">(+) neu</a>
</nav> </nav>
<main id="content" layout:fragment="content"> <main id="content" layout:fragment="content">
Lorem Ipsum Lorem Ipsum

@ -0,0 +1,29 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{base}"
lang="">
<head>
<title>Home</title>
</head>
<body>
<main id="content" layout:fragment="content">
<form th:action="@{/document/new}" th:object="${form}" method="post">
<label for="name">name</label>
<input id="name" type="text" th:field="*{name}" required>
<label for="description">beschreibung</label>
<textarea id="description" th:field="*{description}"></textarea>
<label for="tags">tags</label>
<select multiple th:field="*{tagIds}" id="tags">
<option th:each="tag: ${tags}" th:value="${tag.id}" th:text="${tag.name}"></option>
</select>
<button type="submit">
anlegen
</button>
</form>
</main>
</body>
</html>
Loading…
Cancel
Save