source: trunk/grails-app/controllers/SearchableController.groovy @ 198

Last change on this file since 198 was 198, checked in by jahn, 10 years ago

Towards finishing the subGrouping for subjects.

File size: 4.4 KB
Line 
1
2/*
3 * Copyright 2007 the original author or authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import org.compass.core.engine.SearchEngineQueryParseException
19
20/**
21 * Basic web interface for Grails Searchable Plugin
22 *
23 * @author Adem and Jahn
24 */
25class SearchableController {
26    def searchableService
27
28    def selectsample = {
29
30            println "in selectsample: "
31            params.each{println it}
32
33            // prepare showing all studies selected in the previous view
34            def selectedStudies = []
35            def selectedStudyIds = params['selectedStudyIds']
36
37            if(selectedStudyIds!=null)
38            {
39                 def list = selectedStudyIds.findAll(/(\d)+/)
40                 selectedStudies = list.collect{ dbnp.studycapturing.Study.get(it) }
41            }
42            else
43            {
44                 def tmpList = []
45                 def studyList = dbnp.studycapturing.Study.list()
46                 selectedStudyIds = []
47                 params.each{ key,values->
48                     if (values=="on")  tmpList.add(key)
49                 }
50
51                 for (i in studyList)
52                     if (tmpList.contains(i.getId().toString()))
53                     {
54                         selectedStudyIds.add(i.id)
55                         selectedStudies.add(i)
56                     }
57           }
58
59
60        // subgroups
61        // provide list of subgroups depending on the type of subgrouping
62        // selected by the user
63        def subgroups = []
64        def submitButton = params["submit"]  // this button's value determines the kind of subgrouping
65
66        switch(submitButton)
67        {
68             case "Subject Groups":
69                  render(params)
70                  render("Subject Groups")
71                  def studyGroups = []
72                  if(selectedStudies!=null)
73                  {
74                     selectedStudies.each{ study ->
75                         study.groups.each{ group -> studyGroups.add[group] }
76                     }
77                     println "study groups: "
78                     studyGroups.each{x-> println x}
79                  }
80
81                  // testing:
82                  // there is a lack of data in the mockup
83                  // as long as there are no groups in the bootstart,
84                  // we use this
85                  subgroups = studyGroups.size()<=0 ?
86                      ["subject group 1","subject group 2"] : studyGroups
87
88                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
89                  break
90             case "Event Groups":
91                  render("Event Groups")
92                  subgroups=["event group 1","event group 2"]
93                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
94                  break
95             case "Starting Time Groups":
96                  render("Starting Time Groups")
97                  subgroups=["time group 1","time group 2"]
98                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
99                  break
100             case ">> Execute and continue with biomarker selection":
101                  render("Starting Time Groups")
102                  break
103             case "<< Back to study selection":
104                  break
105        }
106        render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
107    }
108
109
110
111    /**
112     * Index page with search form and results
113     */
114    def index = {
115        if (!params.q?.trim()) {
116            return [:]
117        }
118        try {
119            return [searchResult: searchableService.search(params.q, params)]
120        } catch (SearchEngineQueryParseException ex) {
121            return [parseException: true]
122        }
123    }
124
125    /**
126     * Perform a bulk index of every searchable object in the database
127     */
128    def indexAll = {
129        Thread.start {
130            searchableService.index()
131        }
132        render("bulk index started in a background thread")
133    }
134
135    /**
136     * Perform a bulk index of every searchable object in the database
137     */
138    def unindexAll = {
139        searchableService.unindex()
140        render("unindexAll done")
141    }
142
143
144    def subjectGroups = { render ("hello") }
145
146
147}
Note: See TracBrowser for help on using the repository browser.