Changeset 1515 for trunk/grails-app
- Timestamp:
- Feb 11, 2011, 2:59:27 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r1514 r1515 148 148 if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_page_two.gsp".grom() 149 149 150 flow.importer_importmappings = ImportMapping.list() 151 150 152 flow.page = 2 151 153 success() 152 154 } 153 155 on("refresh") { 156 flow.importer_importmappings = ImportMapping.list() 157 154 158 // a name was given to the current property mapping, try to store it 155 159 if (params.mappingname) { 156 flash ['mappingname'] = params.mappingname157 propertiesSaveImportMappingPage(flow, flash, params) 160 flash.importer_columnproperty = params.columnproperty 161 propertiesSaveImportMappingPage(flow, flash, params) 158 162 } 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() 161 169 }.to "pageTwo" 162 170 … … 338 346 flow.importer_datamatrix_start = params.datamatrix_start.toInteger() - 1 // 0 == first row 339 347 flow.importer_headerrow = params.headerrow.toInteger() 348 flow.importer_entityclass = entityClass.getClass() 340 349 341 350 // Get the header from the Excel file using the arguments given in the first step of the wizard … … 346 355 entityClass) 347 356 348 // Initialize 'selected entities', used to show entities above the columns349 flow.importer_header.each {350 selectedentities.add([name: entityName, columnindex: it.key.toInteger()])351 }352 353 flow.importer_selectedentities = selectedentities354 355 357 session.importer_datamatrix = ImporterService.getDatamatrix( 356 358 session.importer_workbook, flow.importer_header, … … 379 381 boolean propertiesSaveImportMappingPage(flow, flash, params) { 380 382 flash.wizardErrors = [:] 383 def isPreferredIdentifier = false 381 384 382 385 // Find actual Template object from the chosen template name 383 386 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 385 391 386 392 params.columnproperty.index.each { columnindex, property -> 387 393 // 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 391 398 def dontimport = (property == "dontimport") ? true : false 392 399 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)*/ 408 416 } 409 417 } -
trunk/grails-app/domain/dbnp/importer/ImportMapping.groovy
r1505 r1515 4 4 class ImportMapping implements Serializable { 5 5 6 static hasMany = [ columns: MappingColumn]6 static hasMany = [mappingcolumns: MappingColumn] 7 7 Template template 8 8 Class entity -
trunk/grails-app/domain/dbnp/importer/MappingColumn.groovy
r1456 r1515 24 24 25 25 static transients = [ "templatefieldtype", "entity" ] 26 static belongsTo = [importmapping:ImportMapping] 26 27 27 28 static constraints = { -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1499 r1515 41 41 def sheetrow = sheet.getRow(datamatrix_start) 42 42 //def header = [] 43 def header = [ :]43 def header = [] 44 44 def df = new DataFormatter() 45 45 def property = new String() -
trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy
r1511 r1515 84 84 def properties = { attrs -> 85 85 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]) 89 89 } 90 90 … … 95 95 * @param importtemplate_id template identifier where fields are retrieved from 96 96 * @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 97 98 * @param MappingColumn object containing all required information 98 99 * @param fuzzymatching boolean true if fuzzy matching should be used, otherwise false … … 108 109 def allfieldtypes = attrs['allfieldtypes'] 109 110 def matchvalue = (attrs['fuzzymatching']=="true") ? attrs['matchvalue'] : "" 111 def selected = (attrs['selected']) ? attrs['selected'] : "" 110 112 111 113 def domainfields = mc.entity.giveDomainFields().findAll { it.type == mc.templatefieldtype } … … 123 125 /*(mc.identifier) ? out << createPropertySelect(attrs['name'], prefcolumn, matchvalue, mc.index) : 124 126 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) 126 128 } 127 129 … … 135 137 * @return HTML select object 136 138 */ 137 def createPropertySelect(String name, options, matchvalue, Integer columnIndex) {139 def createPropertySelect(String name, options, matchvalue, selected, Integer columnIndex) { 138 140 // Determine which field in the options list matches the best with the matchvalue 139 141 def mostsimilar = (matchvalue) ? ImporterService.mostSimilar(matchvalue, options) : "" … … 146 148 res += "<option value=\"${f.name}\"" 147 149 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() ) ? 149 152 " selected>" : 150 153 ">" 151 154 152 155 res += (f.preferredIdentifier) ? 153 156 "${f.name} (IDENTIFIER)</option>" : -
trunk/grails-app/views/importer/common/_on_page.gsp
r1514 r1515 46 46 // attach event to apply fuzzy matching 47 47 $('#fuzzymatchselect').click(function() { 48 $("#fuzzymatching").val("true") 48 49 refreshFlow() 49 50 }); 50 51 52 // open load box 53 $('#loadpropertiesbutton').click(function() { 54 $("#loadmapping").toggle("scale") 55 }); 56 57 // open save box 51 58 $('#savepropertiesbutton').click(function() { 52 59 var width = 500 -
trunk/grails-app/views/importer/common/_properties_horizontal.gsp
r1514 r1515 16 16 17 17 18 <!-- saveproperties action was defined in the form --> 19 ${flash.mappingname} 18 <!-- saveproperties action was defined in the form --> 19 ${mappingname} 20 20 21 <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> 25 23 <tr> 26 24 <td class="header" width="55px"> 27 25 <input class="buttonsmall" id="clearselect" type="button" value="Clear" name="clearselect"> 28 26 <input class="buttonsmall" id="fuzzymatchselect" type="button" value="Match" name="fuzzymatchselect"> 27 <input type="hidden" name="fuzzymatching" id="fuzzymatching" value="false"> 29 28 <input class="buttonsmall" id="savepropertiesbutton" type="button" value="Save" name="savepropertiesbutton"> 29 <input class="buttonsmall" id="loadpropertiesbutton" type="button" value="Load" name="loadpropertiesbutton"> 30 30 <div id="savemapping" style="display:none"> 31 31 Give current mapping a name and press Save: 32 32 <input type="text" name="mappingname" size="20" id="mappingname"> 33 33 </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 + '']}"/> 41 42 </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> 42 48 </g:each> 43 49 </tr> … … 55 61 </tr> 56 62 </g:each> 57 58 <% } %> <!-- end of JSP if--> 59 </g:each> 63 60 64 </table>
Note: See TracChangeset
for help on using the changeset viewer.