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

     1  module Components.NodeUpdate 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.Font as Font
     8  import UI.Form as Form
     9  import UI.Icon as Icon
    10  import UI.NodeInputs as NodeInputs
    11  import UI.Style as Style exposing (colors)
    12  import UI.ViewIf exposing (viewIf)
    13  
    14  
    15  view : NodeOptions msg -> Element msg
    16  view o =
    17      column
    18          [ width fill
    19          , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 }
    20          , Border.color Style.colors.black
    21          , spacing 6
    22          ]
    23      <|
    24          wrappedRow [ spacing 10 ]
    25              [ Icon.update
    26              , text <|
    27                  Point.getText o.node.points Point.typeDescription ""
    28              ]
    29              :: (if o.expDetail then
    30                      let
    31                          labelWidth =
    32                              165
    33  
    34                          opts =
    35                              oToInputO o labelWidth
    36  
    37                          textInput =
    38                              NodeInputs.nodeTextInput opts "0"
    39  
    40                          numberInput =
    41                              NodeInputs.nodeNumberInput opts "0"
    42  
    43                          checkboxInput =
    44                              NodeInputs.nodeCheckboxInput opts "0"
    45  
    46                          osDownloaded =
    47                              Point.getText o.node.points Point.typeOSDownloaded "0"
    48  
    49                          error =
    50                              Point.getText o.node.points Point.typeError "0"
    51  
    52                          versionHW =
    53                              case Point.get o.node.points Point.typeVersionHW "" of
    54                                  Just point ->
    55                                      "HW: " ++ point.text
    56  
    57                                  Nothing ->
    58                                      ""
    59  
    60                          versionOS =
    61                              case Point.get o.node.points Point.typeVersionOS "" of
    62                                  Just point ->
    63                                      "OS: " ++ point.text
    64  
    65                                  Nothing ->
    66                                      ""
    67  
    68                          versionApp =
    69                              case Point.get o.node.points Point.typeVersionApp "" of
    70                                  Just point ->
    71                                      "App: " ++ point.text
    72  
    73                                  Nothing ->
    74                                      ""
    75  
    76                          discardButton =
    77                              if osDownloaded /= "" then
    78                                  Form.button
    79                                      { label = "Discard"
    80                                      , color = colors.orange
    81                                      , onPress = opts.onEditNodePoint [ Point Point.typeDiscardDownload "0" opts.now 1 "" 0 ]
    82                                      }
    83  
    84                              else
    85                                  none
    86  
    87                          rebootButton =
    88                              if osDownloaded /= "" then
    89                                  Form.button
    90                                      { label = "Reboot"
    91                                      , color = colors.red
    92                                      , onPress = opts.onEditNodePoint [ Point Point.typeReboot "0" opts.now 1 "" 0 ]
    93                                      }
    94  
    95                              else
    96                                  none
    97                      in
    98                      [ textInput Point.typeDescription "Description" ""
    99                      , textInput Point.typeURI "Update server" "http://..."
   100                      , textInput Point.typePrefix "Prefix" ""
   101                      , textInput Point.typeDirectory "Dest dir" ""
   102                      , numberInput Point.typePollPeriod "Chk interval (min)"
   103                      , checkboxInput Point.typeAutoDownload "Auto download"
   104                      , checkboxInput Point.typeAutoReboot "Auto reboot/install"
   105                      , viewIf (versionHW /= "" || versionOS /= "" || versionApp /= "") <|
   106                          text
   107                              ("Current version: "
   108                                  ++ versionHW
   109                                  ++ " "
   110                                  ++ versionOS
   111                                  ++ " "
   112                                  ++ versionApp
   113                              )
   114                      , if osDownloaded /= "" then
   115                          column [ spacing 10 ]
   116                              [ el [ Font.color Style.colors.blue ] <|
   117                                  text <|
   118                                      "OS downloaded, reboot to install: "
   119                                          ++ osDownloaded
   120                              ]
   121  
   122                        else
   123                          let
   124                              downloadOS =
   125                                  Point.getText o.node.points Point.typeDownloadOS "0"
   126  
   127                              downloading =
   128                                  downloadOS /= ""
   129                          in
   130                          if downloading then
   131                              column [ spacing 10 ]
   132                                  [ el [ Font.color Style.colors.blue ] <|
   133                                      text <|
   134                                          "Downloading OS version: "
   135                                              ++ downloadOS
   136                                  ]
   137  
   138                          else
   139                              let
   140                                  osUpdates =
   141                                      Point.getAll o.node.points Point.typeOSUpdate |> Point.filterDeleted |> List.sortWith Point.sort
   142                              in
   143                              column [] <|
   144                                  [ el [ paddingXY 20 0 ] <| text "OS Updates:"
   145                                  , osUpdatesView opts osUpdates
   146                                  ]
   147                      , el [ Font.color Style.colors.red ] <| text error
   148                      , Form.buttonRow <|
   149                          [ Form.button
   150                              { label = "Refresh"
   151                              , color = colors.blue
   152                              , onPress = opts.onEditNodePoint [ Point Point.typeRefresh "0" opts.now 1 "" 0 ]
   153                              }
   154                          , discardButton
   155                          , rebootButton
   156                          ]
   157                      ]
   158  
   159                  else
   160                      []
   161                 )
   162  
   163  
   164  osUpdatesView : NodeInputs.NodeInputOptions msg -> List Point -> Element msg
   165  osUpdatesView opt pts =
   166      table [ paddingEach { top = 0, bottom = 0, right = 0, left = 70 } ]
   167          { data = pts
   168          , columns =
   169              [ { header = text ""
   170                , width = fill
   171                , view = \p -> el [ centerY ] <| text p.text
   172                }
   173              , { header = text ""
   174                , width = fill
   175                , view =
   176                      \p ->
   177                          el [ padding 2 ] <|
   178                              Form.button
   179                                  { label = "install"
   180                                  , color = colors.blue
   181                                  , onPress = opt.onEditNodePoint [ Point Point.typeDownloadOS "0" opt.now 0 p.text 0 ]
   182                                  }
   183                }
   184              ]
   185          }