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

     1  module Components.NodeAction exposing (view)
     2  
     3  import Api.Node as Node
     4  import Api.Point as Point
     5  import Components.NodeOptions exposing (CopyMove(..), NodeOptions, findNode, oToInputO)
     6  import Element exposing (..)
     7  import Element.Background as Background
     8  import Element.Border as Border
     9  import Element.Font as Font
    10  import UI.Icon as Icon
    11  import UI.NodeInputs as NodeInputs
    12  import UI.Style as Style
    13  import UI.ViewIf exposing (viewIf)
    14  
    15  
    16  view : NodeOptions msg -> Element msg
    17  view o =
    18      let
    19          icon =
    20              if o.node.typ == Node.typeAction then
    21                  Icon.trendingUp
    22  
    23              else
    24                  Icon.trendingDown
    25  
    26          active =
    27              Point.getBool o.node.points Point.typeActive "0"
    28  
    29          descBackgroundColor =
    30              if active then
    31                  Style.colors.blue
    32  
    33              else
    34                  Style.colors.none
    35  
    36          descTextColor =
    37              if active then
    38                  Style.colors.white
    39  
    40              else
    41                  Style.colors.black
    42  
    43          error =
    44              Point.getText o.node.points Point.typeError "0"
    45  
    46          disabled =
    47              Point.getBool o.node.points Point.typeDisabled ""
    48  
    49          titleBackground =
    50              if disabled then
    51                  Style.colors.ltgray
    52  
    53              else if error /= "" then
    54                  Style.colors.red
    55  
    56              else
    57                  Style.colors.none
    58      in
    59      column
    60          [ width fill
    61          , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 }
    62          , Border.color Style.colors.black
    63          , spacing 6
    64          ]
    65      <|
    66          wrappedRow
    67              [ spacing 10
    68              , paddingEach { top = 0, right = 10, bottom = 0, left = 0 }
    69              , Background.color titleBackground
    70              , width fill
    71              ]
    72              [ icon
    73              , el [ Background.color descBackgroundColor, Font.color descTextColor ] <|
    74                  text <|
    75                      Point.getText o.node.points Point.typeDescription ""
    76              , if Point.getBool o.node.points Point.typeDisabled "" then
    77                  text "(disabled)"
    78  
    79                else
    80                  text ""
    81              ]
    82              :: (if o.expDetail then
    83                      let
    84                          labelWidth =
    85                              150
    86  
    87                          opts =
    88                              oToInputO o labelWidth
    89  
    90                          textInput =
    91                              NodeInputs.nodeTextInput opts "0"
    92  
    93                          optionInput =
    94                              NodeInputs.nodeOptionInput opts "0"
    95  
    96                          numberInput =
    97                              NodeInputs.nodeNumberInput opts "0"
    98  
    99                          actionType =
   100                              Point.getText o.node.points Point.typeAction "0"
   101  
   102                          actionSetValue =
   103                              actionType == Point.valueSetValue
   104  
   105                          actionPlayAudio =
   106                              actionType == Point.valuePlayAudio
   107  
   108                          valueType =
   109                              Point.getText o.node.points Point.typeValueType "0"
   110  
   111                          nodeId =
   112                              Point.getText o.node.points Point.typeNodeID "0"
   113  
   114                          checkboxInput =
   115                              NodeInputs.nodeCheckboxInput opts "0"
   116                      in
   117                      [ textInput Point.typeDescription "Description" ""
   118                      , optionInput Point.typeAction
   119                          "Action"
   120                          [ ( Point.valueNotify, "notify" )
   121                          , ( Point.valueSetValue, "set node value" )
   122                          , ( Point.valuePlayAudio, "play audio" )
   123                          ]
   124                      , viewIf actionSetValue <|
   125                          optionInput Point.typePointType
   126                              "Point Type"
   127                              [ ( Point.typeValue, "value" )
   128                              , ( Point.typeValueSet, "set value (use for remote devices)" )
   129                              , ( Point.typeLightSet, "set light state" )
   130                              , ( Point.typeSwitchSet, "set switch state" )
   131                              ]
   132                      , viewIf actionSetValue <| textInput Point.typePointKey "Point Key" ""
   133                      , viewIf actionSetValue <| textInput Point.typeNodeID "Node ID" ""
   134                      , if nodeId /= "" then
   135                          let
   136                              nodeDesc =
   137                                  case findNode o.nodes nodeId of
   138                                      Just node ->
   139                                          el [ Background.color Style.colors.ltblue ] <|
   140                                              text <|
   141                                                  "("
   142                                                      ++ Node.getBestDesc node
   143                                                      ++ ")"
   144  
   145                                      Nothing ->
   146                                          el [ Background.color Style.colors.orange ] <| text "(node not found)"
   147                          in
   148                          el [ Font.italic, paddingEach { top = 0, right = 0, left = 170, bottom = 0 } ] <|
   149                              nodeDesc
   150  
   151                        else
   152                          Element.none
   153                      , viewIf actionSetValue <|
   154                          case o.copy of
   155                              CopyMoveNone ->
   156                                  Element.none
   157  
   158                              Copy id _ desc ->
   159                                  if nodeId /= id then
   160                                      let
   161                                          label =
   162                                              row
   163                                                  [ spacing 10 ]
   164                                                  [ text <| "paste ID for node: "
   165                                                  , el
   166                                                      [ Font.italic
   167                                                      , Background.color Style.colors.ltblue
   168                                                      ]
   169                                                    <|
   170                                                      text desc
   171                                                  ]
   172                                      in
   173                                      NodeInputs.nodePasteButton opts label Point.typeNodeID id
   174  
   175                                  else
   176                                      Element.none
   177                      , viewIf actionSetValue <|
   178                          optionInput Point.typeValueType
   179                              "Point Value Type"
   180                              [ ( Point.valueNumber, "number" )
   181                              , ( Point.valueOnOff, "on/off" )
   182                              , ( Point.valueText, "text" )
   183                              ]
   184                      , viewIf actionSetValue <|
   185                          case valueType of
   186                              "number" ->
   187                                  numberInput Point.typeValue "Value"
   188  
   189                              "onOff" ->
   190                                  let
   191                                      onOffInput =
   192                                          NodeInputs.nodeOnOffInput opts "0"
   193                                  in
   194                                  onOffInput Point.typeValue Point.typeValue "Value"
   195  
   196                              "text" ->
   197                                  textInput Point.typeValueText "Value" ""
   198  
   199                              _ ->
   200                                  Element.none
   201                      , viewIf actionPlayAudio <|
   202                          textInput Point.typeDevice "Device" ""
   203                      , viewIf actionPlayAudio <|
   204                          numberInput Point.typeChannel "Channel"
   205                      , viewIf actionPlayAudio <|
   206                          textInput Point.typeFilePath "Wav file path" "/absolute/path/to/sound.wav"
   207                      , checkboxInput Point.typeDisabled "Disabled"
   208                      , NodeInputs.nodeKeyValueInput opts Point.typeTag "Tags" "Add Tag"
   209                      , el [ Font.color Style.colors.red ] <| text error
   210                      ]
   211  
   212                  else
   213                      []
   214                 )