Changeset 476 for trunk/grails-app/controllers
- Timestamp:
- Apr 7, 2010, 1:49:22 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/TaskDetailedController.groovy
r475 r476 2 2 import org.codehaus.groovy.grails.commons.ConfigurationHolder 3 3 import com.zeddware.grails.plugins.filterpane.FilterUtils 4 import org.springframework.web.servlet.support.RequestContextUtils as RCU 4 5 5 6 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) … … 35 36 36 37 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) 38 def setSearchCalendarParamsMax = { 39 def max = 1000 40 if(params.newMax.isInteger()) { 41 def i = params.newMax.toInteger() 42 if(i > 0 && i <= max) 43 session.taskSearchCalendarParamsMax = params.newMax 44 if(i > max) 45 session.taskSearchCalendarParamsMax = max 46 } 47 forward(action: 'searchCalendar', params: params) 48 } 49 50 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) 37 51 def search = { 38 52 … … 41 55 42 56 // Protect filterPane. 43 params.max = Math.min( params.max ? params.max.toInteger() : 10, 1000 )57 params.max = Math.min( params.max ? params.max.toInteger() : 20, 1000 ) 44 58 45 59 def taskInstanceList = [] 46 60 def taskInstanceTotal 47 def filterParams = [:] 48 def personInstance = authService.currentUser 49 50 // Quick Search: 51 if(!FilterUtils.isFilterApplied(params)) { 52 53 if(params.quickSearch == "searchMyTodays") { 54 taskInstanceList = taskSearchService.getMyTodays(params) 55 if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } 56 else { params.message = "No tasks found for today." } 57 } 58 else if(params.quickSearch == "searchInTheLastWeek") { 59 taskInstanceList = taskSearchService.getInTheLastWeek(params) 60 if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } 61 else { params.message = "No tasks found for the last week." } 62 } 63 else if(params.quickSearch == "searchMyInTheLastWeek") { 64 taskInstanceList = taskSearchService.getMyInTheLastWeek(params) 65 if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } 66 else { params.message = "No tasks found for the last week." } 67 } 68 else { 69 //Default: 70 taskInstanceList = taskSearchService.getTodays(params) 71 if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } 72 else { params.message = "No tasks found for today." } 73 params.quickSearch = "searchTodays" 74 } 75 76 taskInstanceTotal = taskInstanceList.totalCount 77 filterParams.quickSearch = params.quickSearch 78 } 79 else { 61 def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 62 def isFilterApplied = FilterUtils.isFilterApplied(params) 63 64 // Restore search unless a new search is being requested. 65 if(!params.quickSearch && !filterParams) { 66 if(session.taskSearchQuickSearch) 67 params.quickSearch = session.taskSearchQuickSearch 68 else if(session.taskSearchFilterParams) { 69 session.taskSearchFilterParams.each() { params[it.key] = it.value } 70 params.filter = session.taskSearchFilter 71 isFilterApplied = FilterUtils.isFilterApplied(params) 72 } 73 } 74 75 if(isFilterApplied) { 80 76 // filterPane: 81 77 taskInstanceList = filterService.filter( params, Task ) 82 78 taskInstanceTotal = filterService.count( params, Task ) 83 79 filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 80 // Remember search. 81 session.taskSearchFilterParams = new LinkedHashMap(filterParams) 82 session.taskSearchFilter = new LinkedHashMap(params.filter) 83 session.taskSearchQuickSearch = null 84 } 85 else { 86 // Quick Search: 87 if(!params.quickSearch) params.quickSearch = "myTodays" 88 def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) 89 taskInstanceList = result.taskInstanceList 90 taskInstanceTotal = result.taskInstanceList.totalCount 91 params.message = result.message 92 filterParams.quickSearch = result.quickSearch 93 // Remember search. 94 session.taskSearchFilterParams = null 95 session.taskSearchFilter = null 96 session.taskSearchQuickSearch = result.quickSearch 84 97 } 85 98 … … 93 106 String title 94 107 if(params.quickSearch) 95 title = "${params.quickSearch} tasks."108 title = params.message 96 109 else 97 110 title = "Filtered tasks." … … 116 129 117 130 return[ taskInstanceList: taskInstanceList, 118 taskInstanceTotal: taskInstanceTotal, 119 filterParams: filterParams ] 120 121 } // end search() 131 taskInstanceTotal: taskInstanceTotal, 132 filterParams: filterParams, 133 params: params ] 134 135 } // search 122 136 123 137 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) 124 138 def searchCalendar = { 125 139 126 if(session.taskSearchParamsMax) 127 params.max = session.taskSearchParamsMax 140 // No pagination for calendar. 141 params.offset = 0 142 143 // Restore params.max 144 if(session.taskSearchCalendarParamsMax) 145 params.max = session.taskSearchCalendarParamsMax 128 146 129 147 // Protect filterPane. 130 params.max = Math.min( params.max ? params.max.toInteger() : 10 , 100)131 132 // Set the month to show.133 def showMonth = new Date()134 if(session.taskSearchCalendarShowMonth)135 showMonth = session.taskSearchCalendarShowMonth136 137 if(params.nextMonth)138 showMonth = dateUtilService.getNextMonth(showMonth)139 else if(params.previousMonth)140 showMonth = dateUtilService.getPreviousMonth(showMonth)141 session.taskSearchCalendarShowMonth = showMonth142 143 // Quick Search:144 if(!FilterUtils.isFilterApplied(params)) {145 def taskInstanceList = []146 def personInstance = authService.currentUser147 148 if(params.quickSearch == "searchMyTodays") {149 taskInstanceList = taskSearchService.getMyTodays(params)150 if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." }151 else { params.message = "No tasks found for today." }152 if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" }153 }154 else if(params.quickSearch == "searchInTheLastWeek") {155 taskInstanceList = taskSearchService.getInTheLastWeek(params)156 if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." }157 else { params.message = "No tasks found for the last week." }158 if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown"}159 }160 else if(params.quickSearch == "searchMyInTheLastWeek") {161 taskInstanceList = taskSearchService.getMyInTheLastWeek(params) 162 if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." }163 else { params.message = "No tasks found for the last week." }164 if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } 165 }166 else {167 //Default:168 taskInstanceList = taskSearchService.getTodays(params)169 if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." }170 else { params.message = "No tasks found for today." }171 if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" }172 params.quickSearch = "searchTodays"173 }174 return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, showMonth: showMonth, filterParams: params]175 }176 // filterPane:177 def taskInstanceTotal = filterService.count( params, Task)178 if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" }179 return[ taskInstanceList: filterService.filter( params, Task ),180 taskInstanceTotal: taskInstanceTotal,181 filterParams : com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),182 showMonth: showMonth,183 params:params ]184 }185 186 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])187 def budget = { 188 params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 )189 190 // Quick Search: 191 if(!FilterUtils.isFilterApplied(params)) {192 def taskInstanceList = []193 def personInstance = authService.currentUser194 195 if(params.quickSearch == "budgetUnplanned") {196 taskInstanceList = taskSearchService.getBudgetUnplanned(params)197 if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." }198 else { params.message = "No tasks found." }199 }200 //else if(params.quickSearch == "budgetPlanned") { 201 else {202 //Default:203 taskInstanceList = taskSearchService.getBudgetPlanned(params)204 if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." }205 else { params.message = "No tasks found.." }206 }207 // export plugin:208 if(params?.format && params.format != "html") {209 210 def dateFmt = { date ->211 formatDate(format: "EEE, dd-MMM-yyyy", date: date)212 } 213 response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]214 response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}")215 List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] 216 Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description",217 "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"]218 Map formatters = [ targetStartDate: dateFmt]219 String title = "${params.quickSearch} tasks in the last week." 220 Map parameters = [title: title, separator: ","]221 222 exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters)223 }224 return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params]225 }226 // filterPane:227 return[ taskInstanceList: filterService.filter( params, Task ),228 taskInstanceTotal: filterService.count( params, Task ),229 filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),230 params:params ] 231 } 148 params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) 149 150 def taskInstanceList = [] 151 def taskInstanceTotal 152 def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 153 def isFilterApplied = FilterUtils.isFilterApplied(params) 154 155 // Restore search unless a new search is being requested. 156 if(!params.quickSearch && !filterParams) { 157 if(session.taskSearchCalendarQuickSearch) 158 params.quickSearch = session.taskSearchCalendarQuickSearch 159 else if(session.taskSearchCalendarFilterParams) { 160 session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value } 161 params.filter = session.taskSearchCalendarFilter 162 isFilterApplied = FilterUtils.isFilterApplied(params) 163 } 164 } 165 166 // The date the calendar will use to determine the month to show. 167 // Use session, if not specified in params, otherwise use today. 168 def showDate = new Date() 169 if(params.showMonth) { 170 if(params.showYear) 171 showDate = dateUtilService.makeDate(params.showYear, params.showMonth) 172 else 173 showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth) 174 // Remember the showDate. 175 session.taskSearchCalendarShowDate = showDate 176 } 177 else if(session.taskSearchCalendarShowDate) 178 showDate = session.taskSearchCalendarShowDate 179 180 // Get the dates for the calendar month controls. 181 def calendarMonthControls = getCalendarMonthControls(showDate) 182 183 if(isFilterApplied) { 184 // filterPane: 185 taskInstanceList = filterService.filter( params, Task ) 186 taskInstanceTotal = filterService.count( params, Task ) 187 filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 188 // Remember search. 189 session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams) 190 session.taskSearchCalendarFilter = new LinkedHashMap(params.filter) 191 session.taskSearchCalendarQuickSearch = null 192 } 193 else { 194 // Quick Search: 195 def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) 196 taskInstanceList = result.taskInstanceList 197 taskInstanceTotal = result.taskInstanceList.totalCount 198 params.message = result.message 199 filterParams.quickSearch = result.quickSearch 200 // Remember search. 201 session.taskSearchCalendarFilterParams = null 202 session.taskSearchCalendarFilter = null 203 session.taskSearchCalendarQuickSearch = result.quickSearch 204 } 205 206 // export plugin: 207 if(params?.format && params.format != "html") { 208 209 def dateFmt = { date -> 210 formatDate(format: "EEE, dd-MMM-yyyy", date: date) 211 } 212 213 String title 214 if(params.quickSearch) 215 title = params.message 216 else 217 title = "Filtered tasks." 218 219 response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] 220 response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") 221 List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] 222 Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", 223 "leadPerson": "Lead Person", "taskPriority": "Task Priority", 224 "taskType": "Task Type", "taskStatus": "Task Status"] 225 Map formatters = [ targetStartDate: dateFmt] 226 Map parameters = [title: title, separator: ","] 227 228 exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) 229 } 230 231 if(taskInstanceTotal > params.max) 232 params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max]) 233 234 // Add some basic params to filterParams. 235 filterParams.max = params.max 236 filterParams.offset = params.offset?.toInteger() ?: 0 237 238 return[taskInstanceList: taskInstanceList, 239 taskInstanceTotal: taskInstanceTotal, 240 filterParams: filterParams, 241 params: params, 242 showDate: showDate, 243 today: calendarMonthControls.today, 244 previousMonth: calendarMonthControls.previousMonth, 245 nextMonth: calendarMonthControls.nextMonth, 246 previousYear: calendarMonthControls.previousYear, 247 nextYear: calendarMonthControls.nextYear] 248 249 } // searchCalendar 232 250 233 251 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) … … 559 577 560 578 // Set the targetStartDate if specified, used by searchCalendar view. 561 if(params.year && params.month && params.day) 562 taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) 579 if(params.year && params.month && params.day) { 580 def date = dateUtilService.makeDate(params.year, params.month, params.day) 581 taskInstance.targetStartDate = date 582 taskInstance.targetCompletionDate = date 583 } 563 584 564 585 // Default leadPerson to current user, unless supplied in params. … … 712 733 } 713 734 735 /** 736 * Get some integers for use by the month control links. 737 */ 738 private getCalendarMonthControls(Date showDate) { 739 def result = [:] 740 result.today = [:] 741 result.today.date = new Date() 742 result.today.month = dateUtilService.getMonthFromDate(result.today.date) 743 result.today.year = dateUtilService.getYearFromDate(result.today.date) 744 result.nextMonth = [:] 745 result.nextMonth.date = dateUtilService.getNextMonth(showDate) 746 result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) 747 result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) 748 result.previousMonth = [:] 749 result.previousMonth.date = dateUtilService.getPreviousMonth(showDate) 750 result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) 751 result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) 752 result.nextYear = [:] 753 result.nextYear.date = dateUtilService.getNextYear(showDate) 754 result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) 755 result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) 756 result.previousYear = [:] 757 result.previousYear.date = dateUtilService.getPreviousYear(showDate) 758 result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) 759 result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) 760 return result 761 } 762 714 763 } // end of class.
Note: See TracChangeset
for help on using the changeset viewer.