Skip to content

Commit

Permalink
Merge branch 'master' into mainflux-596
Browse files Browse the repository at this point in the history
  • Loading branch information
beres authored Mar 13, 2019
2 parents 8f759c2 + a0ed73d commit 33cf9aa
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 92 deletions.
2 changes: 1 addition & 1 deletion ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
43 changes: 10 additions & 33 deletions ui/src/Channel.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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)
13 changes: 4 additions & 9 deletions ui/src/Connection.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion ui/src/HttpMF.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +19,16 @@ url =
}


path =
{ users = "users"
, tokens = "tokens"
, things = "things"
, channels = "channels"
, messages = "messages"
, version = "version"
}



-- EXPECT

Expand Down
19 changes: 5 additions & 14 deletions ui/src/Message.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
)
Expand Down Expand Up @@ -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
25 changes: 8 additions & 17 deletions ui/src/Thing.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,12 +40,6 @@ query =
}


url =
{ base = "http://localhost"
, path = [ "things" ]
}


defaultType =
"app"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions ui/src/User.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,7 +69,7 @@ update msg model =
, create
model.email
model.password
(B.crossOrigin url.base url.usersPath [])
(B.relative [ path.users ] [])
)

Created result ->
Expand All @@ -92,7 +85,7 @@ update msg model =
, getToken
model.email
model.password
(B.crossOrigin url.base url.tokensPath [])
(B.relative [ path.tokens ] [])
)

GotToken result ->
Expand Down
9 changes: 2 additions & 7 deletions ui/src/Version.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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)
}
)
Expand Down

0 comments on commit 33cf9aa

Please sign in to comment.