htmlTask.dcl 6.88 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
definition module htmlTask

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
3
// library for controlling interactive Tasks (iTask) based on iData
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
4
// (c) 2006,2007 MJP
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
5
6
7
8
9

import StdHtml

:: *TSt										// task state
:: Task a		:== St *TSt a				// an interactive task
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
10
11
12
13
14
15
16
:: Void 		= Void						// for tasks returning non interesting results

derive gForm 	Void
derive gUpd 	Void
derive gParse 	Void
derive gPrint 	Void
derive gerda 	Void
17

18
/* Initiating the iTask library:
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
19
20
21
startTask		:: start function for iTasks for user with indicated id		
singleUserTask 	:: start wrapper function for single user 
multiUserTask 	:: start wrapper function for user with indicated id with option to switch between [0..users - 1]  
22
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
23
24
25
startTask 		:: !Int !(Task a) 	!*HSt -> (a,[BodyTag],!*HSt) 	| iData a 
singleUserTask 	:: !(Task a) 		!*HSt -> (Html,*HSt) 			| iData a 
multiUserTask 	:: !Int !(Task a)  	!*HSt -> (Html,*HSt) 			| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
26

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
27
28
/* Global Attribute settings: iTask are by default Lifespan = Session, StorageFormt = PlainString
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
29
class setTaskAttr a :: !a *TSt -> *TSt
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
30

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
31
instance setTaskAttr Lifespan, StorageFormat, Mode
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
32

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
33
/* Operations on Task state
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
34
taskId			:: id assigned to task
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
35
36
37
userId			:: id of application user
*/

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
38
taskId			:: TSt -> (Int,TSt)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
39
40
userId 			:: TSt -> (Int,TSt)

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
41
/* Assign tasks with informative name to user with indicated id
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
42
43
(@:)			:: will prompt who is waiting for what
(@::)			:: no prompting
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
44
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
45
46
(@:)  infix 4 	:: !(!Int,!String) (Task a)	-> (Task a)			| iData a
(@::) infix 4 	:: !Int (Task a)		    -> (Task a)			| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
47

48
/* Promote any TSt state transition function to an iTask:
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
49
50
recTask			:: to create a function which can recursively be called as a task
repeatTask		:: infinitely repeating Task
51
52
53
54
recTaskGC		:: same, and garbage collect *all* (persistent) subtasks
repeatTaskGC	:: same, and garbage collect *all* (persistent) subtasks
recTask2		:: same, non optimized version will increase stack
repeatTask2		:: same, non optimized version will increase stack
55
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
56
recTask 		:: !String (Task a) 		-> (Task a) 		| iData a 
57
58
59
60
repeatTask		:: (Task a) 				-> Task a 			| iData a

recTaskGC 		:: !String (Task a) 		-> (Task a) 		| iData a 
repeatTaskGC	:: (Task a) 				-> Task a 			| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
61

62
recTask2 		:: !String (Task a) 		-> (Task a) 		| iData a 
63
64
repeatTask2 	:: (Task a) 				-> Task a 			| iData a

65

66
/*	Sequential Tasks:
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
67
68
69
STask			:: a Sequential iTask
STask_button	:: do corresponding iTask when button pressed
STasks			:: do all iTasks one after another, task completed when all done
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
70
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
71
72
73
STask 			:: String a 			-> (Task a)				| iData a 
STask_button	:: String (Task a)		-> (Task a) 			| iData a
STasks			:: [(String,Task a)] 	-> (Task [a])			| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
74

75
/* Choose one Task out of n:
76
CTask			:: Choose one iTask from list, depending on button pressed
77
78
CTask_pdmenu	:: Choose one iTask from list, depending on pulldownmenu item selected
*/
79
CTask		 	:: [(String,Task a)] 	-> (Task a) 			| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
80
CTask_pdmenu 	:: [(String,Task a)] 	-> (Task a)	 			| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
81

