add, edit, delete and assign themes to dates

This commit is contained in:
Jottyfan
2023-12-16 22:51:27 +01:00
parent 5356e51f09
commit 0999d41d64
13 changed files with 505 additions and 29 deletions

View File

@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false

View File

@ -8,7 +8,7 @@ plugins {
}
group = 'de.jottyfan.bico'
version = '0.0.3'
version = '0.0.4'
description = """BibleClassOrganizer"""
@ -41,7 +41,7 @@ war {
}
dependencies {
implementation 'de.jottyfan:bicolib:3'
implementation 'de.jottyfan:bicolib:4'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

View File

@ -1,8 +1,14 @@
package de.jottyfan.bico.modules.subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.modules.CommonController;
/**
@ -13,8 +19,44 @@ import de.jottyfan.bico.modules.CommonController;
@Controller
public class SubjectController extends CommonController {
@Autowired
private SubjectService service;
@GetMapping("/subject/list")
public String getSubjectList(Model model) {
model.addAttribute("list", service.getSubjects());
return "/subject/list";
}
@GetMapping("/subject/{id}")
public String getSubject(@PathVariable("id") Integer pkSubject, Model model) {
model.addAttribute("bean", service.getSubject(pkSubject));
model.addAttribute("sources", service.getSources());
return "/subject/item";
}
@PostMapping("/subject/save")
public String saveSubject(@ModelAttribute("bean") TSubjectRecord bean) {
service.save(bean);
return "redirect:/subject/list";
}
@GetMapping("/subject/{id}/delete")
public String checkDeletionOfSubject(@PathVariable("id") Integer pkSubject, Model model) {
model.addAttribute("bean", service.getBeanIfDeletable(pkSubject));
return "/subject/delete";
}
@GetMapping("/subject/{id}/remove")
public String removeSubject(@PathVariable("id") Integer pkSubject, Model model) {
service.removeSubject(pkSubject);
return "redirect:/subject/list";
}
@GetMapping("/subject/new")
public String loadNewSubjectForm() {
return "/subject/new";
public String loadNewSubjectForm(Model model) {
model.addAttribute("bean", new TSubjectRecord());
model.addAttribute("sources", service.getSources());
return "/subject/item";
}
}

View File

@ -0,0 +1,115 @@
package de.jottyfan.bico.modules.subject;
import static de.jottyfan.bico.db.Tables.T_LESSON_SUBJECT;
import static de.jottyfan.bico.db.Tables.T_SOURCE;
import static de.jottyfan.bico.db.Tables.T_SUBJECT;
import static de.jottyfan.bico.db.Tables.V_LESSON;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.DeleteConditionStep;
import org.jooq.InsertValuesStep8;
import org.jooq.SelectConditionStep;
import org.jooq.SelectOrderByStep;
import org.jooq.SelectWhereStep;
import org.jooq.UpdateConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TSourceRecord;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.tables.records.VLessonRecord;
/**
*
* @author jotty
*
*/
@Repository
public class SubjectRepository {
private static final Logger LOGGER = LogManager.getLogger(SubjectRepository.class);
@Autowired
private DSLContext jooq;
public List<VLessonRecord> getSubjects() {
SelectWhereStep<VLessonRecord> sql = jooq.selectFrom(V_LESSON);
LOGGER.trace(sql);
return sql.fetch().stream().toList();
}
public List<TSourceRecord> getSources() {
SelectWhereStep<TSourceRecord> sql = jooq.selectFrom(T_SOURCE);
LOGGER.trace(sql);
return sql.fetch().stream().toList();
}
public TSubjectRecord getSubject(Integer pkSubject) {
SelectConditionStep<TSubjectRecord> sql = jooq
// @formatter:off
.selectFrom(T_SUBJECT)
.where(T_SUBJECT.PK_SUBJECT.eq(pkSubject));
// @formatter:on
LOGGER.trace(sql);
return sql.fetchOne();
}
public void addSubject(TSubjectRecord bean) {
InsertValuesStep8<TSubjectRecord, Integer, String, String, String, String, String, String, Integer> sql = jooq
// @formatter:off
.insertInto(T_SUBJECT,
T_SUBJECT.FK_SOURCE,
T_SUBJECT.THEME,
T_SUBJECT.SUBTHEME,
T_SUBJECT.BOOK_PAGES,
T_SUBJECT.WORKSHEETS,
T_SUBJECT.BIBLEVERSE,
T_SUBJECT.NOTES,
T_SUBJECT.ORDER_NR)
.values(bean.getFkSource(), bean.getTheme(), bean.getSubtheme(), bean.getBookPages(), bean.getWorksheets(),
bean.getBibleverse(), bean.getNotes(), bean.getOrderNr());
// @formatter:on
LOGGER.trace(sql);
sql.execute();
}
public void updateSubject(TSubjectRecord bean) {
UpdateConditionStep<TSubjectRecord> sql = jooq
// @formatter:off
.update(T_SUBJECT)
.set(T_SUBJECT.FK_SOURCE, bean.getFkSource())
.set(T_SUBJECT.THEME, bean.getTheme())
.set(T_SUBJECT.SUBTHEME, bean.getSubtheme())
.set(T_SUBJECT.BOOK_PAGES, bean.getBookPages())
.set(T_SUBJECT.WORKSHEETS, bean.getWorksheets())
.set(T_SUBJECT.BIBLEVERSE, bean.getBibleverse())
.set(T_SUBJECT.NOTES, bean.getNotes())
.set(T_SUBJECT.ORDER_NR, bean.getOrderNr())
.where(T_SUBJECT.PK_SUBJECT.eq(bean.getPkSubject()));
// @formatter:on
LOGGER.trace(sql);
sql.execute();
}
public TSubjectRecord getBeanIfDeletable(Integer pkSubject) {
SelectOrderByStep<TSubjectRecord> sql = jooq
// @formatter:off
.selectFrom(T_SUBJECT)
.where(T_SUBJECT.PK_SUBJECT.notIn(jooq
.select(T_LESSON_SUBJECT.FK_SUBJECT)
.from(T_LESSON_SUBJECT)))
.and(T_SUBJECT.PK_SUBJECT.eq(pkSubject));
// @formatter:off
LOGGER.trace(sql);
return sql.fetchOne();
}
public void removeSubject(Integer pkSubject) {
DeleteConditionStep<TSubjectRecord> sql = jooq.deleteFrom(T_SUBJECT).where(T_SUBJECT.PK_SUBJECT.eq(pkSubject));
LOGGER.trace(sql);
sql.execute();
}
}

View File

@ -0,0 +1,50 @@
package de.jottyfan.bico.modules.subject;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.TSourceRecord;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.tables.records.VLessonRecord;
/**
*
* @author jotty
*
*/
@Service
public class SubjectService {
@Autowired
private SubjectRepository repository;
public List<VLessonRecord> getSubjects() {
return repository.getSubjects();
}
public TSubjectRecord getSubject(Integer pkSubject) {
return repository.getSubject(pkSubject);
}
public List<TSourceRecord> getSources() {
return repository.getSources();
}
public void save(TSubjectRecord bean) {
if (bean.getPkSubject() == null) {
repository.addSubject(bean);
} else {
repository.updateSubject(bean);
}
}
public TSubjectRecord getBeanIfDeletable(Integer pkSubject) {
return repository.getBeanIfDeletable(pkSubject);
}
public void removeSubject(Integer pkSubject) {
repository.removeSubject(pkSubject);
}
}

View File

@ -0,0 +1,164 @@
package de.jottyfan.bico.modules.subject.model;
import java.io.Serializable;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
/**
*
* @author jotty
*
*/
public class SubjectBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pkSubject;
private Integer fkSource;
private String theme;
private String subtheme;
private String bookPages;
private String worksheets;
private String bibleverse;
private String notes;
private Integer orderNr;
public static final SubjectBean of(TSubjectRecord r) {
SubjectBean bean = new SubjectBean();
bean.setPkSubject(r.getPkSubject());
bean.setFkSource(r.getFkSource());
bean.setTheme(r.getTheme());
bean.setSubtheme(r.getSubtheme());
bean.setBookPages(r.getBookPages());
bean.setWorksheets(r.getWorksheets());
bean.setBibleverse(r.getBibleverse());
bean.setNotes(r.getNotes());
bean.setOrderNr(r.getOrderNr());
return bean;
}
/**
* @return the pkSubject
*/
public Integer getPkSubject() {
return pkSubject;
}
/**
* @param pkSubject the pkSubject to set
*/
public void setPkSubject(Integer pkSubject) {
this.pkSubject = pkSubject;
}
/**
* @return the fkSource
*/
public Integer getFkSource() {
return fkSource;
}
/**
* @param fkSource the fkSource to set
*/
public void setFkSource(Integer fkSource) {
this.fkSource = fkSource;
}
/**
* @return the theme
*/
public String getTheme() {
return theme;
}
/**
* @param theme the theme to set
*/
public void setTheme(String theme) {
this.theme = theme;
}
/**
* @return the subtheme
*/
public String getSubtheme() {
return subtheme;
}
/**
* @param subtheme the subtheme to set
*/
public void setSubtheme(String subtheme) {
this.subtheme = subtheme;
}
/**
* @return the bookPages
*/
public String getBookPages() {
return bookPages;
}
/**
* @param bookPages the bookPages to set
*/
public void setBookPages(String bookPages) {
this.bookPages = bookPages;
}
/**
* @return the worksheets
*/
public String getWorksheets() {
return worksheets;
}
/**
* @param worksheets the worksheets to set
*/
public void setWorksheets(String worksheets) {
this.worksheets = worksheets;
}
/**
* @return the bibleverse
*/
public String getBibleverse() {
return bibleverse;
}
/**
* @param bibleverse the bibleverse to set
*/
public void setBibleverse(String bibleverse) {
this.bibleverse = bibleverse;
}
/**
* @return the notes
*/
public String getNotes() {
return notes;
}
/**
* @param notes the notes to set
*/
public void setNotes(String notes) {
this.notes = notes;
}
/**
* @return the orderNr
*/
public Integer getOrderNr() {
return orderNr;
}
/**
* @param orderNr the orderNr to set
*/
public void setOrderNr(Integer orderNr) {
this.orderNr = orderNr;
}
}

