Permalink
Browse files

added front-end for story managment

  • Loading branch information...
1 parent ba7e10b commit 598fe039a068807652e3f620fee3036f32adec7d @henyojess committed Jan 16, 2012
@@ -0,0 +1,106 @@
+package timelog
+
+import org.springframework.dao.DataIntegrityViolationException
+
+class StoryController {
+
+ static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
+ def springSecurityService
+
+ def index() {
+ redirect(action: "list", params: params)
+ }
+
+ def list() {
+ params.max = Math.min(params.max ? params.int('max') : 10, 100)
+ [storyInstanceList: Story.list(params), storyInstanceTotal: Story.count()]
+ }
+
+ def create() {
+ [storyInstance: new Story(params)]
+ }
+
+ def save() {
+ def storyInstance = new Story(params)
+ storyInstance.createdBy = springSecurityService.getPrincipal().username
+ if (!storyInstance.save(flush: true)) {
+ render(view: "create", model: [storyInstance: storyInstance])
+ return
+ }
+
+ flash.message = message(code: 'default.created.message', args: [message(code: 'story.label', default: 'Story'), storyInstance.id])
+ redirect(action: "show", id: storyInstance.id)
+ }
+
+ def show() {
+ def storyInstance = Story.get(params.id)
+ if (!storyInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ [storyInstance: storyInstance]
+ }
+
+ def edit() {
+ def storyInstance = Story.get(params.id)
+ if (!storyInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ [storyInstance: storyInstance]
+ }
+
+ def update() {
+ def storyInstance = Story.get(params.id)
+ if (!storyInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ if (params.version) {
+ def version = params.version.toLong()
+ if (storyInstance.version > version) {
+ storyInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
+ [message(code: 'story.label', default: 'Story')] as Object[],
+ "Another user has updated this Story while you were editing")
+ render(view: "edit", model: [storyInstance: storyInstance])
+ return
+ }
+ }
+
+ storyInstance.properties = params
+ storyInstance.updatedBy = springSecurityService.getPrincipal().username
+
+ if (!storyInstance.save(flush: true)) {
+ render(view: "edit", model: [storyInstance: storyInstance])
+ return
+ }
+
+ flash.message = message(code: 'default.updated.message', args: [message(code: 'story.label', default: 'Story'), storyInstance.id])
+ redirect(action: "show", id: storyInstance.id)
+ }
+
+ def delete() {
+ def storyInstance = Story.get(params.id)
+ if (!storyInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "list")
+ return
+ }
+
+ try {
+ storyInstance.delete(flush: true)
+ flash.message = message(code: 'default.deleted.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "list")
+ }
+ catch (DataIntegrityViolationException e) {
+ flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'story.label', default: 'Story'), params.id])
+ redirect(action: "show", id: params.id)
+ }
+ }
+}
@@ -0,0 +1,44 @@
+<%@ page import="timelog.Story" %>
+
+<div class="fieldcontain ${hasErrors(bean: storyInstance, field: 'project', 'error')} required">
+ <label for="project">
+ <g:message code="story.project.label" default="Project" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:select id="project" name="project.id" from="${timelog.Project.list()}" optionKey="id" optionValue="name" required="" value="${storyInstance?.project?.id}" class="many-to-one"/>
+</div>
+
+
+<div class="fieldcontain ${hasErrors(bean: storyInstance, field: 'description', 'error')} required">
+ <label for="description">
+ <g:message code="story.description.label" default="Description" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:textField name="description" required="" value="${storyInstance?.description}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: storyInstance, field: 'releaseTarget', 'error')} required">
+ <label for="releaseTarget">
+ <g:message code="story.releaseTarget.label" default="Release Target" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:textField name="releaseTarget" required="" value="${storyInstance?.releaseTarget}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: storyInstance, field: 'status', 'error')} required">
+ <label for="status">
+ <g:message code="story.status.label" default="Status" />
+ <span class="required-indicator">*</span>
+ </label>
+ <g:textField name="status" required="" value="${storyInstance?.status}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: storyInstance, field: 'active', 'error')} ">
+ <label for="active">
+ <g:message code="story.active.label" default="Active" />
+
+ </label>
+ <g:checkBox name="active" value="${storyInstance?.active}" />
+</div>
+
+
@@ -0,0 +1,39 @@
+<%@ page import="timelog.Story" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'story.label', default: 'Story')}" />
+ <title><g:message code="default.create.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#create-story" 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-story" 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="${storyInstance}">
+ <ul class="errors" role="alert">
+ <g:eachError bean="${storyInstance}" 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="timelog.Story" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'story.label', default: 'Story')}" />
+ <title><g:message code="default.edit.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#edit-story" 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-story" 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="${storyInstance}">
+ <ul class="errors" role="alert">
+ <g:eachError bean="${storyInstance}" 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="${storyInstance?.id}" />
+ <g:hiddenField name="version" value="${storyInstance?.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,62 @@
+
+<%@ page import="timelog.Story" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="main">
+ <g:set var="entityName" value="${message(code: 'story.label', default: 'Story')}" />
+ <title><g:message code="default.list.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <a href="#list-story" 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-story" 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="project" title="${message(code: 'story.project.label', default: 'Project')}" />
+
+ <g:sortableColumn property="description" title="${message(code: 'story.description.label', default: 'Description')}" />
+
+ <g:sortableColumn property="releaseTarget" title="${message(code: 'story.releaseTarget.label', default: 'Release Target')}" />
+
+ <g:sortableColumn property="status" title="${message(code: 'story.status.label', default: 'Status')}" />
+
+ <g:sortableColumn property="active" title="${message(code: 'story.active.label', default: 'Active')}" />
+
+ </tr>
+ </thead>
+ <tbody>
+ <g:each in="${storyInstanceList}" status="i" var="storyInstance">
+ <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
+
+ <td>${fieldValue(bean: storyInstance.project, field: "name")}</td>
+
+ <td><g:link action="show" id="${storyInstance.id}">${fieldValue(bean: storyInstance, field: "description")}</g:link></td>
+
+ <td>${fieldValue(bean: storyInstance, field: "releaseTarget")}</td>
+
+ <td>${fieldValue(bean: storyInstance, field: "status")}</td>
+
+ <td><g:formatBoolean boolean="${storyInstance.active}" /></td>
+
+ </tr>
+ </g:each>
+ </tbody>
+ </table>
+ <div class="pagination">
+ <g:paginate total="${storyInstanceTotal}" />
+ </div>
+ </div>
+ </body>
+</html>
Oops, something went wrong. Retry.

0 comments on commit 598fe03

Please sign in to comment.