Changeset 203 for trunk


Ignore:
Timestamp:
Feb 18, 2010, 8:10:35 AM (10 years ago)
Author:
tabma
Message:
  • rewrote to HashMap? based columns (columns are always unique, storing in array tricky/redundancy)
  • entities can be chosen in the preview
  • properties page shows columns grouped per entity
  • properties page allows mapping of column to property (TODO: get all fields per entity)
Location:
trunk
Files:
2 added
8 edited

Legend:

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

    r200 r203  
    4646        def datamatrix= ImporterService.getDatamatrix(wb, 0, 5)
    4747
     48        session.header = header
     49
    4850        render (view:"step1", model:[header:header, datamatrix:datamatrix])
    4951
     
    5355        def entities  = request.getParameterValues("entity")
    5456
    55         render(view:"step2", model:[entities:entities])
     57        render(view:"step2", model:[entities:entities, header:session.header])
    5658    }
    5759}
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r169 r203  
    1919import org.apache.poi.poifs.filesystem.POIFSFileSystem
    2020import org.apache.poi.ss.usermodel.DataFormatter
    21 
     21import dbnp.importer.Column
    2222
    2323class ImporterService {
     
    4343        def sheet = wb.getSheetAt(sheetindex)
    4444        def datamatrix_start = sheet.getFirstRowNum() + 1
    45         def header = []       
     45        //def header = []
     46        def header = [:]
    4647        def df = new DataFormatter()
     48
    4749
    4850        for (HSSFCell c: sheet.getRow(sheet.getFirstRowNum())) {
     
    5456            switch (c.getCellType()) {
    5557                    case HSSFCell.CELL_TYPE_STRING:                     
    56                         header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     58                        header[c.getColumnIndex()] = new dbnp.importer.Column(value:df.formatCellValue(c), type:datamatrix_celltype);
    5759                        break
    5860                    case HSSFCell.CELL_TYPE_NUMERIC:
    59                         header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     61                        header[c.getColumnIndex()] = new dbnp.importer.Column(value:df.formatCellValue(c), type:datamatrix_celltype);
    6062                        break
    6163                    case HSSFCell.CELL_TYPE_BLANK:
    62                         header.add (columnindex:c.getColumnIndex(), value:"-", celltype:datamatrix_celltype);
     64                        header[c.getColumnIndex()] = new dbnp.importer.Column(value:df.formatCellValue(c), type:datamatrix_celltype);
    6365                        break
    6466                    default:
    65                         header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     67                        header[c.getColumnIndex()] = new dbnp.importer.Column(value:df.formatCellValue(c), type:datamatrix_celltype);
    6668                        break
    6769            }
  • trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy

    r200 r203  
    1818class ImporterTagLib {
    1919    static namespace = 'importer'
    20     def entities = [[value:0, name:"Study"], [value:1, name:"Subject"], [value:2, name:"Event"],
    21                         [value:3, name:"Protocol"], [value:4, name:"Sample"]]
     20    def standardentities = [[type:0, name:"Study"], [type:1, name:"Subject"], [type:2, name:"Event"],
     21                        [type:3, name:"Protocol"], [type:4, name:"Sample"]]
    2222
    23     def celltypes = [[value:0, name:"Numeric"], [value:1, name:"String"], [value:2, name:"Formula"],
    24                          [value:3, name:"Blank"], [value:4, name:"Boolean"], [value:5, name:"Error"]]
     23    def standardcelltypes = [[type:0, name:"Numeric"], [type:1, name:"String"], [type:2, name:"Formula"],
     24                         [type:3, name:"Blank"], [type:4, name:"Boolean"], [type:5, name:"Error"]]
    2525
    2626    /**
     
    4545     */
    4646    def properties = { attrs ->
    47         def ent = []
     47        def selectedentities = []
     48        def header = attrs['header']
    4849
    49         attrs['entities'].each { e ->
    50             def temp = e.split(":")         
     50        attrs['entities'].each { se ->
     51            def temp = se.split(":")
    5152            def entity = [type:temp[0],columnindex:temp[1]]
    52             ent.add(entity)
     53            selectedentities.add(entity)
    5354        }
    5455
    55         out << render (template:"common/properties", model:[entities:ent])
     56        out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header])
    5657    }
    5758
     
    6061
    6162        options.each { e ->
    62             res += "<option value=\"${e.value}:${customvalue}\""
    63             res += (e.value == selected) ? " selected" : ""
     63            res += "<option value=\"${e.type}:${customvalue}\""
     64            res += (e.type.toInteger() == selected) ? " selected" : ""
    6465            res += ">${e.name}</option>"
    6566        }
     
    7879        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
    7980        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
    80         out << createSelect(selected, attrs['name'], entities, customvalue)
     81        out << createSelect(selected, attrs['name'], standardentities, customvalue)
    8182    }
    8283
     
    9091        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
    9192        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
    92         out << createSelect(selected, attrs['name'], celltypes, customvalue)
     93        out << createSelect(selected, attrs['name'], standardcelltypes, customvalue)
    9394    }
    9495}
  • trunk/grails-app/views/importer/common/_preview.gsp

    r200 r203  
    1919          <g:each var="column" in="${header}">
    2020              <td class="header">
    21                   <b>${column.value}</b>
     21                  <b>${column.value.value}</b>
    2222              </td>
    2323          </g:each>
     
    2525
    2626        <tr>
    27             <td>Datatype:</td>
     27            <td>Celltype:</td>
    2828            <g:each var="column" in="${header}">
    2929                <td class="header">
    30                     <importer:celltypeSelect selected="${column.celltype}" name="celltype" customvalue="${column.columnindex.toString()}"/>
     30                    <importer:celltypeSelect selected="${column.value.type.toInteger()}" name="celltype" customvalue="${column.key.toString()}"/>
    3131                </td>
    3232            </g:each>
     
    3737            <g:each var="column" in="${header}">
    3838                <td class="header">
    39                     <importer:entitySelect name="entity" customvalue="${column.columnindex.toString()}"/>
     39                    <importer:entitySelect name="entity" customvalue="${column.key.toString()}"/>
    4040                </td>
    4141            </g:each>
  • trunk/grails-app/views/importer/common/_properties.gsp

    r200 r203  
    1515<g:form name="propertiesform" action="saveproperties">
    1616    <table>
    17         <tr>
    18           <td>Entity:</td>
    19 
    20           <g:each var="entity" in="${entities}">
    21               <td class="header">
    22                   <b>${entity}</b>
    23               </td>
     17          <g:each var="stdentity" in ="${standardentities}">
     18              <tr><td colspan="2"><h4>${stdentity.name}</h4></td></tr>
     19              <tr>
     20                  <td>Columnname:</td><td>Property:</td>
     21              </tr>           
     22                <g:each var="selentity" in="${selectedentities}">
     23                    <g:if test="${selentity.type.toLong()==stdentity.type}">
     24                        <tr>
     25                            <td class="header" width="200px">
     26                                <b>${header[selentity.columnindex.toInteger()].value}</b>
     27                            </td>
     28                            <td>
     29                                <g:select name="property" from="${['BMI', 'DOB', 'Gender']}" />
     30                            </td>
     31                    </g:if>
     32                </g:each>
     33              <tr>
     34                  <td colspan="2">
     35                      <hr />
     36                  </td>
     37              </tr>
    2438          </g:each>
    2539    </table>
  • trunk/grails-app/views/importer/step1.gsp

    r169 r203  
    2727  <importer:preview header="${header}" datamatrix="${datamatrix}"/>
    2828  </body>
     29
    2930</html>
  • trunk/grails-app/views/importer/step2.gsp

    r200 r203  
    2626    <h1>Step 2: import wizard entities/properties</h1>
    2727    <p>Below you see the entities and columns, assign properties to the columns.</p>
    28   <importer:properties entities="${entities}" />
     28  <importer:properties entities="${entities}" header="${header}"/>
    2929  </body>
    3030</html>
  • trunk/grails-app/views/sandbox/index.gsp

    r146 r203  
    3030</tr>
    3131</table>
     32<%@
     33 def a = new Column(value:"value", name:"naam")
     34 println a.name
     35%>
    3236</body>
    3337</html>
Note: See TracChangeset for help on using the changeset viewer.