Changeset 825


Ignore:
Timestamp:
Aug 17, 2010, 6:22:24 PM (13 years ago)
Author:
duh
Message:
Location:
trunk/grails-app
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy

    r823 r825  
    611611                                flow.page = 6
    612612                        }
     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"
    613645                        on("previous") {
     646                                // handle form data
     647                                assayPage(flow, flash, params)
     648
     649                                // ignore errors
     650                                flash.errors = [:]
     651
     652                                success()
    614653                        }.to "samples"
    615654                        on("next") {
    616                         }.to "assayGroups"
     655                                // handle form data
     656                                assayPage(flow, flash, params) ? success() : error()
     657                        }.to "assays"
    617658                }
    618659
     
    623664                        }
    624665                        on("previous") {
     666                                // handle form data
     667                                assayGroupPage(flow, flash, params)
     668
     669                                // ignore errors
     670                                flash.errors = [:]
     671
     672                                success()
    625673                        }.to "assays"
    626674                        on("next") {
     675                                // handle form data
     676                                assayGroupPage(flow, flash, params) ? success() : error()
    627677                        }.to "confirm"
    628678                }
     
    11661216
    11671217        /**
     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        /**
    11681265         * groovy / java equivalent of php's ucwords function
    11691266         *
  • trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy

    r784 r825  
    66 * this data can be found.
    77 */
    8 class Assay extends Identity {
    9 
    10         /** The name of the assay, which should indicate the measurements represented in this assay to the user. */
     8class Assay extends TemplateEntity {
     9        // The name of the assay, which should indicate the measurements represented in this assay to the user.
    1110        String name
    1211
    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. */
    1413        AssayModule module
    1514
     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
    1619        /**
    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
    1922         */
    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        ]
    2141
    2242        // An Assay always belongs to one study.
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r803 r825  
    3131        Map templateBooleanFields       = [:]
    3232        Map templateTemplateFields      = [:]
     33        Map templateModuleFields        = [:]
     34        Map templateLongFields          = [:]
    3335
    3436        // N.B. If you try to set Long.MIN_VALUE for a reltime field, an error will occur
     
    4042        // define relationships
    4143        static hasMany = [
    42                 templateStringFields: String,
    43                 templateTextFields: String,
     44                templateStringFields    : String,
     45                templateTextFields              : String,
    4446                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
    5559        ]
    5660
     
    314318                        return (!error)
    315319                })
    316                 templateTemplateFields(validator: { fields, obj, errors ->
    317                         def error = false
    318                         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 = true
    325                                                 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                 })
    336320                templateBooleanFields(validator: { fields, obj, errors ->
    337321                        def error = false
     
    341325                                } else {
    342326                                        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                                        }
    343384                                }
    344385                        }
     
    380421                        case TemplateFieldType.TEMPLATE:
    381422                                return templateTemplateFields
     423                        case TemplateFieldType.MODULE:
     424                                return templateModuleFields
     425                        case TemplateFieldType.LONG:
     426                                return templateLongFields
    382427                        default:
    383428                                throw new NoSuchFieldException("Field type ${fieldType} not recognized")
     
    583628                }
    584629
    585                 // Magic setter for template fields
     630                // Magic setter for TEMPLATE fields
    586631                if (field.type == TemplateFieldType.TEMPLATE && value && value.class == String) {
    587632                        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())
    588644                }
    589645
     
    600656                                // the value to 0, otherwise, setting it to NULL
    601657                                switch (field.type.toString()) {
    602                                         case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME']:
     658                                        case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME', 'LONG']:
    603659                                                this[field.name] = 0;
    604660                                                break;
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy

    r803 r825  
    33/**
    44 * Enum describing the type of a TemplateField.
     5 *
    56 * Revision information:
    67 * $Rev$
     
    910 */
    1011public 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
    2326    // TODO: add a timezone-aware date type to use for study start date
    2427
     
    3033
    3134        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]
    3336        }
    3437
     
    5457                                return ""
    5558                        case BOOLEAN:
    56                                 return false;
     59                                return false
    5760                        case TEMPLATE:
    58                                 return null;
     61                                return null
     62                        case MODULE:
     63                                return null
     64                        case LONG:
     65                                return Long.MIN_VALUE
    5966                        default:
    6067                                throw new NoSuchFieldException("Field type ${fieldType} not recognized")
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r804 r825  
    902902
    903903                                switch (it.type.toString()) {
    904                                         case ['STRING', 'INTEGER', 'FLOAT', 'DOUBLE']:
     904                                        case ['STRING', 'INTEGER', 'FLOAT', 'DOUBLE', 'LONG']:
    905905                                                inputElement = (renderType == 'element') ? 'textFieldElement' : 'textField'
    906906                                                out << "$inputElement"(
     
    10381038                                                ){helpText}
    10391039                                                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
    10401050                                        default:
    10411051                                                // unsupported field type
  • trunk/grails-app/views/templateEditor/elements/_template.gsp

    r820 r825  
    11<%
    22/**
    3  * Template Editor 'Template' template (to keep it simple)
     3 * Template Editor TEMPLATE template (to keep it simple)
    44 *
    55 * @author      Jeroen Wesbeek
  • trunk/grails-app/views/wizard/pages/_assays.gsp

    r823 r825  
    1616%>
    1717<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
    1930</wizard:pageContent>
Note: See TracChangeset for help on using the changeset viewer.