summaryrefslogtreecommitdiff
path: root/assignment-7/appointments.icl
blob: 9de3c2691f08816a708f5f851f0fbf4f33e06777 (plain) (blame)
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
module appointments

from StdFunc import flip
from Data.Func import $
import iTasks

:: Appointment =
	{ title        :: String
	, when         :: DateTime
	, duration     :: Time
	, owner        :: User
	, participants :: [User]
	}

derive class iTask Appointment

appointments :: Shared [Appointment]
appointments = sharedStore "appointments" []

Start :: *World -> *World
Start w = startEngine
	(   addWorkFlows
	>>| loginAndManageWorkList "Scheduler" worklist
	) w
where
	addWorkFlows :: Task [Workflow]
	addWorkFlows = upd (flip (++) newwfs) workflows
	where
		newwfs =
			[ transientWorkflow "Show appointments" "Show appointments" showAppointments
			, transientWorkflow "Make appointment"  "Make appointment"  makeAppointment
			]

	worklist :: [Workflow]
	worklist = [workflow "Manage users" "Manage users" manageUsers]

showAppointments :: Task [Appointment]
showAppointments =
	get currentUser >>= \user ->
	viewSharedInformation
		(Title "Future appointments")
		[ViewAs $ filter (\a -> a.owner == user)]
		appointments

makeAppointment :: Task [Appointment]
makeAppointment =
	enterInformation (Title "Make appointment") [] >>= \app ->
	upd (flip (++) [app]) appointments