Changeset 503 for trunk/grails-app/services
- Timestamp:
- Apr 20, 2010, 3:56:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/TaskSearchService.groovy
r490 r503 23 23 def getQuickSearch(params, locale) { 24 24 def result = [:] 25 result.quickSearch = params.quickSearch ?: "plannersRange" 26 25 27 def currentUser = authService.currentUser 26 result.quickSearch = params.quickSearch ?: "searchPlannersRange" 28 def startOfToday = dateUtilService.today 29 def startOfYesterday = dateUtilService.yesterday 30 def startOfTomorrow = dateUtilService.tomorrow 31 def oneWeekAgo = dateUtilService.oneWeekAgo 32 33 def formattedStartOfToday = g.formatDate(format: "EEE, dd-MMM-yyyy", date: startOfToday) 34 def formattedStartOfYesterday = g.formatDate(format: "EEE, dd-MMM-yyyy", date: startOfYesterday) 35 def formattedStartOfTomorrow = g.formatDate(format: "EEE, dd-MMM-yyyy", date: startOfTomorrow) 36 def formattedOneWeekAgo = g.formatDate(format: "EEE, dd-MMM-yyyy", date: oneWeekAgo) 27 37 28 38 def getMessage = { Map m -> … … 32 42 switch (result.quickSearch) { 33 43 case "myTodays": 34 result.taskInstanceList = getMyTodays(params) 35 if(result.taskInstanceList.totalCount > 0) 36 result.message = getMessage(code:"task.search.text.my.todays", args:[currentUser]) 37 else 38 result.message = getMessage(code:"task.search.text.my.todays.none.found", args:[currentUser]) 44 result.taskInstanceList = getPersonsTasks(params) 45 if(result.taskInstanceList.totalCount > 0) 46 result.message = getMessage(code:"task.search.text.persons.tasks.message", 47 args:[currentUser, formattedStartOfToday]) 48 else 49 result.message = getMessage(code:"task.search.text.persons.tasks.none.found", 50 args:[currentUser, formattedStartOfToday]) 39 51 break 40 52 case "myYesterdays": 41 result.taskInstanceList = getMyTodays(params, -1) 42 if(result.taskInstanceList.totalCount > 0) 43 result.message = getMessage(code:"task.search.text.my.yesterdays", args:[currentUser]) 44 else 45 result.message = getMessage(code:"task.search.text.my.yesterdays.none.found", args:[currentUser]) 53 result.taskInstanceList = getPersonsTasks(params, currentUser, startOfYesterday, startOfToday) 54 if(result.taskInstanceList.totalCount > 0) 55 result.message = getMessage(code:"task.search.text.persons.tasks.message", 56 args:[currentUser, formattedStartOfYesterday]) 57 else 58 result.message = getMessage(code:"task.search.text.persons.tasks.none.found", 59 args:[currentUser, formattedStartOfYesterday]) 46 60 break 47 61 case "myTomorrows": 48 result.taskInstanceList = getMyTodays(params, 1) 49 if(result.taskInstanceList.totalCount > 0) 50 result.message = getMessage(code:"task.search.text.my.tomorrows", args:[currentUser]) 51 else 52 result.message = getMessage(code:"task.search.text.my.tomorrows.none.found", args:[currentUser]) 62 result.taskInstanceList = getPersonsTasks(params, currentUser, startOfTomorrow, startOfTomorrow+1) 63 if(result.taskInstanceList.totalCount > 0) 64 result.message = getMessage(code:"task.search.text.persons.tasks.message", 65 args:[currentUser, formattedStartOfTomorrow]) 66 else 67 result.message = getMessage(code:"task.search.text.persons.tasks.none.found", 68 args:[currentUser, formattedStartOfTomorrow]) 53 69 break 54 70 case "myPastWeek": 55 result.taskInstanceList = getMyPastWeek(params) 56 if(result.taskInstanceList.totalCount > 0) 57 result.message = getMessage(code:"task.search.text.my.past.week", args:[currentUser]) 58 else 59 result.message = getMessage(code:"task.search.text.my.past.week.none.found", args:[currentUser]) 71 result.taskInstanceList = getPersonsTasks(params, currentUser, oneWeekAgo, startOfTomorrow) 72 if(result.taskInstanceList.totalCount > 0) 73 result.message = getMessage(code:"task.search.text.persons.tasks.between.message", 74 args:[currentUser, formattedOneWeekAgo, formattedStartOfToday]) 75 else 76 result.message = getMessage(code:"task.search.text.persons.tasks.between.none.found", 77 args:[currentUser, formattedOneWeekAgo, formattedStartOfToday]) 60 78 break 61 79 case "todays": 62 result.taskInstanceList = getTodays(params) 63 if(result.taskInstanceList.totalCount > 0) 64 result.message = getMessage(code:"task.search.text.todays") 65 else 66 result.message = getMessage(code:"task.search.text.todays.none.found") 80 result.taskInstanceList = getTasks(params) 81 if(result.taskInstanceList.totalCount > 0) 82 result.message = getMessage(code:"task.search.text.all.tasks.message", 83 args:[formattedStartOfToday]) 84 else 85 result.message = getMessage(code:"task.search.text.all.tasks.none.found", 86 args:[formattedStartOfToday]) 67 87 break 68 88 case "yesterdays": 69 result.taskInstanceList = getTodays(params, -1) 70 if(result.taskInstanceList.totalCount > 0) 71 result.message = getMessage(code:"task.search.text.yesterdays") 72 else 73 result.message = getMessage(code:"task.search.text.yesterdays.none.found") 89 result.taskInstanceList = getTasks(params, startOfYesterday, startOfToday) 90 if(result.taskInstanceList.totalCount > 0) 91 result.message = getMessage(code:"task.search.text.all.tasks.message", 92 args:[formattedStartOfYesterday]) 93 else 94 result.message = getMessage(code:"task.search.text.all.tasks.none.found", 95 args:[formattedStartOfYesterday]) 74 96 break 75 97 case "tomorrows": 76 result.taskInstanceList = getTodays(params, 1) 77 if(result.taskInstanceList.totalCount > 0) 78 result.message = getMessage(code:"task.search.text.tomorrows") 79 else 80 result.message = getMessage(code:"task.search.text.tomorrows.none.found") 98 result.taskInstanceList = getTasks(params, startOfTomorrow, startOfTomorrow+1) 99 if(result.taskInstanceList.totalCount > 0) 100 result.message = getMessage(code:"task.search.text.all.tasks.message", 101 args:[formattedStartOfTomorrow]) 102 else 103 result.message = getMessage(code:"task.search.text.all.tasks.none.found", 104 args:[formattedStartOfTomorrow]) 81 105 break 82 106 case "pastWeek": 83 result.taskInstanceList = getPastWeek(params) 84 if(result.taskInstanceList.totalCount > 0) 85 result.message = getMessage(code:"task.search.text.past.week") 86 else 87 result.message = getMessage(code:"task.search.text.past.week.none.found") 107 result.taskInstanceList = getTasks(params, oneWeekAgo, startOfTomorrow) 108 if(result.taskInstanceList.totalCount > 0) 109 result.message = getMessage(code:"task.search.text.all.tasks.between.message", 110 args:[formattedOneWeekAgo, formattedStartOfToday]) 111 else 112 result.message = getMessage(code:"task.search.text.all.tasks.between.none.found", 113 args:[formattedOneWeekAgo, formattedStartOfToday]) 88 114 break 89 115 case "budgetUnplanned": 90 result.taskInstanceList = getBudgetUnplanned(params) 91 if(result.taskInstanceList.totalCount > 0) 92 result.message = getMessage(code:"task.search.text.budget.unplanned") 93 else 94 result.message = getMessage(code:"task.search.text.budget.unplanned.none.found") 116 result.taskInstanceList = getBudgetTasks(params, TaskBudgetStatus.read(1), oneWeekAgo, startOfTomorrow) 117 if(result.taskInstanceList.totalCount > 0) 118 result.message = getMessage(code:"task.search.text.budget.unplanned.message", 119 args:[formattedOneWeekAgo, formattedStartOfToday]) 120 else 121 result.message = getMessage(code:"task.search.text.budget.unplanned.none.found", 122 args:[formattedOneWeekAgo, formattedStartOfToday]) 95 123 break 96 124 case "budgetPlanned": 97 result.taskInstanceList = getBudgetPlanned(params) 98 if(result.taskInstanceList.totalCount > 0) 99 result.message = getMessage(code:"task.search.text.budget.planned") 100 else 101 result.message = getMessage(code:"task.search.text.budget.planned.none.found") 125 result.taskInstanceList = getBudgetTasks(params, TaskBudgetStatus.read(2), oneWeekAgo, startOfTomorrow) 126 if(result.taskInstanceList.totalCount > 0) 127 result.message = getMessage(code:"task.search.text.budget.planned.message", 128 args:[formattedOneWeekAgo, formattedStartOfToday]) 129 else 130 result.message = getMessage(code:"task.search.text.budget.planned.none.found", 131 args:[formattedOneWeekAgo, formattedStartOfToday]) 102 132 break 103 133 default: 104 result.taskInstanceList = getPlannersRange(params) 105 if(result.taskInstanceList.totalCount > 0) 106 result.message = getMessage(code:"task.search.text.planners.range") 107 else 108 result.message = getMessage(code:"task.search.text.planners.range.none.found") 134 //case "plannersRange": 135 result.taskInstanceList = getTasks(params, oneWeekAgo, startOfToday+15) 136 if(result.taskInstanceList.totalCount > 0) 137 result.message = getMessage(code:"task.search.text.all.tasks.between.message", 138 args:[formattedOneWeekAgo, 139 g.formatDate(format: "EEE, dd-MMM-yyyy", date: startOfToday+14)]) 140 else 141 result.message = getMessage(code:"task.search.text.all.tasks.between.none.found", 142 args:[formattedOneWeekAgo, 143 g.formatDate(format: "EEE, dd-MMM-yyyy", date: startOfToday+14)]) 109 144 break 110 145 } // switch. … … 116 151 117 152 /** 118 * Get all tasks that are not in the trash , by default today's tasks.153 * Get all tasks that are not in the trash bin, by default today's tasks. 119 154 * @param params The request params. 120 * @param dayAdjustment The number of days to adjust from today, defaults to 0. 121 */ 122 def getTodays(params, dayAdjustment=0) { 155 * @param startDate The start date to get tasks for, defaults to the start of today and is inclusive (greater than or equal to). 156 * @param endDate The end date to get tasks for, defaults to the start of tomorrow and is exclusive (less than). 157 */ 158 def getTasks(params, startDate=null, endDate=null) { 123 159 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 124 160 params.offset = params?.offset?.toInteger() ?: 0 125 161 params.sort = params?.sort ?: "attentionFlag" 126 162 params.order = params?.order ?: "desc" 163 164 startDate = startDate ?: dateUtilService.today 165 endDate = endDate ?: dateUtilService.tomorrow 127 166 128 167 def taskInstanceList = Task.createCriteria().list( … … 131 170 sort: params.sort, 132 171 order: params.order) { 133 lt("targetStartDate", dateUtilService.tomorrow+dayAdjustment)134 ge("targetCompletionDate", dateUtilService.today+dayAdjustment)172 lt("targetStartDate", endDate) 173 ge("targetCompletionDate", startDate) 135 174 eq("trash", false) 136 175 } // createCriteria 137 } 138 139 /** 140 * Get current user's tasks, by defaulttoday's tasks.141 * " Approved tasks where I am the lead or have been assigned"176 } // getTasks() 177 178 /** 179 * Get a person's tasks, by default current user and today's tasks. 180 * "My tasks and approved tasks that I am assigned to" 142 181 * @param params The request params. 143 * @param dayAdjustment The number of days to adjust from today, defaults to 0. 144 */ 145 def getMyTodays(params, dayAdjustment=0) { 182 * @param person The person to get tasks for, defaults to current user. 183 * @param startDate The start date to get tasks for, defaults to the start of today and is inclusive (greater than or equal to). 184 * @param endDate The end date to get tasks for, defaults to the start of tomorrow and is exclusive (less than). 185 */ 186 def getPersonsTasks(params, person=null, startDate=null, endDate=null) { 146 187 def paginateParams = [:] 147 188 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) … … 153 194 154 195 def namedParams = [:] 155 namedParams. currentUser =authService.currentUser156 namedParams.start OfDay = dateUtilService.today+dayAdjustment157 namedParams. startOfNextDay = dateUtilService.tomorrow+dayAdjustment196 namedParams.person = person ?: authService.currentUser 197 namedParams.startDate = startDate ?: dateUtilService.today 198 namedParams.endDate = endDate ?: dateUtilService.tomorrow 158 199 159 200 def baseQuery = "from Task as task \ … … 166 207 and task.approved = true \ 167 208 and ( \ 168 task.targetStartDate < : startOfNextDay\169 and task.targetCompletionDate >= :start OfDay\209 task.targetStartDate < :endDate \ 210 and task.targetCompletionDate >= :startDate \ 170 211 ) \ 171 212 and ( \ 172 task.leadPerson = : currentUser\173 or assignedPerson = : currentUser\174 or assignedPersonViaGroup = : currentUser\213 task.leadPerson = :person \ 214 or assignedPerson = :person \ 215 or assignedPersonViaGroup = :person \ 175 216 ) \ 176 217 )" … … 184 225 def taskInstanceList = new PagedResultList(list, totalCount) 185 226 return taskInstanceList 186 } // get MyTodays187 188 /** 189 * Get all tasks that are not in the trash, during the past week.227 } // getPersonsTasks() 228 229 /** 230 * Get tasks by budget status, by default planned in the last week. 190 231 * @param params The request params. 191 */ 192 def getPastWeek(params) { 193 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 194 params.offset = params?.offset?.toInteger() ?: 0 195 params.sort = params?.sort ?: "attentionFlag" 196 params.order = params?.order ?: "desc" 197 198 def taskInstanceList = Task.createCriteria().list( 199 max: params.max, 200 offset: params.offset, 201 sort: params.sort, 202 order: params.order) { 203 lt("targetStartDate", dateUtilService.tomorrow) 204 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 205 eq("trash", false) 206 } // createCriteria 207 } 208 209 /** 210 * Get current user's tasks in the past week. 211 * "Approved tasks where I am the lead or have been assigned" 212 * @param params The request params. 213 */ 214 def getMyPastWeek(params) { 215 def paginateParams = [:] 216 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 217 paginateParams.offset = params?.offset?.toInteger() ?: 0 218 219 def sort = "task." + (params?.sort ?: "attentionFlag") 220 def order = params?.order == "asc" ? "asc" : "desc" 221 def orderBy = " order by " + sort + ' ' + order 222 223 def namedParams = [:] 224 namedParams.currentUser = authService.currentUser 225 namedParams.startOfDay = dateUtilService.oneWeekAgo 226 namedParams.startOfNextDay = dateUtilService.tomorrow 227 228 def baseQuery = "from Task as task \ 229 left join task.assignedPersons as assignedPersonOfTask \ 230 left join assignedPersonOfTask.person as assignedPerson \ 231 left join task.assignedGroups as assignedGroupOfTask \ 232 left join assignedGroupOfTask.personGroup as personGroup \ 233 left join personGroup.persons as assignedPersonViaGroup \ 234 where (task.trash = false \ 235 and task.approved = true \ 236 and ( \ 237 task.targetStartDate < :startOfNextDay \ 238 and task.targetCompletionDate >= :startOfDay \ 239 ) \ 240 and ( \ 241 task.leadPerson = :currentUser \ 242 or assignedPerson = :currentUser \ 243 or assignedPersonViaGroup = :currentUser \ 244 ) \ 245 )" 246 247 def searchQuery = "select distinct task " + baseQuery + orderBy 248 def list = Task.executeQuery(searchQuery, namedParams, paginateParams) 249 250 def countQuery = "select count(distinct task) as taskCount " + baseQuery 251 def totalCount = Task.executeQuery(countQuery, namedParams)[0].toInteger() 252 253 def taskInstanceList = new PagedResultList(list, totalCount) 254 return taskInstanceList 255 } // getMyTodays 256 257 /** 258 * "Tasks with budget status of Planned, in the past week." 259 * @param params The request params. 260 */ 261 def getBudgetPlanned(params) { 232 * @param budgetStatus Defaults to planned. 233 * @param startDate The start date to get tasks for, defaults to the start of today and is inclusive (greater than or equal to). 234 * @param endDate The end date to get tasks for, defaults to the start of tomorrow and is exclusive (less than). 235 */ 236 def getBudgetTasks(params, budgetStatus=null, startDate=null, endDate=null) { 262 237 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 263 238 params.offset = params?.offset?.toInteger() ?: 0 264 239 params.sort = params?.sort ?: "targetStartDate" 265 240 params.order = params?.order ?: "asc" 241 242 budgetStatus = budgetStatus ?: TaskBudgetStatus.read(2) // Planned. 243 startDate = startDate ?: dateUtilService.today 244 endDate = endDate ?: dateUtilService.tomorrow 266 245 267 246 def taskInstanceList = Task.createCriteria().list( … … 270 249 sort: params.sort, 271 250 order: params.order) { 272 eq("taskBudgetStatus", TaskBudgetStatus.read(2))251 eq("taskBudgetStatus", budgetStatus) 273 252 lt("targetStartDate", dateUtilService.tomorrow) 274 253 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 275 254 eq("trash", false) 276 255 } // createCriteria 277 } 278 279 /** 280 * "Tasks with budget status of Unplanned, in the past week." 281 * @param params The request params. 282 */ 283 def getBudgetUnplanned(params) { 284 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 285 params.offset = params?.offset?.toInteger() ?: 0 286 params.sort = params?.sort ?: "targetStartDate" 287 params.order = params?.order ?: "asc" 288 289 def taskInstanceList = Task.createCriteria().list( 290 max: params.max, 291 offset: params.offset, 292 sort: params.sort, 293 order: params.order) { 294 eq("taskBudgetStatus", TaskBudgetStatus.read(1)) 295 lt("targetStartDate", dateUtilService.tomorrow) 296 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 297 eq("trash", false) 298 } // createCriteria 299 } 300 301 /** 302 * "Tasks in the past week and two weeks ahead." 303 * @param params The request params. 304 */ 305 def getPlannersRange(params) { 306 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 307 params.offset = params?.offset?.toInteger() ?: 0 308 params.sort = params?.sort ?: "targetStartDate" 309 params.order = params?.order ?: "asc" 310 311 def taskInstanceList = Task.createCriteria().list( 312 max: params.max, 313 offset: params.offset, 314 sort: params.sort, 315 order: params.order) { 316 ge("targetStartDate", dateUtilService.oneWeekAgo) 317 lt("targetStartDate", dateUtilService.today + 15) 318 eq("trash", false) 319 } // createCriteria 320 } 256 } // getBudgetTasks() 321 257 322 258 /** 323 259 * Get work done by person and date. 324 * A person ID and date may be specified in params otherwise the current User and today are used.260 * A person ID and date may be specified in params otherwise the current user and today are used. 325 261 * @param params The request params. 326 262 * @returns A map containing entries, totalEntries, startOfDay, person, totalHours, totalMinutes. … … 370 306 371 307 return result 372 } 308 } // getWorkDone() 373 309 374 310 } // end class
Note: See TracChangeset
for help on using the changeset viewer.