X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=Shares%2FmTaskShare.icl;h=ee6282b775eb5803d4dc803235dd72ccbadb6dc5;hb=a2df77cbda43d5a24eeb8ac7db7452baae9f18aa;hp=ad2e3413d857482a81480b81e083280b816a4f09;hpb=b3d2bd33a99a2dbdc4907b6876a965c16c37314c;p=mTask.git diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index ad2e341..ee6282b 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -1,2 +1,63 @@ implementation module Shares.mTaskShare +import dynamic_string +import Utils.SDS +import Utils.Devices +import iTasks +import mTask +import Data.List +from Data.Func import $ +from StdFunc import flip + +derive class iTask MTaskShareType, MTaskShare + +manageShares :: [MTaskShare] -> Task () +manageShares shares = withShared Nothing $ \cs->forever $ + (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical) + @! () + +updateShares :: [MTaskShare] -> Task BCValue +updateShares shares = anyTask (map updateS shares) <<@ ArrangeWithTabs + +updateS :: MTaskShare -> Task BCValue +updateS sh = flip (<<@) (Title $ toString sh.identifier) $ forever $ + viewSharedInformation "Current value" [] (getSDSShare sh) + ||- ( + updateSharedInformation "New value" [] (getSDSShare sh) + >>= \nv->allTasks (map (withDevice treturn) sh.withDevice) + >>= \devs->allTasks (map (sendMessages [MTUpd sh.identifier nv]) devs) + >>| treturn nv + ) + <<@ ArrangeHorizontal + +viewSharesGrid :: (Shared (Maybe MTaskShare)) [MTaskShare] -> Task [BCValue] +viewSharesGrid _ [] = viewInformation "No shares yet" [] [] +viewSharesGrid cs sh = (allTasks [watch (getSDSShare m)\\m<-sh] <<@ NoUserInterface) + >&^ \st->flip (<<@) NoUserInterface $ whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id] + [{MTaskShare|ss&value=s}\\s<-fromJust mshs & ss<-sh] + >>* [OnValue (withValue $ \s->Just (set (Just s) cs))] + @! fromJust mshs + +viewShare :: MTaskShare -> Task BCValue +viewShare m = viewSharedInformation "" [] (getSDSShare m) + <<@ Title ("SDS: " +++ toString m.identifier) + +getSDSShare :: MTaskShare -> Shared BCValue +getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value + +makeShare :: String String Int BCValue -> Task MTaskShare +makeShare withTask withDevice identifier value = treturn + {MTaskShare + |withTask=[withTask] + ,withDevice=[withDevice] + ,identifier=identifier + ,value=value + ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier + } >>= \sh->set value (getSDSShare sh) >>| treturn sh + +updateShare :: Int BCValue -> Task () +updateShare ident val = get sdsStore + >>= \sh->(case find (\s->s.identifier==ident) sh of + Nothing = abort "Help, no share found with this ident" + Just mts = set val (getSDSShare mts)) + >>| traceValue "Updated" @! ()