Skip to content
This repository
Browse code

refactored the new comment form

  • Loading branch information...
commit dc31688257ed069dc8646f296f094359b7eed59b 1 parent dca22ee
Jettro Coenradie authored November 29, 2009
56  grails-app/conf/BootStrap.groovy
@@ -2,33 +2,37 @@ import org.joda.time.DateTime
2 2
 
3 3
 class BootStrap {
4 4
     def init = {
5  
-//        servletContext ->
6  
-//          def statussus = ['OK', 'WARNING', 'PROBLEM', 'COLD']
7  
-//        statussus.each {
8  
-//            statusName ->
9  
-//            def newStatus = new Status(name: statusName)
10  
-//            newStatus.save()
11  
-//        }
12  
-//
13  
-//        def vlans = [['Middleware', 'middle_dev'], ['Backend', 'backend_dev'], ['Beheer', 'maint_dev'], ['Backup', 'backup_dev']]
14  
-//        vlans.each {
15  
-//            vlanFunction, vlanName ->
16  
-//            def newVlan = new Vlan(name: vlanName, function: vlanFunction)
17  
-//            newVlan.save()
18  
-//        }
19  
-//
20  
-//        def environments = ['Development', 'Test', 'Acceptation', 'Production']
21  
-//        environments.each {
22  
-//            name ->
23  
-//            def environment = new Environment(name: name, lastDeploy:new DateTime())
24  
-//            environment.save()
25  
-//        }
26  
-//
27  
-//        def okStatus = Status.findByName("OK")
28  
-//        def warningStatus = Status.findByName("WARNING")
29  
-//        def errorStatus = Status.findByName("PROBLEM")
30  
-//        def coldStatus = Status.findByName("COLD")
  5
+        servletContext ->
  6
+          def statussus = ['OK', 'WARNING', 'PROBLEM', 'COLD']
  7
+        statussus.each {
  8
+            statusName ->
  9
+            def newStatus = new Status(name: statusName)
  10
+            newStatus.save()
  11
+        }
31 12
 
  13
+        def vlans = [['Middleware', 'middle_dev'], ['Backend', 'backend_dev'], ['Beheer', 'maint_dev'], ['Backup', 'backup_dev']]
  14
+        vlans.each {
  15
+            vlanFunction, vlanName ->
  16
+            def newVlan = new Vlan(name: vlanName, function: vlanFunction)
  17
+            newVlan.save()
  18
+        }
  19
+
  20
+        def environments = ['Development', 'Test', 'Acceptation', 'Production']
  21
+        environments.each {
  22
+            name ->
  23
+            def environment = new Environment(name: name, lastDeploy:new DateTime())
  24
+            environment.save()
  25
+        }
  26
+
  27
+        def okStatus = Status.findByName("OK")
  28
+        def warningStatus = Status.findByName("WARNING")
  29
+        def errorStatus = Status.findByName("PROBLEM")
  30
+        def coldStatus = Status.findByName("COLD")
  31
+
  32
+        def backend1 = new Server(name:'backend 1',function:'appserver',status:okStatus,externalIp:'127.0.0.1')
  33
+
  34
+        def devEnvironment = Environment.findByName("Development")
  35
+        devEnvironment.addToServers(backend1)
32 36
     }
33 37
     def destroy = {
34 38
     }
10  grails-app/controllers/OverviewController.groovy
@@ -16,9 +16,13 @@ class OverviewController {
16 16
         render(template:"/shared/comment",model:[comments:allComments, server:currentServer])
17 17
     }
18 18
 
19  
-    def addComment = {
20  
-        commentService.createComment(params.serverId.toLong(),params.name,params.content)
21  
-        redirect(action:'index')
  19
+    def addComment = {Comment comment ->
  20
+        if (!comment.validate()) {
  21
+            render(view:'newComment',model:[comment:comment, server:comment.server])
  22
+            return
  23
+        }
  24
+        commentService.createComment(comment.server.id,comment.name,comment.content)
  25
+            redirect(action:'index')
22 26
     }
23 27
 
24 28
     def newComment = {
1  grails-app/services/CommentService.groovy
@@ -17,6 +17,7 @@ class CommentService {
17 17
         if (comment.save()) {
18 18
             return comment
19 19
         } else {
  20
+            log.info "Error while saving a comment"
20 21
             throw new CommentException (message: 'invalid comment being created', comment:comment)
21 22
         }
22 23
         
42  grails-app/views/layouts/main.gsp
... ...
@@ -1,23 +1,23 @@
1 1
 <html>
2  
-    <head>
3  
-        <title><g:layoutTitle default="Grails" /></title>
4  
-        <link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
5  
-        <link rel="shortcut icon" href="${resource(dir:'images',file:'favicon.ico')}" type="image/x-icon" />
6  
-        <g:layoutHead />
7  
-        <g:javascript library="application" />
8  
-        <g:javascript library="prototype" />
9  
-    </head>
10  
-    <body>
11  
-        <div id="spinner" class="spinner" style="display:none;">
12  
-            <img src="${resource(dir:'images',file:'spinner.gif')}" alt="Spinner" />
13  
-        </div>	
14  
-        <div class="logo"><img src="${resource(dir:'images',file:'serverpark_logo.png')}" alt="ServerPark" /></div>
15  
-        <g:if test="${flash.error}">
16  
-            <div class="flasherror">${flash.error}</div>
17  
-        </g:if>
18  
-        <g:if test="${flash.message}">
19  
-            <div class="flash">${flash.message}</div>    
20  
-        </g:if>
21  
-        <g:layoutBody />
22  
-    </body>	
  2
+<head>
  3
+  <title><g:layoutTitle default="Grails"/></title>
  4
+  <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}"/>
  5
+  <link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon"/>
  6
+  <g:layoutHead/>
  7
+  <g:javascript library="application"/>
  8
+  <g:javascript library="prototype"/>
  9
+</head>
  10
+<body>
  11
+<div id="spinner" class="spinner" style="display:none;">
  12
+  <img src="${resource(dir: 'images', file: 'spinner.gif')}" alt="Spinner"/>
  13
+</div>
  14
+<div class="logo"><img src="${resource(dir: 'images', file: 'serverpark_logo.png')}" alt="ServerPark"/></div>
  15
+<g:if test="${flash.error}">
  16
+  <div class="flasherror">${flash.error}</div>
  17
+</g:if>
  18
+<g:if test="${flash.message}">
  19
+  <div class="flash">${flash.message}</div>
  20
+</g:if>
  21
+<g:layoutBody/>
  22
+</body>
23 23
 </html>
11  grails-app/views/overview/newComment.gsp
@@ -10,10 +10,15 @@
10 10
     <span class="menuButton"><a class="home" href="${resource(dir: '')}">Home</a></span>
11 11
 </div>
12 12
     <span>New comment for ${server.toString()}</span>
  13
+    <g:hasErrors>
  14
+      <div class="errors">
  15
+          <g:renderErrors bean="${comment}" as="list"/>
  16
+      </div>
  17
+    </g:hasErrors>
13 18
     <g:form action="addComment" method="POST">
14  
-        <g:hiddenField name="serverId" value="${server.id}"/>
15  
-        Name : <g:textField name="name" value=""/><br/>
16  
-        Content : <g:textArea name="content" value=""/><br/>
  19
+        <g:hiddenField name="server.id" value="${server.id}"/>
  20
+        Name : <g:textField name="name" value="${comment?.name}"/><br/>
  21
+        Content : <g:textArea name="content" value="${comment?.content}"/><br/>
17 22
         <g:actionSubmit value="Add Comment"/>
18 23
     </g:form>
19 24
 </body>
12  grails-app/views/shared/_comment.gsp
... ...
@@ -1,13 +1,7 @@
1  
-<%--
2  
-  Created by IntelliJ IDEA.
3  
-  User: jettropro
4  
-  Date: Nov 5, 2009
5  
-  Time: 10:46:51 AM
6  
-  To change this template use File | Settings | File Templates.
7  
---%>
8  
-
  1
+%{-- Do something with pagination--}%
  2
+%{-- Use ajax to load and commit the form --}%
9 3
 <div class="comment">
10  
-    <span class="title">${server.name}</span><span class="action"><g:link controller="comment" action="create" params="['server.id':server.id]">create comment</g:link><g:link controller="overview" action="newComment" params="['serverid':server.id]">create form</g:link></span>
  4
+    <span class="title">${server.name}</span><span class="action"><g:link controller="overview" action="newComment" params="['serverid':server.id]">create comment</g:link></span>
11 5
     <g:each in="${comments}" status="i" var="comment">
12 6
         <div>
13 7
             <span class="author">${comment.name}</span>

0 notes on commit dc31688

Please sign in to comment.
Something went wrong with that request. Please try again.