WorkListHandler.icl 4.65 KB
Newer Older
1 2 3
implementation module WorkListHandler

import StdEnv
4
import Http, Session
5
import Text
6
import JSON
7
import Time
8
import iDataForms
9
import TaskTree, TaskTreeFilters, InternaliTasksCommon
10

11 12 13 14 15
:: WorkList			= 	{ success		:: Bool
						, total			:: Int
						, worklist		:: [WorkListItem]
						}
						
16
:: WorkListItem 	= 	{ taskid		:: String 					// Task id of the work item
Bas Lijnse's avatar
Bas Lijnse committed
17
						, delegator		:: String 					// Id of the user who issued the work
18 19 20
						, processname	:: String					// Name given to the work process the task belongs to
				 		, subject		:: String 					// Name give to the task, which can be a short description of the work to do
				 		, priority		:: TaskPriority				// Priority of the task
21
				 		, timestamp		:: Int						// Time stamp when the task was issued
22 23 24 25
				 		, tree_path		:: [Bool]					// Path in the tree structure
				 		, tree_last		:: Bool						// Is this item the last of a set of siblings
				 		, tree_icon		:: String					// An icon name. The actual icon image is defined in the css.
				 													// Current possible values: editTask, orTask, andTask, conditionTask, timeTask, systemTask, finishedTask 
26 27
				  		}											// And also: andTaskMU, maybeTask
																	
28
derive JSONEncode WorkList, WorkListItem, TaskPriority
29

30 31
handleWorkListRequest :: !(Task a) !HTTPRequest !Session *HSt -> (!HTTPResponse, !*HSt) | iData a
handleWorkListRequest mainTask request session hst
32
	# uid							= session.Session.userId
33
	# (toServer, htmlTree, maybeError, maybeProcessTable, maybeThreadTable,hst)	
34 35
									= calculateTaskTree uid False False False mainTask hst 	// Calculate the TaskTree given the id of the current user
	# workitems						= determineWorkItems uid htmlTree
36 37 38 39
	# worklist								= { success		= True
											  , total		= length workitems
											  , worklist	= workitems
											  }
40 41
	
	= ({http_emptyResponse & rsp_data = toJSON worklist}, hst)
42 43


44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
determineWorkItems :: !UserId !HtmlTree -> [WorkListItem]
determineWorkItems uid tree = markLast (determineWorkItems` uid [] defaultDesc tree)
where
	determineWorkItems` uid path pdesc (desc @@: tree)
		# rest	= determineWorkItems` uid path desc tree
		| desc.taskWorkerId == uid	= [	{ taskid 		= desc.taskNrId
										, delegator		= toString desc.delegatorId
										, processname	= desc.workflowLabel
										, subject		= desc.taskLabel
										, priority		= desc.taskPriority
										, timestamp		= (\(Time i) -> i) desc.timeCreated
										, tree_path		= path
										, tree_last		= False
										, tree_icon		= "editTask"
										} : rest] 
		| otherwise					= rest

	determineWorkItems` uid path pdesc (CondAnd label nr trees)
		# subpath = path ++ [False]
		# rest = markLast (flatten [[mkCondItem pdesc desc subpath: determineWorkItems` uid subpath pdesc tree] \\ (desc,tree) <- trees])
		= [	{ taskid 		= pdesc.taskNrId
			, delegator		= toString pdesc.delegatorId
			, processname	= pdesc.workflowLabel
			, subject		= pdesc.workflowLabel
			, priority		= pdesc.taskPriority
			, timestamp		= (\(Time i) -> i) pdesc.timeCreated
			, tree_path		= path
			, tree_last		= True
			, tree_icon		= label
			} : rest] 
74

75 76 77 78 79 80 81 82 83
	determineWorkItems` uid path pdesc (tree1 +|+ tree2)
		# list1	= determineWorkItems` uid path pdesc tree1
		# list2 = determineWorkItems` uid path pdesc tree2
		= list1 ++ list2
		
	determineWorkItems` uid path pdesc (tree1 +-+ tree2)
		# list1	= determineWorkItems` uid path pdesc tree1
		# list2 = determineWorkItems` uid path pdesc tree2
		= list1 ++ list2	
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	determineWorkItems` uid path pdesc (DivCode id tree) 
		= determineWorkItems` uid path pdesc tree
	
	determineWorkItems` uid path pdesc (TaskTrace traceinfo tree)
		= determineWorkItems` uid path pdesc tree
		
	determineWorkItems` uid path pdesc (BT html inputs)
		= []
		
	markLast :: [WorkListItem] -> [WorkListItem]
	markLast [] = []
	markLast items = reverse ((\[x:xs] -> [{x & tree_last = True}:xs]) (reverse items))
	
	mkCondItem :: TaskDescription CondAndDescription [Bool] -> WorkListItem
	mkCondItem pdesc cdesc path
		= 	{ taskid 		= cdesc.caTaskNrId
			, delegator		= toString pdesc.delegatorId
			, processname	= pdesc.workflowLabel
			, subject		= pdesc.taskLabel +++ " - Part " +++ (toString cdesc.caIndex)
			, priority		= pdesc.taskPriority
			, timestamp		= (\(Time i) -> i) pdesc.timeCreated
			, tree_path		= path
			, tree_last		= False
			, tree_icon		= if cdesc.caStatus "finishedTask" "editTask"
			}
	
	defaultDesc :: TaskDescription
	defaultDesc
		=	{ delegatorId	= 0								
			, taskWorkerId	= 0								
			, taskNrId		= ""								
			, processNr		= 0								
			, workflowLabel	= "Non-existing"							
			, taskLabel		= "Non-existing"								
			, timeCreated	= Time 0
			, taskPriority	= LowPriority
			, curStatus		= True
			}