Changeset 136 for trunk/grails-app/domain
- Timestamp:
- May 15, 2009, 4:09:30 PM (16 years ago)
- Location:
- trunk/grails-app/domain
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/Period.groovy
r131 r136 5 5 6 6 static hasMany = [taskRecurringSchedules: TaskRecurringSchedule] 7 // 7 8 static mappedBy = [taskRecurringSchedules:"recurPeriod"] 9 8 10 // static belongsTo = [] 9 // 11 10 12 // static constraints = { 11 13 // -
trunk/grails-app/domain/TaskRecurringSchedule.groovy
r135 r136 1 import org.codehaus.groovy.runtime.TimeCategory 2 1 3 class TaskRecurringSchedule { 2 4 3 5 Task lastGeneratedSubTask 4 Period period 6 Period recurPeriod 7 Period generateAheadPeriod 8 Period taskDurationPeriod 5 9 6 10 Integer recurEvery = 1 11 Integer taskDuration = 0 12 Integer generateAhead = 1 7 13 Date startDate = new Date() 8 14 Date lastGeneratedDate 9 Date nextDueDate 15 Date nextTargetStartDate = new Date() 16 Date nextTargetCompletionDate = new Date() 17 Date nextGenerationDate = new Date() 10 18 boolean isEnabled = true 11 19 … … 15 23 16 24 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) 17 29 lastGeneratedDate(blank:true, nullable:true) 18 30 lastGeneratedSubTask(blank:true, nullable:true) … … 20 32 21 33 String toString() { 22 "Recur every ${recurEvery} ${ period}"34 "Recur every ${recurEvery} ${recurPeriod}" 23 35 } 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 24 100 } 25 101
Note: See TracChangeset
for help on using the changeset viewer.