Changeset 290


Ignore:
Timestamp:
Mar 22, 2010, 11:38:25 AM (7 years ago)
Author:
keesvb
Message:

debugged EventDescription?.save, added comment field for template fields, add code comments to setFieldValue, added missing events to PPSH demo in BootStrap?, cleaned up home menu, re-added searchable

Location:
trunk
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/application.properties

    r285 r290  
    11#Grails Metadata file
    2 #Thu Mar 18 16:30:01 CET 2010
     2#Fri Mar 19 11:53:03 CET 2010
    33app.grails.version=1.2.1
    44app.name=gscf
     
    1010plugins.mail=0.9
    1111plugins.nimble=0.3-SNAPSHOT
     12plugins.searchable=0.5.5
    1213plugins.shiro=1.0.1
    1314plugins.tomcat=1.2.1
  • trunk/grails-app/conf/BootStrap.groovy

    r269 r290  
    198198                                name: '#Mice in cage',type: TemplateFieldType.INTEGER))
    199199                        .addToFields(new TemplateField(
    200                                 name: 'Litter size',type: TemplateFieldType.INTEGER))   
     200                                name: 'Litter size',type: TemplateFieldType.INTEGER))
    201201                        .addToFields(new TemplateField(
    202202                                name: 'Weight (g)', type: TemplateFieldType.DOUBLE, unit: 'gram'))
     
    515515          }
    516516
    517           humanStudy.addToEventGroups rootGroup
     517          humanStudy.addToEvents(fastingEvent)
     518          humanStudy.addToSamplingEvents(bloodSamplingEvent)
     519          humanStudy.addToEventGroups rootGroup
    518520          humanStudy.save()
    519521
  • trunk/grails-app/controllers/dbnp/studycapturing/EventDescriptionController.groovy

    r289 r290  
    116116            description.name=params['name']
    117117
    118             // description.description=params['description']   // has to be a Term
     118            description.description=params['description']
    119119            // description.classification=params['classification']  // has to be a Term
    120120            description.isSamplingEvent= params['isSample']=='true'?true:false
     
    244244
    245245
    246         // make changes persitant
    247 
    248         if (description.save(flush: true)) {
    249             flash.message = "${message(code: 'default.created.message', args: [message(code: 'description.label', default: 'EventDescription'), description.id])}"
    250             redirect(action: "show", id: description.id)
    251         }
    252         else {
    253             render(view: "create", model: [description: description])
    254         }
    255 
    256         render( action: 'list' )
     246        // Check for errors in protocol, and if none, persist it
     247        protocol.validate()
     248        if (protocol.hasErrors()) {
     249                render "Errors during save of protool:\n"
     250                for (e in description.errors) {
     251                        render e
     252                }
     253        }
     254        else {
     255                protocol.save(flush:true)
     256        }
     257
     258
     259        // Important: add protocol to EventDescription
     260        description.protocol = protocol
     261
     262
     263        // Check for errors in EventDescription, if no errors, persist the data
     264        description.validate()
     265        if (description.hasErrors()) {
     266                render "Errors during save of event description:\n"
     267                for (e in description.errors) {
     268                        render e
     269                }
     270        }
     271        else {
     272                if (description.save(flush: true)) {
     273                        flash.message = "${message(code: 'default.created.message', args: [message(code: 'description.label', default: 'EventDescription'), description.id])}"
     274                    redirect(view: "show", id: description.id)
     275
     276                }
     277                else {
     278                    redirect(view: "create", model: [description: description])
     279                }
     280        }
     281
    257282    }
    258283
     
    264289        if (!eventDescriptionInstance) {
    265290            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}"
    266             redirect(action: "list")
     291            redirect(view: "list")
    267292        }
    268293
    269294        else {
    270295            [eventDescriptionInstance: eventDescriptionInstance, params:params]
     296            // Since show.gsp is not implemented yet, redirect to edit
     297            redirect(action:'edit',id:params.id)
    271298        }
    272299    }
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r257 r290  
    7070
    7171        /**
    72          * Find a template field by its name and return its value for this subject
    73          * @param fieldName The name of the template subject field
     72         * Find a template field by its name and return its value for this entity
     73         * @param fieldName The name of the template field
    7474         * @return the value of the field (class depends on the field type)
    7575         * @throws NoSuchFieldException If the field is not found or the field type is not supported
     
    8181        }
    8282
     83        /**
     84         * Set a template/entity field value
     85         * @param fieldName The name of the template or entity field
     86         * @param value The value to be set, this should align with the (template) field type, but there are some convenience setters
     87         *
     88         */
    8389        def setFieldValue(String fieldName, value) {
     90
     91                // First, search if there is an entity property with the given name, and if so, set that
    8492                if (this.properties.containsKey(fieldName)) {
    8593                        this[fieldName] = value
    8694                }
    87                 else
    88                 if (template == null) {
    89                         throw new NoSuchFieldException("Field ${fieldName} not found in class properties")
     95                // If not the found, then it is a template field, so check if there is a template
     96                else if (template == null) {
     97                        throw new NoSuchFieldException("Field ${fieldName} not found in class properties: template not set")
    9098                }
     99                // If there is a template, check the template fields
    91100                else {
     101                        // Find the target template field, if not found, throw an error
    92102                        TemplateField field = this.template.fields.find { it.name == fieldName}
    93103                        if (field == null) {
    94104                                throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields")
    95105                        }
     106                        // Set the value of the found template field
    96107                        else {
     108                                // Convenience setter for template string list fields: find TemplateFieldListItem by name
    97109                                if (field.type == TemplateFieldType.STRINGLIST && value.class == String) {
    98                                         // Convenience setter: find template item by name
    99110                                        value = field.listEntries.find { it.name == value }
    100111                                }
    101112
    102                                 // handle string values for date fields
     113                                // Convenience setter for dates: handle string values for date fields
    103114                                if (field.type == TemplateFieldType.DATE && value.class == String) {
    104115                                        // a string was given, attempt to transform it into a date instance
     
    119130                                }
    120131
    121                                 // Caution: this assumes that all template...Field Maps are already initialized
    122                                 // Otherwise, the results are pretty much unpredictable!
     132                                // Set the field value
     133                                // Caution: this assumes that all template...Field Maps are already initialized (as is done now above as [:])
     134                                // If that is ever changed, the results are pretty much unpredictable (random Java object pointers?)!
    123135                                getStore(field.type)[fieldName] = value
    124136                                return this
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy

    r247 r290  
    1313        TemplateFieldType type
    1414        String unit
     15        String comment // help string for the user interface
    1516
    1617    static hasMany = [listEntries : TemplateFieldListItem] // to store the entries to choose from when the type is 'item from predefined list'
     
    1920                name(unique: true)
    2021                unit(nullable: true, blank: true)
     22                comment(nullable:true, blank: true)
     23        }
     24
     25        static mapping = {
     26                comment type: 'text'
    2127        }
    2228
  • trunk/grails-app/views/common/_topnav.gsp

    r247 r290  
    33    <ul class="topnav">
    44     <li><g:link url="/${meta(name: 'app.name')}/">Home</g:link></li>
    5      <li>
     5<n:isLoggedIn>
     6     <li><g:link controller="study" action="list">My studies</g:link></li>
     7</n:isLoggedIn>     <li>
    68      <a href="#">Studies</a>
    79      <ul class="subnav">
     
    1012      </ul>
    1113     </li>
    12      <li><g:link controller="load" action="index">Loading data</g:link></li>
     14     <li>
     15      <a href="#">Events</a>
     16      <ul class="subnav">
     17        <li><g:link controller="protocol" action="list">View protocols</g:link></li>
     18        <li><g:link controller="eventDescription" action="list">View event descriptions</g:link></li>
     19      </ul>
     20     </li>
     21         <li><g:link controller="importer" action="index">Import data</g:link></li>
     22    <g:if env="development">
    1323     <li><g:link controller="query" action="index">Query database</g:link></li>
    14 <n:isLoggedIn>
    15      <li><g:link controller="study" action="list">My studies</g:link></li>
    16 </n:isLoggedIn>
    17      <li>
     24         <li>
    1825          <a href="#">Scaffolded controllers</a>
    1926          <ul class="subnav"><g:each var="c" in="${grailsApplication.controllerClasses}">
     
    2128          </ul>
    2229     </li>
     30        </g:if>
    2331<n:isAdministrator>
    2432     <li>
  • trunk/grails-app/views/eventDescription/showMyProtocolFilled.gsp

    r289 r290  
    255255
    256256    <% def protocols = dbnp.studycapturing.Protocol.list() %>
     257        <td>Name</td>
     258</tr>
     259<tr class="prop">
    257260    <td>
    258261           <g:if test="${protocol==null}">
Note: See TracChangeset for help on using the changeset viewer.