Ignore:
Timestamp:
Dec 22, 2009, 1:26:58 PM (15 years ago)
Author:
gav
Message:

Integrate create data functions with appConfig.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/AppCoreController.groovy

    r216 r237  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22
     3/**
     4* Controller class for the application core views.
     5*/
    36class AppCoreController extends BaseController {
    47
    58    def personService
    69    def createDataService
     10    def appConfigService
    711
    812    def index = { redirect(action:start,params:params) }
     
    2529    }
    2630
     31    /**
     32    * Render the start view.
     33    */
    2734    def start = {
    2835    }
    2936
     37    /**
     38    * Allow a person to change their session timeout setting.
     39    */
    3040    def changeSessionTimeout = {
    3141        if (request.method == 'GET') {
     
    4858    }
    4959
     60    /**
     61    * Allow a person to change their password.
     62    */
    5063    def changePassword = {
    5164        //def principal = authenticateService.principal()
     
    8396    }
    8497
     98    /**
     99    * Render the manager view for manager or admin roles.
     100    */
    85101    @Secured(['ROLE_Manager','ROLE_AppAdmin'])
    86102    def manager = {
    87103    }
    88104
     105    /**
     106    * Render the appAdmin view for admin roles.
     107    */
    89108    @Secured(['ROLE_AppAdmin'])
    90109    def appAdmin = {
     110
     111        def offerBaseDataCreation = false
     112        def offerDemoDataCreation = false
     113        def baseDataCreated = appConfigService.exists("baseDataCreated")
     114        def demoDataCreated = appConfigService.exists("demoDataCreated")
     115        def demoDataCreationDisabled = appConfigService.exists("demoDataCreationDisabled")
     116
     117        if(!baseDataCreated)
     118            offerBaseDataCreation = true
     119
     120        if(baseDataCreated && !demoDataCreated && !demoDataCreationDisabled)
     121            offerDemoDataCreation = true
     122
     123        return[baseDataCreated: baseDataCreated,
     124                        demoDataCreated: demoDataCreated,
     125                        offerDemoDataCreation: offerDemoDataCreation,
     126                        offerBaseDataCreation: offerBaseDataCreation,
     127                        demoDataCreationDisabled: demoDataCreationDisabled]
    91128    }
    92129
     130    /**
     131    * Allow admin to disable demo data creation.
     132    */
     133    @Secured(['ROLE_AppAdmin'])
     134    def disableDemoDataCreation = {
     135        if(!appConfigService.set("demoDataCreationDisabled")) {
     136            flash.message = "Demo data creation could not be disabled."
     137            redirect(action: appAdmin)
     138            return
     139        }
     140
     141        // Success.
     142        flash.message = "Demo data creation disabled."
     143        redirect(action: appAdmin)
     144    }
     145
     146    /**
     147    * Allow admin to create base data.
     148    */
    93149    @Secured(['ROLE_AppAdmin'])
    94150    def createBaseData = {
    95         createDataService.createBaseData()
    96         redirect(action:appAdmin)
     151        if(!createDataService.createBaseData()) {
     152            flash.message = "Base data could not be created."
     153            redirect(action: appAdmin)
     154            return
     155        }
     156
     157        // Success.
     158        flash.message = "Base data created."
     159        redirect(action: appAdmin)
    97160    }
    98161
     162    /**
     163    * Allow admin to create demo data.
     164    */
    99165    @Secured(['ROLE_AppAdmin'])
    100166    def createDemoData = {
    101         createDataService.createDemoData()
    102         redirect(action:appAdmin)
     167        if(!createDataService.createDemoData()) {
     168            flash.message = "Demo data could not be created."
     169            redirect(action: appAdmin)
     170            return
     171        }
     172
     173        // Success.
     174        flash.message = "Demo data created."
     175        redirect(action: appAdmin)
    103176    }
    104177
    105 }
     178} // end of class.
Note: See TracChangeset for help on using the changeset viewer.