Permalink
Browse files

GRAILS-8998 - test structured editors

  • Loading branch information...
1 parent 3c3e561 commit e711ee7d310473bfc3e9186fbef8625f221e63b1 @jeffbrown jeffbrown committed May 30, 2012
@@ -10,4 +10,6 @@ beans = {
widget(Widget) {
name = 'Good Name'
}
+
+ goalPropertyEditorRegistrar(structurededitor.GoalPropertyEditorRegistrar)
}
@@ -0,0 +1,103 @@
+package structurededitor
+
+import org.springframework.dao.DataIntegrityViolationException
+
+class GameController {
+
+ static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
+
+ def index() {
+ redirect(action: "list", params: params)
+ }
+
+ def list() {
+ params.max = Math.min(params.max ? params.int('max') : 10, 100)
+ [gameInstanceList: Game.list(params), gameInstanceTotal: Game.count()]
+ }
+
+ def create() {
+ [gameInstance: new Game(params)]
+ }
+
+ def save() {
+ def gameInstance = new Game(params)
+ if (!gameInstance.save(flush: true)) {
+ render(view: "create", model: [gameInstance: gameInstance])
+ return
+ }
+
+ flash.message = message(code: 'default.created.message', args: [message(code: 'game.label', default: 'Game'), gameInstance.id])
+ redirect(action: "show", id: gameInstance.id)
+ }
+
+ def show() {
+ def gameInstance = Game.get(params.id)
+ if (!gameInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ [gameInstance: gameInstance]
+ }
+
+ def edit() {
+ def gameInstance = Game.get(params.id)
+ if (!gameInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ [gameInstance: gameInstance]
+ }
+
+ def update() {
+ def gameInstance = Game.get(params.id)
+ if (!gameInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ if (params.version) {
+ def version = params.version.toLong()
+ if (gameInstance.version > version) {
+ gameInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
+ [message(code: 'game.label', default: 'Game')] as Object[],
+ "Another user has updated this Game while you were editing")
+ render(view: "edit", model: [gameInstance: gameInstance])
+ return
+ }
+ }
+
+ gameInstance.properties = params
+
+ if (!gameInstance.save(flush: true)) {
+ render(view: "edit", model: [gameInstance: gameInstance])
+ return
+ }
+
+ flash.message = message(code: 'default.updated.message', args: [message(code: 'game.label', default: 'Game'), gameInstance.id])
+ redirect(action: "show", id: gameInstance.id)
+ }
+
+ def delete() {
+ def gameInstance = Game.get(params.id)
+ if (!gameInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ try {
+ gameInstance.delete(flush: true)
+ flash.message = message(code: 'default.deleted.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "list")
+ }
+ catch (DataIntegrityViolationException e) {
+ flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'game.label', default: 'Game'), params.id])
+ redirect(action: "show", id: params.id)
+ }
+ }
+}
@@ -0,0 +1,23 @@
+package structurededitor
+
+class Game {
+
+ String name
+ Goal goal
+
+ static constraints = {
+ name(blank: false, unique: true, bindable: true)
+ goal(nullable: false, bindable: true)
+ }
+
+ public String toString() {
+ return "${name} ${goal.own}"
+ }
+
+ static mapping = {
+ goal type: GoalHibernateUserType, {
+ column name: "own_goals"
+ column name: "other_goals"
+ }
+ }
+}
@@ -0,0 +1,21 @@
+<%@ page import="structurededitor.Game" %>
+
+
+
+<div class="fieldcontain ${hasErrors(bean: gameInstance, field: 'name', 'error')} required">
+ <label for="name">
+ <g:message code="game.name.label" default="Name" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:textField name="name" required="" value="${gameInstance?.name}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: gameInstance, field: 'goal', 'error')} required">
+ <label for="goal">
+ <g:message code="game.goal.label" default="Goal" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:hiddenField name="goal" value="struct"/>
+ <g:textField name="goal_own" value="${gameInstance?.goal?.own}"/> : <g:textField name="goal_other" value="${gameInstance?.goal?.other}"/>
+</div>
+
@@ -0,0 +1,39 @@
+<%@ page import="structurededitor.Game" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'game.label', default: 'Game')}" />
+ <title><g:message code="default.create.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#create-game" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
+ <div class="nav" role="navigation">
+ <ul>
+ <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
+ <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
+ </ul>
+ </div>
+ <div id="create-game" class="content scaffold-create" role="main">
+ <h1><g:message code="default.create.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message" role="status">${flash.message}</div>
+ </g:if>
+ <g:hasErrors bean="${gameInstance}">
+ <ul class="errors" role="alert">
+ <g:eachError bean="${gameInstance}" var="error">
+ <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
+ </g:eachError>
+ </ul>
+ </g:hasErrors>
+ <g:form action="save" >
+ <fieldset class="form">
+ <g:render template="form"/>
+ </fieldset>
+ <fieldset class="buttons">
+ <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
+ </fieldset>
+ </g:form>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,43 @@
+<%@ page import="structurededitor.Game" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'game.label', default: 'Game')}" />
+ <title><g:message code="default.edit.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#edit-game" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
+ <div class="nav" role="navigation">
+ <ul>
+ <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
+ <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
+ <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
+ </ul>
+ </div>
+ <div id="edit-game" class="content scaffold-edit" role="main">
+ <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message" role="status">${flash.message}</div>
+ </g:if>
+ <g:hasErrors bean="${gameInstance}">
+ <ul class="errors" role="alert">
+ <g:eachError bean="${gameInstance}" var="error">
+ <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
+ </g:eachError>
+ </ul>
+ </g:hasErrors>
+ <g:form method="post" >
+ <g:hiddenField name="id" value="${gameInstance?.id}" />
+ <g:hiddenField name="version" value="${gameInstance?.version}" />
+ <fieldset class="form">
+ <g:render template="form"/>
+ </fieldset>
+ <fieldset class="buttons">
+ <g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />
+ <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" formnovalidate="" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
+ </fieldset>
+ </g:form>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,50 @@
+
+<%@ page import="structurededitor.Game" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'game.label', default: 'Game')}" />
+ <title><g:message code="default.list.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#list-game" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
+ <div class="nav" role="navigation">
+ <ul>
+ <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
+ <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
+ </ul>
+ </div>
+ <div id="list-game" class="content scaffold-list" role="main">
+ <h1><g:message code="default.list.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message" role="status">${flash.message}</div>
+ </g:if>
+ <table>
+ <thead>
+ <tr>
+
+ <g:sortableColumn property="name" title="${message(code: 'game.name.label', default: 'Name')}" />
+
+ <g:sortableColumn property="goal" title="${message(code: 'game.goal.label', default: 'Goal')}" />
+
+ </tr>
+ </thead>
+ <tbody>
+ <g:each in="${gameInstanceList}" status="i" var="gameInstance">
+ <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
+
+ <td><g:link action="show" id="${gameInstance.id}">${fieldValue(bean: gameInstance, field: "name")}</g:link></td>
+
+ <td>${fieldValue(bean: gameInstance, field: "goal")}</td>
+
+ </tr>
+ </g:each>
+ </tbody>
+ </table>
+ <div class="pagination">
+ <g:paginate total="${gameInstanceTotal}" />
+ </div>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,54 @@
+
+<%@ page import="structurededitor.Game" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'game.label', default: 'Game')}" />
+ <title><g:message code="default.show.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#show-game" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
+ <div class="nav" role="navigation">
+ <ul>
+ <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
+ <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
+ <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
+ </ul>
+ </div>
+ <div id="show-game" class="content scaffold-show" role="main">
+ <h1><g:message code="default.show.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message" role="status">${flash.message}</div>
+ </g:if>
+ <ol class="property-list game">
+
+ <g:if test="${gameInstance?.name}">
+ <li class="fieldcontain">
+ <span id="name-label" class="property-label"><g:message code="game.name.label" default="Name" /></span>
+
+ <span class="property-value" aria-labelledby="name-label"><g:fieldValue bean="${gameInstance}" field="name"/></span>
+
+ </li>
+ </g:if>
+
+ <g:if test="${gameInstance?.goal}">
+ <li class="fieldcontain">
+ <span id="goal-label" class="property-label"><g:message code="game.goal.label" default="Goal" /></span>
+
+ <span class="property-value" aria-labelledby="goal-label"><g:fieldValue bean="${gameInstance}" field="goal"/></span>
+
+ </li>
+ </g:if>
+
+ </ol>
+ <g:form>
+ <fieldset class="buttons">
+ <g:hiddenField name="id" value="${gameInstance?.id}" />
+ <g:link class="edit" action="edit" id="${gameInstance?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
+ <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
+ </fieldset>
+ </g:form>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,17 @@
+package structurededitor
+
+/**
+ * Represents goal balance
+ *
+ * @author Carsten Block
+ * @version 1.0 - 05.04.12
+ */
+class Goal implements Serializable {
+
+ Integer own
+ Integer other
+
+ public String toString() {
+ return "${own}:${other}"
+ }
+}
Oops, something went wrong.

0 comments on commit e711ee7

Please sign in to comment.