manipulate projects
This commit is contained in:
@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author henkej
|
* @author henkej
|
||||||
@ -93,6 +95,34 @@ public class DoneController {
|
|||||||
return toItem(bean, model);
|
return toItem(bean, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@GetMapping("/done/edit/project/{id}")
|
||||||
|
public String toProject(@PathVariable Integer id, Model model) {
|
||||||
|
TProjectRecord project = doneService.getProject(id);
|
||||||
|
model.addAttribute("projectBean", project);
|
||||||
|
return "done/project";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@RequestMapping(value = "/done/upsert/project", method = RequestMethod.POST)
|
||||||
|
public String doUpsert(Model model, @ModelAttribute TProjectRecord bean) {
|
||||||
|
Integer amount = doneService.doUpsertProject(bean);
|
||||||
|
return amount.equals(1) ? getList(new DoneModel(), model) : toProject(bean.getPk(), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@RequestMapping(value = "/done/add/project", method = RequestMethod.GET)
|
||||||
|
public String toAddProject(Model model) {
|
||||||
|
return toProject(null, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("timetrack_user")
|
||||||
|
@GetMapping(value = "/done/delete/project/{id}")
|
||||||
|
public String doDeleteProject(@PathVariable Integer id, Model model) {
|
||||||
|
Integer amount = doneService.doDeleteProject(id);
|
||||||
|
return amount.equals(1) ? getList(new DoneModel(), model) : toProject(id, model);
|
||||||
|
}
|
||||||
|
|
||||||
@RolesAllowed("timetrack_user")
|
@RolesAllowed("timetrack_user")
|
||||||
@RequestMapping(value = "/done/upsert", method = RequestMethod.POST)
|
@RequestMapping(value = "/done/upsert", method = RequestMethod.POST)
|
||||||
public String doUpsert(Model model, @ModelAttribute DoneBean bean) {
|
public String doUpsert(Model model, @ModelAttribute DoneBean bean) {
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
||||||
@ -33,4 +34,10 @@ public interface IDoneService {
|
|||||||
public Integer doUpsert(DoneBean bean, String username);
|
public Integer doUpsert(DoneBean bean, String username);
|
||||||
|
|
||||||
public Integer doDelete(Integer id);
|
public Integer doDelete(Integer id);
|
||||||
|
|
||||||
|
public TProjectRecord getProject(Integer id);
|
||||||
|
|
||||||
|
public Integer doUpsertProject(TProjectRecord bean);
|
||||||
|
|
||||||
|
public Integer doDeleteProject(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package de.jottyfan.timetrack.spring.done.impl;
|
package de.jottyfan.timetrack.spring.done.impl;
|
||||||
|
|
||||||
import static de.jottyfan.timetrack.db.done.Tables.T_BILLING;
|
|
||||||
import static de.jottyfan.timetrack.db.done.Tables.T_DONE;
|
import static de.jottyfan.timetrack.db.done.Tables.T_DONE;
|
||||||
import static de.jottyfan.timetrack.db.done.Tables.T_JOB;
|
import static de.jottyfan.timetrack.db.done.Tables.T_PROJECT;
|
||||||
import static de.jottyfan.timetrack.db.done.Tables.T_MODULE;
|
import static de.jottyfan.timetrack.db.done.Tables.V_BILLING;
|
||||||
|
import static de.jottyfan.timetrack.db.done.Tables.V_JOB;
|
||||||
|
import static de.jottyfan.timetrack.db.done.Tables.V_MODULE;
|
||||||
import static de.jottyfan.timetrack.db.done.Tables.V_PROJECT;
|
import static de.jottyfan.timetrack.db.done.Tables.V_PROJECT;
|
||||||
import static de.jottyfan.timetrack.db.profile.Tables.T_LOGIN;
|
import static de.jottyfan.timetrack.db.profile.Tables.T_LOGIN;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.jooq.DSLContext;
|
import org.jooq.DSLContext;
|
||||||
import org.jooq.DeleteConditionStep;
|
import org.jooq.DeleteConditionStep;
|
||||||
|
import org.jooq.InsertReturningStep;
|
||||||
import org.jooq.InsertValuesStep7;
|
import org.jooq.InsertValuesStep7;
|
||||||
import org.jooq.Record7;
|
import org.jooq.Record7;
|
||||||
import org.jooq.Result;
|
import org.jooq.Result;
|
||||||
@ -29,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
||||||
@ -103,7 +106,7 @@ public class DoneGateway {
|
|||||||
if (includeNull) {
|
if (includeNull) {
|
||||||
list.add(new VModuleRecord());
|
list.add(new VModuleRecord());
|
||||||
}
|
}
|
||||||
list.addAll(getJooq().selectFrom(T_MODULE).orderBy(T_MODULE.NAME).fetchInto(VModuleRecord.class));
|
list.addAll(getJooq().selectFrom(V_MODULE).orderBy(V_MODULE.NAME).fetchInto(VModuleRecord.class));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +127,7 @@ public class DoneGateway {
|
|||||||
if (includeNull) {
|
if (includeNull) {
|
||||||
list.add(new VJobRecord());
|
list.add(new VJobRecord());
|
||||||
}
|
}
|
||||||
list.addAll(getJooq().selectFrom(T_JOB).orderBy(T_JOB.NAME).fetchInto(VJobRecord.class));
|
list.addAll(getJooq().selectFrom(V_JOB).orderBy(V_JOB.NAME).fetchInto(VJobRecord.class));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +146,9 @@ public class DoneGateway {
|
|||||||
throws DataAccessException, ClassNotFoundException, SQLException {
|
throws DataAccessException, ClassNotFoundException, SQLException {
|
||||||
List<VBillingRecord> list = new ArrayList<>();
|
List<VBillingRecord> list = new ArrayList<>();
|
||||||
if (includeNull) {
|
if (includeNull) {
|
||||||
list.add(new VBillingRecord(null, null, "---", null, null));
|
list.add(new VBillingRecord());
|
||||||
}
|
}
|
||||||
list.addAll(getJooq().selectFrom(T_BILLING).orderBy(T_BILLING.NAME).fetchInto(VBillingRecord.class));
|
list.addAll(getJooq().selectFrom(V_BILLING).orderBy(V_BILLING.NAME).fetchInto(VBillingRecord.class));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,4 +365,48 @@ public class DoneGateway {
|
|||||||
LOGGER.debug(sql.toString());
|
LOGGER.debug(sql.toString());
|
||||||
return sql.execute();
|
return sql.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TProjectRecord getProject(Integer id) {
|
||||||
|
SelectConditionStep<TProjectRecord> sql = getJooq().selectFrom(T_PROJECT).where(T_PROJECT.PK.eq(id));
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.fetchOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer upsertProject(TProjectRecord bean) {
|
||||||
|
return bean.getPk() != null ? updateProject(bean) : insertProject(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer insertProject(TProjectRecord bean) {
|
||||||
|
InsertReturningStep<TProjectRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.insertInto(T_PROJECT,
|
||||||
|
T_PROJECT.NAME)
|
||||||
|
.values(bean.getName())
|
||||||
|
.onConflict(T_PROJECT.NAME)
|
||||||
|
.doNothing();
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer updateProject(TProjectRecord bean) {
|
||||||
|
UpdateConditionStep<TProjectRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.update(T_PROJECT)
|
||||||
|
.set(T_PROJECT.NAME, bean.getName())
|
||||||
|
.where(T_PROJECT.PK.eq(bean.getPk()));
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug(sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer deleteProject(Integer id) {
|
||||||
|
DeleteConditionStep<TProjectRecord> sql = getJooq()
|
||||||
|
// @formatter:off
|
||||||
|
.deleteFrom(T_PROJECT)
|
||||||
|
.where(T_PROJECT.PK.eq(id));
|
||||||
|
// @formatter:on
|
||||||
|
LOGGER.debug("{}", sql.toString());
|
||||||
|
return sql.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
||||||
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
||||||
@ -128,4 +129,34 @@ public class DoneService implements IDoneService {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TProjectRecord getProject(Integer id) {
|
||||||
|
try {
|
||||||
|
return id == null ? new TProjectRecord() : new DoneGateway(dsl).getProject(id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer doUpsertProject(TProjectRecord bean) {
|
||||||
|
try {
|
||||||
|
return new DoneGateway(dsl).upsertProject(bean);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer doDeleteProject(Integer id) {
|
||||||
|
try {
|
||||||
|
return new DoneGateway(dsl).deleteProject(id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,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="project : ${projectList}">
|
<tr th:each="project : ${projectList}">
|
||||||
<td><span th:text="${project.name}"></span></td>
|
<td><span th:text="${project.name}"></span></td>
|
||||||
<td><span th:text="${project.percentUsage}"></span></td>
|
<td><span th:text="${project.percentUsage}"></span></td>
|
||||||
|
<td><a th:href="@{/done/edit/project/{id}(id=${project.pk})}" th:title="${project.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/project}">neues Projekt</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div id="div_module" class="tab-pane fade tab-pane-table">
|
<div id="div_module" class="tab-pane fade tab-pane-table">
|
||||||
|
42
src/main/resources/templates/done/project.html
Normal file
42
src/main/resources/templates/done/project.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>Projekt aktualisieren</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ul layout:fragment="menu">
|
||||||
|
</ul>
|
||||||
|
<main layout:fragment="content">
|
||||||
|
<div class="container formpane">
|
||||||
|
<form th:action="@{/done/upsert/project}" th:object="${projectBean}" method="post">
|
||||||
|
<div class="row mb-3" th:if="${projectBean.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="${projectBean.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/project/{id}(id=${projectBean.pk})}">endgültig löschen</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user