finished view, lack of persistence on changes of camp locations

This commit is contained in:
Jörg Henke 2023-03-11 07:55:09 +01:00
parent 5a012c3e19
commit bd0cdd681f
5 changed files with 70 additions and 1 deletions

View File

@ -121,6 +121,7 @@ public class AdminController extends CommonController {
public String prepareAddLocation(Model model, HttpServletRequest request) { public String prepareAddLocation(Model model, HttpServletRequest request) {
super.setupSession(model, request); super.setupSession(model, request);
model.addAttribute("bean", new LocationBean()); model.addAttribute("bean", new LocationBean());
model.addAttribute("documents", service.getLocationDocuments());
return "/admin/location_edit"; return "/admin/location_edit";
} }
@ -128,6 +129,7 @@ public class AdminController extends CommonController {
public String prepareAddLocation(@PathVariable Integer id, Model model, HttpServletRequest request) { public String prepareAddLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
super.setupSession(model, request); super.setupSession(model, request);
model.addAttribute("bean", service.getLocation(id)); model.addAttribute("bean", service.getLocation(id));
model.addAttribute("documents", service.getLocationDocuments());
return "/admin/location_edit"; return "/admin/location_edit";
} }

View File

@ -13,11 +13,13 @@ import java.util.Set;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jooq.Condition;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.jooq.DeleteConditionStep; import org.jooq.DeleteConditionStep;
import org.jooq.Field; import org.jooq.Field;
import org.jooq.InsertResultStep; import org.jooq.InsertResultStep;
import org.jooq.InsertReturningStep; import org.jooq.InsertReturningStep;
import org.jooq.Record4;
import org.jooq.Record5; import org.jooq.Record5;
import org.jooq.SelectConditionStep; import org.jooq.SelectConditionStep;
import org.jooq.SelectSeekStep1; import org.jooq.SelectSeekStep1;
@ -121,6 +123,36 @@ public class AdminRepository {
return list; return list;
} }
/**
* get all documents from the database that fit to condition
*
* @param condition the where condition, e.g. to filter for doctype
*
* @return all documents
*/
public List<DocumentBean> getAllDocumentsWith(Condition condition) {
SelectConditionStep<Record4<Integer, String, EnumDocument, EnumFiletype>> sql = jooq
// @formatter:off
.select(T_DOCUMENT.PK,
T_DOCUMENT.NAME,
T_DOCUMENT.DOCTYPE,
T_DOCUMENT.FILETYPE)
.from(T_DOCUMENT)
.where(condition);
// @formatter:on
LOGGER.debug(sql.toString());
List<DocumentBean> list = new ArrayList<>();
for (Record4<Integer, String, EnumDocument, EnumFiletype> r : sql.fetch()) {
DocumentBean bean = new DocumentBean();
bean.setPk(r.get(T_DOCUMENT.PK));
bean.setName(r.get(T_DOCUMENT.NAME));
bean.setDoctype(r.get(T_DOCUMENT.DOCTYPE));
bean.setFiletype(r.get(T_DOCUMENT.FILETYPE));
list.add(bean);
}
return list;
}
/** /**
* upsert document in t_document * upsert document in t_document
* *

View File

@ -1,5 +1,7 @@
package de.jottyfan.camporganizer.module.admin; package de.jottyfan.camporganizer.module.admin;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENT;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -11,6 +13,7 @@ import org.jooq.exception.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.db.jooq.enums.EnumDocument;
import de.jottyfan.camporganizer.module.mail.MailBean; import de.jottyfan.camporganizer.module.mail.MailBean;
import de.jottyfan.camporganizer.module.mail.MailRepository; import de.jottyfan.camporganizer.module.mail.MailRepository;
@ -103,4 +106,13 @@ public class AdminService {
public void deleteLocation(Integer id) { public void deleteLocation(Integer id) {
throw new DataAccessException("not yet implemented"); throw new DataAccessException("not yet implemented");
} }
/**
* get all documents that fit to the location definitions
*
* @return the location documents
*/
public List<DocumentBean> getLocationDocuments() {
return adminRepository.getAllDocumentsWith(T_DOCUMENT.DOCTYPE.eq(EnumDocument.location));
}
} }

View File

@ -2,6 +2,9 @@ package de.jottyfan.camporganizer.module.admin;
import java.io.Serializable; import java.io.Serializable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import de.jottyfan.camporganizer.db.jooq.tables.records.TLocationRecord; import de.jottyfan.camporganizer.db.jooq.tables.records.TLocationRecord;
/** /**
@ -13,8 +16,12 @@ public class LocationBean implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Integer pk; private Integer pk;
@NotBlank
private String name; private String name;
@NotNull
private Integer fkDocument; private Integer fkDocument;
@NotBlank
private String url; private String url;
public static LocationBean of(TLocationRecord r) { public static LocationBean of(TLocationRecord r) {

View File

@ -28,7 +28,23 @@
th:class="${'form-control ' + (#fields.hasErrors('name') ? 'inputerror' : '')}"> th:class="${'form-control ' + (#fields.hasErrors('name') ? 'inputerror' : '')}">
</div> </div>
</div> </div>
<!-- TODO: url and dropdown of documents --> <div class="row mb-2">
<label for="inputURL" class="col-sm-2 col-form-label">URL</label>
<div class="col-sm-10">
<span class="error" th:each="error : ${#fields.errors('url')}">[[${error}]]<br /></span> <input id="inputURL" type="text" th:field="*{url}"
th:class="${'form-control ' + (#fields.hasErrors('url') ? 'inputerror' : '')}">
</div>
</div>
<div class="row mb-2">
<label for="inputDoc" class="col-sm-2 col-form-label">Wegbeschreibung</label>
<div class="col-sm-10">
<span class="error" th:each="error : ${#fields.errors('fkDocument')}">[[${error}]]<br /></span> <select id="inputDoc" th:field="*{fkDocument}"
th:class="${'form-select ' + (#fields.hasErrors('fkDocument') ? 'inputerror' : '')}">
<option value="">--- bitte wählen ---</option>
<option th:each="d : ${documents}" th:value="${d.pk}" th:text="${d.name}"></option>
</select>
</div>
</div>
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-2"></div> <div class="col-sm-2"></div>
<div class="col-sm-10"> <div class="col-sm-10">