delegate.icl 1.65 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module delegate

import StdEnv, StdHtml

derive gForm [], Maybe
derive gUpd [], Maybe
derive gPrint Maybe
derive gParse Maybe
//derive gerda Maybe

npersons = 5

Start world = doHtmlServer (multiUserTask npersons (delegate mytask (Time 0 0 15))) world

mytask = STask "Done" 0


delegate taskToDelegate time 
=						[Txt "Choose persons you want to delegate work to:",Br,Br] 
						?>>	determineSet [] =>> \set -> delegateToSet set
where
	delegateToSet set = recTask "delegateToSet" delegateToSet`
	where 
		delegateToSet`						
		  =					PCTasks [("Waiting", who @:: STask "I Will Do It" Void #>> returnV who) \\ who <- set]
			=>> \who 	->	who @:: (timedTask time taskToDelegate)	
			=>> \(b,work)->	if b (returnV work) (delegateToSet set )

	determineSet set = recTask "determineSet" determineSet`
	where
		determineSet`	
		= 					[Txt ("Current set:" +++ print set)] 
							?>> CTask	[("Add Person", cancelTask choosePerson =>> \nr  -> returnV nr)
										,("Finished",	returnV Nothing)
										]
			=>> \result -> case result of
							(Just new)  -> determineSet (sort (removeDup [new:set])) 
							Nothing		-> returnV set

		choosePerson =	STask "Set" (PullDown (1,100) (0,[toString i \\ i <- [1..npersons]]))
						=>> \whomPD  -> returnV (Just (toInt(toString whomPD)))

		cancelTask task = PCTask2 (task,STask "Cancel" Void #>> returnV createDefault)
		
		print [] = ""
		print [x:xs] = toString x +++ " " +++ print xs

	timedTask time task	= PCTask2  	( PCTasks 	[ ("TimedTask",task =>> \value -> returnV (True,value))
												, ("Return", returnV (False,createDefault))
												] 
						 			, waitForTimerTask time #>> returnV (False,createDefault)
						  			)