diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index e889521..e479558 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/build.gradle b/build.gradle index 4de7960..00fd421 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java b/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java index 80cfa91..0049a72 100644 --- a/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java +++ b/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java @@ -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"; } } diff --git a/src/main/java/de/jottyfan/bico/modules/subject/SubjectRepository.java b/src/main/java/de/jottyfan/bico/modules/subject/SubjectRepository.java new file mode 100644 index 0000000..7aebf16 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/subject/SubjectRepository.java @@ -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 getSubjects() { + SelectWhereStep sql = jooq.selectFrom(V_LESSON); + LOGGER.trace(sql); + return sql.fetch().stream().toList(); + } + + public List getSources() { + SelectWhereStep sql = jooq.selectFrom(T_SOURCE); + LOGGER.trace(sql); + return sql.fetch().stream().toList(); + } + + public TSubjectRecord getSubject(Integer pkSubject) { + SelectConditionStep 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 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 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 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 sql = jooq.deleteFrom(T_SUBJECT).where(T_SUBJECT.PK_SUBJECT.eq(pkSubject)); + LOGGER.trace(sql); + sql.execute(); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/subject/SubjectService.java b/src/main/java/de/jottyfan/bico/modules/subject/SubjectService.java new file mode 100644 index 0000000..6843de6 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/subject/SubjectService.java @@ -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 getSubjects() { + return repository.getSubjects(); + } + + public TSubjectRecord getSubject(Integer pkSubject) { + return repository.getSubject(pkSubject); + } + + public List 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); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/subject/model/SubjectBean.java b/src/main/java/de/jottyfan/bico/modules/subject/model/SubjectBean.java new file mode 100644 index 0000000..5aac4e4 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/subject/model/SubjectBean.java @@ -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; + } +} diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index ce1197b..3e29c32 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -45,4 +45,9 @@ body { padding: 4px; margin: 4px; border-radius: 4px; +} + +.centeredalert { + width: 400px; + margin: auto; } \ No newline at end of file diff --git a/src/main/resources/templates/sheet.html b/src/main/resources/templates/sheet.html index 1599d1a..5fe7e39 100644 --- a/src/main/resources/templates/sheet.html +++ b/src/main/resources/templates/sheet.html @@ -32,15 +32,14 @@ - + + ein neues Datum anlegen - ein neues Thema anlegen diff --git a/src/main/resources/templates/subject/delete.html b/src/main/resources/templates/subject/delete.html new file mode 100644 index 0000000..4e1b68d --- /dev/null +++ b/src/main/resources/templates/subject/delete.html @@ -0,0 +1,18 @@ + + + + +
+
+ Soll das Thema wirklich gelöscht werden? +
+
+ Ja, wirklich löschen +
+
+ Dieses Thema kann nicht gelöscht werden. Möglicherweise wurde es bereits in der Vergangenheit gehalten. +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/subject/item.html b/src/main/resources/templates/subject/item.html new file mode 100644 index 0000000..72249c6 --- /dev/null +++ b/src/main/resources/templates/subject/item.html @@ -0,0 +1,40 @@ + + + + +
+
+ +
+
+
Quelle
+
+
Thema
+
+
Unterthema
+
+
Buchseiten
+
+
Arbeitsblätter
+
+
Bibelvers / Lernvers
+
+
Anmerkungen
+
+
Reihenfolge
+
+
 
+
+ + Abbrechen + Löschen +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/subject/list.html b/src/main/resources/templates/subject/list.html new file mode 100644 index 0000000..b551283 --- /dev/null +++ b/src/main/resources/templates/subject/list.html @@ -0,0 +1,52 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
QuelleThemagehaltenReihenfolge
+
+
+
+ + +
+ ein neues Thema anlegen +
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/subject/new.html b/src/main/resources/templates/subject/new.html deleted file mode 100644 index 3477e3a..0000000 --- a/src/main/resources/templates/subject/new.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - -
- TODO: implement -
-			fields:
-				fk_source
-				theme
-				subtheme
-				book_pages
-				worksheets
-				bibleverse
-				notes
-				order_nr
-			
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index c2e061e..6e65907 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -22,7 +22,8 @@