From 2d4dfda88eda0e1d58d0abe63139a640e2c77c1e Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 20 Aug 2019 13:47:17 +0200 Subject: [PATCH] 7gui 1-5 --- 7gui/test.icl | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/7gui/test.icl b/7gui/test.icl index 6265465..8bb3901 100644 --- a/7gui/test.icl +++ b/7gui/test.icl @@ -8,6 +8,13 @@ import iTasks import iTasks.Extensions.DateTime import iTasks.UI.Editor.Common +import qualified Data.Map as DM +import Data.Map.GenJSON + +//Start w = doTasks (gui1 0) w +//Start w = doTasks gui2 w +//Start w = doTasks gui3 w +//Start w = doTasks (get currentTimestamp >>- \t->gui4 30 t) w Start w = doTasks gui5 w gui1 :: Int -> Task Int @@ -20,11 +27,11 @@ gui2 = withShared 42.0 \sh-> -|| updateSharedInformation "Fahrenheit" [UpdateAs (\c->1.8*c+32.0) \_ f->(f-32.0)/1.8] sh +//This should be possible with just a custom editor... :: Flight = OneWay Date | Return (Date, Date) derive class iTask Flight - gui3 :: Task Flight gui3 = get currentDate >>- \now->editChoice () [] ["one-way flight", "return flight"] (Just "one-way flight") @@ -48,11 +55,21 @@ where toProgress (now, duration) = (Just $ toInt $ on (-) (toReal o toInt) now startTime / toReal duration * 100.0, Nothing) -gui5 = withShared [(0, "Emil", "Hans"), (1, "Mustermann", "Max"), (2, "Tisch", "Roman")] \data-> +:: Name = {name :: String, surname :: String} +name :: String String -> Name +name name surname = {name=name, surname=surname} +derive class iTask Name +instance toString Name where toString n = n.Name.name +++ ", " +++ n.surname + +gui5 = withShared ('DM'.fromList [(0, name "Emil" "Hans"), (1, name "Mustermann" "Max"), (2, name "Tisch" "Roman")]) \data-> enterInformation "Filter prefix" [] >&> \v->whileUnchanged (mapRead (fromMaybe " ") v) \filter-> - tune ArrangeHorizontal - $ enterChoiceWithShared () [ChooseFromList (\(_, f, l)->f +++ ", " +++ l)] data - >&> \v->whileUnchanged v \selection->case selection of - Nothing = viewInformation "Nothing selected" [] () @? const NoValue - Just x = updateInformation () [] x + tune ArrangeHorizontal + $ enterChoiceWithShared () [ChooseFromList (toString o snd)] (mapRead 'DM'.toList data) + >&> \sh->whileUnchanged sh \v->case v of + Nothing = return () @? const NoValue + Just x = updateInformation () [UpdateAs snd (tuple o fst)] x + >^* [ OnAction (Action "new") $ always $ upd (\l->'DM'.put (inc $ maxList $ 'DM'.keys l) (name "-" "-") l) data + , OnAction (Action "update") $ withValue \(i, n)->Just $ upd ('DM'.put i n) data + , OnAction (Action "delete") $ withValue \(i, n)->Just $ upd ('DM'.del i) data + ] -- 2.20.1