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

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