Skip to content

Commit 170ff7f

Browse files
edit, new, delete und unlock
1 parent 3afc04f commit 170ff7f

File tree

6 files changed

+207
-11
lines changed

6 files changed

+207
-11
lines changed

src/main/java/org/woehlke/beachbox/service/VinylService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public interface VinylService {
1616
Vinyl findById(long id);
1717

1818
Vinyl save(Vinyl vinyl);
19+
20+
void deleteById(long id);
1921
}

src/main/java/org/woehlke/beachbox/service/VinylServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ public Vinyl findById(long id) {
4040
public Vinyl save(Vinyl vinyl) {
4141
return vinylRepository.saveAndFlush(vinyl);
4242
}
43+
44+
@Override
45+
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
46+
public void deleteById(long id) {
47+
vinylRepository.delete(id);
48+
}
4349
}

src/main/java/org/woehlke/beachbox/web/SessionBean.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class SessionBean implements Serializable {
1818
private String sort;
1919
private String sortDir;
2020
private int pageSize;
21+
private boolean bearbeiten = false;
2122

2223
public String getSearchString() {
2324
return searchString;
@@ -75,6 +76,14 @@ public void setPageSize(int pageSize) {
7576
this.pageSize = pageSize;
7677
}
7778

79+
public boolean isBearbeiten() {
80+
return bearbeiten;
81+
}
82+
83+
public void setBearbeiten(boolean bearbeiten) {
84+
this.bearbeiten = bearbeiten;
85+
}
86+
7887
public boolean isEmpty() {
7988
boolean retVal = false;
8089
if(searchString == null || searchString.isEmpty()){

src/main/java/org/woehlke/beachbox/web/VinylController.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,60 @@ public String editPost(@PathVariable long id, @Valid Vinyl vinyl,Model model){
121121
}
122122
return "redirect:/"+pageInfo;
123123
}
124+
125+
@RequestMapping(value = "/new", method = RequestMethod.GET)
126+
public String newGet(Model model){
127+
Vinyl vinyl = new Vinyl();
128+
model.addAttribute("vinyl",vinyl);
129+
model.addAttribute("rubrik", Rubrik.values());
130+
model.addAttribute("tontraeger", Tontraeger.values());
131+
return "new";
132+
}
133+
134+
@RequestMapping(value = "/new", method = RequestMethod.POST)
135+
public String newPost(@Valid Vinyl vinyl,Model model){
136+
vinyl = vinylService.save(vinyl);
137+
model.addAttribute("vinyl",vinyl);
138+
String pageInfo = "";
139+
if(model.containsAttribute("searchItem")) {
140+
SessionBean searchItem = (SessionBean) model.asMap().get("searchItem");
141+
pageInfo +=
142+
"?page.page="+searchItem.getCurrentIndex()+
143+
"&page.size="+searchItem.getPageSize()+
144+
"&page.sort="+searchItem.getSort()+
145+
"&page.sort.dir="+searchItem.getSortDir();
146+
}
147+
return "redirect:/"+pageInfo;
148+
}
149+
150+
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
151+
public String deleteGet(@PathVariable long id, Model model){
152+
vinylService.deleteById(id);
153+
String pageInfo = "";
154+
if(model.containsAttribute("searchItem")) {
155+
SessionBean searchItem = (SessionBean) model.asMap().get("searchItem");
156+
pageInfo +=
157+
"?page.page="+searchItem.getCurrentIndex()+
158+
"&page.size="+searchItem.getPageSize()+
159+
"&page.sort="+searchItem.getSort()+
160+
"&page.sort.dir="+searchItem.getSortDir();
161+
}
162+
return "redirect:/"+pageInfo;
163+
}
164+
165+
@RequestMapping(value = "/unlockEdit", method = RequestMethod.GET)
166+
public String getAll(Model model){
167+
SessionBean searchItem = (SessionBean) model.asMap().get("searchItem");
168+
searchItem.setBearbeiten(true);
169+
model.addAttribute("searchItem",searchItem);
170+
String pageInfo = "";
171+
if(model.containsAttribute("searchItem")) {
172+
pageInfo +=
173+
"?page.page="+searchItem.getCurrentIndex()+
174+
"&page.size="+searchItem.getPageSize()+
175+
"&page.sort="+searchItem.getSort()+
176+
"&page.sort.dir="+searchItem.getSortDir();
177+
}
178+
return "redirect:/"+pageInfo;
179+
}
124180
}

src/main/webapp/WEB-INF/views/all.jsp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<%@ include file="/WEB-INF/views/includes/taglibs.jsp"%>
23
<!DOCTYPE html>
34
<html lang="de">
@@ -70,24 +71,32 @@
7071
</ul>
7172
</div>
7273

74+
<c:url var="neuUrl" value="/new" />
75+
76+
<div>
7377
<table class="table table-striped table-hover">
7478
<tr>
7579
<c:url var="startUrl" value="/?page.page=1&page.size=${page.size}"/>
76-
<th><a href="${startUrl}&page.sort=id&page.sort.dir=asc">id</a></th>
77-
<th><a href="${startUrl}&page.sort=rubrik&page.sort.dir=asc">rubrik</th>
78-
<th><a href="${startUrl}&page.sort=tontraeger&page.sort.dir=asc">tontraeger</th>
79-
<th><a href="${startUrl}&page.sort=interpret&page.sort.dir=asc">interpret</th>
80-
<th><a href="${startUrl}&page.sort=song&page.sort.dir=asc">song</th>
81-
<th><a href="${startUrl}&page.sort=name&page.sort.dir=asc">name</th>
82-
<th><a href="${startUrl}&page.sort=seite&page.sort.dir=asc">seite</th>
83-
<th><a href="${startUrl}&page.sort=jahr&page.sort.dir=asc">jahr</th>
84-
<th><a href="${startUrl}&page.sort=genre&page.sort.dir=asc">genre</th>
85-
<th><a href="${startUrl}&page.sort=label&page.sort.dir=asc">label</th>
86-
<th><a href="${startUrl}&page.sort=bemerkung&page.sort.dir=asc">bemerkung</th>
80+
<th><a href="${startUrl}&page.sort=id&page.sort.dir=asc">Id</a></th>
81+
<th><a href="${startUrl}&page.sort=rubrik&page.sort.dir=asc">Rubrik</th>
82+
<th><a href="${startUrl}&page.sort=tontraeger&page.sort.dir=asc">Tontraeger</th>
83+
<th><a href="${startUrl}&page.sort=interpret&page.sort.dir=asc">Interpret</th>
84+
<th><a href="${startUrl}&page.sort=song&page.sort.dir=asc">Song</th>
85+
<th><a href="${startUrl}&page.sort=name&page.sort.dir=asc">Name</th>
86+
<th><a href="${startUrl}&page.sort=seite&page.sort.dir=asc">Seite</th>
87+
<th><a href="${startUrl}&page.sort=jahr&page.sort.dir=asc">Jahr</th>
88+
<th><a href="${startUrl}&page.sort=genre&page.sort.dir=asc">Genre</th>
89+
<th><a href="${startUrl}&page.sort=label&page.sort.dir=asc">Label</th>
90+
<th><a href="${startUrl}&page.sort=bemerkung&page.sort.dir=asc">Bemerkung</th>
91+
<c:if test="${searchItem.bearbeiten}">
92+
<th>&auml;ndern</th>
93+
<th>l&ouml;schen</th>
94+
</c:if>
8795
</tr>
8896
<c:forEach items="${page.content}" var="v">
8997
<tr>
9098
<c:url var="editUrl" value="/edit"/>
99+
<c:url var="deleteUrl" value="/delete"/>
91100
<td><a href="${editUrl}/${v.id}" title="id">${v.id}</a></td>
92101
<td>${v.rubrik}</td>
93102
<td>${v.tontraeger}</td>
@@ -99,9 +108,20 @@
99108
<td>${v.genre}</td>
100109
<td>${v.label}</td>
101110
<td>${v.bemerkung}</td>
111+
<c:if test="${searchItem.bearbeiten}">
112+
<td><a href="${editUrl}/${v.id}" title="id"><span class="glyphicon glyphicon-edit" /></a></td>
113+
<td><a href="${deleteUrl}/${v.id}" title="id"><span class="glyphicon glyphicon-trash" /></a></td>
114+
</c:if>
102115
</tr>
103116
</c:forEach>
104117
</table>
118+
<c:if test="${searchItem.bearbeiten}">
119+
<span class="glyphicon glyphicon-plus-sign" ></span> <a href="${neuUrl}">Neuer Eintrag</a>
120+
</c:if>
121+
<c:if test="${not searchItem.bearbeiten}">
122+
<c:url var="unlockEditUrl" value="/unlockEdit" />
123+
<span class="glyphicon glyphicon-circle-arrow-right" ></span> <a href="${unlockEditUrl}">Bearbeiten</a>
124+
</c:if>
105125
</div>
106126
</body>
107127
</html>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<%@ include file="/WEB-INF/views/includes/taglibs.jsp"%>
2+
<!DOCTYPE html>
3+
<html lang="de">
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<title>BeachBox</title>
7+
<!-- Bootstrap -->
8+
<link href="webjars/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
9+
<!-- Optional theme -->
10+
<link rel="stylesheet" href="webjars/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
11+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
12+
<script type="text/javascript" src="webjars/jquery/2.1.0-2/jquery.js"></script>
13+
<!-- Include all compiled plugins (below), or include individual files as needed -->
14+
<script type="text/javascript" src="webjars/bootstrap/3.1.1/js/bootstrap.min.js"></script>
15+
</head>
16+
<body>
17+
<div class="container">
18+
<h1>BeachBox</h1>
19+
<form:form id="formId" commandName="vinyl" method="post"
20+
class="form-horizontal">
21+
<div class="input-group">
22+
<form:label path="rubrik" class="control-label">Rubrik</form:label>
23+
<div class="controls">
24+
<form:select path="rubrik">
25+
<form:options items="${rubrik}"/>
26+
</form:select>
27+
</div>
28+
<form:errors path="rubrik" class="alert alert-danger"/>
29+
</div>
30+
<div class="input-group">
31+
<form:label path="tontraeger" class="control-label">Tontraeger</form:label>
32+
<div class="controls">
33+
<form:select path="tontraeger">
34+
<form:options items="${tontraeger}" />
35+
</form:select>
36+
</div>
37+
<form:errors path="tontraeger" class="alert alert-danger"/>
38+
</div>
39+
40+
<div class="input-group">
41+
<form:label path="interpret" class="control-label">Interpret</form:label>
42+
<div class="controls">
43+
<form:input path="interpret" class="form-control" />
44+
</div>
45+
<form:errors path="interpret" class="alert alert-danger"/>
46+
</div>
47+
<div class="input-group">
48+
<form:label path="song" class="control-label">Song</form:label>
49+
<div class="controls">
50+
<form:input path="song" class="form-control" />
51+
</div>
52+
<form:errors path="song" class="alert alert-danger"/>
53+
</div>
54+
<div class="input-group">
55+
<form:label path="name" class="control-label">Name</form:label>
56+
<div class="controls">
57+
<form:input path="name" class="form-control" />
58+
</div>
59+
<form:errors path="name" class="alert alert-danger"/>
60+
</div>
61+
<div class="input-group">
62+
<form:label path="seite" class="control-label">Seite</form:label>
63+
<div class="controls">
64+
<form:input path="seite" class="form-control" />
65+
</div>
66+
<form:errors path="seite" class="alert alert-danger"/>
67+
</div>
68+
<div class="input-group">
69+
<form:label path="jahr" class="control-label">Jahr</form:label>
70+
<div class="controls">
71+
<form:input path="jahr" class="form-control" />
72+
</div>
73+
<form:errors path="jahr" class="alert alert-danger"/>
74+
</div>
75+
<div class="input-group">
76+
<form:label path="genre" class="control-label">Genre</form:label>
77+
<div class="controls">
78+
<form:input path="genre" class="form-control" />
79+
</div>
80+
<form:errors path="genre" class="alert alert-danger"/>
81+
</div>
82+
<div class="input-group">
83+
<form:label path="label" class="control-label">Label</form:label>
84+
<div class="controls">
85+
<form:input path="label" class="form-control" />
86+
</div>
87+
<form:errors path="label" class="alert alert-danger"/>
88+
</div>
89+
<div class="input-group">
90+
<form:label path="bemerkung" class="control-label">Bemerkung</form:label>
91+
<div class="controls">
92+
<form:input path="bemerkung" class="form-control" />
93+
</div>
94+
<form:errors path="bemerkung" class="alert alert-danger"/>
95+
</div>
96+
<div class="controls">
97+
<form:hidden path="id"/>
98+
<input id="createNewVinyl" type="submit" value="Speichern" class="btn btn-primary" />
99+
</div>
100+
</form:form>
101+
</div>
102+
</body>
103+
</html>

0 commit comments

Comments
 (0)