\r
instance + String where + s t = s +++ t\r
\r
-Start w = doTasks (changeName student) w\r
+Start w = doTasks (changeNameEdcomb student) w\r
\r
enterStudent :: Task Student\r
enterStudent = enterInformation "Enter a student" []\r
selectStudent = enterChoice "Pick a student" []\r
\r
selectStudentOnlyName :: ([Student] -> Task Student)\r
-selectStudentOnlyName = enterChoice "Pick a student" [ChooseFromDropdown \s->s.Student.name]\r
+selectStudentOnlyName = enterChoice "Pick a student" [ChooseFromDropdown \{Student|name}->name]\r
\r
selectStudentFormat :: ([Student] -> Task Student)\r
selectStudentFormat = enterChoice "Pick a student" [ChooseFromDropdown gToString{|*|}]\r
\r
selectPartner :: ([Student] -> Task [Student])\r
-selectPartner = enterMultipleChoice "Pick a partner" [ChooseFromDropdown \s->s.Student.name + "(" + gToString{|*|} s.Student.bama + ")"]\r
+selectPartner = enterMultipleChoice "Pick a partner" [ChooseFromDropdown \{name,bama}->name + "(" + gToString{|*|} bama + ")"]\r
\r
changeName :: Student -> Task Student\r
changeName s\r
= viewInformation "Student to change" [] s\r
- ||- updateInformation "New name" [UpdateAs (\s->s.Student.name) (\s n->{Student | s & name=n})] s\r
+ ||- updateInformation "New name" [UpdateAs (\{Student|name}->name) (\s n->{Student | s & name=n})] s\r
\r
changeNameEdcomb :: Student -> Task Student\r
changeNameEdcomb s\r
- = updateInformation "New name" [UpdateUsing id (\_ v->v) studed] s\r
+ = updateInformation "New name" [UpdateUsing id (\_ v->v) nameEditor] s\r
+ >>= viewInformation "done" []\r
where\r
- studed :: Editor Student\r
- studed = bijectEditorValue\r
- (\s->(s.Student.name, s.snum, s.bama, s.year))\r
+ nameEditor :: Editor Student\r
+ nameEditor = bijectEditorValue\r
+ (\{name=n,snum=s,bama=b,year=y}->(n, s, b, y))\r
(\(n,s,b,y)->{name=n,snum=s,bama=b,year=y})\r
(container4\r
- gEditor{|*|}\r
- (withChangedEditMode toView gEditor{|*|})\r
- (withChangedEditMode toView gEditor{|*|})\r
- (withChangedEditMode toView gEditor{|*|})\r
+ (gEditor{|*|} <<@ labelAttr "name")\r
+ (withChangedEditMode toView gEditor{|*|} <<@ labelAttr "snum")\r
+ (withChangedEditMode toView gEditor{|*|} <<@ labelAttr "bama")\r
+ (withChangedEditMode toView gEditor{|*|} <<@ labelAttr "year")\r
)\r
+\r
toView (Update a) = View a\r
toView v = v\r
--- /dev/null
+module a5
+
+import Data.List
+import Data.Func
+import Text
+
+import iTasks
+
+derive class iTask Function, Question
+:: Function = Student | Teacher | Admin
+:: Question =
+ { question :: String
+ , answers :: [String]
+ , correct :: Int
+ }
+
+questions :: Shared [Question]
+questions = sharedStore "questions"
+ [{question="Afp cool?"
+ ,answers=["yes", "no"]
+ ,correct=0}
+ ,{question="Mart the awesomest TA?"
+ ,answers=["yes", "no"]
+ ,correct=0}
+ ]
+
+Start w = doTasks login w
+
+login :: Task [Question]
+login = enterInformation "Enter your function" []
+ >>= \function->case function of
+ Teacher = teacher
+ Admin = admin
+ Student = student
+
+student :: Task [Question]
+student = get questions
+ >>= \qs->sequence (map makeQuestion qs) @ distillResult
+ >>= viewInformation "Result" []
+ >>* [OnAction (Action "Quit") (always login)]
+where
+ makeQuestion :: Question -> Task Bool
+ makeQuestion q = enterChoice q.question [ChooseFromList snd] (zip2 [0..] q.answers)
+ @? \v->case v of
+ NoValue = NoValue
+ Value (idx, _) _ = Value (idx == q.correct) True
+
+ distillResult :: [Bool] -> String
+ distillResult [] = "No questions answered!"
+ distillResult b = concat
+ [ "You had "
+ , toString good
+ , " answers correct and "
+ , toString bad
+ , " answers incorrect which results in a score of: "
+ , toString $ good*100 / (good+bad)
+ , "/100"
+ ]
+ where
+ good = length [()\\True<-b]
+ bad = length [()\\False<-b]
+
+admin :: Task [Question]
+admin = updateSharedInformation "Questions" [] questions
+
+teacher :: Task [Question]
+teacher = forever
+ $ enterChoiceWithShared "Choose an item to edit" [ChooseFromList id] questions
+ >>*
+ [ OnAction (Action "Append") (withValue $ Just o append)
+ , OnAction (Action "Delete") (withValue $ Just o delete)
+ , OnAction (Action "Edit") (withValue $ Just o edit)
+ , OnAction (Action "Clear") (withValue $ Just o clear)
+ , OnAction (Action "First") (always first)
+ , OnAction (Action "Quit") (always login)
+ ]
+where
+ append choice = orCancel (enterInformation () []) \nq->upd (insertAfter choice nq) questions
+ delete choice = upd (deleteBy (===) choice) questions
+ edit choice = orCancel (updateInformation () [] choice) $ replace choice
+ clear choice = orCancel (enterInformation () []) $ replace choice
+ first = orCancel (enterInformation () []) \nq->upd (\x->[nq:x]) questions
+
+ replace choice nq = upd (deleteBy (===) choice o insertAfter choice nq) questions
+
+ insertAfter :: a a [a] -> [a] | gEq{|*|} a
+ insertAfter after el [] = [el]
+ insertAfter after el [e:es]
+ | e === after = [e,el:es]
+ = insertAfter after el es
+
+ orCancel do done = do >>*
+ [ OnAction (Action "Cancel") (always teacher)
+ , OnAction (Action "Continue") (withValue (Just o done))
+ ]