Skip to content

Commit

Permalink
Merge pull request #245 from AtlasOfLivingAustralia/feature/issue242
Browse files Browse the repository at this point in the history
Fix for allowRowDelete #242
  • Loading branch information
salomon-j authored Apr 18, 2024
2 parents 8189cec + 48c2a3c commit 265d330
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
10 changes: 7 additions & 3 deletions grails-app/taglib/au/org/ala/ecodata/forms/ModelTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,12 @@ class ModelTagLib {
}

static boolean getAllowRowDelete(attrs, name, context) {
def ard = getAttribute(attrs, name, context, 'allowRowDelete') ?: 'true'
return ard.toBoolean()
Map dataModel = getAttribute(attrs.model.dataModel, name)
def allowRowDelete = true
if (dataModel?.allowRowDelete != null) {
allowRowDelete = Boolean.valueOf(dataModel.allowRowDelete)
}
allowRowDelete
}


Expand All @@ -1031,7 +1035,7 @@ class ModelTagLib {
return target ? target[attribute] : null
}

def getAttribute(model, name) {
static def getAttribute(Collection model, String name) {
return model.findResult( {

if (it.name == name) {
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/forms/ModelTagLibSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ class ModelTagLibSpec extends Specification implements TagLibUnitTest<ModelTagLi

}

def "The allowRowDelete method supports nested tables"() {
setup:
Map attrs = [model:[dataModel:[
[dataType:'list', name:"test", columns:[], allowRowDelete:true],
[dataType:'list', name:"test2", columns:[], allowRowDelete:"true"],
[dataType:'list', name:"test3", columns:[], allowRowDelete:"false"],
[dataType:'list', name:"test4", columns:[], allowRowDelete:false],

[dataType:'list', name:"test5", columns:[
[dataType:'list', name:"test6", allowRowDelete: false]
]]
]]]

expect:
ModelTagLib.getAllowRowDelete(attrs, "test", null) == true
ModelTagLib.getAllowRowDelete(attrs, "test2", null) == true
ModelTagLib.getAllowRowDelete(attrs, "test3", null) == false
ModelTagLib.getAllowRowDelete(attrs, "test4", null) == false
ModelTagLib.getAllowRowDelete(attrs, "test5", null) == true // default is true
ModelTagLib.getAllowRowDelete(attrs, "test6", null) == false
}

}

0 comments on commit 265d330

Please sign in to comment.