diff --git a/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java b/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java new file mode 100644 index 0000000..80cfa91 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/subject/SubjectController.java @@ -0,0 +1,20 @@ +package de.jottyfan.bico.modules.subject; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +import de.jottyfan.bico.modules.CommonController; + +/** + * + * @author jotty + * + */ +@Controller +public class SubjectController extends CommonController { + + @GetMapping("/subject/new") + public String loadNewSubjectForm() { + return "/subject/new"; + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/theme/ThemeController.java b/src/main/java/de/jottyfan/bico/modules/theme/ThemeController.java new file mode 100644 index 0000000..b832648 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/theme/ThemeController.java @@ -0,0 +1,54 @@ +package de.jottyfan.bico.modules.theme; + +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.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import de.jottyfan.bico.db.tables.records.TLessonRecord; +import de.jottyfan.bico.modules.CommonController; +import jakarta.servlet.http.HttpServletRequest; + +/** + * + * @author jotty + * + */ +@Controller +public class ThemeController extends CommonController { + + @Autowired + private ThemeService service; + + @GetMapping("/theme") + public String getThemeManipulationBySlotId(@RequestParam("slotId") Integer slotId, Model model) { + model.addAttribute("slotId", slotId); + model.addAttribute("list", service.getThemeManipulation(slotId)); + model.addAttribute("themes", service.getAllThemes()); + model.addAttribute("lesson", service.getLesson(slotId)); + return "/theme"; + } + + @PostMapping("/theme/add") + public String addThemeToSlot(@RequestParam("slotId") Integer slotId, Model model, HttpServletRequest request) { + String subjectId = request.getParameter("pkSubject"); + Integer pkSubject = Integer.valueOf(subjectId); + service.addThemeToSlot(slotId, pkSubject); + return "redirect:/theme?slotId=" + slotId; + } + + @GetMapping("/theme/delete") + public String addThemeToSlot(@RequestParam("lessonSubjectId") Integer pkLessonSubject, @RequestParam("slotId") Integer slotId) { + service.removeThemeFromSlot(pkLessonSubject); + return "redirect:/theme?slotId=" + slotId; + } + + @PostMapping("/theme/update") + public String updateLesson(@RequestParam("slotId") Integer slotId, @ModelAttribute("lesson") TLessonRecord bean) { + service.updateLesson(bean); + return "redirect:/theme?slotId=" + bean.getFkSlot(); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/theme/ThemeRepository.java b/src/main/java/de/jottyfan/bico/modules/theme/ThemeRepository.java new file mode 100644 index 0000000..98c3aa3 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/theme/ThemeRepository.java @@ -0,0 +1,141 @@ +package de.jottyfan.bico.modules.theme; + +import static de.jottyfan.bico.db.Tables.T_LESSON; +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 java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.jboss.logging.Logger; +import org.jooq.DSLContext; +import org.jooq.DeleteConditionStep; +import org.jooq.InsertOnDuplicateStep; +import org.jooq.Record10; +import org.jooq.Record4; +import org.jooq.SelectConditionStep; +import org.jooq.SelectSeekStep1; +import org.jooq.UpdateConditionStep; +import org.jooq.impl.DSL; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import de.jottyfan.bico.db.tables.records.TLessonRecord; +import de.jottyfan.bico.db.tables.records.TLessonSubjectRecord; +import de.jottyfan.bico.modules.theme.model.KeyValueBean; +import de.jottyfan.bico.modules.theme.model.ThemeBean; + +/** + * + * @author jotty + * + */ +@Repository +public class ThemeRepository { + private static final Logger LOGGER = Logger.getLogger(ThemeRepository.class); + + @Autowired + private DSLContext jooq; + + public List getThemeManipulation(Integer slotId) { + SelectConditionStep> sql = jooq + // @formatter:off + .select(T_SUBJECT.THEME, T_SUBJECT.SUBTHEME, T_SUBJECT.BOOK_PAGES, T_SUBJECT.WORKSHEETS, T_SUBJECT.BIBLEVERSE, T_SUBJECT.NOTES, + T_SOURCE.NAME, + T_LESSON.PK_LESSON, T_LESSON.NOTES, + T_LESSON_SUBJECT.PK_LESSON_SUBJECT) + .from(T_LESSON) + .leftJoin(T_LESSON_SUBJECT).on(T_LESSON_SUBJECT.FK_LESSON.eq(T_LESSON.PK_LESSON)) + .leftJoin(T_SUBJECT).on(T_SUBJECT.PK_SUBJECT.eq(T_LESSON_SUBJECT.FK_SUBJECT)) + .leftJoin(T_SOURCE).on(T_SOURCE.PK_SOURCE.eq(T_SUBJECT.FK_SOURCE)) + .where(T_LESSON.FK_SLOT.eq(slotId)); + // @formatter:on + LOGGER.trace(sql); + Iterator> i = sql.fetch() + .iterator(); + List list = new ArrayList<>(); + while (i.hasNext()) { + Record10 r = i.next(); + ThemeBean bean = ThemeBean.of(r.get(T_LESSON.PK_LESSON)); + bean.setSlotId(slotId); + bean.setPkLessonSubject(r.get(T_LESSON_SUBJECT.PK_LESSON_SUBJECT)); + bean.setTheme(r.get(T_SUBJECT.THEME)); + bean.setSubtheme(r.get(T_SUBJECT.SUBTHEME)); + bean.setBookPages(r.get(T_SUBJECT.BOOK_PAGES)); + bean.setWorksheets(r.get(T_SUBJECT.WORKSHEETS)); + bean.setBibleverse(r.get(T_SUBJECT.BIBLEVERSE)); + bean.setNotes(r.get(T_SUBJECT.NOTES)); + bean.setSourceName(r.get(T_SOURCE.NAME)); + bean.setLessonNotes(r.get(T_LESSON.NOTES)); + list.add(bean); + } + return list; + } + + public List getAllThemes() { + SelectSeekStep1, Integer> sql = jooq + // @formatter:off + .select(T_SUBJECT.PK_SUBJECT, T_SUBJECT.THEME, T_SUBJECT.SUBTHEME, T_SOURCE.NAME) + .from(T_SUBJECT) + .leftJoin(T_SOURCE).on(T_SOURCE.PK_SOURCE.eq(T_SUBJECT.FK_SOURCE)) + .orderBy(T_SUBJECT.ORDER_NR); + // @formatter:on + LOGGER.trace(sql); + List list = new ArrayList<>(); + Iterator> i = sql.fetch().iterator(); + while (i.hasNext()) { + Record4 r = i.next(); + StringBuilder buf = new StringBuilder(); + buf.append(r.get(T_SOURCE.NAME)).append(": "); + buf.append(r.get(T_SUBJECT.THEME)).append(", "); + buf.append(r.get(T_SUBJECT.SUBTHEME)); + list.add(KeyValueBean.of(r.get(T_SUBJECT.PK_SUBJECT), buf.toString())); + } + return list; + } + + public void addThemeToSlot(Integer slotId, Integer pkSubject) { + InsertOnDuplicateStep sql = jooq + // @formatter:off + .insertInto(T_LESSON_SUBJECT, T_LESSON_SUBJECT.FK_LESSON, T_LESSON_SUBJECT.FK_SUBJECT) + .select(jooq + .select(T_LESSON.PK_LESSON, DSL.val(pkSubject)) + .from(T_LESSON) + .where(T_LESSON.FK_SLOT.eq(slotId)) + ); + // @formatter:on + LOGGER.trace(sql); + sql.execute(); + } + + public void removeThemeFromSlot(Integer pkLessonSubject) { + DeleteConditionStep sql = jooq.deleteFrom(T_LESSON_SUBJECT) + .where(T_LESSON_SUBJECT.PK_LESSON_SUBJECT.eq(pkLessonSubject)); + LOGGER.trace(sql); + sql.execute(); + } + + public TLessonRecord getLesson(Integer slotId) { + SelectConditionStep sql = jooq + // @formatter:off + .selectFrom(T_LESSON) + .where(T_LESSON.FK_SLOT.eq(slotId)); + // @formatter:on + LOGGER.trace(sql); + return sql.fetchOne(); + } + + public void updateLesson(TLessonRecord bean) { + UpdateConditionStep sql = jooq + // @formatter:off + .update(T_LESSON) + .set(T_LESSON.NOTES, bean.getNotes()) + .where(T_LESSON.PK_LESSON.eq(bean.getPkLesson())); + // @formatter:on + LOGGER.trace(sql); + sql.execute(); + } + +} diff --git a/src/main/java/de/jottyfan/bico/modules/theme/ThemeService.java b/src/main/java/de/jottyfan/bico/modules/theme/ThemeService.java new file mode 100644 index 0000000..35ba04c --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/theme/ThemeService.java @@ -0,0 +1,47 @@ +package de.jottyfan.bico.modules.theme; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import de.jottyfan.bico.db.tables.records.TLessonRecord; +import de.jottyfan.bico.modules.theme.model.KeyValueBean; +import de.jottyfan.bico.modules.theme.model.ThemeBean; + +/** + * + * @author jotty + * + */ +@Service +public class ThemeService { + + @Autowired + private ThemeRepository repository; + + public List getThemeManipulation(Integer slotId) { + return repository.getThemeManipulation(slotId); + } + + public List getAllThemes() { + return repository.getAllThemes(); + } + + public void addThemeToSlot(Integer slotId, Integer pkSubject) { + repository.addThemeToSlot(slotId, pkSubject); + } + + public void removeThemeFromSlot(Integer pkLessonSubject) { + repository.removeThemeFromSlot(pkLessonSubject); + } + + public TLessonRecord getLesson(Integer slotId) { + return repository.getLesson(slotId); + } + + public void updateLesson(TLessonRecord bean) { + repository.updateLesson(bean); + } + +} diff --git a/src/main/java/de/jottyfan/bico/modules/theme/model/KeyValueBean.java b/src/main/java/de/jottyfan/bico/modules/theme/model/KeyValueBean.java new file mode 100644 index 0000000..38c49ad --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/theme/model/KeyValueBean.java @@ -0,0 +1,48 @@ +package de.jottyfan.bico.modules.theme.model; + +import java.io.Serializable; + +/** + * + * @author jotty + * + */ +public class KeyValueBean implements Serializable { + private static final long serialVersionUID = 7364119756528512005L; + + private Integer key; + private String value; + + public static final KeyValueBean of(Integer key, String value) { + KeyValueBean bean = new KeyValueBean(); + bean.setKey(key); + bean.setValue(value); + return bean; + } + + /** + * @return the key + */ + public Integer getKey() { + return key; + } + /** + * @param key the key to set + */ + public void setKey(Integer key) { + this.key = key; + } + /** + * @return the value + */ + public String getValue() { + return value; + } + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/main/java/de/jottyfan/bico/modules/theme/model/ThemeBean.java b/src/main/java/de/jottyfan/bico/modules/theme/model/ThemeBean.java new file mode 100644 index 0000000..893f52c --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/theme/model/ThemeBean.java @@ -0,0 +1,201 @@ +package de.jottyfan.bico.modules.theme.model; + +import java.io.Serializable; + +/** + * + * @author jotty + * + */ +public class ThemeBean implements Serializable { + private static final long serialVersionUID = 1L; + + private Integer lessonId; + private Integer slotId; + private Integer pkLessonSubject; + + private String theme; + private String subtheme; + private String bookPages; + private String worksheets; + private String bibleverse; + private String notes; + + private String sourceName; + + private String lessonNotes; + + public static ThemeBean of(Integer lessonId) { + ThemeBean bean = new ThemeBean(); + bean.setLessonId(lessonId); + return bean; + } + + /** + * @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 sourceName + */ + public String getSourceName() { + return sourceName; + } + + /** + * @param sourceName the sourceName to set + */ + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + + /** + * @return the slotId + */ + public Integer getSlotId() { + return slotId; + } + + + /** + * @param slotId the slotId to set + */ + public void setSlotId(Integer slotId) { + this.slotId = slotId; + } + + + /** + * @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 lessonNotes + */ + public String getLessonNotes() { + return lessonNotes; + } + + + /** + * @param lessonNotes the lessonNotes to set + */ + public void setLessonNotes(String lessonNotes) { + this.lessonNotes = lessonNotes; + } + + + /** + * @return the lessonId + */ + public Integer getLessonId() { + return lessonId; + } + + + /** + * @param lessonId the lessonId to set + */ + public void setLessonId(Integer lessonId) { + this.lessonId = lessonId; + } + + /** + * @return the pkLessonSubject + */ + public Integer getPkLessonSubject() { + return pkLessonSubject; + } + + /** + * @param pkLessonSubject the pkLessonSubject to set + */ + public void setPkLessonSubject(Integer pkLessonSubject) { + this.pkLessonSubject = pkLessonSubject; + } +} diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 4a9a6c7..ce1197b 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -34,4 +34,15 @@ body { .rightpadding64 { margin-right: 64px; +} + +.sidenote { + font-style: italic; +} + +.blockframe { + border: 1px solid gray; + padding: 4px; + margin: 4px; + border-radius: 4px; } \ No newline at end of file diff --git a/src/main/resources/templates/sheet.html b/src/main/resources/templates/sheet.html index ca41b5c..1599d1a 100644 --- a/src/main/resources/templates/sheet.html +++ b/src/main/resources/templates/sheet.html @@ -18,15 +18,30 @@ -
-
+ +
+
+
+
+
+
+
+
+ +
+
+
+ - einen neues Datum anlegen + + ein neues Datum anlegen + ein neues Thema anlegen + diff --git a/src/main/resources/templates/subject/new.html b/src/main/resources/templates/subject/new.html new file mode 100644 index 0000000..3477e3a --- /dev/null +++ b/src/main/resources/templates/subject/new.html @@ -0,0 +1,21 @@ + + + + +
+ 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/theme.html b/src/main/resources/templates/theme.html new file mode 100644 index 0000000..eaea0b8 --- /dev/null +++ b/src/main/resources/templates/theme.html @@ -0,0 +1,64 @@ + + + + +
+
+ +
+
Thema:
+
+
+ +
+
Unterthema:
+
+
Buchseiten:
+
+
Arbeitsblätter:
+
+
Bibelvers (Lernvers):
+
+
Anmerkungen zum Thema:
+
+
Quelle:
+
+
+
+
+ +
+
Anmerkungen zur Stunde
+
+ +
+
 
+
+ + +
+
+
+
+
+
ein Thema hinzufügen
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file