Changeset 1426 for trunk/grails-app/taglib
- Timestamp:
- Jan 21, 2011, 7:37:02 PM (10 years ago)
- Location:
- trunk/grails-app/taglib/dbnp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy
r1277 r1426 4 4 * The importer tag library gives support for automating several 'components' 5 5 * 6 * @package 7 * @author 8 * @since 6 * @package importer 7 * @author t.w.abma@umcutrecht.nl 8 * @since 20100202 9 9 * 10 10 * Revision information: … … 15 15 16 16 package dbnp.importer 17 import dbnp.studycapturing.Template 18 import dbnp.studycapturing.TemplateFieldType 17 18 import dbnp.studycapturing.* 19 import nl.grails.plugins.gdt.* 19 20 import org.apache.poi.ss.usermodel.Cell 20 21 import org.apache.poi.ss.usermodel.DataFormatter 21 22 22 23 class ImporterTagLib { 23 static namespace = 'importer' 24 def ImporterService 25 26 /** 27 * @param header string array containing header 28 * @param datamatrix two dimensional array containing actual data 29 * @return preview of the data with the ability to adjust the datatypes 30 */ 31 def preview = { attrs -> 32 33 def header = attrs['header'] 34 def datamatrix = attrs['datamatrix'] 35 36 out << render (template:"common/preview", model:[header:header, datamatrix:datamatrix]) 37 } 38 39 /** 40 * @param datamatrix two dimensional array containing entities with read values 41 * @return postview of the imported data 42 */ 43 def postview = { attrs -> 44 def datamatrix = attrs['datamatrix'] 45 46 out << render (template:"common/postview", model:[datamatrix:datamatrix]) 47 } 48 49 def entity = { attrs -> 50 out << entities[attrs['index']].name 51 } 52 53 def datapreview = { attrs -> 54 def datamatrix = attrs['datamatrix'] 55 out << render (template:"common/datapreview", model:[datamatrix:datamatrix]) 56 } 57 58 /** 59 * Show missing properties 60 */ 61 def missingProperties = { attrs -> 62 def datamatrix = attrs['datamatrix'] 63 def failedcells = attrs['failedcells'] 64 out << render (template:"common/missingproperties", model:[datamatrix:datamatrix, failedcells:failedcells]) 65 } 66 67 /** 68 * Show failed cells 69 */ 70 def failedCells = { attrs -> 71 def failedcells = attrs['failedcells'] 72 out << render (template:"common/failedcells", model:[failedcells:failedcells]) 73 } 74 75 /** 76 * @param entities array containing selected entities 77 * @param header array containing mappingcolumn objects 78 * @param allfieldtypes if set, show all fields 79 */ 80 def properties = { attrs -> 81 def header = attrs['header'] 82 def entities = attrs['entities'] 83 84 out << render ( template:"common/properties_horizontal" ) 85 } 86 87 /** 88 * Possibly this will later on return an AJAX-like autocompletion chooser for the fields? 89 * 90 * @param name name for the property chooser element 91 * @param importtemplate_id template identifier where fields are retrieved from 92 * @param matchvalue value which will be looked up via fuzzy matching against the list of options and will be selected 93 * @param MappingColumn object containing all required information 94 * @param allfieldtypes boolean true if all templatefields should be listed, otherwise only show filtered templatefields 95 * @return chooser object 96 * */ 97 def propertyChooser = { attrs -> 98 // TODO: this should be changed to retrieving fields per entity instead of from one template 99 // and session variables should not be used inside the service, migrate to controller 100 101 def t = Template.get(attrs['template_id']) 102 def mc = attrs['mappingcolumn'] 103 def allfieldtypes = attrs['allfieldtypes'] 104 def matchvalue = attrs['matchvalue'] 105 def domainfields = mc.entity.giveDomainFields().findAll { it.type == mc.templatefieldtype } 106 domainfields = domainfields.findAll { it.preferredIdentifier != mc.identifier} 107 108 //def templatefields = (allfieldtypes=="true") ? t.fields : t.fields.findAll { it.type == mc.templatefieldtype } 109 def templatefields = (allfieldtypes=="true") ? 110 t.fields + mc.entity.giveDomainFields() : 111 t.fields.findAll { it.type == mc.templatefieldtype } + domainfields 112 113 // map identifier to preferred column 114 def prefcolumn = mc.entity.giveDomainFields().findAll { it.preferredIdentifier == true } 115 116 (mc.identifier) ? out << createPropertySelect(attrs['name'], prefcolumn, matchvalue, mc.index) : 117 out << createPropertySelect(attrs['name'], templatefields, matchvalue, mc.index) 118 } 119 120 /** 121 * Create the property chooser select element 122 * 123 * @param name name of the HTML select object 124 * @param options list of options (fields) to be used 125 * @param matchvalue value which will be looked up via fuzzy matching against the list of options and will be selected 126 * @param columnIndex column identifier (corresponding to position in header of the Excel sheet) 127 * @return HTML select object 128 */ 129 def createPropertySelect(String name, options, matchvalue, Integer columnIndex) 130 { 131 // Determine which field in the options list matches the best with the matchvalue 132 def mostsimilar = ImporterService.mostSimilar(matchvalue, options) 133 134 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${columnIndex}\">" 135 136 res += "<option value=\"dontimport\">Don't import</option>" 137 138 options.each { f -> 139 res+= "<option value=\"${f.name}\"" 140 141 res+= (mostsimilar.toString().toLowerCase()==f.name.toLowerCase()) ? 142 " selected>" : 143 ">" 144 145 res+= (f.preferredIdentifier) ? 146 "${f.name} (IDENTIFIER)</option>" : 147 "${f.name}</option>" 148 } 149 150 res += "</select>" 151 return res 152 } 153 154 /** 155 * @param selected selected TemplateFieldType 156 * @param custval custom value to be combined in the option(s) of the selector 157 * @param name name of the HTML select object 158 * @return HTML select object 159 * 160 * @see dbnp.studycapturing.TemplateFieldType 161 */ 162 163 def entitySelect = { attrs -> 164 def sel = (attrs['selected']==null) ? -1 : attrs['selected'] 165 def custval = (attrs['customvalue']==null) ? "" : attrs['customvalue'] 166 def name = (attrs['name']==null) ? -1 : attrs['name'] 167 168 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${custval}\">" 169 170 grailsApplication.config.gscf.domain.importableEntities.each { e -> 171 res += "<option value=\"${e.value.name}\"" 172 res += (e.value.type == sel) ? " selected" : "" 173 res += ">${e.value.name}</option>" 174 } 175 176 res += "</select>" 177 out << res 178 } 179 180 /** 181 * Create a templatefieldtype selector 182 * 183 * @param selected selected TemplateFieldType 184 * @param customvalue custom value to be combined in the option(s) of the selector 185 * @param name name of the HTML select object 186 * @return HTML select object 187 * 188 * @see dbnp.studycapturing.TemplateFieldType 189 */ 190 def templatefieldtypeSelect = { attrs -> 191 def selected = (attrs['selected']==null) ? -1 : attrs['selected'] 192 def custval = (attrs['customvalue']==null) ? "" : attrs['customvalue'] 193 def name = (attrs['name']==null) ? "" : attrs['name'] 194 195 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${custval}\">" 196 197 TemplateFieldType.list().each { e -> 198 res += "<option value=\"${e}\"" 199 res += (e == selected) ? " selected" : "" 200 res += ">${e}</option>" 201 } 202 203 res += "</select>" 204 205 out << res 206 } 207 208 /** 209 * @param cell Cell variable 210 * @return good representation of variable (instead of toString()) 211 */ 212 def displayCell = { attrs -> 213 def cell = attrs['cell'] 214 def df = new DataFormatter() 215 216 switch (cell.getCellType()) { 217 case Cell.CELL_TYPE_STRING : out << cell.getStringCellValue() 218 break 219 case Cell.CELL_TYPE_NUMERIC : out << df.formatCellValue(cell) 220 break 221 } 222 } 24 static namespace = 'importer' 25 def ImporterService 26 27 /** 28 * @param header string array containing header 29 * @param datamatrix two dimensional array containing actual data 30 * @return preview of the data with the ability to adjust the datatypes 31 */ 32 def preview = { attrs -> 33 34 def header = attrs['header'] 35 def datamatrix = attrs['datamatrix'] 36 37 out << render(template: "common/preview", model: [header: header, datamatrix: datamatrix]) 38 } 39 40 /** 41 * @param datamatrix two dimensional array containing entities with read values 42 * @return postview of the imported data 43 */ 44 def postview = { attrs -> 45 def datamatrix = attrs['datamatrix'] 46 47 out << render(template: "common/postview", model: [datamatrix: datamatrix]) 48 } 49 50 def entity = { attrs -> 51 out << entities[attrs['index']].name 52 } 53 54 def datapreview = { attrs -> 55 def datamatrix = attrs['datamatrix'] 56 out << render(template: "common/datapreview", model: [datamatrix: datamatrix]) 57 } 58 59 /** 60 * Show missing properties 61 */ 62 def missingProperties = { attrs -> 63 def datamatrix = attrs['datamatrix'] 64 def failedcells = attrs['failedcells'] 65 out << render(template: "common/missingproperties", model: [datamatrix: datamatrix, failedcells: failedcells]) 66 } 67 68 /** 69 * Show failed cells 70 */ 71 def failedCells = { attrs -> 72 def failedcells = attrs['failedcells'] 73 out << render(template: "common/failedcells", model: [failedcells: failedcells]) 74 } 75 76 /** 77 * @param entities array containing selected entities 78 * @param header array containing mappingcolumn objects 79 * @param allfieldtypes if set, show all fields 80 */ 81 def properties = { attrs -> 82 def header = attrs['header'] 83 def entities = attrs['entities'] 84 85 out << render(template: "common/properties_horizontal") 86 } 87 88 /** 89 * Possibly this will later on return an AJAX-like autocompletion chooser for the fields? 90 * 91 * @param name name for the property chooser element 92 * @param importtemplate_id template identifier where fields are retrieved from 93 * @param matchvalue value which will be looked up via fuzzy matching against the list of options and will be selected 94 * @param MappingColumn object containing all required information 95 * @param allfieldtypes boolean true if all templatefields should be listed, otherwise only show filtered templatefields 96 * @return chooser object 97 * */ 98 def propertyChooser = { attrs -> 99 // TODO: this should be changed to retrieving fields per entity instead of from one template 100 // and session variables should not be used inside the service, migrate to controller 101 102 def t = Template.get(attrs['template_id']) 103 def mc = attrs['mappingcolumn'] 104 def allfieldtypes = attrs['allfieldtypes'] 105 def matchvalue = attrs['matchvalue'] 106 def domainfields = mc.entity.giveDomainFields().findAll { it.type == mc.templatefieldtype } 107 domainfields = domainfields.findAll { it.preferredIdentifier != mc.identifier} 108 109 //def templatefields = (allfieldtypes=="true") ? t.fields : t.fields.findAll { it.type == mc.templatefieldtype } 110 def templatefields = (allfieldtypes == "true") ? 111 t.fields + mc.entity.giveDomainFields() : 112 t.fields.findAll { it.type == mc.templatefieldtype } + domainfields 113 114 // map identifier to preferred column 115 def prefcolumn = mc.entity.giveDomainFields().findAll { it.preferredIdentifier == true } 116 117 (mc.identifier) ? out << createPropertySelect(attrs['name'], prefcolumn, matchvalue, mc.index) : 118 out << createPropertySelect(attrs['name'], templatefields, matchvalue, mc.index) 119 } 120 121 /** 122 * Create the property chooser select element 123 * 124 * @param name name of the HTML select object 125 * @param options list of options (fields) to be used 126 * @param matchvalue value which will be looked up via fuzzy matching against the list of options and will be selected 127 * @param columnIndex column identifier (corresponding to position in header of the Excel sheet) 128 * @return HTML select object 129 */ 130 def createPropertySelect(String name, options, matchvalue, Integer columnIndex) { 131 // Determine which field in the options list matches the best with the matchvalue 132 def mostsimilar = ImporterService.mostSimilar(matchvalue, options) 133 134 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${columnIndex}\">" 135 136 res += "<option value=\"dontimport\">Don't import</option>" 137 138 options.each { f -> 139 res += "<option value=\"${f.name}\"" 140 141 res += (mostsimilar.toString().toLowerCase() == f.name.toLowerCase()) ? 142 " selected>" : 143 ">" 144 145 res += (f.preferredIdentifier) ? 146 "${f.name} (IDENTIFIER)</option>" : 147 "${f.name}</option>" 148 } 149 150 res += "</select>" 151 return res 152 } 153 154 /** 155 * @param selected selected TemplateFieldType 156 * @param custval custom value to be combined in the option(s) of the selector 157 * @param name name of the HTML select object 158 * @return HTML select object 159 * 160 * @see nl.grails.plugins.gdt.TemplateFieldType 161 */ 162 163 def entitySelect = { attrs -> 164 def sel = (attrs['selected'] == null) ? -1 : attrs['selected'] 165 def custval = (attrs['customvalue'] == null) ? "" : attrs['customvalue'] 166 def name = (attrs['name'] == null) ? -1 : attrs['name'] 167 168 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${custval}\">" 169 170 grailsApplication.config.gscf.domain.importableEntities.each { e -> 171 res += "<option value=\"${e.value.name}\"" 172 res += (e.value.type == sel) ? " selected" : "" 173 res += ">${e.value.name}</option>" 174 } 175 176 res += "</select>" 177 out << res 178 } 179 180 /** 181 * Create a templatefieldtype selector 182 * 183 * @param selected selected TemplateFieldType 184 * @param customvalue custom value to be combined in the option(s) of the selector 185 * @param name name of the HTML select object 186 * @return HTML select object 187 * 188 * @see nl.grails.plugins.gdt.TemplateFieldType 189 */ 190 def templatefieldtypeSelect = { attrs -> 191 def selected = (attrs['selected'] == null) ? -1 : attrs['selected'] 192 def custval = (attrs['customvalue'] == null) ? "" : attrs['customvalue'] 193 def name = (attrs['name'] == null) ? "" : attrs['name'] 194 195 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${custval}\">" 196 197 TemplateFieldType.list().each { e -> 198 res += "<option value=\"${e}\"" 199 res += (e == selected) ? " selected" : "" 200 res += ">${e}</option>" 201 } 202 203 res += "</select>" 204 205 out << res 206 } 207 208 /** 209 * @param cell Cell variable 210 * @return good representation of variable (instead of toString()) 211 */ 212 def displayCell = { attrs -> 213 def cell = attrs['cell'] 214 def df = new DataFormatter() 215 216 switch (cell.getCellType()) { 217 case Cell.CELL_TYPE_STRING: out << cell.getStringCellValue() 218 break 219 case Cell.CELL_TYPE_NUMERIC: out << df.formatCellValue(cell) 220 break 221 } 222 } 223 223 } -
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r1356 r1426 2 2 3 3 import dbnp.studycapturing.* 4 import nl.grails.plugins.gdt.* 4 5 import dbnp.authentication.SecUser 5 import dbnp.data.*6 6 import cr.co.arquetipos.crypto.Blowfish 7 7 import nl.grails.plugins.ajaxflow.AjaxflowTagLib
Note: See TracChangeset
for help on using the changeset viewer.