Permalink
Browse files

make it easier to create new releases with specialised form

  • Loading branch information...
1 parent 188b9e5 commit 8dd6e6f3ae7b0583d8699da6233280dbc039c694 @graemerocher graemerocher committed Dec 19, 2012
@@ -13,14 +13,41 @@ class DownloadAdminController {
[downloadInstanceList: Download.list(params), downloadInstanceTotal: Download.count()]
}
+ def saveRelease(ReleaseInfoCommand cmd) {
+ if(cmd.hasErrors()) {
+ render view:"create", model:[releaseInfo:cmd]
+ }
+ else {
+ Download.withTransaction { status ->
+ def d = new Download(softwareName:"Grails", softwareVersion: cmd.softwareVersion, betaRelease:cmd.betaRelease)
+
+ def zip = new DownloadFile(title:"Binary Zip", fileType: DownloadFile.FileType.BINARY)
+ zip.addToMirrors(new Mirror(file:zip, name:"Amazon", urlString:cmd.binaryZip))
+ d.addToFiles(zip)
+
+ def doc = new DownloadFile(title:"Documentation", fileType: DownloadFile.FileType.DOCUMENTATION)
+ doc.addToMirrors(new Mirror(file:doc, name:"Amazon", urlString:cmd.documentationZip))
+ d.addToFiles(doc)
+
+
+ d.save(flush:true)
+ if(cmd.latestRelease) {
+ downloadService.markAsLatest(d)
+ }
+ flash.message = "Release $d created"
+ redirect action:'list'
+
+ }
+
+ }
+ }
def show() {
def downloadInstance = Download.findById(params.id)
[downloadInstance: downloadInstance]
}
def create() {
- def downloadInstance = new Download( releaseDate: new org.joda.time.DateTime() )
- [downloadInstance: downloadInstance]
+ [releaseInfo: new ReleaseInfoCommand()]
}
def edit() {
@@ -36,3 +63,19 @@ class DownloadAdminController {
}
}
+class ReleaseInfoCommand {
+ String binaryZip
+ String documentationZip
+ String softwareVersion
+ Boolean latestRelease
+ Boolean betaRelease = false
+
+ static constraints = {
+ binaryZip nullable:false, blank:false
+ documentationZip nullable:false, blank:false
+ softwareVersion nullable:false, blank:false
+ latestRelease nullable:false
+
+
+ }
+}
@@ -1,29 +1,30 @@
-<div class="control-group ${hasErrors(bean: downloadInstance, field: 'softwareName', 'error')}">
- <label class="control-label" for="softwareName">Software Name</label>
+
+<div class="control-group ${hasErrors(bean: releaseInfo, field: 'softwareVersion', 'error')}">
+ <label class="control-label" for="softwareVersion">Version</label>
<div class="controls">
- <g:textField name="softwareName" value="${downloadInstance.softwareName}" class="input-xxlarge" />
+ <g:textField name="softwareVersion" value="${releaseInfo.softwareVersion}" class="input-xxlarge" />
</div>
</div>
-<div class="control-group ${hasErrors(bean: downloadInstance, field: 'softwareVersion', 'error')}">
- <label class="control-label" for="softwareVersion">URL</label>
+<div class="control-group ${hasErrors(bean: releaseInfo, field: 'binaryZip', 'error')}">
+ <label class="control-label" for="binaryZip">Binary Zip URL</label>
<div class="controls">
- <g:textField name="softwareVersion" value="${downloadInstance.softwareVersion}" class="input-xxlarge" />
+ <g:textField name="binaryZip" value="${releaseInfo.binaryZip}" class="input-xxlarge" />
</div>
</div>
-<div class="control-group ${hasErrors(bean: downloadInstance, field: 'releaseDate', 'error')}">
- <label class="control-label" for="releaseDate">Release Date</label>
+<div class="control-group ${hasErrors(bean: releaseInfo, field: 'documentationZip', 'error')}">
+ <label class="control-label" for="documentationZip">Documentation Zip URL</label>
<div class="controls">
- <joda:dateTimePicker name="releaseDate" value="${downloadInstance.releaseDate}"/>
+ <g:textField name="documentationZip" value="${releaseInfo.documentationZip}" class="input-xxlarge" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="latestRelease">Latest Release?</label>
<div class="controls">
<label class="checkbox">
- <g:checkBox name="latestRelease" value="${downloadInstance.latestRelease}"/>
+ <g:checkBox name="latestRelease" value="${releaseInfo.latestRelease}"/>
If this is checked, this download will appear as the current version of Grails
</label>
</div>
@@ -33,7 +34,7 @@
<label class="control-label" for="betaRelease">Beta Release?</label>
<div class="controls">
<label class="checkbox">
- <g:checkBox name="betaRelease" value="${downloadInstance.betaRelease}"/>
+ <g:checkBox name="betaRelease" value="${releaseInfo.betaRelease}"/>
If this is checked, this download will appear as a 'Beta' in the downloads page
</label>
</div>
@@ -6,7 +6,7 @@
<body>
<h1 class="page-header">
- Create Download
+ Create Grails Release
<span class="pull-right">
<g:link class="btn" action="list">Download List</g:link>
</span>
@@ -22,10 +22,10 @@
</div>
</g:hasErrors>
-<g:form action="save" class="form-horizontal">
+<g:form action="saveRelease" class="form-horizontal">
<fieldset>
- <g:render template="form" bean="${downloadInstance}" />
+ <g:render template="form" bean="${releaseInfo}" />
<div class="form-actions">
<g:submitButton name="create" class="btn btn-primary" value="Create" />

0 comments on commit 8dd6e6f

Please sign in to comment.