Skip to content

Commit

Permalink
request-related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherKamila committed Mar 13, 2018
1 parent 2bb97dc commit ba633e6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions webui/src/CsvTsdb/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ decode_error = Decode.decode
|> Decode.optional "error" (Decode.string) ""
|> Decode.resolve

post_ignore_response : String -> Http.Body -> Http.Request ()
post_ignore_response url body =
Http.request
{ method = "POST"
, headers = []
, url = url
, body = body
, expect = Http.expectStringResponse (\response -> Ok ())
, timeout = Nothing
, withCredentials = False
}

get_records msg =
Http.getString track_url
|> Http.send (mapError toString >> andThen decode_records >> msg)

send_input : String -> Http.Request String
send_input : String -> Http.Request ()
send_input input =
Http.post track_url (Http.stringBody "text/plain" input) decode_error
post_ignore_response track_url (Http.stringBody "text/plain" input)
4 changes: 2 additions & 2 deletions webui/src/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type alias Model =


type Msg = SelectTab Tab
| NewData (Result String (List CsvTsdb.Record))
| RequestDone (Result Http.Error String)
| NewData (Result String (List CsvTsdb.Record)) -- TODO change to Http.Error when possible
| RequestDone (Result Http.Error ())
| RefreshWanted
| DataInput String
| SliderInput Float
Expand Down
2 changes: 1 addition & 1 deletion webui/src/TrackView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ recents : List Record -> Html msg
recents records = Table.table
[ cs "full-width", Elevation.e2 ]
[ Table.tbody []
(records |> List.map (\record ->
(records |> List.reverse |> List.map (\record ->
Table.tr []
[ Table.td [] [ text (view_date record.date) ]
, Table.td [] [ text record.label ]
Expand Down
4 changes: 2 additions & 2 deletions webui/src/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ update msg model =
case msg of
SelectTab new -> ({model | tab = new}, Cmd.none)
NewData r -> check r update_data Cmd.none model
RequestDone r -> check r (\_ -> identity) Cmd.none model
RequestDone r -> check r (\_ -> identity) refresh model
DataInput s -> ({model | data_input = s}, Cmd.none)
SliderInput x -> ({model | data_input = add_or_replace_value model.data_input x, slider_input = x}, Cmd.none)
RefreshWanted -> (model, refresh)
DataSubmit -> ({model | data_input = ""}, send_input model.data_input)
DataSubmit -> ({model | data_input = ""}, send_input model.data_input) -- TODO validation
Mdl m -> Material.update Mdl m model -- Mdl action handler

update_data new model = {model | data = new, recent_labels = find_labels new}
Expand Down

0 comments on commit ba633e6

Please sign in to comment.