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

Last change on this file since 259 was 259, checked in by tabma, 14 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: 259 $
12 * $Author: tabma $
13 * $Date: 2010-03-12 10:51:33 +0000 (vr, 12 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    /**
26    * @param header string array containing header
27    * @param datamatrix two dimensional array containing actual data
28    * @return preview of the data with the ability to adjust the datatypes
29    */
30    def preview = { attrs ->
31       
32        def header = attrs['header']
33        def datamatrix = attrs['datamatrix']
34
35        out << render (template:"common/preview", model:[header:header, datamatrix:datamatrix])
36    }
37
38    def entity = { attrs ->
39        out << entities[attrs['index']].name
40    }
41
42    /**
43     * @param entities array in the format of columnindex:entitytype format
44     */
45    def properties = { attrs ->
46        def selectedentities = []
47        def header = attrs['header']
48
49        attrs['entities'].each { se ->
50            def temp = se.split(":")
51            def entity = [type:temp[1],columnindex:temp[0]]
52            selectedentities.add(entity)
53        }
54
55        out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header])
56    }
57
58    /**
59     * Possibly this will later on return an AJAX-like autocompletion chooser for the fields?
60     *
61     * @param importtemplate_id template identifier where fields are retrieved from
62     * @param columnindex column in the header we're talking about
63     * @return chooser object
64     * */
65    def propertyChooser = { attrs ->
66        // TODO: this should be changed to retrieving fields per entity
67        def t = Template.get(session.importtemplate_id)
68        def columnindex = attrs['columnindex']
69
70        switch (attrs['entitytype']) {
71            case 0  : createPropertySelect(attrs['name'], t.fields, columnindex)
72                      break
73            case 1  : break
74            case 2  : break
75            case 3  : break
76            default : out << createPropertySelect(attrs['name'], t.fields, columnindex)
77                     break
78        }
79    }
80
81    /**
82     * @param name name of the HTML select object
83     * @param options list of options to be used
84     * @param columnIndex column identifier (corresponding to position in header of the Excel sheet)
85     * @return HTML select object
86     */
87    def createPropertySelect(String name, options, String columnIndex)
88    {
89        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
90
91        options.each { f ->
92            res += "<option value=\"${columnIndex}:${f.id}\""
93            //res += (e.type.toInteger() == selected) ? " selected" : ""
94            res += ">${f}</option>"
95        }
96
97        res += "</select>"
98        return res
99    }
100
101    /**
102    * @param selected selected TemplateFieldType
103    * @param custval custom value to be combined in the option(s) of the selector
104    * @param name name of the HTML select object
105    * @return HTML select object
106    *
107    * @see dbnp.studycapturing.TemplateFieldType
108    */
109
110     def entitySelect = { attrs ->
111        def sel = (attrs['selected']==null) ? -1 : attrs['selected']
112        def custval = (attrs['customvalue']==null) ? "" : attrs['customvalue']
113        def name = (attrs['name']==null) ? -1 : attrs['name']
114
115        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
116
117        standardentities.each { e ->
118            res += "<option value=\"${custval}:${e.type}\""
119            res += (e.type == sel) ? " selected" : ""
120            res += ">${e.name}</option>"
121        }
122
123        res += "</select>"
124        out << res
125    }
126
127    /**
128    * @param selected selected TemplateFieldType
129    * @param customvalue custom value to be combined in the option(s) of the selector
130    * @param name name of the HTML select object
131    * @return HTML select object
132    *
133    * @see dbnp.studycapturing.TemplateFieldType
134    */
135    def templatefieldtypeSelect = { attrs ->
136        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
137        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
138        def name = (attrs['name']==null) ? "" : attrs['name']   
139
140        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
141
142        TemplateFieldType.list().each { e ->
143            res += "<option value=\"${customvalue}:${e}\""
144            res += (e == selected) ? " selected" : ""
145            res += ">${e}</option>"
146        }
147
148        res += "</select>"
149
150        out << res
151    }
152}
Note: See TracBrowser for help on using the repository browser.