| [69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
|---|
| [165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
|---|
| [209] | 3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
|---|
| [476] | 4 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
|---|
| [69] | 5 | |
|---|
| [298] | 6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
|---|
| [85] | 7 | class TaskDetailedController extends BaseController { |
|---|
| [66] | 8 | |
|---|
| [291] | 9 | def authService |
|---|
| [180] | 10 | def taskService |
|---|
| [143] | 11 | def taskSearchService |
|---|
| [585] | 12 | def taskReportService |
|---|
| [140] | 13 | def filterService |
|---|
| [165] | 14 | def exportService |
|---|
| [214] | 15 | def dateUtilService |
|---|
| [139] | 16 | |
|---|
| [181] | 17 | // these actions only accept POST requests |
|---|
| [418] | 18 | static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST', |
|---|
| 19 | approve:'POST', renegeApproval:'POST', complete:'POST', |
|---|
| 20 | reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST'] |
|---|
| [66] | 21 | |
|---|
| [298] | 22 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [196] | 23 | def index = { redirect(action: 'search', params: params) } |
|---|
| [140] | 24 | |
|---|
| [298] | 25 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [326] | 26 | def setSearchParamsMax = { |
|---|
| [262] | 27 | def max = 1000 |
|---|
| [615] | 28 | if(params.newMax?.isInteger()) { |
|---|
| [260] | 29 | def i = params.newMax.toInteger() |
|---|
| [262] | 30 | if(i > 0 && i <= max) |
|---|
| 31 | session.taskSearchParamsMax = params.newMax |
|---|
| 32 | if(i > max) |
|---|
| 33 | session.taskSearchParamsMax = max |
|---|
| 34 | } |
|---|
| [260] | 35 | forward(action: 'search', params: params) |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| [298] | 38 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [476] | 39 | def setSearchCalendarParamsMax = { |
|---|
| 40 | def max = 1000 |
|---|
| [615] | 41 | if(params.newMax?.isInteger()) { |
|---|
| [476] | 42 | def i = params.newMax.toInteger() |
|---|
| 43 | if(i > 0 && i <= max) |
|---|
| 44 | session.taskSearchCalendarParamsMax = params.newMax |
|---|
| 45 | if(i > max) |
|---|
| 46 | session.taskSearchCalendarParamsMax = max |
|---|
| 47 | } |
|---|
| 48 | forward(action: 'searchCalendar', params: params) |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| [483] | 51 | /** |
|---|
| 52 | * Search for tasks. |
|---|
| 53 | */ |
|---|
| [476] | 54 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [139] | 55 | def search = { |
|---|
| [143] | 56 | |
|---|
| [260] | 57 | if(session.taskSearchParamsMax) |
|---|
| 58 | params.max = session.taskSearchParamsMax |
|---|
| 59 | |
|---|
| [468] | 60 | // Protect filterPane. |
|---|
| [525] | 61 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
|---|
| [260] | 62 | |
|---|
| [713] | 63 | // View main data. |
|---|
| [260] | 64 | def taskInstanceList = [] |
|---|
| 65 | def taskInstanceTotal |
|---|
| [476] | 66 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
|---|
| 67 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
|---|
| [260] | 68 | |
|---|
| [476] | 69 | // Restore search unless a new search is being requested. |
|---|
| 70 | if(!params.quickSearch && !filterParams) { |
|---|
| [713] | 71 | if(session.taskSearchFilterParams) { |
|---|
| [476] | 72 | session.taskSearchFilterParams.each() { params[it.key] = it.value } |
|---|
| 73 | params.filter = session.taskSearchFilter |
|---|
| 74 | isFilterApplied = FilterUtils.isFilterApplied(params) |
|---|
| [144] | 75 | } |
|---|
| [476] | 76 | } |
|---|
| [713] | 77 | if(!params.quickSearch) { |
|---|
| 78 | if(session.taskSearchQuickSearch) { |
|---|
| 79 | params.quickSearch = session.taskSearchQuickSearch |
|---|
| 80 | params.person = Person.get(session.taskQuickSearchPersonId.toLong()) |
|---|
| 81 | params.startDate = session.taskQuickSearchStartDate |
|---|
| 82 | params.endDate = session.taskQuickSearchEndDate |
|---|
| 83 | params.includeCompleted = session.taskQuickSearchIncludeCompleted |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| [260] | 86 | |
|---|
| [486] | 87 | // Remember sort if supplied, otherwise try to restore. |
|---|
| 88 | if(params.sort && params.order) { |
|---|
| [582] | 89 | // Reset to defaultSort if requested. |
|---|
| 90 | if(params.sort == 'defaultSort') { |
|---|
| 91 | params.sort = null |
|---|
| 92 | params.order = null |
|---|
| 93 | session.removeAttribute("taskSearchSort") |
|---|
| 94 | session.removeAttribute("taskSearchOrder") |
|---|
| 95 | } |
|---|
| 96 | else { |
|---|
| 97 | session.taskSearchSort = params.sort |
|---|
| 98 | session.taskSearchOrder = params.order |
|---|
| 99 | } |
|---|
| [486] | 100 | } |
|---|
| 101 | else if(session.taskSearchSort && session.taskSearchOrder) { |
|---|
| 102 | params.sort = session.taskSearchSort |
|---|
| 103 | params.order = session.taskSearchOrder |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| [476] | 106 | if(isFilterApplied) { |
|---|
| [260] | 107 | // filterPane: |
|---|
| [582] | 108 | params.sort = params.sort ?: "id" |
|---|
| 109 | params.order = params.order ?: "desc" |
|---|
| [513] | 110 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
|---|
| 111 | params.sort = "id" |
|---|
| [516] | 112 | // Prevent tasks in the trash being returned unless explicitly requested. |
|---|
| 113 | if(!params.filter.op.trash) { |
|---|
| 114 | params.filter.op.trash = "Equal" |
|---|
| 115 | params.filter.trash = "false" |
|---|
| 116 | } |
|---|
| 117 | // Call filterService. |
|---|
| [260] | 118 | taskInstanceList = filterService.filter( params, Task ) |
|---|
| 119 | taskInstanceTotal = filterService.count( params, Task ) |
|---|
| 120 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
|---|
| [476] | 121 | // Remember search. |
|---|
| 122 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
|---|
| 123 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
|---|
| [260] | 124 | } |
|---|
| [476] | 125 | else { |
|---|
| 126 | // Quick Search: |
|---|
| 127 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
|---|
| 128 | taskInstanceList = result.taskInstanceList |
|---|
| 129 | taskInstanceTotal = result.taskInstanceList.totalCount |
|---|
| 130 | params.message = result.message |
|---|
| [713] | 131 | params.quickSearch = result.quickSearch |
|---|
| 132 | params.person = result.person |
|---|
| 133 | params.startDate = result.startDate |
|---|
| 134 | params.endDate = result.endDate |
|---|
| 135 | params.includeCompleted = result.includeCompleted |
|---|
| [476] | 136 | // Remember search. |
|---|
| [488] | 137 | session.removeAttribute("taskSearchFilterParams") |
|---|
| 138 | session.removeAttribute("taskSearchFilter") |
|---|
| [476] | 139 | session.taskSearchQuickSearch = result.quickSearch |
|---|
| [713] | 140 | session.taskQuickSearchPersonId = result.person.id |
|---|
| 141 | session.taskQuickSearchStartDate = result.startDate |
|---|
| 142 | session.taskQuickSearchEndDate = result.endDate |
|---|
| 143 | session.taskQuickSearchIncludeCompleted = result.includeCompleted |
|---|
| [476] | 144 | } |
|---|
| [143] | 145 | |
|---|
| [260] | 146 | // export plugin: |
|---|
| 147 | if(params?.format && params.format != "html") { |
|---|
| 148 | |
|---|
| 149 | def dateFmt = { date -> |
|---|
| 150 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | String title |
|---|
| 154 | if(params.quickSearch) |
|---|
| [476] | 155 | title = params.message |
|---|
| [260] | 156 | else |
|---|
| 157 | title = "Filtered tasks." |
|---|
| 158 | |
|---|
| 159 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
|---|
| [390] | 160 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
|---|
| [475] | 161 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
|---|
| [260] | 162 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
|---|
| [475] | 163 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
|---|
| 164 | "taskType": "Task Type", "taskStatus": "Task Status"] |
|---|
| [260] | 165 | Map formatters = [ targetStartDate: dateFmt] |
|---|
| 166 | Map parameters = [title: title, separator: ","] |
|---|
| 167 | |
|---|
| 168 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | // Add some basic params to filterParams. |
|---|
| 172 | filterParams.max = params.max |
|---|
| 173 | filterParams.offset = params.offset?.toInteger() ?: 0 |
|---|
| [582] | 174 | filterParams.sort = params.sort ?: "id" |
|---|
| [260] | 175 | filterParams.order = params.order ?: "desc" |
|---|
| 176 | |
|---|
| [552] | 177 | // Get some associatedProperty values for filterpane. |
|---|
| 178 | def associatedPropertyValues = [:] |
|---|
| 179 | def associatedPropertyMax = 10000 |
|---|
| 180 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 181 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
|---|
| 182 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
|---|
| 183 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
|---|
| 184 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
|---|
| 185 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 186 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 187 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 188 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 189 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
|---|
| 190 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
|---|
| 191 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
|---|
| 192 | |
|---|
| [260] | 193 | return[ taskInstanceList: taskInstanceList, |
|---|
| [476] | 194 | taskInstanceTotal: taskInstanceTotal, |
|---|
| 195 | filterParams: filterParams, |
|---|
| [552] | 196 | params: params, |
|---|
| [713] | 197 | associatedPropertyValues: associatedPropertyValues, |
|---|
| 198 | quickSearchSelection: taskSearchService.quickSearchSelection] |
|---|
| [260] | 199 | |
|---|
| [476] | 200 | } // search |
|---|
| [260] | 201 | |
|---|
| [298] | 202 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [155] | 203 | def searchCalendar = { |
|---|
| [140] | 204 | |
|---|
| [476] | 205 | // No pagination for calendar. |
|---|
| 206 | params.offset = 0 |
|---|
| [474] | 207 | |
|---|
| [476] | 208 | // Restore params.max |
|---|
| 209 | if(session.taskSearchCalendarParamsMax) |
|---|
| 210 | params.max = session.taskSearchCalendarParamsMax |
|---|
| 211 | |
|---|
| [474] | 212 | // Protect filterPane. |
|---|
| [476] | 213 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
|---|
| [474] | 214 | |
|---|
| [585] | 215 | def displayList = [] |
|---|
| [476] | 216 | def taskInstanceList = [] |
|---|
| 217 | def taskInstanceTotal |
|---|
| 218 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
|---|
| 219 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
|---|
| [474] | 220 | |
|---|
| [476] | 221 | // Restore search unless a new search is being requested. |
|---|
| 222 | if(!params.quickSearch && !filterParams) { |
|---|
| [713] | 223 | if(session.taskSearchCalendarFilterParams) { |
|---|
| [476] | 224 | session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value } |
|---|
| 225 | params.filter = session.taskSearchCalendarFilter |
|---|
| 226 | isFilterApplied = FilterUtils.isFilterApplied(params) |
|---|
| 227 | } |
|---|
| 228 | } |
|---|
| [713] | 229 | if(!params.quickSearch) { |
|---|
| 230 | if(session.taskSearchCalendarQuickSearch) { |
|---|
| 231 | params.quickSearch = session.taskSearchCalendarQuickSearch |
|---|
| 232 | params.person = Person.get(session.taskCalendarQuickSearchPersonId.toLong()) |
|---|
| 233 | params.startDate = session.taskCalendarQuickSearchStartDate |
|---|
| 234 | params.endDate = session.taskCalendarQuickSearchEndDate |
|---|
| 235 | params.includeCompleted = session.taskCalendarQuickSearchIncludeCompleted |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| [474] | 238 | |
|---|
| [476] | 239 | // The date the calendar will use to determine the month to show. |
|---|
| 240 | // Use session, if not specified in params, otherwise use today. |
|---|
| 241 | def showDate = new Date() |
|---|
| 242 | if(params.showMonth) { |
|---|
| 243 | if(params.showYear) |
|---|
| 244 | showDate = dateUtilService.makeDate(params.showYear, params.showMonth) |
|---|
| 245 | else |
|---|
| 246 | showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth) |
|---|
| 247 | // Remember the showDate. |
|---|
| 248 | session.taskSearchCalendarShowDate = showDate |
|---|
| 249 | } |
|---|
| 250 | else if(session.taskSearchCalendarShowDate) |
|---|
| 251 | showDate = session.taskSearchCalendarShowDate |
|---|
| [155] | 252 | |
|---|
| [476] | 253 | // Get the dates for the calendar month controls. |
|---|
| 254 | def calendarMonthControls = getCalendarMonthControls(showDate) |
|---|
| 255 | |
|---|
| 256 | if(isFilterApplied) { |
|---|
| 257 | // filterPane: |
|---|
| [589] | 258 | params.sort = params.sort ?: "id" |
|---|
| 259 | params.order = params.order ?: "desc" |
|---|
| [516] | 260 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
|---|
| 261 | params.sort = "id" |
|---|
| 262 | // Prevent tasks in the trash being returned unless explicitly requested. |
|---|
| 263 | if(!params.filter.op.trash) { |
|---|
| 264 | params.filter.op.trash = "Equal" |
|---|
| 265 | params.filter.trash = "false" |
|---|
| 266 | } |
|---|
| 267 | // Call filterService. |
|---|
| [476] | 268 | taskInstanceList = filterService.filter( params, Task ) |
|---|
| 269 | taskInstanceTotal = filterService.count( params, Task ) |
|---|
| 270 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
|---|
| 271 | // Remember search. |
|---|
| 272 | session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams) |
|---|
| 273 | session.taskSearchCalendarFilter = new LinkedHashMap(params.filter) |
|---|
| [139] | 274 | } |
|---|
| [476] | 275 | else { |
|---|
| 276 | // Quick Search: |
|---|
| 277 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
|---|
| 278 | taskInstanceList = result.taskInstanceList |
|---|
| 279 | taskInstanceTotal = result.taskInstanceList.totalCount |
|---|
| 280 | params.message = result.message |
|---|
| [713] | 281 | params.quickSearch = result.quickSearch |
|---|
| 282 | params.person = result.person |
|---|
| 283 | params.startDate = result.startDate |
|---|
| 284 | params.endDate = result.endDate |
|---|
| 285 | params.includeCompleted = result.includeCompleted |
|---|
| [476] | 286 | // Remember search. |
|---|
| [488] | 287 | session.removeAttribute("taskSearchCalendarFilterParams") |
|---|
| 288 | session.removeAttribute("taskSearchCalendarFilter") |
|---|
| [476] | 289 | session.taskSearchCalendarQuickSearch = result.quickSearch |
|---|
| [713] | 290 | session.taskCalendarQuickSearchPersonId = result.person.id |
|---|
| 291 | session.taskCalendarQuickSearchStartDate = result.startDate |
|---|
| 292 | session.taskCalendarQuickSearchEndDate = result.endDate |
|---|
| 293 | session.taskCalendarQuickSearchIncludeCompleted = result.includeCompleted |
|---|
| [476] | 294 | } |
|---|
| [140] | 295 | |
|---|
| [588] | 296 | // displayList = taskReportService.getWorkLoadSummary( |
|---|
| 297 | // [taskInstanceList: taskInstanceList], RCU.getLocale(request) |
|---|
| 298 | // ).displayList |
|---|
| [585] | 299 | |
|---|
| [476] | 300 | // export plugin: |
|---|
| 301 | if(params?.format && params.format != "html") { |
|---|
| [165] | 302 | |
|---|
| [476] | 303 | def dateFmt = { date -> |
|---|
| 304 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
|---|
| [165] | 305 | } |
|---|
| [260] | 306 | |
|---|
| [476] | 307 | String title |
|---|
| 308 | if(params.quickSearch) |
|---|
| 309 | title = params.message |
|---|
| 310 | else |
|---|
| 311 | title = "Filtered tasks." |
|---|
| [165] | 312 | |
|---|
| [476] | 313 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
|---|
| 314 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
|---|
| 315 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
|---|
| 316 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
|---|
| 317 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
|---|
| 318 | "taskType": "Task Type", "taskStatus": "Task Status"] |
|---|
| 319 | Map formatters = [ targetStartDate: dateFmt] |
|---|
| 320 | Map parameters = [title: title, separator: ","] |
|---|
| 321 | |
|---|
| 322 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
|---|
| [165] | 323 | } |
|---|
| 324 | |
|---|
| [588] | 325 | if(taskInstanceTotal > params.max) |
|---|
| 326 | params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max]) |
|---|
| [476] | 327 | |
|---|
| 328 | // Add some basic params to filterParams. |
|---|
| 329 | filterParams.max = params.max |
|---|
| 330 | filterParams.offset = params.offset?.toInteger() ?: 0 |
|---|
| [589] | 331 | filterParams.sort = params.sort ?: "id" |
|---|
| 332 | filterParams.order = params.order ?: "desc" |
|---|
| [476] | 333 | |
|---|
| [589] | 334 | // Get some associatedProperty values for filterpane. |
|---|
| 335 | def associatedPropertyValues = [:] |
|---|
| 336 | def associatedPropertyMax = 10000 |
|---|
| 337 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 338 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
|---|
| 339 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
|---|
| 340 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
|---|
| 341 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
|---|
| 342 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 343 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 344 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 345 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
|---|
| 346 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
|---|
| 347 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
|---|
| 348 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
|---|
| 349 | |
|---|
| [588] | 350 | return[taskInstanceList: taskInstanceList, |
|---|
| [476] | 351 | taskInstanceTotal: taskInstanceTotal, |
|---|
| 352 | filterParams: filterParams, |
|---|
| 353 | params: params, |
|---|
| [589] | 354 | associatedPropertyValues: associatedPropertyValues, |
|---|
| [476] | 355 | showDate: showDate, |
|---|
| 356 | today: calendarMonthControls.today, |
|---|
| 357 | previousMonth: calendarMonthControls.previousMonth, |
|---|
| 358 | nextMonth: calendarMonthControls.nextMonth, |
|---|
| 359 | previousYear: calendarMonthControls.previousYear, |
|---|
| [713] | 360 | nextYear: calendarMonthControls.nextYear, |
|---|
| 361 | quickSearchSelection: taskSearchService.quickSearchSelection] |
|---|
| [476] | 362 | |
|---|
| 363 | } // searchCalendar |
|---|
| 364 | |
|---|
| [298] | 365 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [66] | 366 | def show = { |
|---|
| [147] | 367 | |
|---|
| [139] | 368 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 369 | if(params._action_Show) |
|---|
| [375] | 370 | params.action='show' |
|---|
| [139] | 371 | |
|---|
| [433] | 372 | // Used by navigation. |
|---|
| 373 | if(params.id == 'nav') { |
|---|
| 374 | params.id = session.currentTaskId ?: null |
|---|
| 375 | redirect(action: show, id: params.id) |
|---|
| 376 | return |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| [225] | 379 | def showTab = [:] |
|---|
| 380 | switch (params.showTab) { |
|---|
| 381 | case "showProcedureTab": |
|---|
| 382 | showTab.procedure = new String("true") |
|---|
| 383 | break |
|---|
| 384 | case "showRecurrenceTab": |
|---|
| 385 | showTab.recurrence = new String("true") |
|---|
| 386 | break |
|---|
| 387 | case "showInventoryTab": |
|---|
| 388 | showTab.inventory = new String("true") |
|---|
| 389 | break |
|---|
| 390 | case "showSubTasksTab": |
|---|
| 391 | showTab.subTasks = new String("true") |
|---|
| 392 | break |
|---|
| 393 | default: |
|---|
| 394 | showTab.task = new String("true") |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| [66] | 397 | def taskInstance = Task.get( params.id ) |
|---|
| 398 | |
|---|
| 399 | if(!taskInstance) { |
|---|
| 400 | flash.message = "Task not found with id ${params.id}" |
|---|
| [196] | 401 | redirect(action: 'search') |
|---|
| [66] | 402 | } |
|---|
| [133] | 403 | else { |
|---|
| [433] | 404 | // Remember the current task id for use with navigation. |
|---|
| 405 | session.currentTaskId = params.id |
|---|
| 406 | |
|---|
| [179] | 407 | params.max = 10 |
|---|
| 408 | params.order = "desc" |
|---|
| 409 | params.sort = "id" |
|---|
| [134] | 410 | |
|---|
| [418] | 411 | def entryFaultList = Entry.withCriteria { |
|---|
| 412 | eq("entryType", EntryType.get(1)) |
|---|
| 413 | eq("task", taskInstance) |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | def entryCauseList = Entry.withCriteria { |
|---|
| [190] | 417 | eq("entryType", EntryType.get(2)) |
|---|
| [179] | 418 | eq("task", taskInstance) |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| [418] | 421 | def entryWorkDoneList = Entry.withCriteria { |
|---|
| 422 | eq("entryType", EntryType.get(3)) |
|---|
| [179] | 423 | eq("task", taskInstance) |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| [196] | 426 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
|---|
| 427 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
|---|
| [134] | 428 | |
|---|
| [175] | 429 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
|---|
| 430 | |
|---|
| [180] | 431 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
|---|
| 432 | |
|---|
| [253] | 433 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
|---|
| 434 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
|---|
| 435 | |
|---|
| [133] | 436 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
|---|
| 437 | def taskProcedureExits = new Boolean("true") |
|---|
| 438 | if(!taskProcedureInstance) { |
|---|
| 439 | taskProcedureExits = false |
|---|
| 440 | } |
|---|
| [175] | 441 | |
|---|
| 442 | params.order = "asc" |
|---|
| 443 | params.sort = "procedureStepNumber" |
|---|
| 444 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
|---|
| 445 | |
|---|
| [134] | 446 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
|---|
| 447 | def taskRecurringScheduleExits= new Boolean("true") |
|---|
| [175] | 448 | if(!taskRecurringScheduleInstance) { |
|---|
| [134] | 449 | taskRecurringScheduleExits = false |
|---|
| 450 | } |
|---|
| [179] | 451 | |
|---|
| [137] | 452 | return [ taskInstance: taskInstance, |
|---|
| [418] | 453 | entryFaultList: entryFaultList, |
|---|
| 454 | entryCauseList: entryCauseList, |
|---|
| [179] | 455 | entryWorkDoneList: entryWorkDoneList, |
|---|
| [133] | 456 | taskProcedureInstance: taskProcedureInstance, |
|---|
| 457 | taskProcedureExits: taskProcedureExits, |
|---|
| [225] | 458 | showTab: showTab, |
|---|
| [179] | 459 | subTaskInstanceList: subTaskInstanceList, |
|---|
| 460 | subTaskInstanceTotal: subTaskInstanceTotal, |
|---|
| 461 | subTaskInstanceMax: params.max, |
|---|
| 462 | maintenanceActionList: maintenanceActionList, |
|---|
| 463 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
|---|
| 464 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
|---|
| [180] | 465 | inventoryMovementList: inventoryMovementList, |
|---|
| [253] | 466 | taskModificationList: taskModificationList, |
|---|
| 467 | assignedGroupList: assignedGroupList, |
|---|
| 468 | assignedPersonList: assignedPersonList] |
|---|
| [131] | 469 | } |
|---|
| [66] | 470 | } |
|---|
| 471 | |
|---|
| [418] | 472 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [181] | 473 | def restore = { |
|---|
| 474 | |
|---|
| 475 | def result = taskService.restore(params) |
|---|
| 476 | |
|---|
| 477 | if(!result.error) { |
|---|
| 478 | flash.message = "Task ${params.id} has been restored." |
|---|
| [418] | 479 | redirect(action: show, id: params.id) |
|---|
| 480 | return |
|---|
| [181] | 481 | } |
|---|
| 482 | |
|---|
| [418] | 483 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 484 | |
|---|
| 485 | if(result.taskInstance) |
|---|
| 486 | redirect(action: show, id: params.id) |
|---|
| 487 | else |
|---|
| 488 | redirect(action: 'search') |
|---|
| 489 | |
|---|
| [181] | 490 | } |
|---|
| 491 | |
|---|
| [418] | 492 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [181] | 493 | def trash = { |
|---|
| 494 | |
|---|
| 495 | def result = taskService.trash(params) |
|---|
| 496 | |
|---|
| 497 | if(!result.error) { |
|---|
| 498 | flash.message = "Task ${params.id} has been moved to trash." |
|---|
| [196] | 499 | redirect(action: 'search') |
|---|
| [418] | 500 | return |
|---|
| [181] | 501 | } |
|---|
| 502 | |
|---|
| [418] | 503 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 504 | |
|---|
| 505 | if(result.taskInstance) |
|---|
| 506 | redirect(action: show, id: params.id) |
|---|
| 507 | else |
|---|
| 508 | redirect(action: 'search') |
|---|
| 509 | |
|---|
| [66] | 510 | } |
|---|
| 511 | |
|---|
| [418] | 512 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
|---|
| [181] | 513 | def approve = { |
|---|
| 514 | |
|---|
| 515 | def result = taskService.approve(params) |
|---|
| 516 | |
|---|
| 517 | if(!result.error) { |
|---|
| 518 | flash.message = "Task ${params.id} has been approved." |
|---|
| [418] | 519 | redirect(action: show, id: params.id) |
|---|
| 520 | return |
|---|
| [181] | 521 | } |
|---|
| 522 | |
|---|
| [418] | 523 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 524 | |
|---|
| 525 | if(result.taskInstance) |
|---|
| 526 | redirect(action: show, id: params.id) |
|---|
| 527 | else |
|---|
| 528 | redirect(action: 'search') |
|---|
| 529 | |
|---|
| [181] | 530 | } |
|---|
| 531 | |
|---|
| [465] | 532 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
|---|
| [181] | 533 | def renegeApproval = { |
|---|
| 534 | |
|---|
| 535 | def result = taskService.renegeApproval(params) |
|---|
| 536 | |
|---|
| 537 | if(!result.error) { |
|---|
| 538 | flash.message = "Task ${params.id} has had approval removed." |
|---|
| [418] | 539 | redirect(action: show, id: params.id) |
|---|
| 540 | return |
|---|
| [181] | 541 | } |
|---|
| 542 | |
|---|
| [418] | 543 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 544 | |
|---|
| 545 | if(result.taskInstance) |
|---|
| 546 | redirect(action: show, id: params.id) |
|---|
| 547 | else |
|---|
| 548 | redirect(action: 'search') |
|---|
| 549 | |
|---|
| [181] | 550 | } |
|---|
| 551 | |
|---|
| [298] | 552 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [181] | 553 | def complete = { |
|---|
| 554 | |
|---|
| 555 | def result = taskService.complete(params) |
|---|
| 556 | |
|---|
| 557 | if(!result.error) { |
|---|
| 558 | flash.message = "Task ${params.id} has been completed." |
|---|
| [418] | 559 | redirect(action: show, id: params.id) |
|---|
| 560 | return |
|---|
| [181] | 561 | } |
|---|
| [418] | 562 | |
|---|
| 563 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 564 | |
|---|
| 565 | if(result.taskInstance) |
|---|
| 566 | redirect(action: show, id: params.id) |
|---|
| 567 | else |
|---|
| 568 | redirect(action: 'search') |
|---|
| 569 | |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| 573 | def setAttentionFlag = { |
|---|
| 574 | |
|---|
| 575 | def result = taskService.setAttentionFlag(params) |
|---|
| 576 | |
|---|
| 577 | if(!result.error) { |
|---|
| 578 | flash.message = "Task ${params.id} has been flagged for attention." |
|---|
| 579 | redirect(action: show, id: params.id) |
|---|
| 580 | return |
|---|
| [181] | 581 | } |
|---|
| 582 | |
|---|
| [418] | 583 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 584 | |
|---|
| 585 | if(result.taskInstance) |
|---|
| 586 | redirect(action: show, id: params.id) |
|---|
| 587 | else |
|---|
| 588 | redirect(action: 'search') |
|---|
| 589 | |
|---|
| [181] | 590 | } |
|---|
| 591 | |
|---|
| [298] | 592 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [418] | 593 | def clearAttentionFlag = { |
|---|
| [181] | 594 | |
|---|
| [418] | 595 | def result = taskService.clearAttentionFlag(params) |
|---|
| 596 | |
|---|
| 597 | if(!result.error) { |
|---|
| 598 | flash.message = "Task ${params.id} attention flag cleared." |
|---|
| 599 | redirect(action: show, id: params.id) |
|---|
| 600 | return |
|---|
| [181] | 601 | } |
|---|
| 602 | |
|---|
| [418] | 603 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 604 | |
|---|
| 605 | if(result.taskInstance) |
|---|
| 606 | redirect(action: show, id: params.id) |
|---|
| 607 | else |
|---|
| 608 | redirect(action: 'search') |
|---|
| 609 | |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| 613 | def reopen = { |
|---|
| 614 | |
|---|
| [181] | 615 | def result = taskService.reopen(params) |
|---|
| 616 | |
|---|
| 617 | if(!result.error) { |
|---|
| 618 | flash.message = "Task ${params.id} has been reopened." |
|---|
| [418] | 619 | redirect(action: show, id: params.id) |
|---|
| 620 | return |
|---|
| [181] | 621 | } |
|---|
| 622 | |
|---|
| [418] | 623 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 624 | |
|---|
| 625 | if(result.taskInstance) |
|---|
| 626 | redirect(action: show, id: params.id) |
|---|
| 627 | else |
|---|
| 628 | redirect(action: 'search') |
|---|
| 629 | |
|---|
| [181] | 630 | } |
|---|
| 631 | |
|---|
| [298] | 632 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [66] | 633 | def edit = { |
|---|
| [147] | 634 | |
|---|
| [139] | 635 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 636 | if(params._action_Edit) |
|---|
| [375] | 637 | params.action='edit' |
|---|
| [169] | 638 | |
|---|
| [433] | 639 | // Used by navigation. |
|---|
| 640 | if(params.id == 'nav') { |
|---|
| 641 | params.id = session.currentTaskId ?: null |
|---|
| 642 | redirect(action: edit, id: params.id) |
|---|
| 643 | return |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| [66] | 646 | def taskInstance = Task.get( params.id ) |
|---|
| 647 | |
|---|
| 648 | if(!taskInstance) { |
|---|
| 649 | flash.message = "Task not found with id ${params.id}" |
|---|
| [196] | 650 | redirect(action: 'search') |
|---|
| [66] | 651 | } |
|---|
| 652 | else { |
|---|
| [433] | 653 | // Remember the current task id for use with navigation. |
|---|
| 654 | session.currentTaskId = params.id |
|---|
| 655 | |
|---|
| [181] | 656 | if(taskInstance.trash) { |
|---|
| [196] | 657 | flash.message = "You may not edit tasks that are in the trash." |
|---|
| 658 | redirect(action: 'show', id: taskInstance.id) |
|---|
| 659 | return |
|---|
| [181] | 660 | } |
|---|
| [246] | 661 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
|---|
| 662 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
|---|
| 663 | return [ taskInstance : taskInstance ] |
|---|
| [84] | 664 | } |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| [298] | 667 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [66] | 668 | def update = { |
|---|
| [179] | 669 | |
|---|
| [180] | 670 | def result = taskService.update(params) |
|---|
| 671 | |
|---|
| 672 | if(!result.error) { |
|---|
| [66] | 673 | flash.message = "Task ${params.id} updated" |
|---|
| [418] | 674 | redirect(action: show, id: params.id) |
|---|
| 675 | return |
|---|
| [180] | 676 | } |
|---|
| 677 | |
|---|
| [418] | 678 | if(result.error.code == "task.modifications.failedToSave") |
|---|
| 679 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 680 | |
|---|
| 681 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
|---|
| 682 | |
|---|
| [66] | 683 | } |
|---|
| 684 | |
|---|
| [473] | 685 | /** |
|---|
| 686 | * The create action is used to create scheduled types of tasks. |
|---|
| 687 | */ |
|---|
| 688 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
|---|
| [66] | 689 | def create = { |
|---|
| 690 | def taskInstance = new Task() |
|---|
| [214] | 691 | |
|---|
| 692 | // Set the targetStartDate if specified, used by searchCalendar view. |
|---|
| [476] | 693 | if(params.year && params.month && params.day) { |
|---|
| 694 | def date = dateUtilService.makeDate(params.year, params.month, params.day) |
|---|
| 695 | taskInstance.targetStartDate = date |
|---|
| 696 | taskInstance.targetCompletionDate = date |
|---|
| 697 | } |
|---|
| [214] | 698 | |
|---|
| [196] | 699 | // Default leadPerson to current user, unless supplied in params. |
|---|
| [291] | 700 | taskInstance.leadPerson = authService.currentUser |
|---|
| [487] | 701 | |
|---|
| 702 | // Apply params, overiding anything above. |
|---|
| [66] | 703 | taskInstance.properties = params |
|---|
| [433] | 704 | |
|---|
| 705 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
|---|
| 706 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
|---|
| 707 | taskInstance.taskPriority = scheduledTaskPriorities.default |
|---|
| 708 | return ['taskInstance': taskInstance, |
|---|
| 709 | 'scheduledTaskTypes': scheduledTaskTypes, |
|---|
| 710 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
|---|
| [66] | 711 | } |
|---|
| 712 | |
|---|
| [298] | 713 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [66] | 714 | def save = { |
|---|
| [394] | 715 | def result = taskService.save(params) |
|---|
| [180] | 716 | |
|---|
| 717 | if(!result.error) { |
|---|
| 718 | flash.message = "Task ${result.taskInstance.id} created." |
|---|
| [196] | 719 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| [418] | 720 | return |
|---|
| [66] | 721 | } |
|---|
| [180] | 722 | |
|---|
| [418] | 723 | if(result.error.code == "task.modifications.failedToSave") |
|---|
| 724 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 725 | |
|---|
| [433] | 726 | |
|---|
| 727 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
|---|
| 728 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
|---|
| 729 | render(view:'create', model:[taskInstance:result.taskInstance, |
|---|
| 730 | 'scheduledTaskTypes': scheduledTaskTypes, |
|---|
| 731 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
|---|
| [66] | 732 | } |
|---|
| [179] | 733 | |
|---|
| [298] | 734 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [179] | 735 | def listSubTasks = { |
|---|
| 736 | def parentTaskInstance = Task.get(params.id) |
|---|
| 737 | |
|---|
| [134] | 738 | if(!parentTaskInstance) { |
|---|
| 739 | flash.message = "Task not found with id ${params.id}" |
|---|
| [196] | 740 | redirect(action: 'search') |
|---|
| [133] | 741 | } |
|---|
| 742 | else { |
|---|
| [630] | 743 | params.max = Math.min( params.max ? params.max.toInteger() : 200, 200) |
|---|
| [196] | 744 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
|---|
| 745 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
|---|
| [179] | 746 | |
|---|
| [134] | 747 | [ taskInstanceList: subTaskInstanceList, |
|---|
| [179] | 748 | taskInstanceTotal: subTaskInstanceTotal, |
|---|
| 749 | parentTaskInstance: parentTaskInstance] |
|---|
| 750 | } |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| [298] | 753 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [196] | 754 | def createSubTask = { |
|---|
| 755 | def parentTaskInstance = Task.get(params.id) |
|---|
| 756 | |
|---|
| 757 | if(parentTaskInstance) { |
|---|
| 758 | |
|---|
| 759 | def result = taskService.createSubTask(parentTaskInstance) |
|---|
| 760 | if(!result.error) { |
|---|
| 761 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
|---|
| 762 | redirect(action: 'edit', id: result.taskInstance.id) |
|---|
| 763 | } |
|---|
| 764 | else { |
|---|
| 765 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
|---|
| [418] | 766 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
|---|
| [196] | 767 | redirect(action: 'show', id: parentTaskInstance.id) |
|---|
| 768 | } |
|---|
| 769 | else { |
|---|
| 770 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
|---|
| 771 | } |
|---|
| 772 | } |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | else { |
|---|
| 776 | flash.message = "Task not found with id ${params.id}" |
|---|
| 777 | redirect(action: 'search') |
|---|
| 778 | } |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| [395] | 781 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [433] | 782 | def createUnscheduled = { |
|---|
| 783 | def taskInstance = new Task() |
|---|
| 784 | |
|---|
| 785 | // Default leadPerson to current user, unless supplied in params. |
|---|
| 786 | taskInstance.leadPerson = authService.currentUser |
|---|
| 787 | taskInstance.properties = params |
|---|
| 788 | |
|---|
| 789 | // Always for Unscheduled task. |
|---|
| 790 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
|---|
| 791 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
|---|
| 792 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
|---|
| 793 | |
|---|
| 794 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
|---|
| 795 | } |
|---|
| 796 | |
|---|
| 797 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| 798 | def saveUnscheduled = { |
|---|
| 799 | def result = taskService.saveUnscheduled(params) |
|---|
| 800 | |
|---|
| 801 | if(!result.error) { |
|---|
| 802 | flash.message = "Task ${result.taskInstance.id} created." |
|---|
| 803 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 804 | return |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | if(result.error.code == "task.modifications.failedToSave") |
|---|
| 808 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 809 | |
|---|
| 810 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
|---|
| 811 | |
|---|
| 812 | render(view:'createUnscheduled', |
|---|
| 813 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [418] | 817 | def createImmediateCallout = { |
|---|
| [395] | 818 | def taskInstance = new Task() |
|---|
| 819 | |
|---|
| 820 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
|---|
| [418] | 821 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
|---|
| 822 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
|---|
| [395] | 823 | |
|---|
| 824 | return ['taskInstance': taskInstance, |
|---|
| 825 | 'entryFaultInstance': entryFaultInstance, |
|---|
| [418] | 826 | 'entryCauseInstance': entryCauseInstance, |
|---|
| [395] | 827 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| [418] | 831 | def saveImmediateCallout = { |
|---|
| 832 | def result = taskService.saveImmediateCallout(params) |
|---|
| [395] | 833 | |
|---|
| 834 | if(!result.error) { |
|---|
| 835 | flash.message = "Task ${result.taskInstance.id} created." |
|---|
| 836 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 837 | return |
|---|
| 838 | } |
|---|
| 839 | |
|---|
| 840 | if(result.error.code == "task.modifications.failedToSave") |
|---|
| 841 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
|---|
| 842 | |
|---|
| [418] | 843 | render(view:'createImmediateCallout', |
|---|
| [395] | 844 | model: ['taskInstance': result.taskInstance, |
|---|
| 845 | 'entryFaultInstance': result.entryFaultInstance, |
|---|
| [418] | 846 | 'entryCauseInstance': result.entryCauseInstance, |
|---|
| [395] | 847 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
|---|
| 848 | |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| [476] | 851 | /** |
|---|
| [490] | 852 | * Render a users total work done hours. |
|---|
| 853 | */ |
|---|
| 854 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| 855 | def workDone = { |
|---|
| 856 | def result = taskSearchService.getWorkDone(params, RCU.getLocale(request)) |
|---|
| 857 | |
|---|
| 858 | params.message = result.message |
|---|
| 859 | |
|---|
| 860 | return[entries: result.entries, |
|---|
| 861 | totalEntries : result.totalEntries, |
|---|
| 862 | startOfDay: result.startOfDay, |
|---|
| 863 | person: result.person, |
|---|
| 864 | totalHours: result.totalHours, |
|---|
| 865 | totalMinutes: result.totalMinutes] |
|---|
| 866 | } // workDone |
|---|
| 867 | |
|---|
| 868 | /** |
|---|
| [701] | 869 | * Render work load hours. |
|---|
| 870 | */ |
|---|
| 871 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
|---|
| 872 | def workLoad= { |
|---|
| 873 | def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request)) |
|---|
| 874 | |
|---|
| 875 | params.message = result.message |
|---|
| 876 | params.errorMessage = result.errorMessage |
|---|
| 877 | |
|---|
| 878 | return[tasks: result.tasks, |
|---|
| 879 | startDate: result.startDate, |
|---|
| 880 | endDate: result.endDate, |
|---|
| 881 | taskGroups: result.taskGroups, |
|---|
| 882 | taskStatusList: result.taskStatusList, |
|---|
| 883 | workLoadGroups: result.workLoadGroups, |
|---|
| 884 | totalHours: result.totalHours, |
|---|
| 885 | totalMinutes: result.totalMinutes] |
|---|
| 886 | } // workLoad |
|---|
| 887 | |
|---|
| 888 | /** |
|---|
| [476] | 889 | * Get some integers for use by the month control links. |
|---|
| 890 | */ |
|---|
| 891 | private getCalendarMonthControls(Date showDate) { |
|---|
| 892 | def result = [:] |
|---|
| 893 | result.today = [:] |
|---|
| 894 | result.today.date = new Date() |
|---|
| 895 | result.today.month = dateUtilService.getMonthFromDate(result.today.date) |
|---|
| 896 | result.today.year = dateUtilService.getYearFromDate(result.today.date) |
|---|
| 897 | result.nextMonth = [:] |
|---|
| [553] | 898 | result.nextMonth.date = dateUtilService.plusMonth(showDate) |
|---|
| [476] | 899 | result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) |
|---|
| 900 | result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) |
|---|
| 901 | result.previousMonth = [:] |
|---|
| [553] | 902 | result.previousMonth.date = dateUtilService.plusMonth(showDate, -1) |
|---|
| [476] | 903 | result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) |
|---|
| 904 | result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) |
|---|
| 905 | result.nextYear = [:] |
|---|
| [552] | 906 | result.nextYear.date = dateUtilService.plusYear(showDate) |
|---|
| [476] | 907 | result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) |
|---|
| 908 | result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) |
|---|
| 909 | result.previousYear = [:] |
|---|
| [552] | 910 | result.previousYear.date = dateUtilService.plusYear(showDate, -1) |
|---|
| [476] | 911 | result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) |
|---|
| 912 | result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) |
|---|
| 913 | return result |
|---|
| 914 | } |
|---|
| 915 | |
|---|
| [196] | 916 | } // end of class. |
|---|