| 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.taskSearchCalendarShowMonth |
| 136 | | |
| 137 | | if(params.nextMonth) |
| 138 | | showMonth = dateUtilService.getNextMonth(showMonth) |
| 139 | | else if(params.previousMonth) |
| 140 | | showMonth = dateUtilService.getPreviousMonth(showMonth) |
| 141 | | session.taskSearchCalendarShowMonth = showMonth |
| 142 | | |
| 143 | | // Quick Search: |
| 144 | | if(!FilterUtils.isFilterApplied(params)) { |
| 145 | | def taskInstanceList = [] |
| 146 | | def personInstance = authService.currentUser |
| 147 | | |
| 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.currentUser |
| 194 | | |
| 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 |