Commit ca8b47f8 authored by Rinus Plasmeijer's avatar Rinus Plasmeijer

deleted vote example

added broadcast and email example

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@923 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent adc5ea75
......@@ -3,7 +3,6 @@ module AllExamples
import iTasks
//Business examples
import Vote
import TravelBooking
//Higher order examples
......@@ -41,8 +40,7 @@ import SharedValues
Start :: *World -> *World
Start world = startEngine workflows world
where
workflows = flatten [ voteExample
, travelBookingExample
workflows = flatten [ travelBookingExample
, movingTaskExample
, deadlineTaskExample
, delegateTaskExample
......
definition module Vote
import iTasks
voteExample :: [Workflow]
\ No newline at end of file
implementation module Vote
//This example lets users give a vote.
//Only the user with role "root" can view the votes
import iTasks
import CommonDomain
derive gPrint Vote
derive gParse Vote
derive gVisualize Vote
derive gUpdate Vote
derive bimap (,), Maybe
:: Vote = { userName :: UserName
, vote :: Int
, comment :: String
}
voteExample :: [Workflow]
voteExample = [{ name = "Examples/Business/Vote/Show votes"
, label = "Show votes"
, roles = ["root"]
, mainTask = showVotes
}
,{ name = "Examples/Business/Vote/New vote"
, label = "Give vote"
, roles = []
, mainTask = giveVote
}
,{ name = "Examples/Business/Vote/New comment"
, label = "Give comment"
, roles = []
, mainTask = giveComment
}
]
showVotes :: Task Void
showVotes
= readVotesDB
>>= \votes -> getDisplayNames [vote.Vote.userName \\ vote <- votes]
>>= \userNames -> showMessage
[ Text "The following votes are given:", BrTag [], BrTag []
, formatVotes [(toString i) \\ i <- [0..10]]
[(toString (number i votes)) \\ i <- [0..10]]
, HrTag []
, formatComments [(u,v) \\ v <- votes & u <- userNames]
, HrTag []
]
where
number i votes = length [n \\ n <- votes | n.vote == i]
formatVotes header data = TableTag [StyleAttr "border: 1px solid #ccc"]
[TrTag [] [ThTag [] [BTag [] [Text th]] \\th <- header]
,TrTag [] [TdTag [] [Text td] \\ td <- data]
]
formatComments rows = TableTag []
[TrTag [] [TdTag [] [Text u,Text ":"],TdTag [] [Text v.comment]] \\ (u,v) <- rows]
giveVote :: Task Void
giveVote
= getCurrentUser
>>= \currentUser -> readMyVoteDB (toUserName currentUser)
>>= \(vote,comment) -> enterChoice
[ Text ("Previous vote given:" +++ if (vote == -1) "No vote given" (toString vote)), BrTag [], BrTag []
, Text "Give your new vote (0 = lowest, 10 = highest)"
] [0..10]
>>= \vote -> readMyVoteDB (toUserName currentUser)
>>= \(_,comment) -> writeVotesDB {userName = toUserName currentUser, vote = vote, comment = comment}
>>| showMessage [Text ("Your vote " +++ toString vote +++ " has been stored!")]
giveComment :: Task Void
giveComment
= getCurrentUser
>>= \currentUser -> readMyVoteDB (toUserName currentUser)
>>= \(vote,comment) -> enterInformation
[ Text "Previous comment given:", BrTag [], BrTag []
, Text (if (comment == "" ) "None" comment), BrTag [], BrTag []
, Text "Submit a new comment:", BrTag [], BrTag []
]
>>= \(Note comment) -> readMyVoteDB (toUserName currentUser)
>>= \(vote,_) ->
writeVotesDB {userName = toUserName currentUser, vote = vote, comment = comment}
>>| showMessage
[ Text "Your comment:", BrTag [], BrTag []
, Text comment, BrTag [], BrTag []
, Text "has been stored!"
]
//Simple votes database
votesId :: DBid [Vote]
votesId = mkDBid "votes"
readVotesDB :: Task [Vote]
readVotesDB = readDB votesId
readMyVoteDB :: UserName -> Task (Int,String)
readMyVoteDB name
= readVotesDB
>>= \votes -> return (case (filter (\vote -> vote.Vote.userName == name) votes) of
[] -> (-1,"")
[vote:_] -> (vote.vote, vote.comment)
)
writeVotesDB :: Vote -> Task [Vote]
writeVotesDB acc
= readVotesDB
>>= \accs -> writeDB votesId [acc:[oacc \\ oacc <- accs | oacc.Vote.userName <> acc.Vote.userName]]
......@@ -9,22 +9,20 @@ import StdList, StdOrdList, StdTuple, StdMisc
import iTasks
import CommonDomain
derive gPrint EMail, Reply, DisplayNews
derive gParse EMail, Reply, DisplayNews
derive gVisualize EMail, Reply, DisplayNews
derive gUpdate EMail, Reply, DisplayNews
derive gPrint EMail, Reply, DisplayNews, Broadcast
derive gParse EMail, Reply, DisplayNews, Broadcast
derive gVisualize EMail, Reply, DisplayNews, Broadcast
derive gUpdate EMail, Reply, DisplayNews, Broadcast
derive bimap Maybe, (,)
ifValid expr = Predicate (\val -> case val of
Invalid -> False
_ -> expr)
newsgroupsExample :: [Workflow]
newsgroupsExample
= [ workflow "Examples/Communication/Newsgroups" handleMenu
, workflow "Examples/Communication/Mail with receive confirmation" internalEmail
, workflow "Examples/Communication/Mail with forced reply" internalEmailReply
, workflow "Examples/Communication/mail" internalEmail
, workflow "Examples/Communication/broadcast" internalBroadcast
, workflow "Examples/Communication/mail with confirmation" internalEmailConf
, workflow "Examples/Communication/mail with forced reply" internalEmailReply
]
// mail handling, to be put in sepparate icl file
......@@ -36,9 +34,38 @@ newsgroupsExample
}
:: Reply = { reply :: !Note
}
:: Broadcast = { subject :: !String
, message :: !Note
, attachements :: ![Document]
}
internalBroadcast :: (Task Broadcast)
internalBroadcast
= enterInformation "Type your broadcast message ..."
>>= \msg -> getCurrentUser
>>= \me -> getUsers
>>= \users -> broadcast me msg users
>>| return msg
where
broadcast :: User Broadcast [User] -> Task Broadcast
broadcast me msg []
= return msg
broadcast me msg [u:us]
= spawnProcess (UserName u.userName u.displayName)True
(showMessageAbout ("You have received the following broadcast message from " <+++ me.displayName) msg <<@ msg.Broadcast.subject)
>>| broadcast me msg us
internalEmail :: (Task EMail)
internalEmail
= enterInformation "Type your email message ..."
>>= \msg -> getCurrentUser
>>= \me -> spawnProcess msg.to True
(showMessageAbout ("You have received the following message from " <+++ me.displayName) msg <<@ msg.EMail.subject)
>>| return msg
internalEmailConf :: (Task EMail)
internalEmailConf
= enterInformation "Type your email message ..."
>>= \msg -> getCurrentUser
>>= \me -> msg.to @: (msg.EMail.subject, showMessageAbout ("You have received the following message from " <+++ me.displayName) msg)
......
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