diff --git a/.project b/.project index 34e790f..bf98eb5 100644 --- a/.project +++ b/.project @@ -25,6 +25,11 @@ + + org.springframework.ide.eclipse.boot.validation.springbootbuilder + + + org.eclipse.jdt.core.javanature diff --git a/.settings/org.springframework.ide.eclipse.prefs b/.settings/org.springframework.ide.eclipse.prefs new file mode 100644 index 0000000..a12794d --- /dev/null +++ b/.settings/org.springframework.ide.eclipse.prefs @@ -0,0 +1,2 @@ +boot.validation.initialized=true +eclipse.preferences.version=1 diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml deleted file mode 100644 index b734677..0000000 --- a/WEB-INF/web.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - BiCO - - index.html - index.htm - index.jsp - default.html - default.htm - default.jsp - - diff --git a/build.gradle b/build.gradle index 21ac55f..4de7960 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'de.jottyfan.bico' -version = '0.0.2' +version = '0.0.3' description = """BibleClassOrganizer""" diff --git a/src/main/java/de/jottyfan/bico/modules/lesson/LessonController.java b/src/main/java/de/jottyfan/bico/modules/lesson/LessonController.java new file mode 100644 index 0000000..6d9bdd7 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/lesson/LessonController.java @@ -0,0 +1,45 @@ +package de.jottyfan.bico.modules.lesson; + +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 org.springframework.web.bind.annotation.RequestParam; + +import de.jottyfan.bico.db.tables.records.TLessonRecord; +import de.jottyfan.bico.modules.CommonController; +/** + * + * @author jotty + * + */ +@Controller +public class LessonController extends CommonController { + + @Autowired + private LessonService service; + + @GetMapping("/lesson") + public String getPerson(@RequestParam("slotId") Integer slotId, Model model) { + model.addAttribute("bean", service.getLesson(slotId, true)); + model.addAttribute("persons", service.getPersons()); + model.addAttribute("slotDay", service.getSlotDay(slotId)); + return "/lesson/item"; + } + + @PostMapping("/lesson/{id}") + public String updateLesson(@PathVariable("id") Integer lessonId, @ModelAttribute("bean") TLessonRecord bean, Model model) { + bean.setPkLesson(lessonId); + service.updateLesson(bean); + return "redirect:/sheet"; + } + + @GetMapping("/lesson/{id}/remove") + public String removeLesson(@PathVariable("id") Integer lessonId) { + service.removeLesson(lessonId); + return "redirect:/sheet"; + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/lesson/LessonRepository.java b/src/main/java/de/jottyfan/bico/modules/lesson/LessonRepository.java new file mode 100644 index 0000000..ac40296 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/lesson/LessonRepository.java @@ -0,0 +1,100 @@ +package de.jottyfan.bico.modules.lesson; + +import static de.jottyfan.bico.db.Tables.T_LESSON; +import static de.jottyfan.bico.db.Tables.T_PERSON; +import static de.jottyfan.bico.db.Tables.T_SLOT; + +import java.time.LocalDate; +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.InsertResultStep; +import org.jooq.Record1; +import org.jooq.SelectConditionStep; +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.TLessonRecord; +import de.jottyfan.bico.db.tables.records.TPersonRecord; + +/** +* +* @author jotty +* +*/ +@Repository +public class LessonRepository { + private final static Logger LOGGER = LogManager.getLogger(LessonRepository.class); + + @Autowired + private DSLContext jooq; + + public TLessonRecord getLesson(Integer slotId, Boolean createIfNecessary) { + SelectConditionStep sql = jooq + // @formatter:off + .selectFrom(T_LESSON) + .where(T_LESSON.FK_SLOT.eq(slotId)); + // @formatter:on + LOGGER.trace(sql); + TLessonRecord r = sql.fetchOne(); + if (r == null && createIfNecessary) { + InsertResultStep sql2 = jooq + // @formatter:off + .insertInto(T_LESSON, + T_LESSON.FK_SLOT) + .values(slotId) + .returning(T_LESSON.PK_LESSON); + // @formatter:on + LOGGER.trace(sql); + Integer pkLesson = sql2.fetchOne(T_LESSON.PK_LESSON); + r = new TLessonRecord(); + r.setPkLesson(pkLesson); + r.setFkSlot(slotId); + } + return r; + } + + public List getPersons() { + SelectWhereStep sql = jooq.selectFrom(T_PERSON); + LOGGER.trace(sql); + return sql.fetchStream().toList(); + } + + public LocalDate getSlotDay(Integer slotId) { + SelectConditionStep> sql = jooq + // @formatter:off + .select(T_SLOT.SLOT_DAY) + .from(T_SLOT) + .where(T_SLOT.PK_SLOT.eq(slotId)); + // @formatter:on + LOGGER.trace(sql); + return sql.fetchOne(T_SLOT.SLOT_DAY); + } + + public void updateLesson(TLessonRecord bean) { + UpdateConditionStep sql = jooq + // @formatter:off + .update(T_LESSON) + .set(T_LESSON.NOTES, bean.getNotes()) + .set(T_LESSON.FK_PERSON, bean.getFkPerson()) + .where(T_LESSON.PK_LESSON.eq(bean.getPkLesson())); + // @formatter:on + LOGGER.trace(sql); + sql.execute(); + } + + public void removeLesson(Integer lessonId) { + DeleteConditionStep sql = jooq + // @formatter:off + .deleteFrom(T_LESSON) + .where(T_LESSON.PK_LESSON.eq(lessonId)); + // @formatter:on + LOGGER.trace(sql); + sql.execute(); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/lesson/LessonService.java b/src/main/java/de/jottyfan/bico/modules/lesson/LessonService.java new file mode 100644 index 0000000..96995ad --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/lesson/LessonService.java @@ -0,0 +1,42 @@ +package de.jottyfan.bico.modules.lesson; + +import java.time.LocalDate; +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.db.tables.records.TPersonRecord; + +/** + * + * @author jotty + * + */ +@Service +public class LessonService { + + @Autowired + private LessonRepository repository; + + public TLessonRecord getLesson(Integer slotId, Boolean createIfNecessary) { + return repository.getLesson(slotId, createIfNecessary); + } + + public List getPersons() { + return repository.getPersons(); + } + + public LocalDate getSlotDay(Integer slotId) { + return repository.getSlotDay(slotId); + } + + public void updateLesson(TLessonRecord bean) { + repository.updateLesson(bean); + } + + public void removeLesson(Integer lessonId) { + repository.removeLesson(lessonId); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java index 76c95ef..3f27594 100644 --- a/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java @@ -32,6 +32,7 @@ public class SlotController extends CommonController { @GetMapping("/slot/{id}") public String load(@PathVariable Integer id, Model model) { model.addAttribute("bean", id == null ? new SlotBean() : service.loadSlot(id)); + model.addAttribute("hasLesson", service.slotHasLesson(id)); return "/slot/item"; } diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java index be6dae6..d728da3 100644 --- a/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java @@ -126,4 +126,20 @@ public class SlotRepository { return null; } } + + /** + * return true if this slot already has at least one lesson + * + * @param slotId the ID of the slot + * @return true or false + */ + public Boolean getHasLesson(Integer slotId) { + SelectConditionStep sql = jooq + // @formatter:off + .selectFrom(T_LESSON) + .where(T_LESSON.FK_SLOT.eq(slotId)); + // @formatter:on + LOGGER.trace(sql); + return sql.fetch().size() > 0; + } } diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java index 8171f53..daf7ea5 100644 --- a/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java @@ -36,4 +36,8 @@ public class SlotService { public SlotBean loadDeletableSlot(Integer id) { return repository.getSlotIfDeletable(id); } + + public Boolean slotHasLesson(Integer id) { + return id == null ? false : repository.getHasLesson(id); + } } diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 3996ef7..4a9a6c7 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -1,16 +1,9 @@ -/* -html { - width: 100%; - height: 100%; -} -*/ - body { background-color: #abc; } [data-bs-theme=dark] body { - background-color: rgb(36, 31, 49); + background-color: #001213; } .borderdist { @@ -23,4 +16,22 @@ body { [data-bs-theme=dark] .borderdist { background-color: #333; +} + +.headerback { + background-color: #eee; + border-bottom: 1px solid silver; +} + +[data-bs-theme=dark] .headerback { + background-color: #333; +} + +.rightaligned { + right: 5px; + position: absolute; +} + +.rightpadding64 { + margin-right: 64px; } \ No newline at end of file diff --git a/src/main/resources/templates/lesson/item.html b/src/main/resources/templates/lesson/item.html new file mode 100644 index 0000000..f8015f6 --- /dev/null +++ b/src/main/resources/templates/lesson/item.html @@ -0,0 +1,41 @@ + + + + +
+
+
+
+

Dozent-Reservierung

+
+
+
+
+
Tag
+
+ +
+
Dozent
+
+ +
+
Anmerkungen
+
+ +
+
+
+   + Abbrechen  + Löschen +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/sheet.html b/src/main/resources/templates/sheet.html index c743509..ca41b5c 100644 --- a/src/main/resources/templates/sheet.html +++ b/src/main/resources/templates/sheet.html @@ -7,29 +7,26 @@ Tag - Kürzel + Wer Thema Notiz - - - + - - - - +
+
+ - einen neues Datum anlegen + einen neues Datum anlegen diff --git a/src/main/resources/templates/slot/item.html b/src/main/resources/templates/slot/item.html index 487810a..ee77f98 100644 --- a/src/main/resources/templates/slot/item.html +++ b/src/main/resources/templates/slot/item.html @@ -4,6 +4,11 @@
+
+
+

Terminfestlegung

+
+
@@ -19,7 +24,15 @@
- Löschen + + Löschen + +
+
Hinweis
+
+
Termine, die bereits für einen Dozenten reserviert wurden, können nicht gelöscht werden. + Reservierung bearbeiten +
diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index 34aa871..c2e061e 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -15,14 +15,14 @@ -