Changeset 1515


Ignore:
Timestamp:
Feb 11, 2011, 2:59:27 PM (7 years ago)
Author:
t.w.abma@…
Message:
  • added load/save button to mappings page
  • fuzzy button applies fuzzy matching
  • fixed bug when pressing save didn't remember selected properties and went into "fuzzy mode"
  • importmapping instance is stored, but adding the mappingcolumns is the last "todo"
Location:
trunk/grails-app
Files:
7 edited

Legend:

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

    r1514 r1515  
    148148                                if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_page_two.gsp".grom()
    149149
     150                flow.importer_importmappings = ImportMapping.list()
     151
    150152                                flow.page = 2
    151153                                success()
    152154                        }
    153155            on("refresh") {
     156                flow.importer_importmappings = ImportMapping.list()
     157
    154158                // a name was given to the current property mapping, try to store it
    155159                if (params.mappingname) {
    156                     flash['mappingname'] = params.mappingname
    157                     propertiesSaveImportMappingPage(flow, flash, params)
     160                    flash.importer_columnproperty = params.columnproperty
     161                    propertiesSaveImportMappingPage(flow, flash, params)                   
    158162                }
    159                 flow.importer_fuzzymatching="true"
    160                                 success()
     163               
     164                if (params.fuzzymatching == "true")
     165                    flow.importer_fuzzymatching="true" else
     166                    flow.importer_fuzzymatching="false"
     167
     168                success()
    161169                        }.to "pageTwo"
    162170
     
    338346                        flow.importer_datamatrix_start = params.datamatrix_start.toInteger() - 1 // 0 == first row
    339347                        flow.importer_headerrow = params.headerrow.toInteger()
     348            flow.importer_entityclass = entityClass.getClass()
    340349
    341350                        // Get the header from the Excel file using the arguments given in the first step of the wizard
     
    346355                                entityClass)
    347356
    348                         // Initialize 'selected entities', used to show entities above the columns
    349                         flow.importer_header.each {
    350                                 selectedentities.add([name: entityName, columnindex: it.key.toInteger()])
    351                         }
    352 
    353                         flow.importer_selectedentities = selectedentities
    354 
    355357                        session.importer_datamatrix = ImporterService.getDatamatrix(
    356358                                session.importer_workbook, flow.importer_header,
     
    379381    boolean propertiesSaveImportMappingPage(flow, flash, params) {
    380382        flash.wizardErrors = [:]
     383        def isPreferredIdentifier = false
    381384
    382385                // Find actual Template object from the chosen template name
    383386                def template = Template.get(flow.importer_template_id)
    384         //def im = new ImportMapping(name:params.mappingname).save()
     387       
     388        // Create new ImportMapping instance and persist it
     389        def im = new ImportMapping(name:params.mappingname, entity: flow.importer_entityclass, template:template).save()
     390       
    385391
    386392                params.columnproperty.index.each { columnindex, property ->
    387393                        // Create an actual class instance of the selected entity with the selected template
    388                         // This should be inside the closure because in some cases in the advanced importer, the fields can have different target entities
    389                         def entityClass = Class.forName(flow.importer_header[columnindex.toInteger()].entity.getName(), true, this.getClass().getClassLoader())
    390                         def entityObj = entityClass.newInstance(template: template)
     394                        // This should be inside the closure because in some cases in the advanced importer, the fields can have different target entities                     
     395                        def entityClass = GdtService.getInstanceByEntityName(flow.importer_header[columnindex.toInteger()].entity.getName())
     396            def entityObj = entityClass.newInstance(template:template)
     397
    391398            def dontimport = (property == "dontimport") ? true : false
    392399
    393             def mc = new MappingColumn (property:property, templatefieldtype:entityObj.giveFieldType(property), dontimport: dontimport )
    394 
    395                         // Store the selected property for this column into the column map for the ImporterService
    396                         /*flow.importer_header[columnindex.toInteger()].property = property
    397 
    398                         // Look up the template field type of the target TemplateField and store it also in the map
    399                         flow.importer_header[columnindex.toInteger()].templatefieldtype = entityObj.giveFieldType(property)
    400 
    401                         // Is a "Don't import" property assigned to the column?
    402                         flow.importer_header[columnindex.toInteger()].dontimport = (property == "dontimport") ? true : false
    403 
    404                         //if it's an identifier set the mapping column true or false
    405                         entityObj.giveFields().each {
    406                                 (it.preferredIdentifier && (it.name == property)) ? flow.importer_header[columnindex.toInteger()].identifier = true : false
    407                         }*/
     400            // Loop through all fields and find the preferred identifier
     401            entityObj.giveFields().each {               
     402                                isPreferredIdentifier = (it.preferredIdentifier && (it.name == property)) ? true : false
     403                        }
     404
     405            // Create new MappingColumn instance
     406            /*def mc = new MappingColumn (name: flow.importer_header[columnindex.toInteger()].name,
     407                                        property:property,
     408                                        index:columnindex,
     409                                        entity:entityClass,
     410                                        templatefieldtype:entityObj.giveFieldType(property),
     411                                        dontimport: dontimport,
     412                                        identifier:isPreferredIdentifier)
     413
     414            println "storing mapping: " + mc.validate()
     415            im.addToMappingColumns(mc)*/
    408416                }
    409417    }
  • trunk/grails-app/domain/dbnp/importer/ImportMapping.groovy

    r1505 r1515  
    44class ImportMapping implements Serializable {
    55
    6         static hasMany = [columns: MappingColumn]   
     6        static hasMany = [mappingcolumns: MappingColumn]
    77    Template template
    88    Class entity
  • trunk/grails-app/domain/dbnp/importer/MappingColumn.groovy

    r1456 r1515  
    2424
    2525    static transients = [ "templatefieldtype", "entity" ]
     26    static belongsTo = [importmapping:ImportMapping]
    2627
    2728    static constraints = {
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1499 r1515  
    4141                def sheetrow = sheet.getRow(datamatrix_start)
    4242                //def header = []
    43                 def header = [:]
     43                def header = []
    4444                def df = new DataFormatter()
    4545                def property = new String()
  • trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy

    r1511 r1515  
    8484        def properties = { attrs ->
    8585                def header = attrs['header']
    86                 def entities = attrs['entities']
    87 
    88                 out << render(template: "common/properties_horizontal")
     86                def entities = attrs['entities']       
     87
     88                out << render(template: "common/properties_horizontal", model: [header:header])
    8989        }
    9090
     
    9595         * @param importtemplate_id template identifier where fields are retrieved from
    9696         * @param matchvalue value which will be looked up via fuzzy matching against the list of options and will be selected
     97     * @param selected value to be selected by default
    9798         * @param MappingColumn object containing all required information
    9899     * @param fuzzymatching boolean true if fuzzy matching should be used, otherwise false
     
    108109                def allfieldtypes = attrs['allfieldtypes']             
    109110        def matchvalue = (attrs['fuzzymatching']=="true") ? attrs['matchvalue'] : ""
     111        def selected = (attrs['selected']) ? attrs['selected'] : ""
    110112
    111113        def domainfields = mc.entity.giveDomainFields().findAll { it.type == mc.templatefieldtype }
     
    123125                /*(mc.identifier) ? out << createPropertySelect(attrs['name'], prefcolumn, matchvalue, mc.index) :
    124126                        out << createPropertySelect(attrs['name'], templatefields, matchvalue, mc.index)*/
    125          out << createPropertySelect(attrs['name'], templatefields, matchvalue, mc.index)
     127         out << createPropertySelect(attrs['name'], templatefields, matchvalue, selected, mc.index)
    126128        }
    127129
     
    135137         * @return HTML select object
    136138         */
    137         def createPropertySelect(String name, options, matchvalue, Integer columnIndex) {
     139        def createPropertySelect(String name, options, matchvalue, selected, Integer columnIndex) {
    138140                // Determine which field in the options list matches the best with the matchvalue
    139141                def mostsimilar = (matchvalue) ? ImporterService.mostSimilar(matchvalue, options) : ""
     
    146148                        res += "<option value=\"${f.name}\""
    147149
    148                         res += (mostsimilar.toString().toLowerCase() == f.name.toLowerCase()) ?
     150                        // mostsimilar string passed as argument or selected value passed?
     151            res += (mostsimilar.toString().toLowerCase() == f.name.toLowerCase() || selected.toLowerCase() == f.name.toLowerCase() ) ?
    149152                                " selected>" :
    150153                                ">"
    151 
     154           
    152155                        res += (f.preferredIdentifier) ?
    153156                                "${f.name} (IDENTIFIER)</option>" :
  • trunk/grails-app/views/importer/common/_on_page.gsp

    r1514 r1515  
    4646         // attach event to apply fuzzy matching
    4747         $('#fuzzymatchselect').click(function() {
     48            $("#fuzzymatching").val("true")
    4849            refreshFlow()
    4950          });
    5051
     52          // open load box
     53          $('#loadpropertiesbutton').click(function() {
     54            $("#loadmapping").toggle("scale")
     55          });
     56
     57          // open save box
    5158          $('#savepropertiesbutton').click(function() {
    5259            var width = 500
  • trunk/grails-app/views/importer/common/_properties_horizontal.gsp

    r1514 r1515  
    1616
    1717
    18 <!-- saveproperties action was defined in the form -->
    19   ${flash.mappingname}
     18<!-- saveproperties action was defined in the form --> 
     19  ${mappingname}
     20
    2021    <table>
    21           <g:each var="stdentity" in ="${GdtService.cachedEntities}">
    22               <% if (importer_selectedentities.any { it.name.toLowerCase() == stdentity.entity.toLowerCase() } && stdentity.entity!="") { %>
    23            
    24               <tr><td colspan="3"><h4>${stdentity.name}</h4></td></tr>
     22              <tr><td colspan="3"><h4>defaultentity</h4></td></tr>
    2523                <tr>
    2624            <td class="header" width="55px">
    2725              <input class="buttonsmall" id="clearselect" type="button" value="Clear" name="clearselect">
    2826              <input class="buttonsmall" id="fuzzymatchselect" type="button" value="Match" name="fuzzymatchselect">
     27              <input type="hidden" name="fuzzymatching" id="fuzzymatching" value="false">
    2928              <input class="buttonsmall" id="savepropertiesbutton" type="button" value="Save" name="savepropertiesbutton">
     29              <input class="buttonsmall" id="loadpropertiesbutton" type="button" value="Load" name="loadpropertiesbutton">
    3030              <div id="savemapping" style="display:none">
    3131                Give current mapping a name and press Save:
    3232                <input type="text" name="mappingname" size="20" id="mappingname">
    3333              </div>
    34             </td>
    35             <g:each var="selentity" in="${importer_selectedentities}">
    36               <g:if test="${selentity.name.toLowerCase()==stdentity.entity.toLowerCase()}">
    37                             <td class="header" width="200px">
    38                                 <b>${importer_header[selentity.columnindex.toInteger()].name}</b>
    39                   <importer:propertyChooser name="columnproperty" mappingcolumn="${importer_header[selentity.columnindex.toInteger()]}" matchvalue="${importer_header[selentity.columnindex.toInteger()].name}" fuzzymatching="${importer_fuzzymatching}" template_id="${importer_template_id}" allfieldtypes="true"/>
    40                             </td>                                       
     34              <div id="loadmapping" style="display:none">
     35                Select an existing mapping and press Load:
     36                <g:select name="importmapping" from="${importer_importmappings}" optionValue="name"/>
     37              </div>
     38            </td>           
     39            <g:each var="mappingcolumn" in="${importer_header}">
     40              <g:if test="${importer_columnproperty}">
     41                <g:set var="selected" value="${importer_columnproperty.index['' + mappingcolumn.index + '']}"/>
    4142              </g:if>
     43
     44                          <td class="header" width="200px">
     45                                <b>${mappingcolumn.name}</b>
     46                  <importer:propertyChooser name="columnproperty" mappingcolumn="${mappingcolumn}" matchvalue="${mappingcolumn.name}" selected="${selected}" fuzzymatching="${importer_fuzzymatching}" template_id="${importer_template_id}" "allfieldtypes="true"/>
     47                          </td>                                 
    4248            </g:each>
    4349                </tr>
     
    5561                </tr>
    5662                </g:each>
    57 
    58           <% }  %> <!-- end of JSP if-->
    59           </g:each>
     63         
    6064    </table>
Note: See TracChangeset for help on using the changeset viewer.