Changeset 445


Ignore:
Timestamp:
Mar 16, 2010, 5:18:20 PM (14 years ago)
Author:
gav
Message:

Add maxSubTasks and useTargetCompletionDate to TaskRecurringSchedule as features to end subTask generation.

Location:
trunk/grails-app
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/TaskRecurringSchedule.groovy

    r210 r445  
    1212    Integer generateAhead = 1
    1313    Integer subTasksGenerated = 0
     14    Integer maxSubTasks = 0
    1415    Date nextGenerationDate = new Date()
    15     Date nextTargetStartDate = new Date()
     16    Date nextTargetStartDate = new Date()+1
    1617    Date nextTargetCompletionDate = new Date()
    1718    boolean enabled = true
     19    boolean useTargetCompletionDate = false
    1820
    1921//     static hasMany = []
  • trunk/grails-app/i18n/messages.properties

    r440 r445  
    129129taskRecurringSchedule.generateAhead=Generate Ahead
    130130taskRecurringSchedule.generateAhead.help=How far ahead of the next target start date to generate sub tasks. \
    131 This allows work packs to be built and work load to be seen and planned. \
    132 Only generate ahead as far as short term planning is done, since all generated sub task values will be set and therefore \
    133 time consuming to change.
     131    This allows work packs to be built and work load to be seen and planned. \
     132    Only generate ahead as far as short term planning is done, since all generated sub task \
     133    values will be set and therefore time consuming to change.
     134taskRecurringSchedule.maxSubTasks=Max Sub Tasks
     135taskRecurringSchedule.maxSubTasks.help=Maximum number of sub tasks to generate. Set to 0 \
     136    for no limit.
     137taskRecurringSchedule.useTargetCompletionDate=Target Completion
     138taskRecurringSchedule.useTargetCompletionDate.help=On to use the parent task's target completion date. \
     139    Off to continue generation past the parent task's target completion date.
    134140taskRecurringSchedule.enabled=Enabled
    135 taskRecurringSchedule.enabled.help=On to enable automatic sub task generation. Off to stop automatic sub task generation.
     141taskRecurringSchedule.enabled.help=On to enable automatic sub task generation. \
     142    Off to stop automatic sub task generation. <br /><br />\
     143    The system will turn this off if there are no further sub tasks to be generated.
    136144
    137145task.primaryAsset=Primary Asset
  • trunk/grails-app/services/TaskRecurringScheduleService.groovy

    r434 r445  
    1515    def generateAll() {
    1616
    17         def taskRecurringScheduleList = TaskRecurringSchedule.findAllByEnabled(true)
    18 
    1917        // Prevent errors if base data has not yet been created.
    2018        if(!appConfigService.exists("baseDataCreated")) {
     
    2624        }
    2725
    28         taskRecurringScheduleList.each() {
     26        def p = [:]
     27        def targetCompletionDate
     28        def nextTargetCompletionDate
     29        def tomorrow = dateUtilService.tomorrow
     30
     31        def taskRecurringScheduleList = TaskRecurringSchedule.findAllByEnabled(true)
     32
     33        // Stop generation if max reached.
     34        def maxSubTasksReached = {
     35            if( (it.maxSubTasks > 0) && (it.subTasksGenerated >= it.maxSubTasks) ) {
     36                it.enabled = false
     37                return true
     38            }
     39            return false
     40        }
     41
     42        // Stop generation by targetCompletionDate.
     43        def targetCompletionDateReached = {
     44            if( it.useTargetCompletionDate) {
     45                targetCompletionDate = dateUtilService.getMidnight(it.task.targetCompletionDate)
     46                nextTargetCompletionDate = dateUtilService.getMidnight(it.nextTargetCompletionDate)
     47                if(nextTargetCompletionDate > targetCompletionDate) {
     48                    it.enabled = false
     49                    return true
     50                }
     51            }
     52            return false
     53        }
     54
     55        // Main loop.
     56        for(it in taskRecurringScheduleList) {
     57
     58            if(maxSubTasksReached(it))
     59                continue
     60
     61            if(targetCompletionDateReached(it))
     62                continue
    2963
    3064            if (dateUtilService.tomorrow > it.nextGenerationDate) {
    31                     def p = [:]
     65                p = [:]
    3266
    33                     // Build the required params.
    34                     p.targetStartDate = it.nextTargetStartDate
    35                     p.targetCompletionDate = it.nextTargetCompletionDate
    36                     if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure
    37                     if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups)
    38                     if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons)
     67                // Build the subTask params.
     68                p.targetStartDate = it.nextTargetStartDate
     69                p.targetCompletionDate = it.nextTargetCompletionDate
     70                if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure
     71                if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups)
     72                if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons)
    3973
    40                     def result = taskService.createSubTask(it.task, p)
    41                     if( !result.error ) {
    42                         it.lastGeneratedSubTask = result.taskInstance
    43                         it.subTasksGenerated++
    44                         it.setNextTargetStartDate()
    45                         it.setNextGenerationDate()
    46                         it.setNextTargetCompletionDate()
    47                     }
    48                     else {
    49                         log.error "Sub task generation for recurring schedule ${it.id} failed."
    50                         log.error result.taskInstance.errors
    51                     }
     74                def result = taskService.createSubTask(it.task, p)
     75                if( !result.error ) {
     76                    it.lastGeneratedSubTask = result.taskInstance
     77                    it.subTasksGenerated++
     78                    it.setNextTargetStartDate()
     79                    it.setNextGenerationDate()
     80                    it.setNextTargetCompletionDate()
     81                }
     82                else {
     83                    log.error "Sub task generation for recurring schedule ${it.id} failed."
     84                    log.error result.taskInstance.errors
     85                }
    5286            }
    5387
    54         }
    55     }
     88            // Run the completion reached checks for a second time so
     89            // that this recurring schedule does not run again if
     90            // there are no more subTasks to be generated.
     91            if(maxSubTasksReached(it))
     92                continue
     93
     94            if(targetCompletionDateReached(it))
     95                continue
     96
     97        } // for()
     98    } // generateAll()
    5699
    57100    /**
  • trunk/grails-app/views/taskDetailed/show.gsp

    r431 r445  
    561561
    562562                                        <tr class="prop">
     563                                            <td valign="top" class="name">Enabled:</td>
     564
     565                                            <td valign="top" class="value">${fieldValue(bean:taskRecurringScheduleInstance, field:'enabled')}</td>
     566                                        </tr>
     567
     568                                        <tr class="prop">
    563569                                            <td valign="top" class="name">Next Generation Date:</td>
    564570
     
    598604                                                <g:formatDate date="${taskRecurringScheduleInstance.nextTargetCompletionDate}" format="EEE, dd-MMM-yyyy"/>
    599605                                            </td>
    600                                         </tr>
    601 
    602                                         <tr class="prop">
    603                                             <td valign="top" class="name">Enabled:</td>
    604 
    605                                             <td valign="top" class="value">${fieldValue(bean:taskRecurringScheduleInstance, field:'enabled')}</td>
    606606                                        </tr>
    607607
  • trunk/grails-app/views/taskRecurringScheduleDetailed/create.gsp

    r213 r445  
    8181                                </td>
    8282                            </tr>
     83                     
     84                            <tr class="prop">
     85                                <td valign="top" class="name">
     86                                    <label for="maxSubTasks">Max Sub Tasks:</label>
     87                                </td>
     88                                <td valign="top" class="value" >
     89                                    <input type="text" class="time ${hasErrors(bean:taskRecurringScheduleInstance,field:'maxSubTasks','errors')}"
     90                                        id="maxSubTasks" name="maxSubTasks" value="${fieldValue(bean:taskRecurringScheduleInstance,field:'maxSubTasks')}" />
     91                                        <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.maxSubTasks" />
     92                                </td>
     93                            </tr>
     94                       
     95                            <tr class="prop">
     96                                <td valign="top" class="name">
     97                                    <label for="useTargetCompletionDate">Use Target Completion Date:</label>
     98                                </td>
     99                                <td valign="top" class="value ${hasErrors(bean:taskRecurringScheduleInstance,field:'useTargetCompletionDate','errors')}">
     100                                    <g:checkBox name="useTargetCompletionDate"
     101                                                            value="${taskRecurringScheduleInstance?.useTargetCompletionDate}" >
     102                                    </g:checkBox>
     103                                    <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.useTargetCompletionDate" />
     104                                    <g:formatDate date="${taskRecurringScheduleInstance.task.targetCompletionDate}"
     105                                                                    format="EEE, dd-MMM-yyyy"/>
     106                                </td>
     107                            </tr>
    83108                       
    84109                            <tr class="prop">
  • trunk/grails-app/views/taskRecurringScheduleDetailed/edit.gsp

    r213 r445  
    3434                                <td valign="top" name="recForTask" class="value">
    3535                                    <g:link controller="taskDetailed" action="show" id="${taskRecurringScheduleInstance?.task?.id}">${taskRecurringScheduleInstance?.task?.encodeAsHTML()}</g:link>
     36                                </td>
     37                            </tr>
     38                       
     39                            <tr class="prop">
     40                                <td valign="top" class="name">
     41                                    <label for="enabled">Enabled:</label>
     42                                </td>
     43                                <td valign="top" class="value ${hasErrors(bean:taskRecurringScheduleInstance,field:'enabled','errors')}">
     44                                    <g:checkBox name="enabled" value="${taskRecurringScheduleInstance?.enabled}" ></g:checkBox>
     45                                        <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.enabled" />
    3646                                </td>
    3747                            </tr>
     
    8292                                </td>
    8393                            </tr>
     94                     
     95                            <tr class="prop">
     96                                <td valign="top" class="name">
     97                                    <label for="maxSubTasks">Max Sub Tasks:</label>
     98                                </td>
     99                                <td valign="top" class="value" >
     100                                    <input type="text" class="time ${hasErrors(bean:taskRecurringScheduleInstance,field:'maxSubTasks','errors')}"
     101                                        id="maxSubTasks" name="maxSubTasks" value="${fieldValue(bean:taskRecurringScheduleInstance,field:'maxSubTasks')}" />
     102                                        <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.maxSubTasks" />
     103                                </td>
     104                            </tr>
    84105                       
    85106                            <tr class="prop">
    86107                                <td valign="top" class="name">
    87                                     <label for="enabled">Enabled:</label>
     108                                    <label for="useTargetCompletionDate">Use Target Completion Date:</label>
    88109                                </td>
    89                                 <td valign="top" class="value ${hasErrors(bean:taskRecurringScheduleInstance,field:'enabled','errors')}">
    90                                     <g:checkBox name="enabled" value="${taskRecurringScheduleInstance?.enabled}" ></g:checkBox>
    91                                         <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.enabled" />
     110                                <td valign="top" class="value ${hasErrors(bean:taskRecurringScheduleInstance,field:'useTargetCompletionDate','errors')}">
     111                                    <g:checkBox name="useTargetCompletionDate"
     112                                                                value="${taskRecurringScheduleInstance?.useTargetCompletionDate}" >
     113                                    </g:checkBox>
     114                                    <g:helpBalloon class="helpballoon" code="taskRecurringSchedule.useTargetCompletionDate" />
     115                                    <g:formatDate date="${taskRecurringScheduleInstance.task.targetCompletionDate}"
     116                                                                    format="EEE, dd-MMM-yyyy"/>
    92117                                </td>
    93118                            </tr>
  • trunk/grails-app/views/taskRecurringScheduleDetailed/show.gsp

    r199 r445  
    3333                            <td valign="top" class="value">${taskRecurringScheduleInstance.encodeAsHTML()}</td>
    3434                        </tr>
     35
     36                        <tr class="prop">
     37                            <td valign="top" class="name">Enabled:</td>
     38
     39                            <td valign="top" class="value">${fieldValue(bean:taskRecurringScheduleInstance, field:'enabled')}</td>
     40                        </tr>
     41
     42                        <g:if test="${taskRecurringScheduleInstance.useTargetCompletionDate}" >
     43                            <tr class="prop">
     44                                <td valign="top" class="name">Task Target Completion:</td>
     45
     46                                <td valign="top" class="value">
     47                                    <g:formatDate date="${taskRecurringScheduleInstance.task.targetCompletionDate}"
     48                                                                    format="EEE, dd-MMM-yyyy"/>
     49                                </td>
     50                            </tr>
     51                        </g:if>
    3552
    3653                        <tr class="prop">
     
    7491                        </tr>
    7592
    76                         <tr class="prop">
    77                             <td valign="top" class="name">Enabled:</td>
    78 
    79                             <td valign="top" class="value">${fieldValue(bean:taskRecurringScheduleInstance, field:'enabled')}</td>
    80                         </tr>
    81 
    8293                    </tbody>
    8394                </table>
     
    100111                            </td>
    101112                        </tr>
     113
     114                        <g:if test="${taskRecurringScheduleInstance.maxSubTasks > 0}" >
     115                            <tr class="prop">
     116                                <td valign="top" class="name">Max Sub Tasks:</td>
     117
     118                                <td valign="top" class="value">
     119                                    ${fieldValue(bean:taskRecurringScheduleInstance, field:'maxSubTasks')}
     120                                </td>
     121                            </tr>
     122                        </g:if>
    102123
    103124                        <g:if test="${taskRecurringScheduleInstance.lastGeneratedSubTask}">
Note: See TracChangeset for help on using the changeset viewer.