Changeset 433 for trunk


Ignore:
Timestamp:
Mar 7, 2010, 4:45:10 PM (15 years ago)
Author:
gav
Message:

Add create unsheduled task feature.
Refactor task priorities.
Limit task types and priorites during task creation.
Add work around for show and edit navigation links in task views.

Location:
trunk/grails-app
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/Config.groovy

    r431 r433  
    148148            [order:11, controller:'taskDetailed', title:'Calendar', action:'searchCalendar', isVisible: { true }],
    149149            [order:20, controller:'taskDetailed', title:'+Scheduled', action:'create', isVisible: { true }],
    150             [order:30, controller:'taskDetailed', title:'+Callout', action:'createImmediateCallout', isVisible: { true }],
    151             [order:90, controller:'taskDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
    152             [order:91, controller:'taskDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
     150            [order:30, controller:'taskDetailed', title:'+Unsheduled', action:'createUnscheduled', isVisible: { true }],
     151            [order:40, controller:'taskDetailed', title:'+Callout', action:'createImmediateCallout', isVisible: { true }],
     152            [order:90, controller:'taskDetailed', title:'Show', action:'show', id:'nav', isVisible: { params.action == 'show' }],
     153            [order:91, controller:'taskDetailed', title:'Edit', action:'edit', id:'nav', isVisible: { params.action == 'edit' }]
    153154        ]
    154155    ],
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r418 r433  
    219219        if(params._action_Show)
    220220            params.action='show'
     221
     222        // Used by navigation.
     223        if(params.id == 'nav') {
     224            params.id = session.currentTaskId ?: null
     225            redirect(action: show, id: params.id)
     226            return
     227        }
    221228
    222229        def showTab = [:]
     
    245252        }
    246253        else {
     254            // Remember the current task id for use with navigation.
     255            session.currentTaskId = params.id
     256
    247257            params.max = 10
    248258            params.order = "desc"
     
    477487            params.action='edit'
    478488
     489        // Used by navigation.
     490        if(params.id == 'nav') {
     491            params.id = session.currentTaskId ?: null
     492            redirect(action: edit, id: params.id)
     493            return
     494        }
     495
    479496        def taskInstance = Task.get( params.id )
    480497
     
    484501        }
    485502        else {
     503            // Remember the current task id for use with navigation.
     504            session.currentTaskId = params.id
     505
    486506            if(taskInstance.trash) {
    487507                flash.message = "You may not edit tasks that are in the trash."
     
    524544        taskInstance.leadPerson = authService.currentUser
    525545        taskInstance.properties = params
    526         return ['taskInstance': taskInstance]
     546
     547        def scheduledTaskTypes = taskService.scheduledTaskTypes
     548        def scheduledTaskPriorities = taskService.scheduledTaskPriorities
     549        taskInstance.taskPriority = scheduledTaskPriorities.default
     550        return ['taskInstance': taskInstance,
     551                    'scheduledTaskTypes': scheduledTaskTypes,
     552                    'scheduledTaskPriorities': scheduledTaskPriorities.list]
    527553    }
    528554
     
    540566            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
    541567
    542         render(view:'create', model:[taskInstance:result.taskInstance])
     568
     569        def scheduledTaskTypes = taskService.scheduledTaskTypes
     570        def scheduledTaskPriorities = taskService.scheduledTaskPriorities
     571        render(view:'create', model:[taskInstance:result.taskInstance,
     572                                                    'scheduledTaskTypes': scheduledTaskTypes,
     573                                                    'scheduledTaskPriorities': scheduledTaskPriorities.list])
    543574    }
    544575
     
    591622
    592623    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     624    def createUnscheduled = {
     625        def taskInstance = new Task()
     626
     627        // Default leadPerson to current user, unless supplied in params.
     628        taskInstance.leadPerson = authService.currentUser
     629        taskInstance.properties = params
     630
     631        // Always for Unscheduled task.
     632        taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin.
     633        def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities
     634        taskInstance.taskPriority = unscheduledTaskPriorities.default
     635
     636        return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]
     637    }
     638
     639    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     640    def saveUnscheduled = {
     641        def result = taskService.saveUnscheduled(params)
     642
     643        if(!result.error) {
     644            flash.message = "Task ${result.taskInstance.id} created."
     645            redirect(action: 'show', id: result.taskInstance.id)
     646            return
     647        }
     648
     649        if(result.error.code == "task.modifications.failedToSave")
     650            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     651
     652        def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities
     653
     654        render(view:'createUnscheduled',
     655                    model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list])
     656    }
     657
     658    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    593659    def createImmediateCallout = {
    594660        def taskInstance = new Task()
  • trunk/grails-app/services/CreateDataService.groovy

    r431 r433  
    702702        def taskPriorityInstance
    703703
    704         taskPriorityInstance = new TaskPriority(name:"Normal") // #1
     704        taskPriorityInstance = new TaskPriority(name:"0 - Immediate") // #1
    705705        saveAndTest(taskPriorityInstance)
    706706
    707         taskPriorityInstance = new TaskPriority(name:"Low") // #2
     707        taskPriorityInstance = new TaskPriority(name:"1 - Very High") // #2
    708708        saveAndTest(taskPriorityInstance)
    709709
    710         taskPriorityInstance = new TaskPriority(name:"High") // #3
     710        taskPriorityInstance = new TaskPriority(name:"2 - High") // #3
    711711        saveAndTest(taskPriorityInstance)
    712712
    713         taskPriorityInstance = new TaskPriority(name:"Immediate") // #4
     713        taskPriorityInstance = new TaskPriority(name:"3 - Normal") // #4
     714        saveAndTest(taskPriorityInstance)
     715
     716        taskPriorityInstance = new TaskPriority(name:"4 - Low") // #5
     717        saveAndTest(taskPriorityInstance)
     718
     719        taskPriorityInstance = new TaskPriority(name:"5 - Minor") //  #6
    714720        saveAndTest(taskPriorityInstance)
    715721    }
  • trunk/grails-app/services/TaskService.groovy

    r432 r433  
    2929
    3030    /**
     31    * Determines and returns a list of possible task types for scheduled tasks.
     32    * @returns A list of the possible task types.
     33    */
     34    def getScheduledTaskTypes() {
     35        def criteria = TaskType.createCriteria()
     36        def scheduledTaskTypes = criteria {
     37            and {
     38                eq('isActive', true)
     39                gt('id', 2L)
     40                }
     41        }
     42    }
     43
     44    /**
     45    * Determines and returns a list of possible task priorites for Scheduled tasks.
     46    * @returns A list of the possible task priorites.
     47    */
     48    def getScheduledTaskPriorities() {
     49        def criteria = TaskPriority.createCriteria()
     50        def scheduledTaskPriorities = [:]
     51        scheduledTaskPriorities.list = criteria {
     52            and {
     53                eq('isActive', true)
     54                gt('id', 1L)
     55                }
     56        }
     57        scheduledTaskPriorities.default = scheduledTaskPriorities.list.find { it.id == 4L } //  1-Normal.
     58        return scheduledTaskPriorities
     59    }
     60
     61    /**
     62    * Determines and returns a list of possible task priorites for Unscheduled tasks.
     63    * @returns A map containing a list of the possible task priorites and the default priority.
     64    */
     65    def getUnscheduledTaskPriorities() {
     66        def criteria = TaskPriority.createCriteria()
     67        def unscheduledTaskPriorities = [:]
     68        unscheduledTaskPriorities.list = criteria {
     69            and {
     70                eq('isActive', true)
     71                lt('id', 5L)
     72                ne('id', 1L)
     73            }
     74        }
     75        unscheduledTaskPriorities.default = unscheduledTaskPriorities.list.find { it.id == 3L } // 2-High.
     76        return unscheduledTaskPriorities
     77    }
     78
     79    /**
    3180    * Creates a new task with the given params.
    3281    * @param params The params to use when creating the new task.
     
    646695
    647696    /**
     697    * Creates a new unscheduled breakin task with the given params.
     698    * @param params The params to use when creating the new task.
     699    * @returns A map containing result.error (if any error) and result.taskInstance.
     700    */
     701    def saveUnscheduled(params) {
     702        Task.withTransaction { status ->
     703            def result = [:]
     704
     705            def fail = { Map m ->
     706                status.setRollbackOnly()
     707                if(result.taskInstance && m.field)
     708                    result.taskInstance.errors.rejectValue(m.field, m.code)
     709                result.error = [ code: m.code, args: ["Task", params.id] ]
     710                return result
     711            }
     712
     713            // If not supplied.
     714            if(!params.taskStatus)
     715                params.taskStatus = TaskStatus.get(1) // Not Started.
     716
     717            result.taskInstance = new Task(params)
     718
     719            // Always for an unscheduled breakin..
     720            result.taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin.
     721            result.taskInstance.taskBudgetStatus = TaskBudgetStatus.get(1) // Unplanned.
     722
     723            if(result.taskInstance.hasErrors() || !result.taskInstance.save())
     724                fail(code:"default.create.failure")
     725
     726            if(!result.error) {
     727                def taskModification = new TaskModification(person: authService.currentUser,
     728                                                                taskModificationType: TaskModificationType.get(1), // Created.
     729                                                                task: result.taskInstance)
     730
     731                if(taskModification.hasErrors() || !taskModification.save())
     732                    fail(field:"taskModifications", code:"task.modifications.failedToSave")
     733            }
     734
     735            // Success.
     736            return result
     737
     738        } //end withTransaction
     739    } // end saveUnscheduled()
     740
     741    /**
    648742    * Creates a new immediate callout task with the given params.
    649743    * @param params The params to use when creating the new task.
     
    671765            result.taskInstance.taskType = TaskType.get(1) // Immediate Callout.
    672766            result.taskInstance.taskBudgetStatus = TaskBudgetStatus.get(1) // Unplanned.
    673             result.taskInstance.taskPriority = TaskPriority.get(4) // Immediate.
     767            result.taskInstance.taskPriority = TaskPriority.get(1) // Immediate.
    674768            result.taskInstance.taskGroup = TaskGroup.get(1) // Engineering Activites.
    675769            result.taskInstance.approved = true
  • trunk/grails-app/views/taskDetailed/create.gsp

    r313 r433  
    104104                                </td>
    105105                                <td valign="top" class="value ${hasErrors(bean:taskInstance,field:'taskPriority','errors')}">
    106                                     <g:select optionKey="id" from="${TaskPriority.list()}" name="taskPriority.id" value="${taskInstance?.taskPriority?.id}" ></g:select>
     106                                    <g:select optionKey="id" from="${scheduledTaskPriorities}" name="taskPriority.id" value="${taskInstance?.taskPriority?.id}" ></g:select>
    107107                                </td>
    108108                            </tr>
     
    140140                                </td>
    141141                                <td valign="top" class="value ${hasErrors(bean:taskInstance,field:'taskType','errors')}">
    142                                     <g:select optionKey="id" from="${TaskType.list()}" name="taskType.id" value="${taskInstance?.taskType?.id}" ></g:select>
     142                                    <g:select optionKey="id" from="${scheduledTaskTypes}" name="taskType.id" value="${taskInstance?.taskType?.id}" ></g:select>
    143143                                </td>
    144144                            </tr>
Note: See TracChangeset for help on using the changeset viewer.