source: trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy @ 203

Last change on this file since 203 was 203, checked in by tabma, 10 years ago
  • 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)
  • Property svn:keywords set to Date Author Rev
File size: 2.8 KB
Line 
1/**
2 * Importer tag library
3 *
4 * The importer tag library gives support for automating several 'components'
5 *
6 * @package     importer
7 * @author      t.w.abma@umcutrecht.nl
8 * @since       20100202
9 *
10 * Revision information:
11 * $Rev: 203 $
12 * $Author: tabma $
13 * $Date: 2010-02-18 07:10:35 +0000 (do, 18 feb 2010) $
14 */
15
16package dbnp.importer
17
18class ImporterTagLib {
19    static namespace = 'importer'
20    def standardentities = [[type:0, name:"Study"], [type:1, name:"Subject"], [type:2, name:"Event"],
21                        [type:3, name:"Protocol"], [type:4, name:"Sample"]]
22
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"]]
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    def entity = { attrs ->
40        out << entities[attrs['index']].name
41    }
42
43    /**
44     * @param entities array of entity:columnindex values
45     */
46    def properties = { attrs ->
47        def selectedentities = []
48        def header = attrs['header']
49
50        attrs['entities'].each { se ->
51            def temp = se.split(":")
52            def entity = [type:temp[0],columnindex:temp[1]]
53            selectedentities.add(entity)
54        }
55
56        out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header])
57    }
58
59    def createSelect(int selected, String name, ArrayList options, String customvalue) {
60        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
61
62        options.each { e ->
63            res += "<option value=\"${e.type}:${customvalue}\""
64            res += (e.type.toInteger() == selected) ? " selected" : ""
65            res += ">${e.name}</option>"
66        }
67
68        res += "</select>"
69        return res
70    }
71
72   
73
74    /**
75     * @param selected selected entity
76     * @param name name of the HTML select object
77     **/
78    def entitySelect = { attrs ->       
79        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
80        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
81        out << createSelect(selected, attrs['name'], standardentities, customvalue)
82    }
83
84    /**
85    * @param selected selected celltype
86    * @param name name of the HTML select object
87    * @see org.apache.poi.ss.usermodel.Cell for the possible cell types
88    * @return HTML select object
89    */
90    def celltypeSelect = { attrs ->
91        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
92        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
93        out << createSelect(selected, attrs['name'], standardcelltypes, customvalue)
94    }
95}
Note: See TracBrowser for help on using the repository browser.