Ignore:
Timestamp:
Nov 29, 2010, 4:56:48 PM (6 years ago)
Author:
robert@…
Message:

Improved the study overview page such that the different tabs are loaded when needed. Also rewritten parts of the code. See ticket #155

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy

    r1203 r1213  
    124124        }
    125125    }
     126
     127        /**
     128     * Shows the subjects tab of one or more studies. Is called when opening the subjects-tab
     129         * on the study overview screen.
     130     */
     131    def show_subjects = {
     132                def studyList = readStudies( params.id );
     133
     134                if( !studyList )
     135                        return
     136
     137                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     138    }
     139
     140        /**
     141     * Shows the events timeline tab of one or more studies. Is called when opening the events timeline-tab
     142         * on the study overview screen.
     143     */
     144    def show_events_timeline = {
     145                def studyList = readStudies( params.id );
     146
     147                if( !studyList )
     148                        return
     149
     150                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     151    }
     152
     153        /**
     154     * Shows the events table tab of one or more studies. Is called when opening the events table-tab
     155         * on the study overview screen.
     156     */
     157    def show_events_table = {
     158                def studyList = readStudies( params.id );
     159
     160                if( !studyList )
     161                        return
     162
     163                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     164    }
     165
     166        /**
     167     * Shows the assays tab of one or more studies. Is called when opening the assays tab
     168         * on the study overview screen.
     169     */
     170    def show_assays = {
     171                def studyList = readStudies( params.id );
     172
     173                if( !studyList )
     174                        return
     175
     176                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     177    }
     178
     179        /**
     180     * Shows the samples tab of one or more studies. Is called when opening the samples-tab
     181         * on the study overview screen.
     182     */
     183    def show_samples = {
     184                def studyList = readStudies( params.id );
     185
     186                if( !studyList )
     187                        return
     188
     189                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     190    }
     191
     192        /**
     193     * Shows the persons tab of one or more studies. Is called when opening the persons tab
     194         * on the study overview screen.
     195     */
     196    def show_persons = {
     197                def studyList = readStudies( params.id );
     198
     199                if( !studyList )
     200                        return
     201
     202                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     203    }
     204
     205        /**
     206     * Shows the publications tab of one or more studies. Is called when opening the publications tab
     207         * on the study overview screen.
     208     */
     209    def show_publications = {
     210                def studyList = readStudies( params.id );
     211
     212                if( !studyList )
     213                        return
     214
     215                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ), loggedInUser: AuthenticationService.getLoggedInUser() ]
     216    }
     217
     218        /**
     219         * Creates the javascript for showing the timeline of one or more studies
     220         */
     221        def createTimelineBandsJs = {
     222                def studyList = readStudies( params.id );
     223
     224                if( !studyList )
     225                        return
     226
     227                [studyList: studyList, studyInstanceTotal: Study.count(), multipleStudies: ( studyList.size() > 1 ) ]
     228        }
     229
     230    /**
     231         * Reads one or more studies from the database and checks whether the logged
     232         * in user is allowed to access them.
     233         *
     234         * Is used by several show_-methods
     235         *
     236         * @return List with Study objects or false if an error occurred.
     237         */
     238        private def readStudies( id ) {
     239                // If nothing has been selected, redirect the user
     240                if( !id || !( id instanceof String)) {
     241            response.status = 500;
     242            render 'No study selected';
     243            return false
     244                }
     245
     246                // Check whether one id has been selected or multiple.
     247                def ids = URLDecoder.decode( id ).split( "," );
     248
     249                // Parse strings to a long
     250                def long_ids = []
     251                ids.each { long_ids.add( Long.parseLong( it ) ) }
     252
     253                def c = Study.createCriteria()
     254
     255        def studyList = c {
     256                        maxResults( Math.min(params.max ? params.int('max') : 10, 100) )
     257                        'in'( "id", long_ids )
     258                }
     259
     260                // Check whether the user may see these studies
     261                def studiesAllowed = []
     262        def loggedInUser = AuthenticationService.getLoggedInUser()
     263
     264                studyList.each { studyInstance ->
     265            if( studyInstance.canRead(loggedInUser) ) {
     266                                studiesAllowed << studyInstance
     267            }
     268                }
     269
     270                // If the user is not allowed to see any of the studies, return 404
     271                if( studiesAllowed.size() == 0 ) {
     272            response.status = 404;
     273            render 'Selected studies not found';
     274            return false
     275                }
     276               
     277                return studyList
     278        }
    126279
    127280    def showByToken = {
Note: See TracChangeset for help on using the changeset viewer.