github.com/simpleiot/simpleiot@v0.18.3/frontend/src/Components/NodeOneWireIO.elm (about)

     1  module Components.NodeOneWireIO exposing (view)
     2  
     3  import Api.Point as Point exposing (Point)
     4  import Components.NodeOptions exposing (NodeOptions, oToInputO)
     5  import Element exposing (..)
     6  import Element.Border as Border
     7  import Element.Input as Input
     8  import Round
     9  import UI.Icon as Icon
    10  import UI.NodeInputs as NodeInputs
    11  import UI.Style exposing (colors)
    12  import UI.ViewIf exposing (viewIf)
    13  
    14  
    15  view : NodeOptions msg -> Element msg
    16  view o =
    17      let
    18          value =
    19              Point.getValue o.node.points Point.typeValue ""
    20  
    21          units =
    22              Point.getText o.node.points Point.typeUnits ""
    23  
    24          valueText =
    25              String.fromFloat (Round.roundNum 2 value)
    26                  ++ (if units == "F" then
    27                          "°F"
    28  
    29                      else
    30                          "°C"
    31                     )
    32  
    33          disabled =
    34              Point.getBool o.node.points Point.typeDisabled ""
    35      in
    36      column
    37          [ width fill
    38          , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 }
    39          , Border.color colors.black
    40          , spacing 6
    41          ]
    42      <|
    43          wrappedRow [ spacing 10 ]
    44              [ Icon.io
    45              , text <|
    46                  Point.getText o.node.points Point.typeDescription ""
    47              , el [ paddingXY 7 0 ] <|
    48                  text <|
    49                      valueText
    50              , viewIf disabled <| text "(disabled)"
    51              ]
    52              :: (if o.expDetail then
    53                      let
    54                          labelWidth =
    55                              150
    56  
    57                          opts =
    58                              oToInputO o labelWidth
    59  
    60                          textInput =
    61                              NodeInputs.nodeTextInput opts "0"
    62  
    63                          counterWithReset =
    64                              NodeInputs.nodeCounterWithReset opts "0"
    65  
    66                          checkboxInput =
    67                              NodeInputs.nodeCheckboxInput opts "0"
    68  
    69                          fCheckboxInput =
    70                              fCheckbox opts "" Point.typeUnits "Fahrenheit?"
    71  
    72                          id =
    73                              Point.getText o.node.points Point.typeID ""
    74                      in
    75                      [ el [ paddingEach { top = 0, right = 0, bottom = 0, left = 70 } ] <|
    76                          text <|
    77                              "ID: "
    78                                  ++ id
    79                      , textInput Point.typeDescription "Description" ""
    80                      , fCheckboxInput
    81                      , checkboxInput Point.typeDisabled "Disabled"
    82                      , counterWithReset Point.typeErrorCount Point.typeErrorCountReset "Error Count"
    83                      , NodeInputs.nodeKeyValueInput opts Point.typeTag "Tags" "Add Tag"
    84                      ]
    85  
    86                  else
    87                      []
    88                 )
    89  
    90  
    91  fCheckbox :
    92      NodeInputs.NodeInputOptions msg
    93      -> String
    94      -> String
    95      -> String
    96      -> Element msg
    97  fCheckbox o key typ lbl =
    98      Input.checkbox
    99          []
   100          { onChange =
   101              \d ->
   102                  let
   103                      t =
   104                          if d then
   105                              "F"
   106  
   107                          else
   108                              "C"
   109                  in
   110                  o.onEditNodePoint
   111                      [ Point typ key o.now 0 t 0 ]
   112          , checked =
   113              Point.getText o.node.points typ key == "F"
   114          , icon = Input.defaultCheckbox
   115          , label =
   116              if lbl /= "" then
   117                  Input.labelLeft [ width (px o.labelWidth) ] <|
   118                      el [ alignRight ] <|
   119                          text <|
   120                              lbl
   121                                  ++ ":"
   122  
   123              else
   124                  Input.labelHidden ""
   125          }