@@ -85,31 +85,35 @@ class NgGenerateAllCommand implements GrailsApplicationCommand {
85
85
List<String > componentProperties = []
86
86
List<String > componentImports = []
87
87
Map<String , String > domainProperties = [:]
88
- List<String > domainConstructorInitializingStatements = []
88
+ Map< String , List<String > > domainConstructorInitializingStatements = [: ]
89
89
List<String > domainImports = []
90
90
91
91
domainModelService. getInputProperties(domainClass). each { DomainProperty property ->
92
92
PersistentProperty prop = property. persistentProperty
93
93
domainProperties. put(property. name, ' any' )
94
94
if (prop instanceof Association ) {
95
- associatedProperties. add(property)
96
95
String type = property. associatedType. simpleName
97
96
String name = GrailsNameUtils . getPropertyName(type)
97
+ associatedProperties. add(property)
98
98
99
- constructorArguments. add(" private ${ name} Service: ${ type} Service" )
100
- initializingStatements. add(" this.${ name} Service.list().subscribe((${ name} List: ${ type} []) => { this.${ name} List = ${ name} List; });" )
101
- componentProperties. add(" ${ name} List: ${ type} [];" )
102
- componentImports. add(" import { ${ type} Service } from '../${ name} /${ name} .service';" )
103
- componentImports. add(" import { ${ type} } from '../${ name} /${ name} ';" )
99
+ if (! prop. bidirectional) {
100
+ constructorArguments. add(" private ${ name} Service: ${ type} Service" )
101
+ initializingStatements. add(" this.${ name} Service.list().subscribe((${ name} List: ${ type} []) => { this.${ name} List = ${ name} List; });" )
102
+ componentProperties. add(" ${ name} List: ${ type} [];" )
103
+ componentImports. add(" import { ${ type} Service } from '../${ name} /${ name} .service';" )
104
+ componentImports. add(" import { ${ type} } from '../${ name} /${ name} ';" )
105
+ }
104
106
domainImports. add(" import { ${ type} } from '../${ name} /${ name} ';" )
107
+
108
+ String initializingStatement
105
109
if (prop instanceof ToMany ) {
106
110
domainProperties. put(property. name, " $type []" )
107
- domainConstructorInitializingStatements . add( " this.${ property.name} = object['${ property.name} '].map((obj: any) => { return new ${ type} (obj); });" )
111
+ initializingStatement = " this.${ property.name} = object['${ property.name} '].map((obj: any) => { return new ${ type} (obj); });"
108
112
} else {
109
113
domainProperties. put(property. name, type)
110
- domainConstructorInitializingStatements . add( " this.${ property.name} = new ${ type} (object['${ property.name} ']);" )
114
+ initializingStatement = " this.${ property.name} = new ${ type} (object['${ property.name} ']);"
111
115
}
112
- domainConstructorInitializingStatements. add( " delete object['${ property.name} '];" )
116
+ domainConstructorInitializingStatements. put(property . name, [initializingStatement, " delete object['${ property.name} '];" ] )
113
117
} else {
114
118
if (fileInputRenderer. supports(property)) {
115
119
hasFileProperty = true
@@ -145,7 +149,7 @@ class NgGenerateAllCommand implements GrailsApplicationCommand {
145
149
File moduleFile = file(" ${ baseDir} /${ module.propertyName} /${ module.propertyName} .module.ts" )
146
150
render template : template(" angular2/javascripts/module.ts" ),
147
151
destination : moduleFile,
148
- model : module. asMap() << [associatedModule : false ],
152
+ model : module. asMap() << [associatedModule : false , importService : true ],
149
153
overwrite : overwrite
150
154
151
155
render template : template(" angular2/javascripts/routing.module.ts" ),
@@ -179,25 +183,27 @@ class NgGenerateAllCommand implements GrailsApplicationCommand {
179
183
}
180
184
181
185
182
- associatedProperties. each {
186
+ associatedProperties. each { DomainProperty prop ->
183
187
184
- Model associatedModel = model(it . associatedType)
188
+ Model associatedModel = model(prop . associatedType)
185
189
186
190
uri = getUri(associatedModel)
187
-
188
- render template : template(" angular2/javascripts/service.ts" ),
189
- destination : file(" ${ baseDir} /${ associatedModel.propertyName} /${ associatedModel.propertyName} .service.ts" ),
190
- model : associatedModel. asMap() << [uri : uri],
191
- overwrite : overwrite
191
+ boolean bidirectional = ((Association )prop. persistentProperty). bidirectional
192
+ if (! bidirectional) {
193
+ render template : template(" angular2/javascripts/service.ts" ),
194
+ destination : file(" ${ baseDir} /${ associatedModel.propertyName} /${ associatedModel.propertyName} .service.ts" ),
195
+ model : associatedModel. asMap() << [uri : uri],
196
+ overwrite : overwrite
197
+ }
192
198
193
199
render template : template(" angular2/javascripts/domain.ts" ),
194
200
destination : file(" ${ baseDir} /${ associatedModel.propertyName} /${ associatedModel.propertyName} .ts" ),
195
- model : associatedModel. asMap() << [domainProperties : [:], domainConstructorInitializingStatements : [], domainImports : []],
201
+ model : associatedModel. asMap() << [domainProperties : [:], domainConstructorInitializingStatements : [: ], domainImports : []],
196
202
overwrite : overwrite
197
203
198
204
render template : template(" angular2/javascripts/module.ts" ),
199
205
destination : file(" ${ baseDir} /${ associatedModel.propertyName} /${ associatedModel.propertyName} .module.ts" ),
200
- model : associatedModel. asMap() << [associatedModule : true ],
206
+ model : associatedModel. asMap() << [associatedModule : true , importService : ! bidirectional ],
201
207
overwrite : overwrite
202
208
203
209
if (angularModuleEditor. addDependency(moduleFile, associatedModel, ' ..' )) {
@@ -223,5 +229,9 @@ class NgGenerateAllCommand implements GrailsApplicationCommand {
223
229
}
224
230
}
225
231
232
+ void renderDomain (PersistentEntity persistentEntity ) {
233
+
234
+ }
235
+
226
236
227
237
}
0 commit comments