<commit_before>package dbnp.studycapturing

import dbnp.data.*

/**
 * Wizard Controler
 *
 * The wizard controller handles the handeling of pages and data flow
 * through the study capturing wizard.
 *
 * TODO: refactor the 'handle*' methods to work as subflows instead
 * 		 of methods outside of the flow
 *
 * @author <NAME>
 * @since 20100107
 * @package studycapturing
 *
 * Revision information:
 * $Rev$
 * $Author$
 * $Date$
 */
class WizardController {
	/**
	 * index method, redirect to the webflow
	 * @void
	 */
	def index = {
		/**
		 * Do you believe it in your head?
		 * I can go with the flow
		 * Don't say it doesn't matter (with the flow) matter anymore
		 * I can go with the flow (I can go)
		 * Do you believe it in your head?
		 */
		redirect(action: 'pages')
	}

	/**
	 * WebFlow definition
	 * @see http://grails.org/WebFlow
	 * @void
	 */
	def pagesFlow = {
		// start the flow
		onStart {
			// define flow variables
			flow.page = 0
			flow.pages = [
				//[title: 'Templates'],			// templates
				[title: 'Start'],				// load or create a study
				[title: 'Study'],				// study
				[title: 'Subjects'],			// subjects
				[title: 'Event Descriptions'],	// event descriptions
				[title: 'Events'],				// events and event grouping
				[title: 'Confirmation'],		// confirmation page
				[title: 'Done']					// finish page
			]
		}

		// render the main wizard page which immediately
		// triggers the 'next' action (hence, the main
		// page dynamically renders the study template
		// and makes the flow jump to the study logic)
		mainPage {
			render(view: "/wizard/index")
			onRender {
				flow.page = 1
			}
			on("next").to "start"
		}

		// create or modify a study
		start {
			render(view: "_start")
			onRender {
				flow.page = 1
			}
			on("next").to "study"
			on("modify").to "modify"
		}

		// load a study to modify
		modify {
			render(view: "_modify")
			onRender {
				flow.page = 1
				flash.cancel = true
			}
			on("cancel").to "start"
			on("next") {
				// TODO: loading a study is not yet implemented
				//       create a error stating this feature is
				//       not yet implemented
				flash.errors = [:]
				this.appendErrorMap(
					['study': 'Loading a study and modifying it has not yet been implemented. Please press \'cancel\' to go back to the initial page...'],
					flash.errors
				)
			}.to "modify"
		}

		// render and handle the study page
		// TODO: make sure both template as well as logic will
		//       handle Study templates as well!!!
		study {
			render(view: "_study")
			onRender {
				flow.page = 2
			}
			on("switchTemplate") {
				// handle study data
				this.handleStudy(flow, flash, params)

				// remove errors as we don't want any warnings now
				flash.errors = [:]
			}.to "study"
			on("previous") {
				flash.errors = [:]

				if (this.handleStudy(flow, flash, params)) {
					success()
				} else {
					error()
				}
			}.to "start"
			on("next") {
				flash.errors = [:]<commit_msg>- small bugfix for modify study page (unset flow.study after cancel)<commit_after>package dbnp.studycapturing

import dbnp.data.*

/**
 * Wizard Controler
 *
 * The wizard controller handles the handeling of pages and data flow
 * through the study capturing wizard.
 *
 * TODO: refactor the 'handle*' methods to work as subflows instead
 * 		 of methods outside of the flow
 *
 * @author <NAME>
 * @since 20100107
 * @package studycapturing
 *
 * Revision information:
 * $Rev$
 * $Author$
 * $Date$
 */
class WizardController {
	/**
	 * index method, redirect to the webflow
	 * @void
	 */
	def index = {
		/**
		 * Do you believe it in your head?
		 * I can go with the flow
		 * Don't say it doesn't matter (with the flow) matter anymore
		 * I can go with the flow (I can go)
		 * Do you believe it in your head?
		 */
		redirect(action: 'pages')
	}

	/**
	 * WebFlow definition
	 * @see http://grails.org/WebFlow
	 * @void
	 */
	def pagesFlow = {
		// start the flow
		onStart {
			// define flow variables
			flow.page = 0
			flow.pages = [
				//[title: 'Templates'],			// templates
				[title: 'Start'],				// load or create a study
				[title: 'Study'],				// study
				[title: 'Subjects'],			// subjects
				[title: 'Event Descriptions'],	// event descriptions
				[title: 'Events'],				// events and event grouping
				[title: 'Confirmation'],		// confirmation page
				[title: 'Done']					// finish page
			]
		}

		// render the main wizard page which immediately
		// triggers the 'next' action (hence, the main
		// page dynamically renders the study template
		// and makes the flow jump to the study logic)
		mainPage {
			render(view: "/wizard/index")
			onRender {
				flow.page = 1
			}
			on("next").to "start"
		}

		// create or modify a study
		start {
			render(view: "_start")
			onRender {
				flow.page = 1
			}
			on("next").to "study"
			on("modify").to "modify"
		}

		// load a study to modify
		modify {
			render(view: "_modify")
			onRender {
				flow.page = 1
				flash.cancel = true
			}
			on("cancel") {
				flow.study = null
			}.to "start"
			on("next") {
				// TODO: loading a study is not yet implemented
				//       create a error stating this feature is
				//       not yet implemented
				flash.errors = [:]
				this.appendErrorMap(
					['study': 'Loading a study and modifying it has not yet been implemented. Please press \'cancel\' to go back to the initial page...'],
					flash.errors
				)
			}.to "modify"
		}

		// render and handle the study page
		// TODO: make sure both template as well as logic will
		//       handle Study templates as well!!!
		study {
			render(view: "_study")
			onRender {
				flow.page = 2
			}
			on("switchTemplate") {
				// handle study data
				this.handleStudy(flow, flash, params)

				// remove errors as we don't want any warnings now
				flash.errors = [:]
			}.to "study"
			on("previous") {
				flash.errors = [:]

				// handle the study
				this.handleStudy(flow, flash, params)

				// reset errors
				flash.errors = [:]

				success()
			}.to "start"
			on("next") {
				flash.errors = [:]
{'fraction_non_alphanumeric': 0.1269553762555574, 'fraction_numerical': 0.004281244854273012, 'mean_word_length': 2.3706992230854604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440105', 'n_tokens_mistral': 2379, 'n_tokens_neox': 1863, 'n_words': 666}