8 import iTasks.Extensions.DateTime
9 import iTasks.UI.Editor.Common
11 import qualified Data.Map as DM
12 import Data.Map.GenJSON
14 //Start w = doTasks (gui1 0) w
15 //Start w = doTasks gui2 w
16 //Start w = doTasks gui3 w
17 //Start w = doTasks (get currentTimestamp >>- \t->gui4 30 t) w
18 Start w = doTasks gui5 w
20 gui1 :: Int -> Task Int
21 gui1 c = viewInformation "Counter" [] c
22 >>* [OnAction (Action "Count") (withValue (Just o gui1 o inc))]
25 gui2 = withShared 42.0 \sh->
26 updateSharedInformation "Celcius" [] sh
27 -|| updateSharedInformation "Fahrenheit"
28 [UpdateAs (\c->1.8*c+32.0) \_ f->(f-32.0)/1.8] sh
30 //This should be possible with just a custom editor...
34 derive class iTask Flight
36 gui3 = get currentDate
37 >>- \now->editChoice () [] ["one-way flight", "return flight"] (Just "one-way flight")
38 >&> \sh-> whileUnchanged sh \v->case fromJust v of
39 "one-way flight" = withShared now \sh->
40 updateSharedInformation () [] sh
41 -|| updateSharedInformation () [UpdateUsing toString const (gEditor{|*|} <<@ enabledAttr False)] sh
42 >>* [OnAction (Action "Book") $ ifValue (\_->True) $ return o OneWay]
44 = updateInformation () [] now
45 -&&- updateInformation () [] now
46 >>* [OnAction (Action "Book") $ ifValue (uncurry (<)) $ return o Return]
48 gui4 :: Timestamp Int -> Task Timestamp
49 gui4 startTime duration = withShared duration \duration->
50 viewSharedInformation "Elapsed time: " [ViewUsing toProgress progressBar] (currentTimestamp >*< duration)
51 -&&- viewSharedInformation () [ViewAs \now->on (-) toInt now startTime] currentTimestamp
52 -&&- updateSharedInformation "Duration: " [UpdateUsing id (const id) $ slider <<@ minAttr 0 <<@ maxAttr 3600] duration
53 >>* [OnAction (Action "Reset") $ always $ get (currentTimestamp >*< duration) >>- uncurry gui4]
55 toProgress (now, duration) =
56 (Just $ toInt $ on (-) (toReal o toInt) now startTime / toReal duration * 100.0, Nothing)
58 :: Name = {name :: String, surname :: String}
59 name :: String String -> Name
60 name name surname = {name=name, surname=surname}
61 derive class iTask Name
62 instance toString Name where toString n = n.Name.name +++ ", " +++ n.surname
64 gui5 = withShared ('DM'.fromList [(0, name "Emil" "Hans"), (1, name "Mustermann" "Max"), (2, name "Tisch" "Roman")]) \data->
65 enterInformation "Filter prefix" []
66 >&> \v->whileUnchanged (mapRead (fromMaybe " ") v) \filter->
67 tune ArrangeHorizontal
68 $ enterChoiceWithShared () [ChooseFromList (toString o snd)] (mapRead 'DM'.toList data)
69 >&> \sh->whileUnchanged sh \v->case v of
70 Nothing = return () @? const NoValue
71 Just x = updateInformation () [UpdateAs snd (tuple o fst)] x
72 >^* [ OnAction (Action "new") $ always $ upd (\l->'DM'.put (inc $ maxList $ 'DM'.keys l) (name "-" "-") l) data
73 , OnAction (Action "update") $ withValue \(i, n)->Just $ upd ('DM'.put i n) data
74 , OnAction (Action "delete") $ withValue \(i, n)->Just $ upd ('DM'.del i) data