Changeset 825
- Timestamp:
- Aug 17, 2010, 6:22:24 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r823 r825 611 611 flow.page = 6 612 612 } 613 on("refresh") { 614 // handle form data 615 assayPage(flow, flash, params) 616 617 // force refresh of the template 618 if (flow.assay && flow.assay.template && flow.assay.template instanceof Template) { 619 flow.assay.template.refresh() 620 } 621 622 // reset errors 623 flash.errors = [:] 624 success() 625 }.to "assays" 626 on("switchTemplate") { 627 // handle form data 628 assayPage(flow, flash, params) 629 630 // find assay template 631 def template = Template.findByName( params.get('template') ) 632 633 if (flow.assay) { 634 // set template 635 flow.assay.template = template 636 } else { 637 // create a new assay instance 638 flow.assay = new Assay(template: template) 639 } 640 641 // reset errors 642 flash.errors = [:] 643 success() 644 }.to "assays" 613 645 on("previous") { 646 // handle form data 647 assayPage(flow, flash, params) 648 649 // ignore errors 650 flash.errors = [:] 651 652 success() 614 653 }.to "samples" 615 654 on("next") { 616 }.to "assayGroups" 655 // handle form data 656 assayPage(flow, flash, params) ? success() : error() 657 }.to "assays" 617 658 } 618 659 … … 623 664 } 624 665 on("previous") { 666 // handle form data 667 assayGroupPage(flow, flash, params) 668 669 // ignore errors 670 flash.errors = [:] 671 672 success() 625 673 }.to "assays" 626 674 on("next") { 675 // handle form data 676 assayGroupPage(flow, flash, params) ? success() : error() 627 677 }.to "confirm" 628 678 } … … 1166 1216 1167 1217 /** 1218 * Handle the wizard assays page 1219 * 1220 * @param Map LocalAttributeMap (the flow scope) 1221 * @param Map localAttributeMap (the flash scope) 1222 * @param Map GrailsParameterMap (the flow parameters = form data) 1223 * @returns boolean 1224 */ 1225 def assayPage(flow, flash, params) { 1226 def errors = false 1227 flash.errors = [:] 1228 1229 // remember the params in the flash scope 1230 flash.values = params 1231 1232 // handle the 'add assay' form 1233 if (flow.assay) { 1234 flow.assay.giveFields().each() { field -> 1235 // set field 1236 flow.assay.setFieldValue( 1237 field.name, 1238 params.get(field.escapedName()) 1239 ) 1240 } 1241 } 1242 1243 return !errors 1244 } 1245 1246 /** 1247 * Handle the wizard assayGroups page 1248 * 1249 * @param Map LocalAttributeMap (the flow scope) 1250 * @param Map localAttributeMap (the flash scope) 1251 * @param Map GrailsParameterMap (the flow parameters = form data) 1252 * @returns boolean 1253 */ 1254 def assayGroupPage(flow, flash, params) { 1255 def errors = false 1256 flash.errors = [:] 1257 1258 // remember the params in the flash scope 1259 flash.values = params 1260 1261 return !errors 1262 } 1263 1264 /** 1168 1265 * groovy / java equivalent of php's ucwords function 1169 1266 * -
trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy
r784 r825 6 6 * this data can be found. 7 7 */ 8 class Assay extends Identity { 9 10 /** The name of the assay, which should indicate the measurements represented in this assay to the user. */ 8 class Assay extends TemplateEntity { 9 // The name of the assay, which should indicate the measurements represented in this assay to the user. 11 10 String name 12 11 13 / **The dbNP module in which the assay omics data can be found. */12 // The dbNP module in which the assay omics data can be found. */ 14 13 AssayModule module 15 14 15 // The assay ID which is used in the dbNP submodule which contains the actual omics data of this assay. 16 // This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay. 17 long externalAssayID 18 16 19 /** 17 The assay ID which is used in the dbNP submodule which contains the actual omics data of this assay.18 This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay.20 * return the domain fields for this domain class 21 * @return List 19 22 */ 20 long externalAssayID 23 static List<TemplateField> giveDomainFields() { return Assay.domainFields } 24 static List<TemplateField> domainFields = [ 25 new TemplateField( 26 name: 'name', 27 type: TemplateFieldType.STRING, 28 preferredIdentifier: true, 29 required: true 30 ), 31 new TemplateField( 32 name: 'module', 33 type: TemplateFieldType.MODULE 34 35 ), 36 new TemplateField( 37 name: 'externalAssayID', 38 type: TemplateFieldType.LONG 39 ) 40 ] 21 41 22 42 // An Assay always belongs to one study. -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r803 r825 31 31 Map templateBooleanFields = [:] 32 32 Map templateTemplateFields = [:] 33 Map templateModuleFields = [:] 34 Map templateLongFields = [:] 33 35 34 36 // N.B. If you try to set Long.MIN_VALUE for a reltime field, an error will occur … … 40 42 // define relationships 41 43 static hasMany = [ 42 templateStringFields : String,43 templateTextFields : String,44 templateStringFields : String, 45 templateTextFields : String, 44 46 templateStringListFields: TemplateFieldListItem, 45 templateIntegerFields: int, 46 templateFloatFields: float, 47 templateDoubleFields: double, 48 templateDateFields: Date, 49 templateTermFields: Term, 50 templateRelTimeFields: long, 51 templateFileFields: String, 52 templateBooleanFields: boolean, 53 templateTemplateFields: Template, 54 systemFields: TemplateField 47 templateIntegerFields : int, 48 templateFloatFields : float, 49 templateDoubleFields : double, 50 templateDateFields : Date, 51 templateTermFields : Term, 52 templateRelTimeFields : long, 53 templateFileFields : String, 54 templateBooleanFields : boolean, 55 templateTemplateFields : Template, 56 templateModuleFields : AssayModule, 57 templateLongFields : long, 58 systemFields : TemplateField 55 59 ] 56 60 … … 314 318 return (!error) 315 319 }) 316 templateTemplateFields(validator: { fields, obj, errors ->317 def error = false318 fields.each { key, value ->319 if (value && value.class != Template) {320 try {321 fields[key] = (value as Template)322 323 } catch (Exception e) {324 error = true325 errors.rejectValue(326 'templateTemplateFields',327 'templateEntity.typeMismatch.template',328 [key, value.class] as Object[],329 'Property {0} must be of type Template and is currently of type {1}'330 )331 }332 }333 }334 return (!error)335 })336 320 templateBooleanFields(validator: { fields, obj, errors -> 337 321 def error = false … … 341 325 } else { 342 326 fields[key] = false; 327 } 328 } 329 return (!error) 330 }) 331 templateTemplateFields(validator: { fields, obj, errors -> 332 def error = false 333 fields.each { key, value -> 334 if (value && value.class != Template) { 335 try { 336 fields[key] = (value as Template) 337 } catch (Exception e) { 338 error = true 339 errors.rejectValue( 340 'templateTemplateFields', 341 'templateEntity.typeMismatch.template', 342 [key, value.class] as Object[], 343 'Property {0} must be of type Template and is currently of type {1}' 344 ) 345 } 346 } 347 } 348 return (!error) 349 }) 350 templateModuleFields(validator: { fields, obj, errors -> 351 def error = false 352 fields.each { key, value -> 353 if (value && value.class != AssayModule) { 354 try { 355 fields[key] = (value as AssayModule) 356 } catch (Exception e) { 357 error = true 358 errors.rejectValue( 359 'templateModuleFields', 360 'templateEntity.typeMismatch.module', 361 [key, value.class] as Object[], 362 'Property {0} must be of type AssayModule and is currently of type {1}' 363 ) 364 } 365 } 366 } 367 return (!error) 368 }) 369 templateLongFields(validator: { fields, obj, errors -> 370 def error = false 371 fields.each { key, value -> 372 if (value && value.class != Long) { 373 try { 374 fields[key] = Long.parseLong(value.trim()) 375 } catch (Exception e) { 376 error = true 377 errors.rejectValue( 378 'templateLongFields', 379 'templateEntity.typeMismatch.long', 380 [key, value.class] as Object[], 381 'Property {0} must be of type Long and is currently of type {1}' 382 ) 383 } 343 384 } 344 385 } … … 380 421 case TemplateFieldType.TEMPLATE: 381 422 return templateTemplateFields 423 case TemplateFieldType.MODULE: 424 return templateModuleFields 425 case TemplateFieldType.LONG: 426 return templateLongFields 382 427 default: 383 428 throw new NoSuchFieldException("Field type ${fieldType} not recognized") … … 583 628 } 584 629 585 // Magic setter for templatefields630 // Magic setter for TEMPLATE fields 586 631 if (field.type == TemplateFieldType.TEMPLATE && value && value.class == String) { 587 632 value = Template.findByName(value) 633 } 634 635 // Magic setter for MODULE fields 636 if (field.type == TemplateFieldType.MODULE && value && value.class == String) { 637 value = AssayModule.findByName(value) 638 } 639 640 // Magic setter for LONG fields 641 if (field.type == TemplateFieldType.LONG && value && value.class == String) { 642 // TODO, check for invalids? 643 value = Long.parseLong(value.trim()) 588 644 } 589 645 … … 600 656 // the value to 0, otherwise, setting it to NULL 601 657 switch (field.type.toString()) { 602 case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME' ]:658 case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME', 'LONG']: 603 659 this[field.name] = 0; 604 660 break; -
trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy
r803 r825 3 3 /** 4 4 * Enum describing the type of a TemplateField. 5 * 5 6 * Revision information: 6 7 * $Rev$ … … 9 10 */ 10 11 public enum TemplateFieldType implements Serializable { 11 STRING('String'), 12 TEXT('Long string'), 13 INTEGER('Integer number'), 14 FLOAT('Floating-point number'), 15 DOUBLE('Double precision floating-point number'), 16 STRINGLIST('List of items'), 17 ONTOLOGYTERM('Ontology Reference'), 18 DATE('Date'), 19 RELTIME('Relative time'), // relative date, e.g. days since start of study 20 FILE('File'), 21 BOOLEAN('Boolean'), 22 TEMPLATE('Template') 12 STRING('String'), // string 13 TEXT('Long string'), // text 14 INTEGER('Integer number'), // integer 15 FLOAT('Floating-point number'), // float 16 DOUBLE('Double precision floating-point number'), // double 17 STRINGLIST('List of items'), // string list 18 ONTOLOGYTERM('Ontology Reference'), // ontology reference 19 DATE('Date'), // date 20 RELTIME('Relative time'), // relative date, e.g. days since start of study 21 FILE('File'), // file 22 BOOLEAN('Boolean'), // boolean 23 TEMPLATE('Template'), // template 24 MODULE('Module'), // third party connected module, 25 LONG('Long number') // long 23 26 // TODO: add a timezone-aware date type to use for study start date 24 27 … … 30 33 31 34 static list() { 32 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE ]35 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG] 33 36 } 34 37 … … 54 57 return "" 55 58 case BOOLEAN: 56 return false ;59 return false 57 60 case TEMPLATE: 58 return null; 61 return null 62 case MODULE: 63 return null 64 case LONG: 65 return Long.MIN_VALUE 59 66 default: 60 67 throw new NoSuchFieldException("Field type ${fieldType} not recognized") -
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r804 r825 902 902 903 903 switch (it.type.toString()) { 904 case ['STRING', 'INTEGER', 'FLOAT', 'DOUBLE' ]:904 case ['STRING', 'INTEGER', 'FLOAT', 'DOUBLE', 'LONG']: 905 905 inputElement = (renderType == 'element') ? 'textFieldElement' : 'textField' 906 906 out << "$inputElement"( … … 1038 1038 ){helpText} 1039 1039 break 1040 case ['MODULE']: 1041 inputElement = (renderType == 'element') ? 'selectElement' : 'select' 1042 out << "$inputElement"( 1043 description: ucName, 1044 name: prependName + it.escapedName(), 1045 from: AssayModule.findAll(), 1046 value: fieldValue 1047 ){helpText} 1048 break 1049 break 1040 1050 default: 1041 1051 // unsupported field type -
trunk/grails-app/views/templateEditor/elements/_template.gsp
r820 r825 1 1 <% 2 2 /** 3 * Template Editor 'Template'template (to keep it simple)3 * Template Editor TEMPLATE template (to keep it simple) 4 4 * 5 5 * @author Jeroen Wesbeek -
trunk/grails-app/views/wizard/pages/_assays.gsp
r823 r825 16 16 %> 17 17 <wizard:pageContent> 18 assays 18 <span class="info"> 19 <span class="title">Add assays to your study</span> 20 WE NEED SOME CONTENT OVER HERE, who's the brilliant copy writer? :) 21 </span> 22 23 <wizard:templateElement name="template" description="Template" value="${assay?.template}" entity="${dbnp.studycapturing.Assay}" addDummy="true" ajaxOnChange="switchTemplate" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" > 24 Choose the type of assay you would like to add 25 </wizard:templateElement> 26 <g:if test="${assay}"> 27 <wizard:templateElements entity="${assay}" /> 28 </g:if> 29 19 30 </wizard:pageContent>
Note: See TracChangeset
for help on using the changeset viewer.