Commit c375c026 authored by Rinus Plasmeijer's avatar Rinus Plasmeijer
Browse files

made small improvements combinators

made selectTasks more general: now one can choose to do the selected tasks in any given oreder, eg
one by one, or all in parallel
parent 8470081e
...@@ -49,9 +49,10 @@ seqTasks :: ![LabeledTask a] -> Task [a] | iCreateAndPrint a ...@@ -49,9 +49,10 @@ seqTasks :: ![LabeledTask a] -> Task [a] | iCreateAndPrint a
/* /*
Select the tasks to do from a given list of tasks: Select the tasks to do from a given list of tasks:
selectTasks :: the first argument is task yielding the task numbers (index in the list) to do; tasks will be done in this order. selectTasks :: the first argument is task yielding the task numbers (index in the list) to do; illegal indices will be ignored
the second argument is a task that should perform these tasks (in any order, sequential or concurrent).
*/ */
selectTasks :: !([LabeledTask a] -> Task [Int]) [LabeledTask a] -> Task [a] | iData a selectTasks :: !([LabeledTask a] -> Task [Int]) !(![LabeledTask a] -> Task [a]) ![LabeledTask a] -> Task [a] | iData a
/* /*
Do m Tasks parallel / interleaved and FINISH as soon as SOME Task completes: Do m Tasks parallel / interleaved and FINISH as soon as SOME Task completes:
......
...@@ -122,8 +122,6 @@ where ...@@ -122,8 +122,6 @@ where
((nuserId,processNr,workflowLabel,taskname) @@: nhtml) ((nuserId,processNr,workflowLabel,taskname) @@: nhtml)
}) })
showUser nr = showLabel ("User " <+++ nr)
// ****************************************************************************************************** // ******************************************************************************************************
// sequencingtasks // sequencingtasks
...@@ -145,12 +143,14 @@ where ...@@ -145,12 +143,14 @@ where
// ****************************************************************************************************** // ******************************************************************************************************
// Select the tasks to do from a list with help of another task for selecting them: // Select the tasks to do from a list with help of another task for selecting them:
selectTasks :: !([LabeledTask a] -> Task [Int]) [LabeledTask a] -> Task [a] | iData a selectTasks :: !([LabeledTask a] -> Task [Int]) !(![LabeledTask a] -> Task [a]) ![LabeledTask a] -> Task [a] | iData a
selectTasks chooser ltasks = newTask "selectTask" selectTasks` selectTasks chooser executer ltasks = newTask "selectTask" selectTasks`
where where
selectTasks` selectTasks`
= chooser ltasks = chooser ltasks
=>> \chosen -> seqTasks [ltasks!!i \\ i <- chosen] =>> \chosen -> executer [ltasks!!i \\ i <- chosen | i >=0 && i < lengthltask]
lengthltask = length ltasks
// ****************************************************************************************************** // ******************************************************************************************************
// Speculative OR-tasks: task ends as soon as one of its subtasks completes // Speculative OR-tasks: task ends as soon as one of its subtasks completes
......
...@@ -51,7 +51,7 @@ chooseTask_pdm :: !HtmlCode !Int ![LabeledTask a] -> Task a | iData a ...@@ -51,7 +51,7 @@ chooseTask_pdm :: !HtmlCode !Int ![LabeledTask a] -> Task a | iData a
chooseTask_radio:: !HtmlCode !Int ![(HtmlCode,LabeledTask a)] chooseTask_radio:: !HtmlCode !Int ![(HtmlCode,LabeledTask a)]
-> Task a | iData a -> Task a | iData a
chooseTask_cbox :: !([LabeledTask a] -> Task [a]) chooseTask_cbox :: !(![LabeledTask a] -> Task [a])
!HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)] !HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)]
-> Task [a] | iData a -> Task [a] | iData a
......
...@@ -90,7 +90,7 @@ where ...@@ -90,7 +90,7 @@ where
chooseTask_btn :: !HtmlCode !Bool![LabeledTask a] -> Task a | iData a chooseTask_btn :: !HtmlCode !Bool![LabeledTask a] -> Task a | iData a
chooseTask_btn prompt horizontal ltasks chooseTask_btn prompt horizontal ltasks
= selectTasks (\lt -> prompt ?>> selectTask_btn horizontal lt) ltasks =>> \la -> return_V (hd la) = selectTasks (\lt -> prompt ?>> selectTask_btn horizontal lt) seqTasks ltasks =>> \la -> return_V (hd la)
where where
selectTask_btn direction ltasks = newTask "selectTask_btn" (selectTask_btn` direction ltasks) selectTask_btn direction ltasks = newTask "selectTask_btn" (selectTask_btn` direction ltasks)
...@@ -106,16 +106,18 @@ where ...@@ -106,16 +106,18 @@ where
# (choice,tst) = liftHst (TableFuncBut (Init,pageFormId options buttonId allButtons)) tst # (choice,tst) = liftHst (TableFuncBut (Init,pageFormId options buttonId allButtons)) tst
# (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) choice.value) tst # (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) choice.value) tst
| chosen.value == -1 = ([],{tst & activated = False,html = html +|+ BT choice.form}) | chosen.value == -1 = ([],{tst & activated = False,html = html +|+ BT choice.form})
= ([chosen.value],{tst & tasknr = tasknr, activated = True, html = html}) = ([chosen.value],{tst & activated = True})
= ([chosen.value],{tst & tasknr = tasknr, activated = True, html = html}) = ([chosen.value],{tst & activated = True})
chooseTask_pdm :: !HtmlCode !Int ![LabeledTask a] -> Task a | iData a chooseTask_pdm :: !HtmlCode !Int ![LabeledTask a] -> Task a | iData a
chooseTask_pdm prompt initial ltasks chooseTask_pdm prompt initial ltasks
= selectTasks (\lt -> prompt ?>> selectTask_pdm initial lt) ltasks =>> \la -> return_V (hd la) = selectTasks (\lt -> prompt ?>> selectTask_pdm initial lt) seqTasks ltasks =>> \la -> return_V (hd la)
where where
selectTask_pdm _ [] tst = return createDefault tst selectTask_pdm initial ltasks = newTask "selectTask_pdm" (selectTask_pdm` initial ltasks)
selectTask_pdm defaultOn taskOptions tst=:{tasknr,html,userId,options} // choose one subtask out of a pulldown menu
selectTask_pdm` _ [] tst = return createDefault tst
selectTask_pdm` defaultOn taskOptions tst=:{tasknr,html,userId,options} // choose one subtask out of a pulldown menu
# taskId = iTaskId userId tasknr ("ChoStPdm" <+++ length taskOptions) # taskId = iTaskId userId tasknr ("ChoStPdm" <+++ length taskOptions)
# (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) id) tst # (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) id) tst
| chosen.value == -1 // no choice made yet | chosen.value == -1 // no choice made yet
...@@ -131,30 +133,16 @@ where ...@@ -131,30 +133,16 @@ where
# (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) (\_ -> chosenIdx)) tst # (chosen,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId -1) (\_ -> chosenIdx)) tst
= ([chosen.value],{tst & tasknr = tasknr, activated = True, html = html}) = ([chosen.value],{tst & tasknr = tasknr, activated = True, html = html})
= ([chosen.value],{tst & activated = True, html = html, tasknr = tasknr}) = ([chosen.value],{tst & activated = True, html = html, tasknr = tasknr})
/*
selectTask_pdm :: !Int ![LabeledTask a] -> Task [Int]
selectTask_pdm defaultOn taskOptions = dochooseTask_pdm taskOptions
where
dochooseTask_pdm [] tst = return createDefault tst
dochooseTask_pdm taskOptions tst=:{tasknr,html,userId,options} // choose one subtask out of a pulldown menu
# numberOfItems = length taskOptions
# defaultOn = if (defaultOn >= 0 && defaultOn <= numberOfItems - 1) defaultOn 0
# taskPdMenuId = iTaskId userId tasknr ("ChoPdm" <+++ numberOfItems)
# (choice,tst) = liftHst (FuncMenu (Init,sessionFormId options taskPdMenuId (defaultOn,[(txt,id) \\ txt <- map fst taskOptions]))) tst
# (_,tst=:{activated=adone,html=ahtml})
= editTaskLabel "" "Done" Void {tst & activated = True, html = BT [], tasknr = [-1:tasknr]}
| not adone = (createDefault,{tst & activated = False, html = html +|+ BT choice.form +|+ ahtml, tasknr = tasknr})
= ([snd choice.value],{tst & activated = True, html = html, tasknr = tasknr})
*/
chooseTask_radio:: !HtmlCode !Int ![(HtmlCode,LabeledTask a)] -> Task a | iData a chooseTask_radio:: !HtmlCode !Int ![(HtmlCode,LabeledTask a)] -> Task a | iData a
chooseTask_radio prompt initial code_ltasks chooseTask_radio prompt initial code_ltasks
= selectTasks (\lt -> prompt ?>> selectTask_radio initial (map fst code_ltasks) lt) (map snd code_ltasks) =>> \la -> return_V (hd la) = selectTasks (\lt -> prompt ?>> selectTask_radio initial (map fst code_ltasks) lt) seqTasks (map snd code_ltasks) =>> \la -> return_V (hd la)
where where
selectTask_radio :: !Int ![HtmlCode] ![LabeledTask a] -> Task [Int] selectTask_radio :: !Int ![HtmlCode] ![LabeledTask a] -> Task [Int]
selectTask_radio defaultOn htmlcodes taskOptions = dochooseTask_pdm taskOptions selectTask_radio defaultOn htmlcodes taskOptions = newTask "selectTask_radio" (selectTask_radio` taskOptions)
where where
dochooseTask_pdm [] tst = return createDefault tst selectTask_radio` [] tst = return createDefault tst
dochooseTask_pdm taskOptions tst=:{tasknr,html,userId,options} // choose one subtask out of a pulldown menu selectTask_radio` taskOptions tst=:{tasknr,html,userId,options} // choose one subtask out of a pulldown menu
# numberOfButtons = length taskOptions # numberOfButtons = length taskOptions
# defaultOn = if (defaultOn >= 0 && defaultOn <= numberOfButtons - 1) defaultOn 0 # defaultOn = if (defaultOn >= 0 && defaultOn <= numberOfButtons - 1) defaultOn 0
# taskId = iTaskId userId tasknr ("ChoStRadio" <+++ numberOfButtons) # taskId = iTaskId userId tasknr ("ChoStRadio" <+++ numberOfButtons)
...@@ -171,16 +159,16 @@ where ...@@ -171,16 +159,16 @@ where
= (createDefault,{tst & activated = False, html = html +|+ BT [radioform] +|+ ahtml, tasknr = tasknr}) = (createDefault,{tst & activated = False, html = html +|+ BT [radioform] +|+ ahtml, tasknr = tasknr})
= ([choice],{tst & activated = True, html = html, tasknr = tasknr}) = ([choice],{tst & activated = True, html = html, tasknr = tasknr})
chooseTask_cbox :: !([LabeledTask a] -> Task [a]) !HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)] -> Task [a] | iData a chooseTask_cbox :: !(![LabeledTask a] -> Task [a]) !HtmlCode ![((!Bool,!ChoiceUpdate,!HtmlCode),LabeledTask a)] -> Task [a] | iData a
chooseTask_cbox whatisthis prompt code_ltasks chooseTask_cbox order prompt code_ltasks
= selectTasks (\lt -> prompt ?>> selectTask_cbox (map fst code_ltasks) lt) (map snd code_ltasks) = selectTasks (\lt -> prompt ?>> selectTask_cbox (map fst code_ltasks) lt) order (map snd code_ltasks)
where where
selectTask_cbox :: ![(!Bool,!ChoiceUpdate,!HtmlCode)] ![LabeledTask a] -> Task [Int] selectTask_cbox :: ![(!Bool,!ChoiceUpdate,!HtmlCode)] ![LabeledTask a] -> Task [Int]
selectTask_cbox htmlcodes taskOptions = domchoiceTasks taskOptions selectTask_cbox htmlcodes taskOptions = newTask "selectTask_cbox" (selectTask_cbox` taskOptions)
where where
domchoiceTasks [] tst = ([],{tst& activated = True}) selectTask_cbox` [] tst = ([],{tst& activated = True})
domchoiceTasks taskOptions tst=:{tasknr,html,options,userId} // choose one subtask out of the list selectTask_cbox` taskOptions tst=:{tasknr,html,options,userId} // choose one subtask out of the list
# seltaskId = iTaskId userId tasknr ("MtpChSel" <+++ length taskOptions) # seltaskId = iTaskId userId tasknr ("MtpChSel" <+++ length taskOptions)
# donetaskId = iTaskId userId tasknr "MtpChSt" # donetaskId = iTaskId userId tasknr "MtpChSt"
# (cboxes,tst) = liftHst (ListFuncCheckBox (Init,cFormId options seltaskId initCheckboxes)) tst # (cboxes,tst) = liftHst (ListFuncCheckBox (Init,cFormId options seltaskId initCheckboxes)) tst
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment