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

     1  module Components.NodeDevice exposing (view)
     2  
     3  import Api.Node as Node
     4  import Api.Point as Point exposing (Point)
     5  import Components.NodeOptions exposing (NodeOptions, oToInputO)
     6  import Element exposing (..)
     7  import Element.Background as Background
     8  import Element.Border as Border
     9  import Element.Input as Input
    10  import Time
    11  import UI.Icon as Icon
    12  import UI.NodeInputs as NodeInputs
    13  import UI.Style as Style exposing (colors)
    14  import UI.ViewIf exposing (viewIf)
    15  import Utils.Duration as Duration
    16  import Utils.Iso8601 as Iso8601
    17  
    18  
    19  view : NodeOptions msg -> Element msg
    20  view o =
    21      let
    22          sysState =
    23              Point.getText o.node.points Point.typeSysState ""
    24  
    25          sysStateIcon =
    26              case sysState of
    27                  -- not sure why I can't use defines in Node.elm here
    28                  "powerOff" ->
    29                      Icon.power
    30  
    31                  "offline" ->
    32                      Icon.cloudOff
    33  
    34                  "online" ->
    35                      Icon.cloud
    36  
    37                  _ ->
    38                      Element.none
    39  
    40          background =
    41              Style.colors.white
    42      in
    43      column
    44          [ width fill
    45          , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 }
    46          , Border.color colors.black
    47          , Background.color background
    48          , spacing 6
    49          ]
    50      <|
    51          wrappedRow
    52              [ spacing 10 ]
    53              [ Icon.device
    54              , sysStateIcon
    55              , Input.text
    56                  [ Background.color background ]
    57                  { onChange =
    58                      \d ->
    59                          o.onEditNodePoint
    60                              [ Point Point.typeDescription "0" o.now 0 d 0 ]
    61                  , text = Node.description o.node
    62                  , placeholder = Just <| Input.placeholder [] <| text "node description"
    63                  , label = Input.labelHidden "node description"
    64                  }
    65              ]
    66              :: (if o.expDetail then
    67                      let
    68                          labelWidth =
    69                              150
    70  
    71                          opts =
    72                              oToInputO o labelWidth
    73  
    74                          latestPointTime =
    75                              case Point.getLatest o.node.points of
    76                                  Just point ->
    77                                      point.time
    78  
    79                                  Nothing ->
    80                                      Time.millisToPosix 0
    81  
    82                          versionHW =
    83                              case Point.get o.node.points Point.typeVersionHW "" of
    84                                  Just point ->
    85                                      "HW: " ++ point.text
    86  
    87                                  Nothing ->
    88                                      ""
    89  
    90                          versionOS =
    91                              case Point.get o.node.points Point.typeVersionOS "" of
    92                                  Just point ->
    93                                      "OS: " ++ point.text
    94  
    95                                  Nothing ->
    96                                      ""
    97  
    98                          versionApp =
    99                              case Point.get o.node.points Point.typeVersionApp "" of
   100                                  Just point ->
   101                                      "App: " ++ point.text
   102  
   103                                  Nothing ->
   104                                      ""
   105                      in
   106                      [ viewPoints <| Point.filterSpecialPoints <| List.sortWith Point.sort o.node.points
   107                      , text ("Last update: " ++ Iso8601.toDateTimeString o.zone latestPointTime)
   108                      , text
   109                          ("Time since last update: "
   110                              ++ Duration.toString
   111                                  (Time.posixToMillis o.now
   112                                      - Time.posixToMillis latestPointTime
   113                                  )
   114                          )
   115                      , viewIf (versionHW /= "" || versionOS /= "" || versionApp /= "") <|
   116                          text
   117                              ("Version: "
   118                                  ++ versionHW
   119                                  ++ " "
   120                                  ++ versionOS
   121                                  ++ " "
   122                                  ++ versionApp
   123                              )
   124                      , NodeInputs.nodeKeyValueInput opts Point.typeTag "Tags" "Add Tag"
   125                      ]
   126  
   127                  else
   128                      []
   129                 )
   130  
   131  
   132  viewPoints : List Point.Point -> Element msg
   133  viewPoints ios =
   134      column
   135          [ padding 16
   136          , spacing 6
   137          ]
   138      <|
   139          List.map (Point.renderPoint >> text) ios