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/services
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.