root/trunk/grails-app/taglib/org/dbxp/metabolomicsModule/MetabolomicsModuleTagLib.groovy @ 163

Revision 163, 5.3 KB (checked in by m.s.vanvliet@…, 3 years ago)

Formatted Assay Page layout

Line 
1package org.dbxp.metabolomicsModule
2
3import org.dbxp.dbxpModuleStorage.UploadedFile
4import org.dbxp.metabolomicsModule.measurements.MeasurementPlatformVersion
5
6/**
7 * The metabolomics module tag library delivers a rich set of tags to make it easier to re-use components
8 * and elements in the interface.
9 *
10 * @version: $Rev$
11 * @author: $Author$
12 * @lastrevision: $Date$
13*/
14
15class MetabolomicsModuleTagLib {
16
17    // abbreviation for Metabolomics Module
18    static namespace = "mm"
19
20    def assayService
21    def uploadedFileService
22    def measurementFactoryService
23
24    def uploadedFileList = { attrs ->
25
26                attrs.dialogProperties['baseUrl'] = resource('/', absolute: true);
27
28                // get file list from attributes
29                def uploadedFiles
30                if (attrs.containsKey('files')) {
31                        uploadedFiles = attrs.get('files')
32                } else {
33                        throw new Exception("required attribute 'files' is missing from the <uploadedFilesList files=\"...\"/> tag")
34                }
35
36                // output file uploadr
37        out << '<h1>Uploaded files</h1>'
38        out << uploadr.add(name: "uploadrArea", path: "/tmp", placeholder: "Drop file(s) here to upload", direction: 'up', maxVisible: 8, rating: true, colorPicker: true, voting: true) {
39            uploadedFiles.each { uploadedFile ->
40                                // add file to the uploadr
41                uploadr.file(name: uploadedFile.fileName) {
42                                        uploadr.deletable { ((uploadedFile.uploader.id == session.user.id || session.user.isAdministrator)) }
43                                        if (uploadedFile.hasProperty('color') && uploadedFile.color) uploadr.color { "${uploadedFile.color}" }
44                                        uploadr.rating { "${uploadedFile.getRating()}" }
45                                        uploadr.fileSize { uploadedFile.fileSize }
46                    uploadr.fileModified { uploadedFile.lastUpdated.time }
47                    uploadr.fileId { uploadedFile.id }
48                }
49            }
50
51            uploadr.onSuccess {
52                                out << g.render(template:'/js/uploadr/onSuccess', model:[])
53            }
54
55            uploadr.onFailure {
56                "console.log('failed uploading ' + file.fileName);"
57            }
58
59            uploadr.onAbort {
60                "console.log('aborted uploading ' + file.fileName);"
61            }
62
63                        uploadr.onView {
64                                out << g.render(template:'/js/uploadr/onView',
65                                        model:[dialogProperties: attrs.dialogProperties]);
66            }
67
68            uploadr.onDownload {
69                                out << g.render(template:'/js/uploadr/onDownload', model:[])
70            }
71
72            uploadr.onDelete {
73                                out << g.render(template:'/js/uploadr/onDelete', model:[])
74            }
75
76                        uploadr.onChangeColor {
77                                out << g.render(template:'/js/uploadr/onChangeColor', model:[])
78                        }
79        }
80    }
81
82    def studyList = { attrs ->
83
84        out << '<h1>Study overview</h1>'
85
86        // find all studies the user can read and have at least one assay
87        def readableStudiesWithAssays = assayService.getAssaysReadableByUserAndGroupedByStudy(session.user)
88        out << '<ul class=studyList>'
89
90        readableStudiesWithAssays.each { study, assays ->
91            out << studyTag(study: study, assays: assays)
92        }
93
94        out << '</ul>'
95
96    }
97   
98    def studyTag = { attrs ->
99
100        out << '<li class="studyTag">' + attrs.study.name + '<span class="sampleCount">' + attrs.assays.collect{it.samples?.size()}.sum() + ' samples</span><ul class="assayList">'
101
102        attrs.assays.each { assay ->
103            out << assayTag(assay: assay)
104        }
105
106        out << '</ul></li>'
107
108    }
109
110    def assayTag = { attrs ->
111
112        //TODO: present the information in a better/nicer way
113
114        def assay = attrs.assay
115
116        def sampleMsg = "${assay.samples?.size()} samples"
117
118        Long uploadedFileId = UploadedFile.findByAssay(assay)?.id
119        UploadedFile uploadedFile = UploadedFile.get(uploadedFileId)
120
121        if (uploadedFile) {
122            if (uploadedFile.matrix) sampleMsg += " (${uploadedFile.determineAmountOfSamplesWithData()} assigned)";
123
124            if (uploadedFile['platformVersionId']) {
125                def mpv = MeasurementPlatformVersion.get((Long) uploadedFile['platformVersionId'])
126                                if (mpv){
127                                        sampleMsg += " ${mpv.measurementPlatform?.name} ($mpv.versionNumber)"
128                                }
129            }
130        }
131
132        out << "<li class=\"assayTag\" >"
133                out <<          g.link(action:"view", controller:"assay", id: assay.id) { assay.name }
134        out << "        <span class=sampleCount>"
135                out <<                  sampleMsg
136                out << "        </span>"
137                out << "</li>"
138
139    }
140
141    /**
142     * Dropdown list control to choose the platform used (DCL lipodomics, et cetera).
143     *
144     * @param assay
145     */
146    def assayPlatformChooser = { attrs, body ->
147        out << "Platform:  <br />"
148        out << '<form>'
149        out << '<select name="platformVersionId" size="8" style="width:100%;" ' + (attrs.disabled ? 'disabled>' : '>')
150
151        measurementFactoryService.findAllMeasurementPlatforms().each { platform ->
152                        // if new studygroup create new label
153                        out << '<optgroup label="' + platform.name + '">'
154            measurementFactoryService.findAllMeasurementPlatformVersions(measurementPlatform:platform).each { platformVersion ->
155
156                out << '<option value="' + platformVersion.id + '" ' + ((platformVersion.id == attrs.assay.measurementPlatformVersion.id) ? 'selected' : '') + '>' + platformVersion.versionNumber + '</option>'
157            }
158
159            out << '</optgroup>'
160
161        }
162
163        out << '</select>'
164        out << '<input type="submit" value="Submit" />'
165        out << '</form>'
166    }
167
168}
Note: See TracBrowser for help on using the browser.