Ignore:
Timestamp:
May 15, 2009, 4:09:30 PM (16 years ago)
Author:
gav
Message:

Work on TaskRecurringSchedule?.

Location:
trunk/grails-app/domain
Files:
2 edited

Legend:

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

    r131 r136  
    55
    66    static hasMany = [taskRecurringSchedules: TaskRecurringSchedule]
    7 //
     7   
     8    static mappedBy = [taskRecurringSchedules:"recurPeriod"]
     9
    810//     static belongsTo = []
    9 //
     11
    1012//     static constraints = {
    1113//
  • trunk/grails-app/domain/TaskRecurringSchedule.groovy

    r135 r136  
     1import org.codehaus.groovy.runtime.TimeCategory
     2
    13class TaskRecurringSchedule {
    24
    35    Task lastGeneratedSubTask
    4     Period period
     6    Period recurPeriod
     7    Period generateAheadPeriod
     8    Period taskDurationPeriod
    59
    610    Integer recurEvery = 1
     11    Integer taskDuration = 0
     12    Integer generateAhead = 1
    713    Date startDate = new Date()
    814    Date lastGeneratedDate
    9     Date nextDueDate
     15    Date nextTargetStartDate = new Date()
     16    Date nextTargetCompletionDate = new Date()
     17    Date nextGenerationDate = new Date()
    1018    boolean isEnabled = true
    1119
     
    1523
    1624    static constraints = {
     25//              startDate(validator: {return (it > new Date())})
     26        recurEvery(min:0, max:365)
     27        taskDuration(min:0, max:365)
     28        generateAhead(min:0, max:365)
    1729        lastGeneratedDate(blank:true, nullable:true)
    1830        lastGeneratedSubTask(blank:true, nullable:true)
     
    2032
    2133    String toString() {
    22         "Recur every ${recurEvery} ${period}"
     34        "Recur every ${recurEvery} ${recurPeriod}"
    2335    }
     36   
     37    //As of Grails 1.1 this does not fire/pass before validation.
     38    //But setting defaults above and placing this code here in the hope that this will be fixed in future versions.
     39    def beforeInsert = {
     40        def now = new Date()
     41       
     42        nextTargetStartDate = startDate
     43       
     44        //nextGenerationDate
     45        switch (generateAheadPeriod.period) {
     46            case "Day(s)":
     47                use(TimeCategory) {
     48                    nextGenerationDate = nextTargetStartDate - generateAhead.days
     49                }
     50                break
     51            case "Week(s)":
     52                use(TimeCategory) {
     53                    nextGenerationDate = nextTargetStartDate - generateAhead.weeks
     54                }
     55                break
     56            case "Month(s)":
     57                use(TimeCategory) {
     58                    nextGenerationDate = nextTargetStartDate - generateAhead.months
     59                }
     60                break
     61            case "Year(s)":
     62                use(TimeCategory) {
     63                    nextGenerationDate = nextTargetStartDate - generateAhead.years
     64                }
     65                break
     66        default:
     67                break
     68        }
     69       
     70        if( nextGenerationDate < now) {nextGenerationDate = now}
     71       
     72        //nextTargetCompletionDate
     73        switch (taskDurationPeriod.period) {
     74            case "Day(s)":
     75                use(TimeCategory) {
     76                    nextTargetCompletionDate = nextTargetStartDate + taskDuration.days
     77                }
     78                break
     79            case "Week(s)":
     80                use(TimeCategory) {
     81                    nextTargetCompletionDate = nextTargetStartDate + taskDuration.weeks
     82                }
     83                break
     84            case "Month(s)":
     85                use(TimeCategory) {
     86                    nextTargetCompletionDate = nextTargetStartDate + taskDuration.months
     87                }
     88                break
     89            case "Year(s)":
     90                use(TimeCategory) {
     91                    nextTargetCompletionDate = nextTargetStartDate + taskDuration.years
     92                }
     93                break
     94        default:
     95                break
     96        }
     97       
     98    }
     99
    24100}
    25101
Note: See TracChangeset for help on using the changeset viewer.