82
83
84
/* Choose m Tasks out of n:
MCTask_ckbox	:: Multiple Choice of iTasks, depending on marked checkboxes
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
85
MCTask_ckbox 	:: [(String,Task a)] 	-> (Task [a]) 			| iData a
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
86

87
88
89
90
/* Do m Tasks parallel / interleaved and FINISH as soon as SOME Task completes:
PCTask2			:: do both iTasks in any order, task completed and ends as soon as first one done
PCTasks			:: do all  iTasks in any order, task completed and ends as soon as first one done
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
91
92
PCTask2			:: (Task a,Task a) 		-> (Task a) 			| iData a 
PCTasks			:: [(String,Task a)] 	-> (Task a)				| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
93

94
95
96
97
98
/* Do Tasks parallel / interleaved and FINISH when ALL Tasks done:
PTask2			:: do both iTasks in any order (paralel), task completed when both done
PTasks			:: do all  iTasks in any order (paralel), task completed when all  done
PMilestoneTasks :: do all  iTasks in any order (paralel), task completed when all  done
					but continue with next task as soon as SOME Task completes
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
99
					string indicates which tasks have completed
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
100
PmuTasks		:: assign task to indicated users, task completed when all done
101
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
102
103
PTask2 			:: (Task a,Task b) 		-> (Task (a,b)) 		| iData a & iData b
PTasks 			:: [(String,Task a)]	-> (Task [a])			| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
104
PMilestoneTasks :: [(String,Task a)] 	-> (Task [(String,a)]) 	| iData a 
105
PmuTasks 		:: String [(Int,Task a)]-> (Task [a]) 			| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
106

107
108
109
110
111
112
/* Tasks that do not require IO actions from the user:
returnV			:: return the value
returnTask		:: return the value and show it 
returnVF		:: return the value and show the Html code specified
returnF			:: add html code
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
113
114
115
returnV 		:: a 					-> (Task a) 			| iData a 
returnTask 		:: a 					-> (Task a) 			| iData a 
returnVF 		:: a [BodyTag] 			-> (Task a) 			| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
116
returnF 		:: [BodyTag] 			-> TSt -> TSt
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
117

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
118
/* Experimental!! DONT USE Setting up communication channels between users:
119
120
121
122
123
124
mkRTask			:: Remote Task: split indicated task in two tasks: a calling task and a receiving task
					the caller will wait until the receiver has completed the task
mkRTaskCall 	:: as mkRTask, but the caller will provide input for the remote task
mkRDynTaskCall 	:: a remote task is set up, but the task that is created will be determined dynamically !
					BE CAREFUL: static dynamics are used here, will work only for one exectable.
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
125
mkRTask 		:: String (Task a) *TSt -> ((Task a,Task a),*TSt) 		| iData a 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
126
mkRTaskCall		:: String b (b -> Task a) *TSt 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
127
										-> ((b -> Task a,Task a),*TSt)	| iData a & iData b
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
128
mkRDynTaskCall 	:: String a *TSt -> (((Task a) -> (Task a),Task a),*TSt)| iData a
129
130
131

/* Time and Date management:
waitForTimeTask	:: Task is done when time has come
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
132
waitForTimerTask:: Task is done when specified amount of time has passed 
133
134
135
waitForDateTask	:: Task is done when date has come
*/
waitForTimeTask	:: HtmlTime				-> (Task HtmlTime)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
136
waitForTimerTask:: HtmlTime				-> (Task HtmlTime)
137
138
139
140
141
142
waitForDateTask	:: HtmlDate				-> (Task HtmlDate)

/* Lifting iData domain to iTask domain
appIData		:: lift iData editors to iTask domain
appHSt			:: lift HSt domain to TSt domain
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
143
144
appIData 		:: (IDataFun a) 		-> (Task a) 			| iData a
appHSt 			:: (HSt -> (a,HSt)) 	-> (Task a)				| iData a
145

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
146
/* monadic shorthands
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
147
148
(=>>)			:: bind
(#>>)			:: bind, no argument passed
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
149

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
150
151
(?>>)			:: prompt as long as task is active but not finished
(!>>)			:: prompt when task is activated
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
152

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
153
154
155
156
157
(*>>)			:: applying function of type: TSt -> (a,TSt)
(@>>)			:: applying function of type: TSt -> TSt

(<|)			:: repeat task as long as predicate does not hold
(<<@)			:: set attribute for indicated task
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
158
159
*/

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
160
161
(=>>) infix  1 	:: w:(St .s .a) v:(.a -> .(St .s .b)) -> u:(St .s .b), [u <= v, u <= w]	
(#>>) infixl 1 	:: w:(St .s .a) v:(St .s .b) -> u:(St .s .b), [u <= v, u <= w]			
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
162
163
(?>>) infix  2 	:: [BodyTag] v:(St TSt .a) -> v:(St TSt .a)
(!>>) infix  2 	:: [BodyTag] v:(St TSt .a) -> v:(St TSt .a)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
164
165
(*>>) infix  4	:: w:(St .s .a)  v:(.a -> .(St .s .b)) -> u:(St .s .b), [u <= v, u <= w]
(@>>) infix  4	:: w:(.s -> .s)  v:(St .s .b) -> u:(St .s .b), [u <= v, u <= w]
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
166
167
(<|)  infix  3 	:: (St TSt a) (a -> .Bool, a -> String) -> (St TSt a) | iData a
(<<@) infix  3 	::  v:(St TSt .a) b  -> u:(St TSt .a) | setTaskAttr b, [u <= v]
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
168