basic theme selection
This commit is contained in:
@ -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";
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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<ThemeBean> getThemeManipulation(Integer slotId) {
|
||||
SelectConditionStep<Record10<String, String, String, String, String, String, String, Integer, String, Integer>> 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<Record10<String, String, String, String, String, String, String, Integer, String, Integer>> i = sql.fetch()
|
||||
.iterator();
|
||||
List<ThemeBean> list = new ArrayList<>();
|
||||
while (i.hasNext()) {
|
||||
Record10<String, String, String, String, String, String, String, Integer, String, Integer> 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<KeyValueBean> getAllThemes() {
|
||||
SelectSeekStep1<Record4<Integer, String, String, String>, 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<KeyValueBean> list = new ArrayList<>();
|
||||
Iterator<Record4<Integer, String, String, String>> i = sql.fetch().iterator();
|
||||
while (i.hasNext()) {
|
||||
Record4<Integer, String, String, String> 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<TLessonSubjectRecord> 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<TLessonSubjectRecord> 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<TLessonRecord> 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<TLessonRecord> 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();
|
||||
}
|
||||
|
||||
}
|
@ -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<ThemeBean> getThemeManipulation(Integer slotId) {
|
||||
return repository.getThemeManipulation(slotId);
|
||||
}
|
||||
|
||||
public List<KeyValueBean> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user