added job manipulation
This commit is contained in:
@ -0,0 +1,14 @@
|
|||||||
|
package de.jottyfan.timetrack.spring.done.job;
|
||||||
|
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author henkej
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IJobService {
|
||||||
|
public TJobRecord get(Integer id);
|
||||||
|
public Integer doUpsert(TJobRecord bean);
|
||||||
|
public Integer doDelete(Integer id);
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package de.jottyfan.timetrack.spring.done.job;
|
||||||
|
|
||||||
|
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.TJobRecord;
|
||||||
|
import de.jottyfan.timetrack.spring.done.DoneController;
|
||||||
|
import de.jottyfan.timetrack.spring.done.DoneModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author henkej
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class JobController {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(JobController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IJobService jobService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DoneController doneController;
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@GetMapping("/done/edit/job/{id}")
|
||||||
|
public String toJob(@PathVariable Integer id, Model model) {
|
||||||
|
TJobRecord job = jobService.get(id);
|
||||||
|
model.addAttribute("jobBean", job);
|
||||||
|
return "done/job";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@RequestMapping(value = "/done/upsert/job", method = RequestMethod.POST)
|
||||||
|
public String doUpsert(Model model, @ModelAttribute TJobRecord bean) {
|
||||||
|
Integer amount = jobService.doUpsert(bean);
|
||||||
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toJob(bean.getPk(), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@RequestMapping(value = "/done/add/job", method = RequestMethod.GET)
|
||||||
|
public String toAddJob(Model model) {
|
||||||
|
return toJob(null, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@GetMapping(value = "/done/delete/job/{id}")
|
||||||
|
public String doDeleteJob(@PathVariable Integer id, Model model) {
|
||||||
|
Integer amount = jobService.doDelete(id);
|
||||||
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toJob(id, model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package de.jottyfan.timetrack.spring.done.job.impl;
|
||||||
|
|
||||||
|
import static de.jottyfan.timetrack.db.done.Tables.T_JOB;
|
||||||
|
|
||||||
|
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.TJobRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class JobGateway {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(JobGateway.class);
|
||||||
|
private final DSLContext jooq;
|
||||||
|
|
||||||
|
public JobGateway(@Autowired DSLContext jooq) throws Exception {
|
||||||
|
this.jooq = jooq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DSLContext getJooq() {
|
||||||
|
return this.jooq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TJobRecord get(Integer id) {
|
||||||
|
SelectConditionStep<TJobRecord> sql = getJooq().selectFrom(T_JOB).where(T_JOB.PK.eq(id));
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.fetchOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer upsert(TJobRecord bean) {
|
||||||
|
return bean.getPk() != null ? update(bean) : insert(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer insert(TJobRecord bean) {
|
||||||
|
InsertReturningStep<TJobRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.insertInto(T_JOB,
|
||||||
|
T_JOB.NAME)
|
||||||
|
.values(bean.getName())
|
||||||
|
.onConflict(T_JOB.NAME)
|
||||||
|
.doNothing();
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer update(TJobRecord bean) {
|
||||||
|
UpdateConditionStep<TJobRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.update(T_JOB)
|
||||||
|
.set(T_JOB.NAME, bean.getName())
|
||||||
|
.where(T_JOB.PK.eq(bean.getPk()));
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer delete(Integer id) {
|
||||||
|
DeleteConditionStep<TJobRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.deleteFrom(T_JOB)
|
||||||
|
.where(T_JOB.PK.eq(id));
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package de.jottyfan.timetrack.spring.done.job.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.TJobRecord;
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||||
|
import de.jottyfan.timetrack.spring.done.job.IJobService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(transactionManager = "transactionManager")
|
||||||
|
public class JobService implements IJobService {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(JobService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DSLContext dsl;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TJobRecord get(Integer id) {
|
||||||
|
try {
|
||||||
|
return id == null ? new TJobRecord() : new JobGateway(dsl).get(id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer doUpsert(TJobRecord bean) {
|
||||||
|
try {
|
||||||
|
return new JobGateway(dsl).upsert(bean);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer doDelete(Integer id) {
|
||||||
|
try {
|
||||||
|
return new JobGateway(dsl).delete(id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface IModuleService {
|
public interface IModuleService {
|
||||||
public TModuleRecord getModule(Integer id);
|
public TModuleRecord get(Integer id);
|
||||||
public Integer doUpsertModule(TModuleRecord bean);
|
public Integer doUpsert(TModuleRecord bean);
|
||||||
public Integer doDeleteModule(Integer id);
|
public Integer doDelete(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class ModuleController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@GetMapping("/done/edit/module/{id}")
|
@GetMapping("/done/edit/module/{id}")
|
||||||
public String toModule(@PathVariable Integer id, Model model) {
|
public String toModule(@PathVariable Integer id, Model model) {
|
||||||
TModuleRecord module = moduleService.getModule(id);
|
TModuleRecord module = moduleService.get(id);
|
||||||
model.addAttribute("moduleBean", module);
|
model.addAttribute("moduleBean", module);
|
||||||
return "done/module";
|
return "done/module";
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ public class ModuleController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@RequestMapping(value = "/done/upsert/module", method = RequestMethod.POST)
|
@RequestMapping(value = "/done/upsert/module", method = RequestMethod.POST)
|
||||||
public String doUpsert(Model model, @ModelAttribute TModuleRecord bean) {
|
public String doUpsert(Model model, @ModelAttribute TModuleRecord bean) {
|
||||||
Integer amount = moduleService.doUpsertModule(bean);
|
Integer amount = moduleService.doUpsert(bean);
|
||||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(bean.getPk(), model);
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(bean.getPk(), model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class ModuleController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@GetMapping(value = "/done/delete/module/{id}")
|
@GetMapping(value = "/done/delete/module/{id}")
|
||||||
public String doDeleteModule(@PathVariable Integer id, Model model) {
|
public String doDeleteModule(@PathVariable Integer id, Model model) {
|
||||||
Integer amount = moduleService.doDeleteModule(id);
|
Integer amount = moduleService.doDelete(id);
|
||||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(id, model);
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toModule(id, model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ModuleService implements IModuleService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TModuleRecord getModule(Integer id) {
|
public TModuleRecord get(Integer id) {
|
||||||
try {
|
try {
|
||||||
return id == null ? new TModuleRecord() : new ModuleGateway(dsl).getModule(id);
|
return id == null ? new TModuleRecord() : new ModuleGateway(dsl).getModule(id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -32,7 +32,7 @@ public class ModuleService implements IModuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer doUpsertModule(TModuleRecord bean) {
|
public Integer doUpsert(TModuleRecord bean) {
|
||||||
try {
|
try {
|
||||||
return new ModuleGateway(dsl).upsert(bean);
|
return new ModuleGateway(dsl).upsert(bean);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -42,7 +42,7 @@ public class ModuleService implements IModuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer doDeleteModule(Integer id) {
|
public Integer doDelete(Integer id) {
|
||||||
try {
|
try {
|
||||||
return new ModuleGateway(dsl).delete(id);
|
return new ModuleGateway(dsl).delete(id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -8,7 +8,7 @@ import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface IProjectService {
|
public interface IProjectService {
|
||||||
public TProjectRecord getProject(Integer id);
|
public TProjectRecord get(Integer id);
|
||||||
public Integer doUpsertProject(TProjectRecord bean);
|
public Integer doUpsert(TProjectRecord bean);
|
||||||
public Integer doDeleteProject(Integer id);
|
public Integer doDelete(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class ProjectController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@GetMapping("/done/edit/project/{id}")
|
@GetMapping("/done/edit/project/{id}")
|
||||||
public String toProject(@PathVariable Integer id, Model model) {
|
public String toProject(@PathVariable Integer id, Model model) {
|
||||||
TProjectRecord project = projectService.getProject(id);
|
TProjectRecord project = projectService.get(id);
|
||||||
model.addAttribute("projectBean", project);
|
model.addAttribute("projectBean", project);
|
||||||
return "done/project";
|
return "done/project";
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public class ProjectController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@RequestMapping(value = "/done/upsert/project", method = RequestMethod.POST)
|
@RequestMapping(value = "/done/upsert/project", method = RequestMethod.POST)
|
||||||
public String doUpsert(Model model, @ModelAttribute TProjectRecord bean) {
|
public String doUpsert(Model model, @ModelAttribute TProjectRecord bean) {
|
||||||
Integer amount = projectService.doUpsertProject(bean);
|
Integer amount = projectService.doUpsert(bean);
|
||||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(bean.getPk(), model);
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(bean.getPk(), model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class ProjectController {
|
|||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@GetMapping(value = "/done/delete/project/{id}")
|
@GetMapping(value = "/done/delete/project/{id}")
|
||||||
public String doDeleteProject(@PathVariable Integer id, Model model) {
|
public String doDeleteProject(@PathVariable Integer id, Model model) {
|
||||||
Integer amount = projectService.doDeleteProject(id);
|
Integer amount = projectService.doDelete(id);
|
||||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(id, model);
|
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(id, model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class ProjectService implements IProjectService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TProjectRecord getProject(Integer id) {
|
public TProjectRecord get(Integer id) {
|
||||||
try {
|
try {
|
||||||
return id == null ? new TProjectRecord() : new ProjectGateway(dsl).getProject(id);
|
return id == null ? new TProjectRecord() : new ProjectGateway(dsl).getProject(id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -30,7 +30,7 @@ public class ProjectService implements IProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer doUpsertProject(TProjectRecord bean) {
|
public Integer doUpsert(TProjectRecord bean) {
|
||||||
try {
|
try {
|
||||||
return new ProjectGateway(dsl).upsert(bean);
|
return new ProjectGateway(dsl).upsert(bean);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -40,7 +40,7 @@ public class ProjectService implements IProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer doDeleteProject(Integer id) {
|
public Integer doDelete(Integer id) {
|
||||||
try {
|
try {
|
||||||
return new ProjectGateway(dsl).delete(id);
|
return new ProjectGateway(dsl).delete(id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
42
src/main/resources/templates/done/job.html
Normal file
42
src/main/resources/templates/done/job.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>Aufgabe aktualisieren</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ul layout:fragment="menu">
|
||||||
|
</ul>
|
||||||
|
<main layout:fragment="content">
|
||||||
|
<div class="container formpane">
|
||||||
|
<form th:action="@{/done/upsert/job}" th:object="${jobBean}" method="post">
|
||||||
|
<div class="row mb-3" th:if="${jobBean.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="${jobBean.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/job/{id}(id=${jobBean.pk})}">endgültig löschen</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -131,14 +131,23 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Benutzt in %</th>
|
<th>Benutzt in %</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="job : ${jobList}">
|
<tr th:each="job : ${jobList}">
|
||||||
<td><span th:text="${job.name}"></span></td>
|
<td><span th:text="${job.name}"></span></td>
|
||||||
<td><span th:text="${job.percentUsage}"></span></td>
|
<td><span th:text="${job.percentUsage}"></span></td>
|
||||||
|
<td><a th:href="@{/done/edit/job/{id}(id=${job.pk})}" th:title="${job.pk}"><i class="fa fa-edit"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<a class="nav-link btn btn-success btn-white-text" th:href="@{/done/add/job}">neue Aufgabe</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div id="div_billing" class="tab-pane fade tab-pane-table">
|
<div id="div_billing" class="tab-pane fade tab-pane-table">
|
||||||
|
Reference in New Issue
Block a user