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

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