draft for links

master
Josha von Gizycki 3 days ago
parent 9af57be306
commit 05ac0ba8a1

@ -0,0 +1,13 @@
package wanijo.wanijo2.domain.event
import jakarta.validation.constraints.Min
import wanijo.wanijo2.domain.Direction
import wanijo.wanijo2.domain.DocumentId
data class AddLinkCommand(
@Min(1)
val documentId: DocumentId,
@Min.List(Min(1))
val otherDocuments: List<DocumentId>,
val direction: Direction
)

@ -0,0 +1,25 @@
package wanijo.wanijo2.domain
import org.springframework.data.annotation.Id
import org.springframework.data.jdbc.core.mapping.AggregateReference
import org.springframework.data.relational.core.mapping.Table
import org.springframework.data.repository.Repository
import java.time.Instant
typealias LinkId = Long
@Table("T_LINK")
data class Link(
@Id
val id: LinkId = 0,
val from: AggregateReference<Document, DocumentId>,
val to: AggregateReference<Document, DocumentId>,
val createdAt: Instant = Instant.now(),
)
enum class Direction {
OUTGOING,
INCOMING
}
interface LinkDao : Repository<Link, LinkId> {}

@ -14,7 +14,6 @@ import wanijo.wanijo2.domain.event.AddLabelFieldCommand
import wanijo.wanijo2.domain.handler.AddDateFieldHandler import wanijo.wanijo2.domain.handler.AddDateFieldHandler
import wanijo.wanijo2.domain.handler.AddLabelFieldHandler import wanijo.wanijo2.domain.handler.AddLabelFieldHandler
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZonedDateTime.now
@Controller @Controller
class AddFieldController( class AddFieldController(

@ -0,0 +1,48 @@
package wanijo.wanijo2.http.controller
import org.springframework.data.domain.Sort
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import wanijo.wanijo2.domain.Direction
import wanijo.wanijo2.domain.DocumentBriefDao
import wanijo.wanijo2.domain.DocumentId
import wanijo.wanijo2.domain.event.AddLinkCommand
@Controller
class LinkController(
val documentBriefDao: DocumentBriefDao,
) {
@GetMapping("/document/{id}/link/add")
fun addLabel(
@PathVariable
id: DocumentId,
model: Model
): String {
model["document"] = documentBriefDao.findById(id)
model["documents"] = documentBriefDao.findAll(Sort.by(Sort.Direction.ASC, "name"))
model["addForm"] = AddLinkCommand(
id,
emptyList(),
Direction.OUTGOING
)
return "addLink"
}
/*@PostMapping("/document/{id}/field/label/add")
fun addLabel(
@PathVariable
id: DocumentId,
@Valid
command: AddLabelFieldCommand
): String {
addLabelFieldHandler.exec(command)
return "redirect:/document/$id"
}*/
}

@ -9,12 +9,15 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PathVariable
import wanijo.wanijo2.domain.DocumentDao import wanijo.wanijo2.domain.DocumentDao
import wanijo.wanijo2.domain.DocumentId import wanijo.wanijo2.domain.DocumentId
import wanijo.wanijo2.domain.Link
import wanijo.wanijo2.domain.LinkDao
import wanijo.wanijo2.domain.TagDao import wanijo.wanijo2.domain.TagDao
import wanijo.wanijo2.http.DocumentNotFound import wanijo.wanijo2.http.DocumentNotFound
@Controller @Controller
class ShowController( class ShowController(
val docDao: DocumentDao, val docDao: DocumentDao,
val linkDao: LinkDao,
val tagDao: TagDao val tagDao: TagDao
) { ) {
@ -36,6 +39,9 @@ class ShowController(
model["documentTags"] = documentTags.sortedBy { it.name.lowercase() } model["documentTags"] = documentTags.sortedBy { it.name.lowercase() }
model["assignableTags"] = (tagDao.findAll() - documentTags).sortedBy { it.name.lowercase() } model["assignableTags"] = (tagDao.findAll() - documentTags).sortedBy { it.name.lowercase() }
model["incomingLinks"] = emptyList<Link>()
model["outgoingLinks"] = emptyList<Link>()
return "show" return "show"
} }

@ -0,0 +1,15 @@
CREATE TABLE t_link
(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
document_from INT NOT NULL,
document_to INT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT fk_link_document_from
FOREIGN KEY (document_from)
REFERENCES t_document (id),
CONSTRAINT fk_link_document_to
FOREIGN KEY (document_to)
REFERENCES t_document (id)
);

@ -11,7 +11,7 @@
<a th:href="@{/document/{id}(id=${document.id})}">&lt;&lt; zurück</a> <a th:href="@{/document/{id}(id=${document.id})}">&lt;&lt; zurück</a>
<h2> <h2>
<span class="low-key-hint">label zu</span> <span class="low-key-hint">beschriftung zu</span>
<th:block th:text="${document.name}"/> <th:block th:text="${document.name}"/>
<span class="low-key-hint">hinzufügen</span> <span class="low-key-hint">hinzufügen</span>
</h2> </h2>

@ -0,0 +1,41 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{base}"
lang="">
<head>
<title th:text="${document.name}"></title>
</head>
<body>
<main id="content" layout:fragment="content">
<a th:href="@{/document/{id}(id=${document.id})}">&lt;&lt; zurück</a>
<h2>
<span class="low-key-hint">verknüpfung für</span>
<th:block th:text="${document.name}"/>
<span class="low-key-hint">hinzufügen</span>
</h2>
<form th:action="@{/document/{id}/link/add(id=${document.id})}"
th:object="${addForm}"
method="post">
<input type="hidden" th:field="*{documentId}">
<label for="otherDocuments">dokumente</label>
<select th:field="*{otherDocuments}" multiple id="otherDocuments">
<option th:each="doc: ${documents}"
th:value="${doc.id}"
th:if="${doc.id != document.id}"
th:text="${doc.name}"></option>
</select>
<button type="submit" value="OUTGOING" name="direction">
ausgehend
</button>
<button type="submit" value="INCOMING" name="direction">
eingehend
</button>
</form>
</main>
</body>
</html>

@ -8,6 +8,14 @@
</head> </head>
<body> <body>
<main id="content" layout:fragment="content"> <main id="content" layout:fragment="content">
<a th:href="@{/document/{id}(id=${form.id})}">&lt;&lt; zurück</a>
<h2>
<span class="low-key-hint">dokument</span>
<th:block th:text="${form.name}"/>
<span class="low-key-hint">bearbeiten</span>
</h2>
<form th:action="@{/document/edit}" th:object="${form}" method="post"> <form th:action="@{/document/edit}" th:object="${form}" method="post">
<input type="hidden" th:field="*{id}"> <input type="hidden" th:field="*{id}">

@ -53,6 +53,33 @@
<div class="show__markdown" th:utext="${descHtml}"></div> <div class="show__markdown" th:utext="${descHtml}"></div>
</fieldset> </fieldset>
<h2 class="low-key-hint">
verknüpfungen
<a th:href="@{/document/{id}/link/add(id=${document.id})}">
<button>
neu
</button>
</a>
</h2>
<h3 class="low-key-hint">
eingehend
</h3>
<ol>
<li th:each="link : ${incomingLinks}">
<a th:href="@{/document/{id}(id=${link.documentFrom})}"
th:text="link.documentFrom"></a>
</li>
</ol>
<h3 class="low-key-hint">
ausgehend
</h3>
<ol>
<li th:each="link : ${outgoingLinks}">
<a th:href="@{/document/{id}(id=${link.documentTo})}"
th:text="link.documentFrom"></a>
</li>
</ol>
<h2 class="low-key-hint"> <h2 class="low-key-hint">
felder felder
<a th:href="@{/document/{id}/field/add(id=${document.id})}"> <a th:href="@{/document/{id}/field/add(id=${document.id})}">
@ -62,7 +89,7 @@
</a> </a>
</h2> </h2>
<h3 class="low-key-hint"> <h3 class="low-key-hint">
label beschriftung
</h3> </h3>
<dl> <dl>
<th:block th:each="field : ${document.labelFieldsSorted()}"> <th:block th:each="field : ${document.labelFieldsSorted()}">

Loading…
Cancel
Save