Changeset 328


Ignore:
Timestamp:
Apr 7, 2010, 11:24:56 AM (14 years ago)
Author:
tabma
Message:
  • study can be selected, imported data fancier postview, lazy loading bug fixed (hopefully)
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy

    r321 r328  
    5656        def datamatrix= ImporterService.getDatamatrix(wb, 0, 5)
    5757
    58         session.header = header
    59         session.importtemplate_id = params.template_id
    60         session.workbook = wb
     58        session.importer_header = header
     59        session.importer_template_id = params.template_id
     60        session.importer_workbook = wb
    6161
    6262        render (view:"step1", model:[header:header, datamatrix:datamatrix])
     
    7777        def entities  = request.getParameterValues("entity")
    7878        def templatefieldtypes = request.getParameterValues("templatefieldtype")
    79         def identifiercolumnindex = params.identifier.toInteger()
     79        def identifiercolumnindex = (params.identifier!=null) ? params.identifier.toInteger() : -1
    8080
    8181        templatefieldtypes.each { t ->     
     
    102102                default: break
    103103            }
    104             session.header[columnindex].templatefieldtype = tft
     104            session.importer_header[columnindex].templatefieldtype = tft
    105105        }
    106106
     
    125125            }
    126126
    127             session.header[columnindex].identifier = (columnindex == identifiercolumnindex) ? true : false
    128             session.header[columnindex].index = columnindex
    129             session.header[columnindex].entity = clazz
     127            session.importer_header[columnindex].identifier = (columnindex == identifiercolumnindex) ? true : false
     128            session.importer_header[columnindex].index = columnindex
     129            session.importer_header[columnindex].entity = clazz
    130130        }
    131131
     
    133133        // TODO: show template fields per entity
    134134       
    135         def templates = Template.get(session.importtemplate_id)
     135        def templates = Template.get(session.importer_template_id)
    136136
    137         render(view:"step2", model:[entities:entities, header:session.header, templates:templates])
     137        render(view:"step2", model:[entities:entities, header:session.importer_header, templates:templates])
    138138    }
    139139
     
    143143    */
    144144    def saveproperties = {
    145         def columnproperties  = request.getParameterValues("columnproperty")
     145        def columnproperties  = request.getParameterValues("columnproperty")   
     146        session.importer_study = Study.get(params.study.id.toInteger())
    146147
    147148        columnproperties.each { cp ->           
    148149                def columnindex = cp.split(":")[0].toInteger()
    149150                def property_id = cp.split(":")[1].toInteger()
    150                 session.header[columnindex].property = TemplateField.get(property_id)           
     151                session.importer_header[columnindex].property = TemplateField.get(property_id)
    151152        }
    152153
    153154        //import workbook
    154         session.importeddata = ImporterService.importdata(session.importtemplate_id, session.workbook, 0, 1, session.header)   
     155        session.importer_importeddata = ImporterService.importdata(session.importer_template_id, session.importer_workbook, 0, 1, session.importer_header)
    155156
    156         render(view:"step3", model:[datamatrix:session.importeddata])
     157        render(view:"step3", model:[datamatrix:session.importer_importeddata])
    157158    }
    158159
    159160    def savepostview = {
    160         ImporterService.savedata(session.importeddata) 
     161        ImporterService.savedata(session.importer_study, session.importer_importeddata)
    161162        render(view:"step4")
    162163    }
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r322 r328  
    200200
    201201    /**
    202      * @param datamatrix two dimensional array containing entities with values read from Excel file
     202     * Method to store a matrix containing the entities in a record like structure. Every row in the table
     203     * contains one or more entity objects (which contain fields with values). So actually a row represents
     204     * a record with fields from one or more different entities.
     205     *
     206     * @param study entity Study
     207     * @param datamatrix two dimensional array containing entities with values read from Excel file     *
    203208     */   
    204     def savedata(datamatrix) {
     209    def savedata(Study study, datamatrix) {
     210        study.refresh()
     211       
    205212        datamatrix.each { record ->
    206213            record.each { entity ->
     
    210217                                    break
    211218                    case Subject :  print "Persisting Subject `" + entity.name + "`: "
    212                                     persistEntity(entity)
     219                                    persistEntity(entity)                                   
     220                                    study.addToSubjects(entity)
    213221                                    break
    214222                    case Event   :  print "Persisting Event `" + entity.eventdescription + "`: "
     
    225233                }
    226234            }
    227         }       
     235        }
    228236    }
    229237
     
    234242     *
    235243     */
    236     def persistEntity(entity) {
    237         println entity.dump()
    238         if (entity.save(flush:true)) {  //.merge?
    239             println "OK"
     244    def persistEntity(entity) {
     245        if (entity.save(flush:true)) {  //.merge?           
    240246        } else entity.errors.allErrors.each {
    241247                println it
  • trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy

    r321 r328  
    8484        //       and session variables should not be used inside the service, migrate to controller
    8585
    86         def t = Template.get(session.importtemplate_id)
     86        def t = Template.get(session.importer_template_id)
    8787        def mc = attrs['mappingcolumn']
    8888
  • trunk/grails-app/views/importer/common/_properties.gsp

    r312 r328  
    1414%>
    1515<g:form name="propertiesform" action="saveproperties">
     16    <p><g:select name="study.id" from="${dbnp.studycapturing.Study.list()}" optionKey="id" class="selectsmall"/></p>
    1617    <table>
    1718          <g:each var="stdentity" in ="${standardentities}">
  • trunk/grails-app/views/importer/step2.gsp

    r319 r328  
    2424  </head>
    2525  <body>
    26     <h1>Step 2: import wizard entities/properties</h1>
    27     <p>Please choose the study you want to add the data to.</p>
    28     <p>Below you see the entities and columns, assign properties to the columns.</p>
     26    <h1>Step 2: import wizard entities/properties</h1>   
     27    <p>First select the study you want to add the data to. The next step is to assign properties to the columns. Below you see the entities and columns, please make your
     28    selections.</p>
    2929  <importer:properties entities="${entities}" header="${header}" templates="${templates}"/>
    3030  </body>
  • trunk/grails-app/views/importer/step3.gsp

    r299 r328  
    2424  <body>
    2525    <h1>Step 3: import wizard imported data postview</h1>
    26     <p>Below you see how all data was imported.</p>
    27   <importer:postview datamatrix="${datamatrix}"/>
     26    <p>A total of ${datamatrix.size()} rows were imported, below an overview of the rows is shown.</span>
     27    <importer:postview datamatrix="${datamatrix}"/>
    2828  </body>
    2929</html>
  • trunk/web-app/css/importer.css

    r322 r328  
    55    border-color: red;
    66    background-color: #DDDDDD;
     7}
     8
     9.selectsmall {
     10    font-size: 10px;
    711}
    812
Note: See TracChangeset for help on using the changeset viewer.