Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fields almost working

embedded properties don't bind in Angular
  • Loading branch information...
commit ca63c417f9bc786be6dfddd9e346a612b37bdefe 1 parent 15ad005
Rob Fletcher authored
View
24 scripts/_NgGenerate.groovy
@@ -65,6 +65,30 @@ class AngularTemplateGenerator extends DefaultGrailsTemplateGenerator {
super(classLoader)
}
+ def renderEditor = { property, prefix ->
+ def domainClass = property.domainClass
+ def cp
+ if (pluginManager?.hasGrailsPlugin('hibernate')) {
+ cp = domainClass.constrainedProperties[property.name]
+ }
+
+ if (!renderEditorTemplate) {
+ // create template once for performance
+ def templateText = getTemplateText('renderEditor.template')
+ renderEditorTemplate = engine.createTemplate(templateText)
+ }
+
+ def binding = [
+ pluginManager: pluginManager,
+ property: property,
+ domainClass: domainClass,
+ cp: cp,
+ domainInstance: getPropertyName(domainClass),
+ prefix: prefix
+ ]
+ renderEditorTemplate.make(binding).toString()
+ }
+
@Override
void generateViews(GrailsDomainClass domainClass, String destdir) {
Assert.hasText destdir, 'Argument [destdir] not specified'
View
2  src/templates/scaffolding/create.html
@@ -40,7 +40,7 @@
<div class="control-group" data-ng-class="{error: errors.${prefix}${p.name}}">
<label class="control-label" for="${prefix}${p.name}">${p.naturalName}</label>
<div class="controls">
- ${renderEditor(p)}
+ ${renderEditor(p, prefix)}
<span class="help-inline" data-ng-show="errors.${prefix}${p.name}">{{errors.${prefix}${p.name}}}</span>
</div>
</div>
View
2  src/templates/scaffolding/edit.html
@@ -42,7 +42,7 @@
<div class="control-group" data-ng-class="{error: errors.${prefix}${p.name}}">
<label class="control-label" for="${prefix}${p.name}">${p.naturalName}</label>
<div class="controls">
- ${renderEditor(p)}
+ ${renderEditor(p, prefix)}
<span class="help-inline" data-ng-show="errors.${prefix}${p.name}">{{errors.${prefix}${p.name}}}</span>
</div>
</div>
View
40 src/templates/scaffolding/renderEditor.template
@@ -1,8 +1,10 @@
<%
+ def name = prefix ? "${prefix}${property.name}" : property.name
+
switch (property.type) {
case Boolean:
case boolean:
- out << renderBooleanEditor(domainClass, property)
+ out << renderBooleanEditor(domainClass, property, name)
break
case Number:
case byte:
@@ -11,40 +13,40 @@
case long:
case float:
case double:
- out << renderNumberEditor(domainClass, property)
+ out << renderNumberEditor(domainClass, property, name)
break
case String:
- out << renderStringEditor(domainClass, property)
+ out << renderStringEditor(domainClass, property, name)
break
}
- private String renderBooleanEditor(domainClass, property) {
+ private String renderBooleanEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input type="checkbox"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
sb << '>'
sb as String
}
- private String renderNumberEditor(domainClass, property) {
+ private String renderNumberEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input'
if (cp.range) {
sb << ' type="range"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
sb << ' min="' << cp.range.from << '"'
sb << ' max="' << cp.range.to << '"'
- sb << '<output for="' << property.name << '">{{' << property.name << '}}</output>'
+ sb << '<output for="' << name << '">{{' << name << '}}</output>'
} else {
if (property.type in [float, double, Float, Double, BigDecimal]) sb << ' type="text"'
else sb << ' type="number"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
if (cp.min != null) sb << ' min="' << cp.min << '"'
if (cp.max != null) sb << ' max="' << cp.max << '"'
if (isRequired()) sb << ' required'
@@ -53,12 +55,12 @@
sb as String
}
- private String renderStringEditor(domainClass, property) {
+ private String renderStringEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input type="text"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
if (cp.matches) sb << ' pattern="' << cp.matches << '"'
if (isRequired()) sb << ' required'
sb << '>'
View
1  test/apps/grails-ng/grails-app/controllers/grails/plugin/angular/test/AlbumController.groovy
@@ -47,6 +47,7 @@ class AlbumController {
}
def update() {
+ println request.JSON
def albumInstance = Album.get(params.id)
if (!albumInstance) {
notFound params.id
View
2  test/apps/grails-ng/src/templates/scaffolding/create.html
@@ -40,7 +40,7 @@
<div class="control-group" data-ng-class="{error: errors.${prefix}${p.name}}">
<label class="control-label" for="${prefix}${p.name}">${p.naturalName}</label>
<div class="controls">
- ${renderEditor(p)}
+ ${renderEditor(p, prefix)}
<span class="help-inline" data-ng-show="errors.${prefix}${p.name}">{{errors.${prefix}${p.name}}}</span>
</div>
</div>
View
2  test/apps/grails-ng/src/templates/scaffolding/edit.html
@@ -42,7 +42,7 @@
<div class="control-group" data-ng-class="{error: errors.${prefix}${p.name}}">
<label class="control-label" for="${prefix}${p.name}">${p.naturalName}</label>
<div class="controls">
- ${renderEditor(p)}
+ ${renderEditor(p, prefix)}
<span class="help-inline" data-ng-show="errors.${prefix}${p.name}">{{errors.${prefix}${p.name}}}</span>
</div>
</div>
View
40 test/apps/grails-ng/src/templates/scaffolding/renderEditor.template
@@ -1,8 +1,10 @@
<%
+ def name = prefix ? "${prefix}${property.name}" : property.name
+
switch (property.type) {
case Boolean:
case boolean:
- out << renderBooleanEditor(domainClass, property)
+ out << renderBooleanEditor(domainClass, property, name)
break
case Number:
case byte:
@@ -11,40 +13,40 @@
case long:
case float:
case double:
- out << renderNumberEditor(domainClass, property)
+ out << renderNumberEditor(domainClass, property, name)
break
case String:
- out << renderStringEditor(domainClass, property)
+ out << renderStringEditor(domainClass, property, name)
break
}
- private String renderBooleanEditor(domainClass, property) {
+ private String renderBooleanEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input type="checkbox"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
sb << '>'
sb as String
}
- private String renderNumberEditor(domainClass, property) {
+ private String renderNumberEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input'
if (cp.range) {
sb << ' type="range"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
sb << ' min="' << cp.range.from << '"'
sb << ' max="' << cp.range.to << '"'
- sb << '<output for="' << property.name << '">{{' << property.name << '}}</output>'
+ sb << '<output for="' << name << '">{{' << name << '}}</output>'
} else {
if (property.type in [float, double, Float, Double, BigDecimal]) sb << ' type="text"'
else sb << ' type="number"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
if (cp.min != null) sb << ' min="' << cp.min << '"'
if (cp.max != null) sb << ' max="' << cp.max << '"'
if (isRequired()) sb << ' required'
@@ -53,12 +55,12 @@
sb as String
}
- private String renderStringEditor(domainClass, property) {
+ private String renderStringEditor(domainClass, property, name) {
def sb = new StringBuilder()
sb << '<input type="text"'
- sb << ' id="' << property.name << '"'
- sb << ' name="' << property.name << '"'
- sb << ' data-ng-model="item.' << property.name << '"'
+ sb << ' id="' << name << '"'
+ sb << ' name="' << name << '"'
+ sb << ' data-ng-model="item.' << name << '"'
if (cp.matches) sb << ' pattern="' << cp.matches << '"'
if (isRequired()) sb << ' required'
sb << '>'
View
1  test/apps/grails-ng/test/casper/specs/alerts-spec.coffee
@@ -39,7 +39,6 @@ casper.then ->
@click 'button.btn-danger'
, ->
@test.fail 'should have gone to the show page'
- @captureSelector 'form.png', 'body'
casper.then ->
@waitForSelector 'tbody tr', ->
View
4 test/apps/grails-ng/web-app/ng-templates/album/create.html
@@ -44,7 +44,7 @@
<div class="control-group" data-ng-class="{error: errors.review.rating}">
<label class="control-label" for="review.rating">Rating</label>
<div class="controls">
- <input type="range" id="rating" name="rating" data-ng-model="item.rating" min="1" max="5"<output for="rating">{{rating}}</output>
+ <input type="range" id="review.rating" name="review.rating" data-ng-model="item.review.rating" min="1" max="5"<output for="review.rating">{{review.rating}}</output>
<span class="help-inline" data-ng-show="errors.review.rating">{{errors.review.rating}}</span>
</div>
@@ -53,7 +53,7 @@
<div class="control-group" data-ng-class="{error: errors.review.text}">
<label class="control-label" for="review.text">Text</label>
<div class="controls">
- <input type="text" id="text" name="text" data-ng-model="item.text">
+ <input type="text" id="review.text" name="review.text" data-ng-model="item.review.text">
<span class="help-inline" data-ng-show="errors.review.text">{{errors.review.text}}</span>
</div>
View
4 test/apps/grails-ng/web-app/ng-templates/album/edit.html
@@ -46,7 +46,7 @@
<div class="control-group" data-ng-class="{error: errors.review.rating}">
<label class="control-label" for="review.rating">Rating</label>
<div class="controls">
- <input type="range" id="rating" name="rating" data-ng-model="item.rating" min="1" max="5"<output for="rating">{{rating}}</output>
+ <input type="range" id="review.rating" name="review.rating" data-ng-model="item.review.rating" min="1" max="5"<output for="review.rating">{{review.rating}}</output>
<span class="help-inline" data-ng-show="errors.review.rating">{{errors.review.rating}}</span>
</div>
@@ -55,7 +55,7 @@
<div class="control-group" data-ng-class="{error: errors.review.text}">
<label class="control-label" for="review.text">Text</label>
<div class="controls">
- <input type="text" id="text" name="text" data-ng-model="item.text">
+ <input type="text" id="review.text" name="review.text" data-ng-model="item.review.text">
<span class="help-inline" data-ng-show="errors.review.text">{{errors.review.text}}</span>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.