github.com/simpleiot/simpleiot@v0.18.3/frontend/src/Components/NodeOptions.elm (about) 1 module Components.NodeOptions exposing (CopyMove(..), NodeOptions, findNode, oToInputO) 2 3 import Api.Node exposing (Node, NodeView) 4 import Api.Point exposing (Point) 5 import Time 6 import Tree exposing (Tree) 7 import Tree.Zipper as Zipper 8 import UI.NodeInputs exposing (NodeInputOptions) 9 10 11 type CopyMove 12 = CopyMoveNone 13 -- ID, source, description 14 | Copy String String String 15 16 17 type alias NodeOptions msg = 18 { now : Time.Posix 19 , zone : Time.Zone 20 , modified : Bool 21 , expDetail : Bool 22 , parent : Maybe Node 23 , node : Node 24 , children : List NodeView 25 , nodes : List (Tree NodeView) 26 , onEditNodePoint : List Point -> msg 27 , onEditScratch : String -> msg 28 , onUploadFile : Bool -> msg 29 , copy : CopyMove 30 , scratch : String 31 } 32 33 34 oToInputO : NodeOptions msg -> Int -> NodeInputOptions msg 35 oToInputO o labelWidth = 36 { onEditNodePoint = o.onEditNodePoint 37 , onEditScratch = o.onEditScratch 38 , node = o.node 39 , now = o.now 40 , zone = o.zone 41 , labelWidth = labelWidth 42 , scratch = o.scratch 43 } 44 45 46 findNodeTree : Tree NodeView -> String -> Maybe NodeView 47 findNodeTree tree id = 48 Zipper.findFromRoot (\n -> n.node.id == id) (Zipper.fromTree tree) 49 |> Maybe.map Zipper.label 50 51 52 findNode : List (Tree NodeView) -> String -> Maybe Node 53 findNode nodes id = 54 List.foldl 55 (\t ret -> 56 case findNodeTree t id of 57 Just found -> 58 Just found.node 59 60 Nothing -> 61 ret 62 ) 63 Nothing 64 nodes