Skip to content

Commit

Permalink
piatek 15:30 - koniec wielu zmian
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Stachewicz committed Dec 19, 2008
1 parent b22e3b9 commit 64f5ef6
Show file tree
Hide file tree
Showing 18 changed files with 8,919 additions and 16 deletions.
5 changes: 3 additions & 2 deletions grails-app/controllers/ParticipationsController.groovy
Expand Up @@ -22,12 +22,13 @@ class ParticipationsController {

def show = {
def participationInstance = Participation.get( params.id )

def postsList = Post.findAll("from Post as p where p.participation=? order by createdAt ASC", [participationInstance])

if(!participationInstance) {
flash.message = "Participation not found with id ${params.id}"
redirect(action:list)
}
else { return [ participationInstance : participationInstance ] }
else { return [ participationInstance : participationInstance, postsList : postsList ] }
}

def delete = {
Expand Down
94 changes: 94 additions & 0 deletions grails-app/controllers/PostsController.groovy
@@ -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])
}
}
}
1 change: 1 addition & 0 deletions grails-app/domain/Participation.groovy
Expand Up @@ -5,4 +5,5 @@ class Participation {

static belongsTo = Exercise
static optionals = ["endMark"]
static hasMany = [posts:Post]
}
19 changes: 19 additions & 0 deletions grails-app/domain/Post.groovy
@@ -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)
}
}
2 changes: 1 addition & 1 deletion grails-app/views/exercises/show.gsp
Expand Up @@ -60,7 +60,7 @@
</div>
<div class="buttons">
<span class="button"><g:link class="edit" action="edit" id="${exerciseInstance?.id}">Edytuj</g:link></span>
<span class="button"><g:link class="delete" action="delete" id="${menuInstance?.id}" onclick="return confirm('Czy jesteś pewny?');">Usuń</g:link></span>
<span class="button"><g:link class="delete" action="delete" id="${participationInstance?.id}" onclick="return confirm('Czy jesteś pewny?');">Usuń</g:link></span>
</div>
</div>
</body>
Expand Down
50 changes: 43 additions & 7 deletions grails-app/views/participations/show.gsp
Expand Up @@ -27,14 +27,14 @@
</tr>

<tr class="prop">
<td valign="top" class="name">End Mark:</td>
<td valign="top" class="name">Ocena Końcowa:</td>

<td valign="top" class="value">${fieldValue(bean:participationInstance, field:'endMark')}</td>

</tr>

<tr class="prop">
<td valign="top" class="name">Start Date Time:</td>
<td valign="top" class="name">Rozpoczęte:</td>

<td valign="top" class="value">${fieldValue(bean:participationInstance, field:'startDateTime')}</td>

Expand All @@ -44,12 +44,48 @@
</table>
</div>
<div class="buttons">
<g:form>
<input type="hidden" name="id" value="${participationInstance?.id}" />
<span class="button"><g:actionSubmit class="edit" value="Edit" /></span>
<span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>
</g:form>
<span class="button"><g:link class="edit" action="edit" id="${participationInstance?.id}">Edytuj</g:link></span>
<span class="button"><g:link class="delete" action="delete" id="${participationInstance?.id}" onclick="return confirm('Czy jesteś pewny?');">Usuń</g:link></span>
</div>

<h2>Wiadomości:</h2>
<ul>
<g:each in="${postsList?}" status="i" var="post">
<li>${fieldValue(bean:post, field:'content')} (${fieldValue(bean:post, field:'createdAt')})</li>
</g:each>
</ul>


<h2>Dodaj wiadomość</h2>
<g:hasErrors bean="${postInstance}">
<div class="errors">
<g:renderErrors bean="${postInstance}" as="list" />
</div>
</g:hasErrors>
<g:form controller="posts" action="save" method="post" >
<input type="hidden" id="participation_id" name="participation.id" value="${fieldValue(bean:participationInstance,field:'id')}"/>
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="content">Treść:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:postInstance,field:'content','errors')}">
<textarea id="content" name="content">${fieldValue(bean:postInstance,field:'content')}</textarea>
</td>
</tr>

</tbody>
</table>
</div>
<div class="buttons">
<span class="button"><input class="save" type="submit" value="Dodaj wiadomość" /></span>
</div>
</g:form>
</div>


</div>
</body>
</html>
74 changes: 74 additions & 0 deletions grails-app/views/posts/create.gsp
@@ -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>
77 changes: 77 additions & 0 deletions grails-app/views/posts/edit.gsp
@@ -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>

0 comments on commit 64f5ef6

Please sign in to comment.