@@ -7,9 +7,10 @@ import de.guite.modulestudio.metamodel.DateTimeRole
77import de.guite.modulestudio.metamodel.DatetimeField
88import de.guite.modulestudio.metamodel.Entity
99import de.guite.modulestudio.metamodel.Field
10- import de.guite.modulestudio.metamodel.IntegerField
1110import de.guite.modulestudio.metamodel.ListField
1211import de.guite.modulestudio.metamodel.NumberField
12+ import de.guite.modulestudio.metamodel.NumberFieldType
13+ import de.guite.modulestudio.metamodel.NumberRole
1314import de.guite.modulestudio.metamodel.RelationAutoCompletionUsage
1415import de.guite.modulestudio.metamodel.RelationEditMode
1516import de.guite.modulestudio.metamodel.Relationship
@@ -20,7 +21,6 @@ import de.guite.modulestudio.metamodel.TextRole
2021import de.guite.modulestudio.metamodel.UploadField
2122import de.guite.modulestudio.metamodel.UploadNamingScheme
2223import de.guite.modulestudio.metamodel.UserField
23- import java.math.BigInteger
2424import java.util.ArrayList
2525import org.zikula.modulestudio.generator.cartridges.symfony.controller.ControllerMethodInterface
2626import org.zikula.modulestudio.generator.cartridges.symfony.models.business.ValidationHelpProvider
@@ -68,7 +68,7 @@ class ConfigureFields implements ControllerMethodInterface {
6868 }*/
6969
7070 val nsSymfonyFormType = ' Symfony\\ Component\\ Form\\ Extension\\ Core\\ Type\\ '
71- if (! formFields. filter(IntegerField ). filter[range ]. empty) {
71+ if (! formFields. filter(NumberField ). filter[NumberRole . RANGE == role ]. empty) {
7272 imports. add(nsSymfonyFormType + ' RangeType' )
7373 }
7474 if (geographical) {
@@ -229,7 +229,6 @@ class ConfigureFields implements ControllerMethodInterface {
229229 def private alignment(Object it ) {
230230 switch it {
231231 BooleanField : ' center'
232- IntegerField : ' right'
233232 NumberField : ' right'
234233 StringField : if (#[StringRole . MAIL , StringRole . URL ]. contains(role)) ' center' else ' left'
235234 default: ' left'
@@ -252,51 +251,19 @@ class ConfigureFields implements ControllerMethodInterface {
252251 calls
253252 }
254253
255- def private dispatch fieldType(IntegerField it ) {
256- if (primaryKey) ' Id' else
257- if (percentage) ' Percent' else
258- if (length >= 12 ) ' Integer' else ' Integer' // EAB recommends Text for bigint, changing this would require passing the value as string though
254+ def private dispatch fieldType(NumberField it ) {
255+ if (primaryKey) ' Id'
256+ else if (NumberRole . MONEY == role) ' Money'
257+ else if (NumberRole . PERCENTAGE == role) ' Percent'
258+ else if (NumberFieldType . DECIMAL == numberType) ' Integer'
259+ else ' Number'
259260 }
260- def private dispatch options(IntegerField it ) {
261+ def private dispatch options(NumberField it ) {
261262 var calls = commonOptions
262263 if (primaryKey) {
263264 // https://symfony.com/bundles/EasyAdminBundle/current/fields/IdField.html
264265 calls + = ' ' ' ->setMaxLength(«length»)' ' '
265- } else if (percentage) {
266- // https://symfony.com/bundles/EasyAdminBundle/current/fields/PercentField.html
267- calls + = ' ' ' ->setNumDecimals(0)' ' '
268- // setRoundingMode(...)
269- calls + = ' ' ' ->setStoredAsFractional(false)' ' '
270- if (null !== unit && ! unit. empty) {
271- calls + = ' ' ' ->setSymbol(' «unit»' )' ' '
272- }
273- /* } else if (length >= 12) {
274- // https://symfony.com/bundles/EasyAdminBundle/current/fields/TextField.html
275- // renderAsHtml()
276- calls += '''->setMaxLength(«length»)'''
277- calls += '''->stripTags()'''*/
278- } else {
279- // https://symfony.com/bundles/EasyAdminBundle/current/fields/IntegerField.html
280- // setNumberFormat(...)
281- }
282- calls
283- }
284-
285- def private dispatch fieldType(NumberField it ) {
286- if (percentage) ' Percent' else
287- if (currency) ' Money' else ' Number'
288- }
289- def private dispatch options(NumberField it ) {
290- var calls = commonOptions
291- if (percentage) {
292- // https://symfony.com/bundles/EasyAdminBundle/current/fields/PercentField.html
293- calls + = ' ' ' ->setNumDecimals(«scale»)' ' '
294- // setRoundingMode(...)
295- // setStoredAsFractional(...)
296- if (null !== unit && ! unit. empty) {
297- calls + = ' ' ' ->setSymbol(' «unit»' )' ' '
298- }
299- } else if (currency) {
266+ } else if (NumberRole . MONEY == role) {
300267 // https://symfony.com/bundles/EasyAdminBundle/current/fields/MoneyField.html
301268 if (entity. hasCurrencyFieldsEntity) {
302269 calls + = ' ' ' ->setCurrencyPropertyPath(' «entity. getCurrencyFieldsEntity. head. name. formatForCode»' )' ' '
@@ -305,6 +272,19 @@ class ConfigureFields implements ControllerMethodInterface {
305272 }
306273 calls + = ' ' ' ->setNumDecimals(«scale»)' ' '
307274 // setStoredAsCents()
275+ } else if (NumberRole . PERCENTAGE == role) {
276+ // https://symfony.com/bundles/EasyAdminBundle/current/fields/PercentField.html
277+ calls + = ' ' ' ->setNumDecimals(«scale»)' ' '
278+ // setRoundingMode(...)
279+ if (NumberFieldType . INTEGER == fieldType) {
280+ calls + = ' ' ' ->setStoredAsFractional(false)' ' '
281+ }
282+ if (null !== unit && ! unit. empty) {
283+ calls + = ' ' ' ->setSymbol(' «unit»' )' ' '
284+ }
285+ } else if (NumberFieldType . INTEGER == fieldType) {
286+ // https://symfony.com/bundles/EasyAdminBundle/current/fields/IntegerField.html
287+ // setNumberFormat(...)
308288 } else {
309289 // https://symfony.com/bundles/EasyAdminBundle/current/fields/NumberField.html
310290 // setNumberFormat(...)
@@ -493,25 +473,18 @@ class ConfigureFields implements ControllerMethodInterface {
493473 «IF readonly»
494474 ' readonly' => ' readonly' ,
495475 «ENDIF»
496- «IF it instanceof IntegerField »
497- «IF range »
476+ «IF it instanceof NumberField »
477+ «IF NumberRole.RANGE == role »
498478 ' min' => «minValue»,
499479 ' max' => «maxValue»,
500480 «ELSE»
501- «IF minValue.compareTo(BigInteger.valueOf(0)) > 0»
481+ «IF minValue > 0»
502482 ' min' => «minValue»,
503483 «ENDIF»
504- «IF maxValue.compareTo(BigInteger.valueOf(0)) > 0»
484+ «IF maxValue > 0»
505485 ' max' => «maxValue»,
506486 «ENDIF»
507487 «ENDIF»
508- «ELSEIF it instanceof NumberField»
509- «IF minValue > 0»
510- ' min' => «minValue»,
511- «ENDIF»
512- «IF maxValue > 0»
513- ' max' => «maxValue»,
514- «ENDIF»
515488 «ENDIF»
516489 ' title' => ' «titleAttribute»' ,
517490 «additionalAttributes»
@@ -546,27 +519,22 @@ class ConfigureFields implements ControllerMethodInterface {
546519 def private dispatch titleAttribute(BooleanField it ) ' ' ' «name.formatForDisplay» ?' ' '
547520 def private dispatch additionalAttributes(BooleanField it ) ' ' ' ' ' '
548521
549- def private dispatch customFormType(IntegerField it ) ' ' ' «IF range»Range«ENDIF»' ' '
550- def private dispatch titleAttribute(IntegerField it ) ' ' ' Enter the «name.formatForDisplay» of the «entity.name.formatForDisplay». Only digits are allowed.' ' '
551- def private dispatch additionalAttributes(IntegerField it ) ' ' '
552- ' maxlength' => «length»,
553- ' ' '
554- def private dispatch additionalOptions(IntegerField it ) ' ' '
555- «IF percentage»
556- ' type' => ' integer' ,
557- «ENDIF»
558- «IF unit != ' ' »
559- ' input_group' => [' right' => t(' «unit»' )],
560- «ENDIF»
561- ' ' '
562-
563- def private dispatch customFormType(NumberField it ) ' ' ' «IF #[' latitude' , ' longitude' ].contains(name)»Geo«ENDIF»' ' '
522+ def private dispatch customFormType(NumberField it ) ' ' ' «IF NumberRole.RANGE == role»Range«ELSEIF #[' latitude' , ' longitude' ].contains(name)»Geo«ENDIF»' ' '
564523
565524 def private dispatch additionalAttributes(NumberField it ) ' ' '
566- ' maxlength' => «(length+3+scale)»,
525+ «IF NumberFieldType.INTEGER == numberType»
526+ ' maxlength' => «length»,
527+ «ELSE»
528+ ' maxlength' => «(length+3+scale)»,
529+ «ENDIF»
567530 ' ' '
568531 def private dispatch additionalOptions(NumberField it ) ' ' '
569- ' scale' => «scale»,
532+ «IF NumberRole.PERCENTAGE == role»
533+ ' type' => ' integer' ,
534+ «ENDIF»
535+ «IF NumberFieldType.INTEGER != numberType»
536+ ' scale' => «scale»,
537+ «ENDIF»
570538 «IF unit != ' ' »
571539 ' input_group' => [' right' => t(' «unit»' )],
572540 «ENDIF»
0 commit comments