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

Last change on this file since 255 was 255, checked in by tabma, 9 years ago
  • rewrite of celltype detection
  • Property svn:keywords set to Author Rev Date
File size: 4.5 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: 255 $
12 * $Author: tabma $
13 * $Date: 2010-03-10 18:27:57 +0000 (wo, 10 mrt 2010) $
14 */
15
16package dbnp.importer
17import dbnp.studycapturing.Template
18import dbnp.studycapturing.TemplateFieldType
19
20class ImporterTagLib {
21    static namespace = 'importer'
22    def standardentities = [[type:-1, name:"Don't import"], [type:0, name:"Study"], [type:1, name:"Subject"], [type:2, name:"Event"],
23                        [type:3, name:"Protocol"], [type:4, name:"Sample"]]
24
25    /*def standardcelltypes = [
26                         [type:0, name:"Numeric"], [type:1, name:"String"], [type:2, name:"Formula"],
27                         [type:3, name:"Blank"], [type:4, name:"Boolean"], [type:5, name:"Error"], [type:6, name:"Date"],
28                         [type:7, name:"Float"], [type:8, name:"Double"], [type:9, name:"List of items"], [type:10, name:"Ontologyterm"]
29                     ]*/
30
31    /**
32    * @param header string array containing header
33    * @param datamatrix two dimensional array containing actual data
34    * @return preview of the data with the ability to adjust the datatypes
35    */
36    def preview = { attrs ->
37       
38        def header = attrs['header']
39        def datamatrix = attrs['datamatrix']
40
41        out << render (template:"common/preview", model:[header:header, datamatrix:datamatrix])
42    }
43
44    def entity = { attrs ->
45        out << entities[attrs['index']].name
46    }
47
48    /**
49     * @param entities array in the format of columnindex:entitytype format
50     */
51    def properties = { attrs ->
52        def selectedentities = []
53        def header = attrs['header']
54
55        attrs['entities'].each { se ->
56            def temp = se.split(":")
57            def entity = [type:temp[1],columnindex:temp[0]]
58            selectedentities.add(entity)
59        }
60
61        out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header])
62    }
63
64    def createSelect(int selected, String name, options, String customvalue) {
65        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
66
67        options.each { e ->
68            res += "<option value=\"${customvalue}:${e.type}\""
69            res += (e.type.toInteger() == selected) ? " selected" : ""
70            res += ">${e.name}</option>"
71        }
72
73        res += "</select>"
74        return res
75    }
76
77    /**
78     * Possibly this will later on return an AJAX-like autocompletion chooser for the fields?
79     *
80     * @param importtemplate_id template identifier where fields are retrieved from
81     * @param columnindex column in the header we're talking about
82     * @return chooser object
83     * */
84    def propertyChooser = { attrs ->
85        // TODO: this should be changed to retrieving fields per entity
86        def t = Template.get(session.importtemplate_id)
87        def columnindex = attrs['columnindex']
88
89        switch (attrs['entitytype']) {
90            case 0  : createPropertySelect(attrs['name'], t.fields, columnindex)
91                      break
92            case 1  : break
93            case 2  : break
94            case 3  : break
95            default : out << createPropertySelect(attrs['name'], t.fields, columnindex)
96                     break
97        }
98    }
99
100    /**
101     * @param name name of the HTML select object
102     * @param options list of options to be used
103     * @param columnIndex column identifier (corresponding to position in header of the Excel sheet)
104     * @return HTML select object
105     */
106    def createPropertySelect(String name, options, String columnIndex)
107    {
108        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
109
110        options.each { f ->
111            res += "<option value=\"${columnIndex}:${f.id}\""
112            //res += (e.type.toInteger() == selected) ? " selected" : ""
113            res += ">${f}</option>"
114        }
115
116        res += "</select>"
117        return res
118    }   
119
120    /**
121     * @param selected selected entity
122     * @param name name of the HTML select object
123     **/
124    def entitySelect = { attrs ->       
125        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
126        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
127        out << createSelect(selected, attrs['name'], standardentities, customvalue)
128    }
129
130    /**
131    * @param selected selected celltype
132    * @param name name of the HTML select object
133    * @see org.apache.poi.ss.usermodel.Cell for the possible cell types
134    * @return HTML select object
135    */
136    def celltypeSelect = { attrs ->
137        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
138        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
139        //out << createSelect(selected, attrs['name'], standardcelltypes, customvalue)
140        out << createSelect(selected, attrs['name'], TemplateFieldType.list(), customvalue)
141    }
142}
Note: See TracBrowser for help on using the repository browser.