Toolbox.icl 2.63 KB
Newer Older
ecrombag's avatar
ecrombag committed
1 2 3 4 5 6
implementation module Toolbox

/*
	This toolbox contains a number of workflows which can be handle unforseen situations. Or can be used as 'units' in other workflows.
*/

ecrombag's avatar
ecrombag committed
7
import iTasks, GenEq
ecrombag's avatar
ecrombag committed
8
import CommonDomain, Messaging
ecrombag's avatar
ecrombag committed
9

ecrombag's avatar
ecrombag committed
10
from HRM import getUserGroups
ecrombag's avatar
ecrombag committed
11 12 13 14 15

derive bimap Maybe, (,)

toolbox :: [Workflow]
toolbox 
ecrombag's avatar
ecrombag committed
16
	= [ workflow "Toolbox/Pick a date" pickADate
ecrombag's avatar
ecrombag committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
	  ]

//========================================================================================================================================================================
// DatePicker
//========================================================================================================================================================================

:: DateVotes :== (HtmlDisplay [DateVote])

:: DateVote = 
	{ date :: Date
	, vote :: (Editable Vote)
	}

:: Vote = Yes | No | Maybe

:: VoteCount =
	{ date 	:: Date
	, yes 	:: Int
	, no 	:: Int
	, maybe :: Int
	}
	
ecrombag's avatar
ecrombag committed
39
derive class iTask	DateVote, Vote, VoteCount
ecrombag's avatar
ecrombag committed
40 41 42
derive gEq			Date

pickADate :: Task Void
Bas Lijnse's avatar
Bas Lijnse committed
43
pickADate = enterInformation "Subject" "What is the subject?"
44
	>>= \subj ->	getCurrentUser
Bas Lijnse's avatar
Bas Lijnse committed
45 46
	>>= \me -> 		updateInformation "Manager" "Who should be managing the decision?" me
	>>= \ref ->		enterInformation "Choose people" "Who else should be involved in the decision?"
ecrombag's avatar
ecrombag committed
47 48 49 50 51 52 53 54 55
	>>= \oth ->		(ref @: datePicker [ref:oth])
	>>= \date ->	broadcast [ref:oth] ("The chosen date for "+++subj+++": ") (Just date)

datePicker :: [User] -> Task Date
datePicker users =  pickDates
	>>= \dates -> allProc [u @>> voteDates dates \\ u <- users] Open
	>>= \votes -> pickFinal votes
where
	pickDates :: Task [Date]
Bas Lijnse's avatar
Bas Lijnse committed
56
	pickDates = enterInformation "Pick dates" "Please select date options"
ecrombag's avatar
ecrombag committed
57 58

	voteDates :: [Date] -> Task DateVotes
Bas Lijnse's avatar
Bas Lijnse committed
59
	voteDates dates = updateInformation "Date preference" "Please indicate your preference" (HtmlDisplay [{DateVote | date = d, vote = (Editable Maybe)} \\ d <- dates])
ecrombag's avatar
ecrombag committed
60 61 62 63 64 65

	pickFinal :: [DateVotes] -> Task Date
	pickFinal votes
		# v = (map fromHtmlDisplay votes)
		# init = [{VoteCount | date = dv.DateVote.date, yes = 0, no = 0, maybe = 0} \\ dv <- (hd v)]
		# overview = foldl countVotes init v
Bas Lijnse's avatar
Bas Lijnse committed
66
		=   enterChoice "Final decision" "Please select the final option" overview
ecrombag's avatar
ecrombag committed
67 68 69 70 71 72 73 74 75 76 77 78
		>>= \final -> return final.VoteCount.date
	where
		countVotes votecount [] = votecount
		countVotes votecount [d:ds]
			# votecount = [if(d.DateVote.date === vc.VoteCount.date) (updateCount vc d.vote) vc \\ vc <- votecount]
			= countVotes votecount ds
			
		updateCount vc=:{yes,no,maybe} (Editable v)
			= case v of
				Yes 	= {vc & yes 	= inc yes}
				No  	= {vc & no  	= inc no}
				Maybe	= {vc & maybe 	= inc maybe}