View File

@ -45,4 +45,9 @@ body {
padding: 4px;
margin: 4px;
border-radius: 4px;
}
.centeredalert {
width: 400px;
margin: auto;
}

View File

@ -32,15 +32,14 @@
</div>
</div>
</td>
<td><span th:text="${s.slotNotes}" class="rightpadding64"></span><a th:href="@{/slot/{id}(id=${s.pkSlot})}" class="btn btn-outline-secondary rightaligned"><i
class="bi bi-pencil"></i></a></td>
<td><a th:href="@{/slot/{id}(id=${s.pkSlot})}" class="btn btn-outline-secondary rightaligned"><i class="bi bi-pencil"></i></a>
<span th:text="${s.slotNotes}" class="rightpadding64"></span></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<a th:href="@{/slot}" class="btn btn-outline-success">ein neues Datum anlegen</a>
<a th:href="@{/subject/new}" class="btn btn-outline-primary">ein neues Thema anlegen</a>
</td>
</tr>
</tfoot>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<body>
<th:block layout:fragment="content">
<div class="borderdist">
<div class="alert alert-danger centeredalert" th:if="${bean}">
Soll das Thema <span th:text="${bean.theme}" style="font-weight: bolder"></span> wirklich gelöscht werden?
<br />
<br />
<a th:href="@{/subject/{id}/remove(id=${bean.pkSubject})}" class="btn btn-outline-danger">Ja, wirklich löschen</a>
</div>
<div class="alert alert-warning centeredalert" th:unless="${bean}">
Dieses Thema kann nicht gelöscht werden. Möglicherweise wurde es bereits in der Vergangenheit gehalten.
</div>
</div>
</th:block>
</body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<body>
<th:block layout:fragment="content">
<div class="borderdist">
<form th:action="@{/subject/save}" method="post" th:object="${bean}">
<input type="hidden" th:field="*{pkSubject}" />
<div class="container">
<div class="row g-2">
<div class="col-sm-3">Quelle</div>
<div class="col-sm-9"><select th:field="*{fkSource}" class="form-select">
<option th:each="o : ${sources}" th:value="${o.pkSource}" th:text="${o.name}"></option>
</select></div>
<div class="col-sm-3">Thema</div>
<div class="col-sm-9"><input type="text" th:field="*{theme}" class="form-control" /></div>
<div class="col-sm-3">Unterthema</div>
<div class="col-sm-9"><input type="text" th:field="*{subtheme}" class="form-control" /></div>
<div class="col-sm-3">Buchseiten</div>
<div class="col-sm-9"><input type="text" th:field="*{bookPages}" class="form-control" /></div>
<div class="col-sm-3">Arbeitsblätter</div>
<div class="col-sm-9"><input type="text" th:field="*{worksheets}" class="form-control" /></div>
<div class="col-sm-3">Bibelvers / Lernvers</div>
<div class="col-sm-9"><input type="text" th:field="*{bibleverse}" class="form-control" /></div>
<div class="col-sm-3">Anmerkungen</div>
<div class="col-sm-9"><input type="text" th:field="*{notes}" class="form-control" /></div>
<div class="col-sm-3">Reihenfolge</div>
<div class="col-sm-9"><input type="number" th:field="*{orderNr}" class="form-control" /></div>
<div class="col-sm-3">&nbsp;</div>
<div class="col-sm-9">
<button type="submit" class="btn btn-outline-primary">Übernehmen</button>
<a th:href="@{/subject/list}" class="btn btn-outline-secondary">Abbrechen</a>
<a th:href="@{/subject/{id}/delete(id=${bean.pkSubject})}" class="btn btn-outline-danger" th:if="${bean.pkSubject}">Löschen</a>
</div>
</div>
</div>
</form>
</div>
</th:block>
</body>
</html>

View File

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<body>
<th:block layout:fragment="content">
<div class="borderdist">
<table id="table" class="table table-striped">
<thead>
<tr>
<th>Quelle</th>
<th>Thema</th>
<th>gehalten</th>
<th>Reihenfolge</th>
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="s : ${list}">
<td th:text="${s.sourceName}"></td>
<td>
<div><span th:text="${s.theme}" style="font-weight: bolder"></span></div>
<div th:text="${s.subtheme}"></div>
</td>
<td><div th:text="${#temporals.format(d, 'dd.MM.yyyy')}" th:each="d : ${s.slots}"></div></td>
<td th:text="${s.orderNr}"></td>
<td>
<a th:href="@{/subject/{id}(id=${s.pkSubject})}" class="btn btn-outline-secondary"><i class="bi bi-pencil"></i></a>
<a th:href="@{/subject/{id}/delete(id=${s.pkSubject})}" class="btn btn-outline-danger" th:if="${s.slots.length < 1}"><i class="bi bi-trash"></i></a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5">
<a th:href="@{/subject/new}" class="btn btn-outline-primary">ein neues Thema anlegen</a>
</td>
</tr>
</tfoot>
</table>
<script th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function() {
$("#table").DataTable({
"order" : [ [ 3, 'asc' ] ],
"language" : locale_de
});
});
/*]]>*/
</script>
</div>
</th:block>
</body>
</html>

View File

@ -1,21 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<body>
<th:block layout:fragment="content">
<div class="borderdist">
TODO: implement
<pre>
fields:
fk_source
theme
subtheme
book_pages
worksheets
bibleverse
notes
order_nr
</pre>
</div>
</th:block>
</body>
</html>

View File

@ -22,7 +22,8 @@
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent" style="margin-right: 20px">
<ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/}" style="margin-left: 12px">Startseite</a></li>
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/}" style="margin-left: 12px">Einteilung</a></li>
<li class="nav-item"><a class="btn btn-outline-secondary" th:href="@{/subject/list}" style="margin-left: 12px">Themen</a></li>
</ul>
<ul layout:fragment="header"></ul>
<ul class="nav navbar-nav ms-auto">