Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomasz Stachewicz
committed
Dec 19, 2008
1 parent
b22e3b9
commit 64f5ef6
Showing
18 changed files
with
8,919 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class PostsController { | ||
|
||
def beforeInterceptor = [action:this.&checkUser,except: ['index','list','show']] | ||
|
||
def checkUser() { | ||
if(!session.user) { | ||
// i.e. user not logged in | ||
redirect(controller:'users',action:'login') | ||
return false | ||
} | ||
} | ||
|
||
def index = { redirect(action:list,params:params) } | ||
|
||
// the delete, save and update actions only accept POST requests | ||
def allowedMethods = [delete:'POST', save:'POST', update:'POST'] | ||
|
||
def list = { | ||
if(!params.max) params.max = 10 | ||
[ postInstanceList: Post.list( params ) ] | ||
} | ||
|
||
def show = { | ||
def postInstance = Post.get( params.id ) | ||
|
||
if(!postInstance) { | ||
flash.message = "Post not found with id ${params.id}" | ||
redirect(action:list) | ||
} | ||
else { return [ postInstance : postInstance ] } | ||
} | ||
|
||
def delete = { | ||
def postInstance = Post.get( params.id ) | ||
if(postInstance) { | ||
postInstance.delete() | ||
flash.message = "Post ${params.id} deleted" | ||
redirect(action:list) | ||
} | ||
else { | ||
flash.message = "Post not found with id ${params.id}" | ||
redirect(action:list) | ||
} | ||
} | ||
|
||
def edit = { | ||
def postInstance = Post.get( params.id ) | ||
|
||
if(!postInstance) { | ||
flash.message = "Post not found with id ${params.id}" | ||
redirect(action:list) | ||
} | ||
else { | ||
return [ postInstance : postInstance ] | ||
} | ||
} | ||
|
||
def update = { | ||
def postInstance = Post.get( params.id ) | ||
if(postInstance) { | ||
postInstance.properties = params | ||
if(!postInstance.hasErrors() && postInstance.save()) { | ||
flash.message = "Post ${params.id} updated" | ||
redirect(action:show,id:postInstance.id) | ||
} | ||
else { | ||
render(view:'edit',model:[postInstance:postInstance]) | ||
} | ||
} | ||
else { | ||
flash.message = "Post not found with id ${params.id}" | ||
redirect(action:edit,id:params.id) | ||
} | ||
} | ||
|
||
def create = { | ||
def postInstance = new Post() | ||
postInstance.properties = params | ||
return ['postInstance':postInstance] | ||
} | ||
|
||
def save = { | ||
def postInstance = new Post(params) | ||
postInstance.user = session.user | ||
postInstance.createdAt = new Date() | ||
if(!postInstance.hasErrors() && postInstance.save()) { | ||
flash.message = "Post ${postInstance.id} created" | ||
redirect(controller:"participations",action:show,id:postInstance.participation.id) | ||
} | ||
else { | ||
render(view:'create',model:[postInstance:postInstance]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ class Participation { | |
|
||
static belongsTo = Exercise | ||
static optionals = ["endMark"] | ||
static hasMany = [posts:Post] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Post { | ||
Date createdAt | ||
String content | ||
User user | ||
Participation participation | ||
|
||
static belongsTo = [Participation,User] | ||
|
||
static mapping = { content type:"text" } | ||
|
||
static constraints = { | ||
content(minLength:20, blank:false) | ||
} | ||
|
||
int compareTo(Object o) { | ||
log.debug "Post position with content ''${content}'' asked to compare my createdAt ${createdAt} with object: ${o} which has createdAt ${o.createdAt}" | ||
this.createdAt.compareTo(((Post)o).createdAt) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<meta name="layout" content="main" /> | ||
<title>Create Post</title> | ||
</head> | ||
<body> | ||
<div class="nav"> | ||
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span> | ||
<span class="menuButton"><g:link class="list" action="list">Post List</g:link></span> | ||
</div> | ||
<div class="body"> | ||
<h1>Create Post</h1> | ||
<g:if test="${flash.message}"> | ||
<div class="message">${flash.message}</div> | ||
</g:if> | ||
<g:hasErrors bean="${postInstance}"> | ||
<div class="errors"> | ||
<g:renderErrors bean="${postInstance}" as="list" /> | ||
</div> | ||
</g:hasErrors> | ||
<g:form action="save" method="post" > | ||
<div class="dialog"> | ||
<table> | ||
<tbody> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="content">Content:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'content','errors')}"> | ||
<input type="text" id="content" name="content" value="${fieldValue(bean:postInstance,field:'content')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="createdAt">Created At:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'createdAt','errors')}"> | ||
<g:datePicker name="createdAt" value="${postInstance?.createdAt}" ></g:datePicker> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="participation">Participation:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'participation','errors')}"> | ||
<g:select optionKey="id" from="${Participation.list()}" name="participation.id" value="${postInstance?.participation?.id}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="user">User:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'user','errors')}"> | ||
<g:select optionKey="id" from="${User.list()}" name="user.id" value="${postInstance?.user?.id}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
<div class="buttons"> | ||
<span class="button"><input class="save" type="submit" value="Create" /></span> | ||
</div> | ||
</g:form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<meta name="layout" content="main" /> | ||
<title>Edit Post</title> | ||
</head> | ||
<body> | ||
<div class="nav"> | ||
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span> | ||
<span class="menuButton"><g:link class="list" action="list">Post List</g:link></span> | ||
<span class="menuButton"><g:link class="create" action="create">New Post</g:link></span> | ||
</div> | ||
<div class="body"> | ||
<h1>Edit Post</h1> | ||
<g:if test="${flash.message}"> | ||
<div class="message">${flash.message}</div> | ||
</g:if> | ||
<g:hasErrors bean="${postInstance}"> | ||
<div class="errors"> | ||
<g:renderErrors bean="${postInstance}" as="list" /> | ||
</div> | ||
</g:hasErrors> | ||
<g:form method="post" > | ||
<input type="hidden" name="id" value="${postInstance?.id}" /> | ||
<div class="dialog"> | ||
<table> | ||
<tbody> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="content">Content:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'content','errors')}"> | ||
<input type="text" id="content" name="content" value="${fieldValue(bean:postInstance,field:'content')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="createdAt">Created At:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'createdAt','errors')}"> | ||
<g:datePicker name="createdAt" value="${postInstance?.createdAt}" ></g:datePicker> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="participation">Participation:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'participation','errors')}"> | ||
<g:select optionKey="id" from="${Participation.list()}" name="participation.id" value="${postInstance?.participation?.id}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="user">User:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'user','errors')}"> | ||
<g:select optionKey="id" from="${User.list()}" name="user.id" value="${postInstance?.user?.id}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
<div class="buttons"> | ||
<span class="button"><g:actionSubmit class="save" value="Update" /></span> | ||
<span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span> | ||
</div> | ||
</g:form> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.