source: trunk/grails-app/controllers/TaskDetailedController.groovy @ 137

Last change on this file since 137 was 137, checked in by gav, 15 years ago

Update to grails-1.1.1 release.
Fix WorkDone? and Fault entries not showing after update, now using criteria.
Work on TaskRecurringSchedule, add DateUtilService class, regenerate views to suite.
Finally have correct rollback behaviour on TaskRecurringSchedule? domain object updates by using transactions.
Added name to copyright since the license has no meaning without it.

File size: 6.4 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class TaskDetailedController extends BaseController {
4   
5    def index = { redirect(action:list,params:params) }
6
7    // the delete, save and update actions only accept POST requests
8    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
9
10//     def list = {
11//         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
12//         def taskInstanceActives = Task.findAllByIsActive( true ).list( params )
13// //         def taskInstanceList = taskInstanceActives.list( params )
14//         return [ taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceActives.count() ]
15//     }
16
17    def list = {
18        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
19        [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
20    }
21
22    def show = {
23        def taskInstance = Task.get( params.id )
24
25        if(!taskInstance) {
26            flash.message = "Task not found with id ${params.id}"
27            redirect(action:list)
28        }
29        else {
30                        params.max = 10
31                        params.order = "desc"
32                        params.sort = "id"
33                       
34                        def entryWorkDoneList = Entry.withCriteria {
35                                                                                                                                def entryType = EntryType.findByName("WorkDone")
36                                                                                                                                eq("entryType", entryType)
37                                                                                                                                eq("task", taskInstance)
38                                                                                                                }
39                       
40                        def entryFaultList = Entry.withCriteria {
41                                                                                                                                def entryType = EntryType.findByName("Fault")
42                                                                                                                                eq("entryType", entryType)
43                                                                                                                                eq("task", taskInstance)
44                                                                                                                }
45
46                        def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params)
47                        def subTaskInstanceTotal = Task.countByParentTask(taskInstance)                                 
48            def showTaskTab = new String("true")
49
50            def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id)
51            def taskProcedureExits = new Boolean("true")
52            if(!taskProcedureInstance) {
53                taskProcedureExits = false
54            }
55//                      else {
56                                params.order = "asc"
57                                params.sort = "procedureStepNumber"
58                                def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params)
59//                      }
60                                               
61            def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id)
62            def taskRecurringScheduleExits= new Boolean("true")
63                        if(!taskRecurringScheduleInstance) {
64                taskRecurringScheduleExits = false
65            }
66                       
67            return [ taskInstance: taskInstance,
68                                                        entryWorkDoneList: entryWorkDoneList,
69                                                        entryFaultList: entryFaultList,
70                            taskProcedureInstance: taskProcedureInstance,
71                            taskProcedureExits: taskProcedureExits,
72                            showTaskTab: showTaskTab,
73                                                        subTaskInstanceList: subTaskInstanceList,
74                                                        subTaskInstanceTotal: subTaskInstanceTotal,
75                                                        subTaskInstanceMax: params.max,
76                                                        maintenanceActionList: maintenanceActionList,
77                                                        taskRecurringScheduleInstance: taskRecurringScheduleInstance,
78                                                        taskRecurringScheduleExits: taskRecurringScheduleExits] 
79        }
80    }
81
82    def delete = {
83        def taskInstance = Task.get( params.id )
84        if(taskInstance) {
85            try {
86                taskInstance.isActive = false
87                flash.message = "Task ${params.id} has been set to inactive."
88                redirect(action:list)
89            }
90            catch(org.springframework.dao.DataIntegrityViolationException e) {
91                flash.message = "Task ${params.id} could not be deleted"
92                redirect(action:show,id:params.id)
93            }
94        }
95        else {
96            flash.message = "Task not found with id ${params.id}"
97            redirect(action:list)
98        }
99    }
100
101    def edit = {
102        def taskInstance = Task.get( params.id )
103
104        if(!taskInstance) {
105            flash.message = "Task not found with id ${params.id}"
106            redirect(action:list)
107        }
108        else {
109            def criteria = taskInstance.createCriteria()
110            def results = criteria {
111                and {
112                    notEqual('id', taskInstance.id)
113                    }
114            }
115            return [ taskInstance : taskInstance, possibleParentList: results ]
116        }
117    }
118
119    def update = {
120        def taskInstance = Task.get( params.id )
121        if(taskInstance) {
122            if(params.version) {
123                def version = params.version.toLong()
124                if(taskInstance.version > version) {
125                   
126                    taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
127                    render(view:'edit',model:[taskInstance:taskInstance])
128                    return
129                }
130            }
131            taskInstance.properties = params
132            if(!taskInstance.hasErrors() && taskInstance.save()) {
133                flash.message = "Task ${params.id} updated"
134                redirect(action:show,id:taskInstance.id)
135            }
136            else {
137                render(view:'edit',model:[taskInstance:taskInstance])
138            }
139        }
140        else {
141            flash.message = "Task not found with id ${params.id}"
142            redirect(action:edit,id:params.id)
143        }
144    }
145
146    def create = {
147        def taskInstance = new Task()
148        taskInstance.properties = params
149        return ['taskInstance':taskInstance]
150    }
151
152    def save = {
153        def taskInstance = new Task(params)
154        if(!taskInstance.hasErrors() && taskInstance.save()) {
155            flash.message = "Task ${taskInstance.id} created"
156            redirect(action:show,id:taskInstance.id)
157        }
158        else {
159            render(view:'create',model:[taskInstance:taskInstance])
160        }
161    }
162       
163        def listSubTasks = {
164                def parentTaskInstance = Task.get(params.id)
165                               
166        if(!parentTaskInstance) {
167            flash.message = "Task not found with id ${params.id}"
168            redirect(action:list)
169        }
170        else {
171                params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
172                def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params)
173                def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance)
174                               
175        [ taskInstanceList: subTaskInstanceList,
176                        taskInstanceTotal:  subTaskInstanceTotal,
177                        parentTaskInstance: parentTaskInstance]
178                }
179        }
180       
181}
Note: See TracBrowser for help on using the repository browser.