1 | package generic.installation |
---|
2 | |
---|
3 | import grails.plugins.springsecurity.Secured |
---|
4 | import dbnp.authentication.SecUser |
---|
5 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
6 | |
---|
7 | /** |
---|
8 | * ajaxflow Controller |
---|
9 | * |
---|
10 | * @author Jeroen Wesbeek |
---|
11 | * @since 20110318 |
---|
12 | * |
---|
13 | * Revision information: |
---|
14 | * $Rev: 66849 $ |
---|
15 | * $Author: duh $ |
---|
16 | * $Date: 2010-12-08 15:12:54 +0100 (Wed, 08 Dec 2010) $ |
---|
17 | */ |
---|
18 | @Secured(['ROLE_ADMIN']) |
---|
19 | class SetupController { |
---|
20 | // the pluginManager is used to check if the Grom |
---|
21 | // plugin is available so we can 'Grom' development |
---|
22 | // notifications to the unified notifications daemon |
---|
23 | // (see http://www.grails.org/plugin/grom) |
---|
24 | def pluginManager |
---|
25 | |
---|
26 | /** |
---|
27 | * index method, redirect to the webflow |
---|
28 | * @void |
---|
29 | */ |
---|
30 | def index = { |
---|
31 | // Grom a development message |
---|
32 | if (pluginManager.getGrailsPlugin('grom')) "redirecting into the webflow".grom() |
---|
33 | |
---|
34 | /** |
---|
35 | * Do you believe it in your head? |
---|
36 | * I can go with the flow |
---|
37 | * Don't say it doesn't matter (with the flow) matter anymore |
---|
38 | * I can go with the flow (I can go) |
---|
39 | * Do you believe it in your head? |
---|
40 | */ |
---|
41 | redirect(action: 'pages') |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * WebFlow definition |
---|
46 | * @void |
---|
47 | */ |
---|
48 | def pagesFlow = { |
---|
49 | def authenticationService |
---|
50 | |
---|
51 | // start the flow |
---|
52 | onStart { |
---|
53 | // Grom a development message |
---|
54 | if (pluginManager.getGrailsPlugin('grom')) "entering the WebFlow".grom() |
---|
55 | |
---|
56 | // get configuration |
---|
57 | def config = ConfigurationHolder.config |
---|
58 | println config.dump() |
---|
59 | println config.dataSource.dump() |
---|
60 | |
---|
61 | def configPath = new File("/etc/${meta(name: 'app.name')}/") |
---|
62 | if (configPath.exists()) { |
---|
63 | println "path exists" |
---|
64 | } else { |
---|
65 | println "path does not exist" |
---|
66 | } |
---|
67 | |
---|
68 | if (configPath.canWrite()) { |
---|
69 | println "path is writable" |
---|
70 | } else { |
---|
71 | println "path is not writable" |
---|
72 | } |
---|
73 | |
---|
74 | def configFile = new File("/etc/${meta(name: 'app.name')}/${grails.util.GrailsUtil.environment}.properties") |
---|
75 | if (configFile.exists()) { |
---|
76 | println "file exists" |
---|
77 | } else { |
---|
78 | println "file does not exist" |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | // define variables in the flow scope which is availabe |
---|
83 | // throughout the complete webflow also have a look at |
---|
84 | // the Flow Scopes section on http://www.grails.org/WebFlow |
---|
85 | // |
---|
86 | // The following flow scope variables are used to generate |
---|
87 | // wizard tabs. Also see common/_tabs.gsp for more information |
---|
88 | flow.page = 0 |
---|
89 | //flow.config = ConfigurationHolder.config |
---|
90 | flow.pages = [ |
---|
91 | [title: 'Configuration Location'], |
---|
92 | [title: 'Database'], |
---|
93 | [title: 'Page Three'], |
---|
94 | [title: 'Page Four'], |
---|
95 | [title: 'Done'] |
---|
96 | ] |
---|
97 | flow.cancel = true |
---|
98 | flow.quickSave = true |
---|
99 | |
---|
100 | // define famfamfam icons |
---|
101 | flow.icons = [ |
---|
102 | 'true' : 'accept', |
---|
103 | false : 'cancel' |
---|
104 | ] |
---|
105 | |
---|
106 | // add configuration information to the flow scope |
---|
107 | flow.configInfo = [ |
---|
108 | path : configPath, |
---|
109 | pathExists : configPath.exists(), |
---|
110 | pathCanRead : configPath.canRead(), |
---|
111 | pathCanWrite : configPath.canWrite(), |
---|
112 | pathSummary : (configPath.exists() && configPath.canRead() && configPath.canWrite()), |
---|
113 | file : configFile, |
---|
114 | fileExists : configFile.exists(), |
---|
115 | fileCanRead : configFile.canRead(), |
---|
116 | fileCanWrite : configFile.canWrite(), |
---|
117 | fileSummary : (configFile.exists() && configFile.canRead() && configFile.canWrite()) |
---|
118 | ] |
---|
119 | |
---|
120 | success() |
---|
121 | } |
---|
122 | |
---|
123 | // render the main wizard page which immediately |
---|
124 | // triggers the 'next' action (hence, the main |
---|
125 | // page dynamically renders the study template |
---|
126 | // and makes the flow jump to the study logic) |
---|
127 | mainPage { |
---|
128 | render(view: "/setup/index") |
---|
129 | onRender { |
---|
130 | // Grom a development message |
---|
131 | if (pluginManager.getGrailsPlugin('grom')) "rendering the main Ajaxflow page (index.gsp)".grom() |
---|
132 | |
---|
133 | // let the view know we're in page 1 |
---|
134 | flow.page = 1 |
---|
135 | success() |
---|
136 | } |
---|
137 | on("next").to "configuration" |
---|
138 | } |
---|
139 | |
---|
140 | // first wizard page |
---|
141 | configuration { |
---|
142 | render(view: "_configuration_location") |
---|
143 | onRender { |
---|
144 | // Grom a development message |
---|
145 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_database.gsp".grom() |
---|
146 | |
---|
147 | flow.page = 1 |
---|
148 | success() |
---|
149 | } |
---|
150 | on("next") { |
---|
151 | // put your bussiness logic (if applicable) in here |
---|
152 | }.to "pageTwo" |
---|
153 | on("toPageTwo") { |
---|
154 | // put your bussiness logic (if applicable) in here |
---|
155 | }.to "pageTwo" |
---|
156 | on("toPageThree") { |
---|
157 | // put your bussiness logic (if applicable) in here |
---|
158 | }.to "pageThree" |
---|
159 | on("toPageFour") { |
---|
160 | // put your bussiness logic (if applicable) in here |
---|
161 | }.to "pageFour" |
---|
162 | on("toPageFive") { |
---|
163 | // put your bussiness logic (if applicable) in here |
---|
164 | flow.page = 5 |
---|
165 | }.to "save" |
---|
166 | on("toConfigurationPath").to "configurationPath" |
---|
167 | on("toConfigurationFile").to "configurationFile" |
---|
168 | } |
---|
169 | |
---|
170 | // second wizard page |
---|
171 | database { |
---|
172 | render(view: "_database") |
---|
173 | onRender { |
---|
174 | // Grom a development message |
---|
175 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_page_two.gsp".grom() |
---|
176 | |
---|
177 | flow.page = 2 |
---|
178 | success() |
---|
179 | } |
---|
180 | on("next").to "pageThree" |
---|
181 | on("previous").to "pageOne" |
---|
182 | on("toPageOne").to "pageOne" |
---|
183 | on("toPageThree").to "pageThree" |
---|
184 | on("toPageFour").to "pageFour" |
---|
185 | on("toPageFive") { |
---|
186 | flow.page = 5 |
---|
187 | }.to "save" |
---|
188 | } |
---|
189 | |
---|
190 | // second wizard page |
---|
191 | pageThree { |
---|
192 | render(view: "_page_three") |
---|
193 | onRender { |
---|
194 | // Grom a development message |
---|
195 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_page_three.gsp".grom() |
---|
196 | |
---|
197 | flow.page = 3 |
---|
198 | success() |
---|
199 | } |
---|
200 | on("next").to "pageFour" |
---|
201 | on("previous").to "pageTwo" |
---|
202 | on("toPageOne").to "pageOne" |
---|
203 | on("toPageTwo").to "pageTwo" |
---|
204 | on("toPageFour").to "pageFour" |
---|
205 | on("toPageFive") { |
---|
206 | flow.page = 5 |
---|
207 | }.to "save" |
---|
208 | } |
---|
209 | |
---|
210 | // second wizard page |
---|
211 | pageFour { |
---|
212 | render(view: "_page_four") |
---|
213 | onRender { |
---|
214 | // Grom a development message |
---|
215 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_page_four.gsp".grom() |
---|
216 | |
---|
217 | flow.page = 4 |
---|
218 | success() |
---|
219 | } |
---|
220 | on("next") { |
---|
221 | // put some logic in here |
---|
222 | flow.page = 5 |
---|
223 | }.to "save" |
---|
224 | on("previous").to "pageThree" |
---|
225 | on("toPageOne").to "pageOne" |
---|
226 | on("toPageTwo").to "pageTwo" |
---|
227 | on("toPageThree").to "pageThree" |
---|
228 | on("toPageFive") { |
---|
229 | flow.page = 5 |
---|
230 | }.to "save" |
---|
231 | } |
---|
232 | |
---|
233 | // save action |
---|
234 | save { |
---|
235 | action { |
---|
236 | // here you can validate and save the |
---|
237 | // instances you have created in the |
---|
238 | // ajax flow. |
---|
239 | try { |
---|
240 | // Grom a development message |
---|
241 | if (pluginManager.getGrailsPlugin('grom')) ".persisting instances to the database...".grom() |
---|
242 | |
---|
243 | // put your bussiness logic in here |
---|
244 | success() |
---|
245 | } catch (Exception e) { |
---|
246 | // put your error handling logic in |
---|
247 | // here |
---|
248 | flow.page = 4 |
---|
249 | error() |
---|
250 | } |
---|
251 | } |
---|
252 | on("error").to "error" |
---|
253 | on(Exception).to "error" |
---|
254 | on("success").to "finalPage" |
---|
255 | } |
---|
256 | |
---|
257 | // render errors |
---|
258 | error { |
---|
259 | render(view: "_error") |
---|
260 | onRender { |
---|
261 | // Grom a development message |
---|
262 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_error.gsp".grom() |
---|
263 | |
---|
264 | // set page to 4 so that the navigation |
---|
265 | // works (it is disabled on the final page) |
---|
266 | flow.page = 4 |
---|
267 | } |
---|
268 | on("next").to "save" |
---|
269 | on("previous").to "pageFour" |
---|
270 | on("toPageOne").to "pageOne" |
---|
271 | on("toPageTwo").to "pageTwo" |
---|
272 | on("toPageThree").to "pageThree" |
---|
273 | on("toPageFour").to "pageFour" |
---|
274 | on("toPageFive").to "save" |
---|
275 | |
---|
276 | } |
---|
277 | |
---|
278 | // last wizard page |
---|
279 | finalPage { |
---|
280 | render(view: "_final_page") |
---|
281 | onRender { |
---|
282 | // Grom a development message |
---|
283 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_final_page.gsp".grom() |
---|
284 | |
---|
285 | success() |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|