added module
This commit is contained in:
@ -0,0 +1,14 @@
|
||||
package de.jottyfan.timetrack.spring.done.module;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
public interface IModuleService {
|
||||
public TModuleRecord getModule(Integer id);
|
||||
public Integer doUpsertModule(TModuleRecord bean);
|
||||
public Integer doDeleteModule(Integer id);
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package de.jottyfan.timetrack.spring.done.module;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
import de.jottyfan.timetrack.spring.done.DoneController;
|
||||
import de.jottyfan.timetrack.spring.done.DoneModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ModuleController {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ModuleController.class);
|
||||
|
||||
@Autowired
|
||||
private IModuleService moduleService;
|
||||
|
||||
@Autowired
|
||||
private DoneController doneController;
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping("/done/edit/module/{id}")
|
||||
public String toModule(@PathVariable Integer id, Model model) {
|
||||
TModuleRecord module = moduleService.getModule(id);
|
||||
model.addAttribute("moduleBean", module);
|
||||
return "done/module";
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/upsert/module", method = RequestMethod.POST)
|
||||
public String doUpsert(Model model, @ModelAttribute TModuleRecord bean) {
|
||||
Integer amount = moduleService.doUpsertModule(bean);
|
||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(bean.getPk(), model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/add/module", method = RequestMethod.GET)
|
||||
public String toAddModule(Model model) {
|
||||
return toModule(null, model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping(value = "/done/delete/module/{id}")
|
||||
public String doDeleteModule(@PathVariable Integer id, Model model) {
|
||||
Integer amount = moduleService.doDeleteModule(id);
|
||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(id, model);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package de.jottyfan.timetrack.spring.done.module.impl;
|
||||
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_MODULE;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertReturningStep;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class ModuleGateway {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ModuleGateway.class);
|
||||
private final DSLContext jooq;
|
||||
|
||||
public ModuleGateway(@Autowired DSLContext jooq) throws Exception {
|
||||
this.jooq = jooq;
|
||||
}
|
||||
|
||||
public DSLContext getJooq() {
|
||||
return this.jooq;
|
||||
}
|
||||
|
||||
public TModuleRecord getModule(Integer id) {
|
||||
SelectConditionStep<TModuleRecord> sql = getJooq().selectFrom(T_MODULE).where(T_MODULE.PK.eq(id));
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.fetchOne();
|
||||
}
|
||||
|
||||
public Integer upsert(TModuleRecord bean) {
|
||||
return bean.getPk() != null ? update(bean) : insert(bean);
|
||||
}
|
||||
|
||||
private Integer insert(TModuleRecord bean) {
|
||||
InsertReturningStep<TModuleRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.insertInto(T_MODULE,
|
||||
T_MODULE.NAME)
|
||||
.values(bean.getName())
|
||||
.onConflict(T_MODULE.NAME)
|
||||
.doNothing();
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
private Integer update(TModuleRecord bean) {
|
||||
UpdateConditionStep<TModuleRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.update(T_MODULE)
|
||||
.set(T_MODULE.NAME, bean.getName())
|
||||
.where(T_MODULE.PK.eq(bean.getPk()));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
public Integer delete(Integer id) {
|
||||
DeleteConditionStep<TModuleRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.deleteFrom(T_MODULE)
|
||||
.where(T_MODULE.PK.eq(id));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package de.jottyfan.timetrack.spring.done.module.impl;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
import de.jottyfan.timetrack.spring.done.module.IModuleService;
|
||||
import de.jottyfan.timetrack.spring.done.project.IProjectService;
|
||||
|
||||
@Service
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public class ModuleService implements IModuleService {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ModuleService.class);
|
||||
|
||||
@Autowired
|
||||
private DSLContext dsl;
|
||||
|
||||
|
||||
@Override
|
||||
public TModuleRecord getModule(Integer id) {
|
||||
try {
|
||||
return id == null ? new TModuleRecord() : new ModuleGateway(dsl).getModule(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doUpsertModule(TModuleRecord bean) {
|
||||
try {
|
||||
return new ModuleGateway(dsl).upsert(bean);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doDeleteModule(Integer id) {
|
||||
try {
|
||||
return new ModuleGateway(dsl).delete(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
@ -106,14 +106,23 @@
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Benutzt in %</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="module : ${moduleList}">
|
||||
<td><span th:text="${module.name}"></span></td>
|
||||
<td><span th:text="${module.percentUsage}"></span></td>
|
||||
<td><a th:href="@{/done/edit/module/{id}(id=${module.pk})}" th:title="${module.pk}"><i class="fa fa-edit"></i></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<a class="nav-link btn btn-success btn-white-text" th:href="@{/done/add/module}">neues Modul</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div id="div_job" class="tab-pane fade tab-pane-table">
|
||||
|
42
src/main/resources/templates/done/module.html
Normal file
42
src/main/resources/templates/done/module.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:sec="http://www.thymeleaf.org/extras/spring-security" layout:decorate="~{layout/main.html}">
|
||||
<head>
|
||||
<title>Modul aktualisieren</title>
|
||||
</head>
|
||||
<body>
|
||||
<ul layout:fragment="menu">
|
||||
</ul>
|
||||
<main layout:fragment="content">
|
||||
<div class="container formpane">
|
||||
<form th:action="@{/done/upsert/module}" th:object="${moduleBean}" method="post">
|
||||
<div class="row mb-3" th:if="${moduleBean.pk} != null">
|
||||
<label for="inputPk" class="col-sm-2 col-form-label">Inhalt von Eintrag</label>
|
||||
<div class="col-sm-10">
|
||||
<input id="inputPk" type="text" th:field="*{pk}" class="form-control" readonly="readonly" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label for="outputDay" class="col-sm-2 col-form-label">Name</label>
|
||||
<div class="col-sm-10">
|
||||
<input id="inputName" type="text" th:field="*{name}" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3" style="margin-top: 8px">
|
||||
<div class="col-sm-2">Änderung</div>
|
||||
<div class="col-sm-10">
|
||||
<button id="okbtn" type="submit" class="btn btn-success">speichern</button>
|
||||
<a class="btn btn-secondary" th:href="@{/done/list}">abbrechen</a>
|
||||
<div class="dropdown float-right" th:if="${moduleBean.pk != null}" sec:authorize="hasRole('timetrack_user')">
|
||||
<button class="btn btn-danger dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Eintrag löschen</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" th:href="@{/done/delete/module/{id}(id=${moduleBean.pk})}">endgültig löschen</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user