Replace crossOrigin with relative path and fix messaging bug (#645)
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
parent
74dfd69767
commit
a0ed73d09b
|
@ -54,7 +54,7 @@ if you want to launch just GUI.
|
|||
|
||||
### Contribute to the GUI development
|
||||
|
||||
Install GUI as a part of Mainflux build or as a a standalone native GUI and run
|
||||
Install GUI as a part of Mainflux build or as a standalone native GUI and run
|
||||
it. Launch Mainflux without ui service, either natively or as a Docker
|
||||
composition. Follow the guidelines for Mainflux contributors found here
|
||||
https://mainflux.readthedocs.io/en/latest/CONTRIBUTING/.
|
||||
|
|
|
@ -24,20 +24,13 @@ import Html exposing (..)
|
|||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import HttpMF
|
||||
import HttpMF exposing (path)
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import ModalMF
|
||||
import Url.Builder as B
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
, thingsPath = [ "things" ]
|
||||
, channelsPath = [ "channels" ]
|
||||
}
|
||||
|
||||
|
||||
query =
|
||||
{ offset = 0
|
||||
, limit = 10
|
||||
|
@ -130,7 +123,7 @@ update msg model token =
|
|||
ProvisionChannel ->
|
||||
( resetEdit model
|
||||
, HttpMF.provision
|
||||
(B.crossOrigin url.base url.channelsPath [])
|
||||
(B.relative [ path.channels ] [])
|
||||
token
|
||||
{ emptyChannel
|
||||
| name = Just model.name
|
||||
|
@ -167,7 +160,7 @@ update msg model token =
|
|||
UpdateChannel ->
|
||||
( resetEdit { model | editMode = False }
|
||||
, HttpMF.update
|
||||
(B.crossOrigin url.base (List.append url.channelsPath [ model.channel.id ]) [])
|
||||
(B.relative [ path.channels, model.channel.id ] [])
|
||||
token
|
||||
{ emptyChannel
|
||||
| name = Just model.name
|
||||
|
@ -188,7 +181,7 @@ update msg model token =
|
|||
RetrieveChannel channelid ->
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base (List.append url.channelsPath [ channelid ]) [])
|
||||
(B.relative [ path.channels, channelid ] [])
|
||||
token
|
||||
RetrievedChannel
|
||||
channelDecoder
|
||||
|
@ -205,10 +198,7 @@ update msg model token =
|
|||
RetrieveChannels ->
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base
|
||||
url.channelsPath
|
||||
(Helpers.buildQueryParamList model.offset model.limit)
|
||||
)
|
||||
(B.relative [ path.channels ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedChannels
|
||||
channelsDecoder
|
||||
|
@ -217,10 +207,7 @@ update msg model token =
|
|||
RetrieveChannelsForThing thingid ->
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base
|
||||
(url.thingsPath ++ [ thingid ] ++ url.channelsPath)
|
||||
(Helpers.buildQueryParamList model.offset model.limit)
|
||||
)
|
||||
(B.relative [ path.things, thingid, path.channels ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedChannels
|
||||
channelsDecoder
|
||||
|
@ -237,7 +224,7 @@ update msg model token =
|
|||
RemoveChannel id ->
|
||||
( resetEdit model
|
||||
, HttpMF.remove
|
||||
(B.crossOrigin url.base (List.append url.channelsPath [ id ]) [])
|
||||
(B.relative [ path.channels, id ] [])
|
||||
token
|
||||
RemovedChannel
|
||||
)
|
||||
|
@ -446,15 +433,12 @@ updateChannelList model token =
|
|||
( model
|
||||
, Cmd.batch
|
||||
[ HttpMF.retrieve
|
||||
(B.crossOrigin url.base
|
||||
url.channelsPath
|
||||
(Helpers.buildQueryParamList model.offset model.limit)
|
||||
)
|
||||
(B.relative [ path.channels ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedChannels
|
||||
channelsDecoder
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base (List.append url.channelsPath [ model.channel.id ]) [])
|
||||
(B.relative [ path.channels, model.channel.id ] [])
|
||||
token
|
||||
RetrievedChannel
|
||||
channelDecoder
|
||||
|
@ -466,15 +450,8 @@ updateChannelListForThing : Model -> String -> String -> ( Model, Cmd Msg )
|
|||
updateChannelListForThing model token thingid =
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(buildUrl (url.thingsPath ++ [ thingid ] ++ url.channelsPath) model.offset model.limit)
|
||||
(B.relative [ path.things, thingid, path.channels ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedChannels
|
||||
channelsDecoder
|
||||
)
|
||||
|
||||
|
||||
buildUrl : List String -> Int -> Int -> String
|
||||
buildUrl path offset limit =
|
||||
B.crossOrigin url.base
|
||||
path
|
||||
(Helpers.buildQueryParamList offset limit)
|
||||
|
|
|
@ -24,17 +24,12 @@ import Html exposing (..)
|
|||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import HttpMF
|
||||
import HttpMF exposing (path)
|
||||
import List.Extra
|
||||
import Thing
|
||||
import Url.Builder as B
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ response : String
|
||||
, things : Thing.Model
|
||||
|
@ -208,11 +203,11 @@ connect checkedThingsIds checkedChannelsIds method token =
|
|||
List.foldr (++)
|
||||
[]
|
||||
(List.map
|
||||
(\thingId ->
|
||||
(\thingid ->
|
||||
List.map
|
||||
(\channelId ->
|
||||
(\channelid ->
|
||||
HttpMF.request
|
||||
(B.crossOrigin url.base [ "channels", channelId, "things", thingId ] [])
|
||||
(B.relative [ path.channels, channelid, path.things, thingid ] [])
|
||||
method
|
||||
token
|
||||
Http.emptyBody
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
-- SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
module HttpMF exposing (expectID, expectRetrieve, expectStatus, provision, remove, request, retrieve, update, url)
|
||||
module HttpMF exposing (expectID, expectRetrieve, expectStatus, path, provision, remove, request, retrieve, update, url)
|
||||
|
||||
import Dict
|
||||
import Helpers
|
||||
|
@ -19,6 +19,16 @@ url =
|
|||
}
|
||||
|
||||
|
||||
path =
|
||||
{ users = "users"
|
||||
, tokens = "tokens"
|
||||
, things = "things"
|
||||
, channels = "channels"
|
||||
, messages = "messages"
|
||||
, version = "version"
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- EXPECT
|
||||
|
||||
|
|
|
@ -23,21 +23,12 @@ import Html exposing (..)
|
|||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import HttpMF
|
||||
import HttpMF exposing (path)
|
||||
import List.Extra
|
||||
import Thing
|
||||
import Url.Builder as B
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
, httpPath = [ "http" ]
|
||||
, thingsPath = [ "things" ]
|
||||
, channelsPath = [ "channels" ]
|
||||
, messagesPath = [ "messages" ]
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ message : String
|
||||
, thingkey : String
|
||||
|
@ -81,7 +72,7 @@ update msg model token =
|
|||
( { model | message = "", thingkey = "", response = "", thingid = "" }
|
||||
, Cmd.batch
|
||||
(List.map
|
||||
(\channelId -> send channelId token model.message)
|
||||
(\channelid -> send channelid model.thingkey model.message)
|
||||
model.checkedChannelsIds
|
||||
)
|
||||
)
|
||||
|
@ -224,10 +215,10 @@ genChannelRows checkedChannelsIds channels =
|
|||
|
||||
|
||||
send : String -> String -> String -> Cmd Msg
|
||||
send channelId token message =
|
||||
send channelid thingkey message =
|
||||
HttpMF.request
|
||||
(B.crossOrigin url.base (url.httpPath ++ url.channelsPath ++ [ channelId ] ++ url.messagesPath) [])
|
||||
(B.relative [ "http", path.channels, channelid, path.messages ] [])
|
||||
"POST"
|
||||
token
|
||||
thingkey
|
||||
(Http.stringBody "application/json" message)
|
||||
SentMessage
|
||||
|
|
|
@ -27,7 +27,7 @@ import Html exposing (..)
|
|||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import HttpMF
|
||||
import HttpMF exposing (path)
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import ModalMF
|
||||
|
@ -40,12 +40,6 @@ query =
|
|||
}
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
, path = [ "things" ]
|
||||
}
|
||||
|
||||
|
||||
defaultType =
|
||||
"app"
|
||||
|
||||
|
@ -149,7 +143,7 @@ update msg model token =
|
|||
ProvisionThing ->
|
||||
( resetEdit model
|
||||
, HttpMF.provision
|
||||
(B.crossOrigin url.base url.path [])
|
||||
(B.relative [ path.things ] [])
|
||||
token
|
||||
{ emptyThing
|
||||
| name = Just model.name
|
||||
|
@ -187,7 +181,7 @@ update msg model token =
|
|||
UpdateThing ->
|
||||
( resetEdit { model | editMode = False }
|
||||
, HttpMF.update
|
||||
(B.crossOrigin url.base (List.append url.path [ model.thing.id ]) [])
|
||||
(B.relative [ path.things, model.thing.id ] [])
|
||||
token
|
||||
{ emptyThing
|
||||
| name = Just model.name
|
||||
|
@ -209,7 +203,7 @@ update msg model token =
|
|||
RetrieveThing thingid ->
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base (List.append url.path [ thingid ]) [])
|
||||
(B.relative [ path.things, thingid ] [])
|
||||
token
|
||||
RetrievedThing
|
||||
thingDecoder
|
||||
|
@ -226,7 +220,7 @@ update msg model token =
|
|||
RetrieveThings ->
|
||||
( model
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base url.path (Helpers.buildQueryParamList model.offset model.limit))
|
||||
(B.relative [ path.things ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedThings
|
||||
thingsDecoder
|
||||
|
@ -243,7 +237,7 @@ update msg model token =
|
|||
RemoveThing id ->
|
||||
( model
|
||||
, HttpMF.remove
|
||||
(B.crossOrigin url.base (List.append url.path [ id ]) [])
|
||||
(B.relative [ path.things, id ] [])
|
||||
token
|
||||
RemovedThing
|
||||
)
|
||||
|
@ -497,15 +491,12 @@ updateThingList model token =
|
|||
( model
|
||||
, Cmd.batch
|
||||
[ HttpMF.retrieve
|
||||
(B.crossOrigin url.base
|
||||
url.path
|
||||
(Helpers.buildQueryParamList model.offset model.limit)
|
||||
)
|
||||
(B.relative [ path.things ] (Helpers.buildQueryParamList model.offset model.limit))
|
||||
token
|
||||
RetrievedThings
|
||||
thingsDecoder
|
||||
, HttpMF.retrieve
|
||||
(B.crossOrigin url.base (List.append url.path [ model.thing.id ]) [])
|
||||
(B.relative [ path.things, model.thing.id ] [])
|
||||
token
|
||||
RetrievedThing
|
||||
thingDecoder
|
||||
|
|
|
@ -19,19 +19,12 @@ import Html exposing (..)
|
|||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import HttpMF
|
||||
import HttpMF exposing (path)
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import Url.Builder as B
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
, usersPath = [ "users" ]
|
||||
, tokensPath = [ "tokens" ]
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ email : String
|
||||
, password : String
|
||||
|
@ -76,7 +69,7 @@ update msg model =
|
|||
, create
|
||||
model.email
|
||||
model.password
|
||||
(B.crossOrigin url.base url.usersPath [])
|
||||
(B.relative [ path.users ] [])
|
||||
)
|
||||
|
||||
Created result ->
|
||||
|
@ -92,7 +85,7 @@ update msg model =
|
|||
, getToken
|
||||
model.email
|
||||
model.password
|
||||
(B.crossOrigin url.base url.tokensPath [])
|
||||
(B.relative [ path.tokens ] [])
|
||||
)
|
||||
|
||||
GotToken result ->
|
||||
|
|
|
@ -10,17 +10,12 @@ import Error
|
|||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Http
|
||||
import HttpMF exposing (path)
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import Url.Builder as B
|
||||
|
||||
|
||||
url =
|
||||
{ base = "http://localhost"
|
||||
, path = [ "version" ]
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ version : String }
|
||||
|
||||
|
@ -41,7 +36,7 @@ update msg model =
|
|||
GetVersion ->
|
||||
( model
|
||||
, Http.get
|
||||
{ url = B.crossOrigin url.base url.path []
|
||||
{ url = B.relative [ path.version ] []
|
||||
, expect = Http.expectJson GotVersion (D.field "version" D.string)
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue