Skip to content

Commit

Permalink
fix: Internal omission/combination pieces not expanding fields (#116)
Browse files Browse the repository at this point in the history
Previously, internal recurrence/omission/combination pieces were not expanding the fields contained within their models, in order to fix this, the internal piece view file has been changes to dynamically select the correct internal piece view file based on the class, additionally a class field has been added to allow for easier identification of the piece class on the front end
  • Loading branch information
Jack-Golding authored Oct 22, 2024
1 parent e28100a commit 766cb9b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ def should_expand = [
]

@Field InternalCombinationPiece internalCombinationPiece
json g.render(internalCombinationPiece, [excludes: ['owner'], expand: should_expand])
json g.render(internalCombinationPiece, [excludes: ['owner'], expand: should_expand]){
'class' internalCombinationPiece.class.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ def should_expand = [
]

@Field InternalOmissionPiece internalOmissionPiece
json g.render(internalOmissionPiece, [expand: should_expand])
json g.render(internalOmissionPiece, [excludes: ['owner'], expand: should_expand]){
'class' internalOmissionPiece.class.name
}
17 changes: 16 additions & 1 deletion service/grails-app/views/internalPiece/_internalPiece.gson
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import groovy.transform.*
import org.olf.internalPiece.InternalPiece
import groovy.transform.Field
import org.grails.orm.hibernate.cfg.GrailsHibernateUtil

def should_expand = ['receivingPieces', 'templateMetadata']

@Field InternalPiece internalPiece
json g.render(internalPiece, [expand: should_expand])
internalPiece = GrailsHibernateUtil.unwrapIfProxy(internalPiece) as InternalPiece

switch(internalPiece.class.name){
case 'org.olf.internalPiece.InternalOmissionPiece':
json g.render (template: '/internalOmissionPiece/internalOmissionPiece', model: [internalOmissionPiece: binding.variables.internalPiece])
break;
case 'org.olf.internalPiece.InternalRecurrencePiece':
json g.render (template: '/internalRecurrencePiece/internalRecurrencePiece', model: [internalRecurrencePiece: binding.variables.internalPiece])
break;
case 'org.olf.internalPiece.InternalCombinationPiece':
json g.render (template: '/internalCombinationPiece/internalCombinationPiece', model: [internalCombinationPiece: binding.variables.internalPiece])
break;
default:
throw new RuntimeException("Unexpected internalPiece class ${internalPiece.class.name}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ def should_expand = [
]

@Field InternalRecurrencePiece internalRecurrencePiece
json g.render(internalRecurrencePiece, [excludes: ['owner'], expand: should_expand])
json g.render(internalRecurrencePiece, [excludes: ['owner'], expand: should_expand]){
'class' internalRecurrencePiece.class.name
}

0 comments on commit 766cb9b

Please sign in to comment.