Skip to content

Commit dde044c

Browse files
committed
add tournament group delete option
1 parent 2bee949 commit dde044c

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

grails-app/controllers/skatdb/TournamentController.groovy

+25-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TournamentController {
4848
def finishTournament() {
4949
setStatus(2)
5050
}
51-
51+
5252
def newRound() {
5353
Tournament tournament = Tournament.findById(params.id)
5454
if(tournament == null) {
@@ -86,6 +86,30 @@ class TournamentController {
8686
redirect(action: "show", id: params.id)
8787
}
8888

89+
def deleteRound() {
90+
TournamentRound round = TournamentRound.findById(params.id)
91+
if(round == null) {
92+
return response.sendError(404, "TournamentRound with id " + params.id + " not found.")
93+
}
94+
deleteTournamentRound(round)
95+
redirect(action: "show", id: round.tournament.id)
96+
}
97+
98+
/**
99+
* Deletes a whole round including all groups and all games played.
100+
*
101+
* @param round to delete
102+
*/
103+
private void deleteTournamentRound(TournamentRound round) {
104+
for(TournamentGroup group : round.groups) {
105+
for(Game game : group.games) {
106+
game.delete()
107+
}
108+
group.delete()
109+
}
110+
round.delete()
111+
}
112+
89113
/**
90114
* Create groups and add them to the round.
91115
*

grails-app/views/tournament/show.gsp

+8-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
<g:each in="${tournamentInstance.rounds}" var="round" status="r">
7777
<div class="panel panel-default">
7878
<div class="panel-heading">
79-
<h3 class="panel-title"><b>Runde ${r + 1}</b></h3>
79+
<h3 class="panel-title">
80+
<b>Runde ${r + 1}</b>
81+
<span class="pull-right">
82+
<a href="javascript:void(0)" onclick="confirm('Gruppe wirklich löschen?') ? document.location.href = '${createLink(controller: 'tournament', action: 'deleteRound', id: round?.id) }' : null">
83+
<span aria-hidden="true" class="glyphicon glyphicon-remove" style="color: gray"></span>
84+
</a>
85+
</span>
86+
</h3>
8087
</div>
8188
<div class="panel-body">
8289
<g:each in="${round.groups}" var="group" status="g">
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package skatdb
2+
3+
4+
5+
import grails.test.mixin.*
6+
import org.junit.*
7+
8+
/**
9+
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
10+
*/
11+
@TestFor(Tournament)
12+
class TournamentTests {
13+
14+
void testSomething() {
15+
fail "Implement me"
16+
}
17+
}

0 commit comments

Comments
 (0)