prepared editing locations
This commit is contained in:
@ -116,4 +116,38 @@ public class AdminController extends CommonController {
|
||||
model.addAttribute("locations", service.getLocations());
|
||||
return "/admin/location";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/add")
|
||||
public String prepareAddLocation(Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
model.addAttribute("bean", new LocationBean());
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/edit/{id}")
|
||||
public String prepareAddLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
model.addAttribute("bean", service.getLocation(id));
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
|
||||
@PostMapping("/admin/location/update")
|
||||
public String updateDocument(@Valid @ModelAttribute("bean") LocationBean bean,
|
||||
final BindingResult bindingResult, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
if (bindingResult.hasErrors()) {
|
||||
for (ObjectError error : bindingResult.getAllErrors())
|
||||
LOGGER.error("error {}: {}", error.getCode(), error.getDefaultMessage());
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
service.updateLocation(bean);
|
||||
return "redirect:/admin/location";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/delete/{id}")
|
||||
public String deleteLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
service.deleteLocation(id);
|
||||
return "redirect:/admin/location";
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import org.jooq.Field;
|
||||
import org.jooq.InsertResultStep;
|
||||
import org.jooq.InsertReturningStep;
|
||||
import org.jooq.Record5;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.SelectSeekStep1;
|
||||
import org.jooq.SelectWhereStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
@ -255,7 +256,19 @@ public class AdminRepository {
|
||||
for (TLocationRecord r : sql.fetch()) {
|
||||
list.add(LocationBean.of(r));
|
||||
}
|
||||
return null;
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the location from the database
|
||||
*
|
||||
* @param id the ID
|
||||
* @return the location bean or null
|
||||
*/
|
||||
public LocationBean getLocation(Integer id) {
|
||||
SelectConditionStep<TLocationRecord> sql = jooq.selectFrom(T_LOCATION).where(T_LOCATION.PK.eq(id));
|
||||
LOGGER.debug(sql.toString());
|
||||
return LocationBean.of(sql.fetchOne());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import javax.validation.Valid;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -84,4 +85,22 @@ public class AdminService {
|
||||
public List<LocationBean> getLocations() {
|
||||
return adminRepository.getLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the location of id
|
||||
*
|
||||
* @param id the id
|
||||
* @return the location or null
|
||||
*/
|
||||
public LocationBean getLocation(Integer id) {
|
||||
return adminRepository.getLocation(id);
|
||||
}
|
||||
|
||||
public void updateLocation(@Valid LocationBean bean) {
|
||||
throw new DataAccessException("not yet implemented");
|
||||
}
|
||||
|
||||
public void deleteLocation(Integer id) {
|
||||
throw new DataAccessException("not yet implemented");
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ public class LocationBean implements Serializable {
|
||||
private String url;
|
||||
|
||||
public static LocationBean of(TLocationRecord r) {
|
||||
if (r == null) {
|
||||
return null;
|
||||
}
|
||||
LocationBean bean = new LocationBean();
|
||||
bean.setPk(r.getPk());
|
||||
bean.setName(r.getName());
|
||||
|
53
src/main/resources/templates/admin/location_edit.html
Normal file
53
src/main/resources/templates/admin/location_edit.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
|
||||
<body>
|
||||
<th:block layout:fragment="header">
|
||||
<ul class="navbar-nav mb-2 mb-lg-0" sec:authorize="hasRole('admin')">
|
||||
<li class="nav-item"><a th:href="@{/rss/admin}" class="btn btn-seconary btn-icon-silent"><i class="fas fa-rss"></i></a></li>
|
||||
</ul>
|
||||
<ul class="navbar-nav mb-2 mb-lg-0">
|
||||
<li class="nav-item"><a th:href="@{/dashboard}" class="btn btn-secondary btn-icon-silent">Hauptseite</a></li>
|
||||
</ul>
|
||||
<ul class="navbar-nav mb-2 mb-lg-0" sec:authorize="hasRole('admin')">
|
||||
<li class="nav-item"><a th:href="@{/admin}" class="btn btn-secondary btn-icon-silent">Administration</a></li>
|
||||
</ul>
|
||||
<ul class="navbar-nav mb-2 mb-lg-0" sec:authorize="hasRole('admin')">
|
||||
<li class="nav-item"><a th:href="@{/admin/document}" class="btn btn-secondary btn-icon-silent">Freizeitheime</a></li>
|
||||
</ul>
|
||||
</th:block>
|
||||
<th:block layout:fragment="content">
|
||||
<div sec:authorize="hasRole('admin')">
|
||||
<form th:action="@{/admin/location/update}" th:object="${bean}" method="post" enctype="multipart/form-data">
|
||||
<div class="tablebox">
|
||||
<div class="container">
|
||||
<input type="hidden" th:field="*{pk}" />
|
||||
<div class="row mb-2">
|
||||
<label for="inputName" class="col-sm-2 col-form-label">Name</label>
|
||||
<div class="col-sm-10">
|
||||
<span class="error" th:each="error : ${#fields.errors('name')}">[[${error}]]<br /></span> <input id="inputName" type="text" th:field="*{name}"
|
||||
th:class="${'form-control ' + (#fields.hasErrors('name') ? 'inputerror' : '')}">
|
||||
</div>
|
||||
</div>
|
||||
<!-- TODO: url and dropdown of documents -->
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-2"></div>
|
||||
<div class="col-sm-10">
|
||||
<input type="submit" class="btn btn-success" value="Ok" />
|
||||
<a th:href="@{/admin/location}" class="btn btn-outline-secondary">Abbrechen</a>
|
||||
<div class="dropdown" style="display: inline">
|
||||
<button class="btn btn-outline-danger dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" th:href="@{/admin/location/delete/{id}(id=${bean.pk})}">Freizeitheim endgültig löschen</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</th:block>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user