mirror of
https://github.com/fluencelabs/dashboard
synced 2025-04-22 06:22:13 +00:00
elm format
This commit is contained in:
parent
fb3b426e78
commit
ea2fcf9971
@ -1,5 +1,6 @@
|
|||||||
module Config exposing (..)
|
module Config exposing (..)
|
||||||
|
|
||||||
|
|
||||||
type alias Config =
|
type alias Config =
|
||||||
{ peerId : String
|
{ peerId : String
|
||||||
, relayId : String
|
, relayId : String
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module HubPage.Model exposing (..)
|
module HubPage.Model exposing (..)
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
module HubPage.Msg exposing (..)
|
module HubPage.Msg exposing (..)
|
||||||
|
|
||||||
type Msg = NoOp
|
|
||||||
|
type Msg
|
||||||
|
= NoOp
|
||||||
|
@ -8,6 +8,7 @@ import Modules.View
|
|||||||
import Services.Model exposing (ServiceInfo)
|
import Services.Model exposing (ServiceInfo)
|
||||||
import Services.View
|
import Services.View
|
||||||
|
|
||||||
|
|
||||||
servicesExample : List ServiceInfo
|
servicesExample : List ServiceInfo
|
||||||
servicesExample =
|
servicesExample =
|
||||||
[ { name = "SQLite", author = "Company Inc", instanceNumber = 2 }
|
[ { name = "SQLite", author = "Company Inc", instanceNumber = 2 }
|
||||||
@ -16,6 +17,7 @@ servicesExample =
|
|||||||
, { name = "Imagemagick", author = "Magic Corp", instanceNumber = 0 }
|
, { name = "Imagemagick", author = "Magic Corp", instanceNumber = 0 }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
modulesExample : List ModuleInfo
|
modulesExample : List ModuleInfo
|
||||||
modulesExample =
|
modulesExample =
|
||||||
[ { name = "sqlite3", instanceNumber = 2 }
|
[ { name = "sqlite3", instanceNumber = 2 }
|
||||||
@ -26,8 +28,10 @@ modulesExample =
|
|||||||
, { name = "basic_auth", instanceNumber = 0 }
|
, { name = "basic_auth", instanceNumber = 0 }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view model = Html.div []
|
view model =
|
||||||
|
Html.div []
|
||||||
[ Services.View.view { services = servicesExample }
|
[ Services.View.view { services = servicesExample }
|
||||||
, Modules.View.view { modules = modulesExample }
|
, Modules.View.view { modules = modulesExample }
|
||||||
]
|
]
|
@ -1,10 +1,9 @@
|
|||||||
module Instances.Model exposing (..)
|
module Instances.Model exposing (..)
|
||||||
|
|
||||||
type alias Instance =
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
type alias Instance =
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
module Instances.Msg exposing (..)
|
module Instances.Msg exposing (..)
|
||||||
|
|
||||||
type Msg = NoOp
|
|
||||||
|
type Msg
|
||||||
|
= NoOp
|
||||||
|
@ -29,7 +29,9 @@ type Route
|
|||||||
|
|
||||||
type alias PeerData =
|
type alias PeerData =
|
||||||
{ services : List Service
|
{ services : List Service
|
||||||
, modules: List String }
|
, modules : List String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
emptyPeerData : PeerData
|
emptyPeerData : PeerData
|
||||||
emptyPeerData =
|
emptyPeerData =
|
||||||
|
@ -3,6 +3,7 @@ module Modules.Air exposing (..)
|
|||||||
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
||||||
import Json.Encode exposing (list, string)
|
import Json.Encode exposing (list, string)
|
||||||
|
|
||||||
|
|
||||||
air : String -> String -> List String -> Air
|
air : String -> String -> List String -> Air
|
||||||
air peerId relayId peers =
|
air peerId relayId peers =
|
||||||
let
|
let
|
||||||
@ -28,4 +29,3 @@ air peerId relayId peers =
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
clientIdSet <| relayIdSet <| peersSet <| airScript
|
clientIdSet <| relayIdSet <| peersSet <| airScript
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
module Modules.Model exposing (..)
|
module Modules.Model exposing (..)
|
||||||
|
|
||||||
|
|
||||||
type alias ModuleInfo =
|
type alias ModuleInfo =
|
||||||
{ name : String
|
{ name : String
|
||||||
, instanceNumber : Int
|
, instanceNumber : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ modules : List ModuleInfo
|
{ modules : List ModuleInfo
|
||||||
}
|
}
|
@ -4,13 +4,17 @@ import Html exposing (Html)
|
|||||||
import Modules.Model exposing (Model, ModuleInfo)
|
import Modules.Model exposing (Model, ModuleInfo)
|
||||||
import Palette exposing (classes)
|
import Palette exposing (classes)
|
||||||
import Utils.Utils exposing (instancesText)
|
import Utils.Utils exposing (instancesText)
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
modulesView = List.map viewService model.modules
|
modulesView =
|
||||||
|
List.map viewService model.modules
|
||||||
in
|
in
|
||||||
Html.div [ classes "cf ph2-ns" ] modulesView
|
Html.div [ classes "cf ph2-ns" ] modulesView
|
||||||
|
|
||||||
|
|
||||||
viewService : ModuleInfo -> Html msg
|
viewService : ModuleInfo -> Html msg
|
||||||
viewService service =
|
viewService service =
|
||||||
Html.div [ classes "fl w-third-ns pa2" ]
|
Html.div [ classes "fl w-third-ns pa2" ]
|
||||||
|
@ -19,12 +19,14 @@ limitations under the License.
|
|||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Html.Attributes exposing (classList)
|
import Html.Attributes exposing (classList)
|
||||||
|
|
||||||
|
|
||||||
classes : String -> Html.Attribute msg
|
classes : String -> Html.Attribute msg
|
||||||
classes cls =
|
classes cls =
|
||||||
classList <|
|
classList <|
|
||||||
List.map (\s -> ( s, True )) <|
|
List.map (\s -> ( s, True )) <|
|
||||||
String.split " " cls
|
String.split " " cls
|
||||||
|
|
||||||
|
|
||||||
shortHashRaw size hash =
|
shortHashRaw size hash =
|
||||||
String.concat
|
String.concat
|
||||||
[ String.left size hash
|
[ String.left size hash
|
||||||
|
@ -20,6 +20,7 @@ routeParser =
|
|||||||
parse url =
|
parse url =
|
||||||
Maybe.withDefault (Page "") <| Url.Parser.parse routeParser url
|
Maybe.withDefault (Page "") <| Url.Parser.parse routeParser url
|
||||||
|
|
||||||
|
|
||||||
routeView : Route -> Html msg
|
routeView : Route -> Html msg
|
||||||
routeView route =
|
routeView route =
|
||||||
case route of
|
case route of
|
||||||
@ -27,19 +28,22 @@ routeView route =
|
|||||||
case page of
|
case page of
|
||||||
"hub" ->
|
"hub" ->
|
||||||
HubPage.view {}
|
HubPage.view {}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Html.text ("undefined page: " ++ page)
|
Html.text ("undefined page: " ++ page)
|
||||||
|
|
||||||
|
|
||||||
Peer peer ->
|
Peer peer ->
|
||||||
Html.text peer
|
Html.text peer
|
||||||
|
|
||||||
|
|
||||||
routeCommand : Model -> Route -> Cmd msg
|
routeCommand : Model -> Route -> Cmd msg
|
||||||
routeCommand m r =
|
routeCommand m r =
|
||||||
case r of
|
case r of
|
||||||
Page s ->
|
Page s ->
|
||||||
let
|
let
|
||||||
_ = Debug.log "page" s
|
_ =
|
||||||
|
Debug.log "page" s
|
||||||
|
|
||||||
clientId =
|
clientId =
|
||||||
set "clientId" <| Encode.string m.peerId
|
set "clientId" <| Encode.string m.peerId
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ module Services.Air exposing (..)
|
|||||||
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
||||||
import Json.Encode exposing (list, string)
|
import Json.Encode exposing (list, string)
|
||||||
|
|
||||||
|
|
||||||
air : String -> String -> List String -> Air
|
air : String -> String -> List String -> Air
|
||||||
air peerId relayId peers =
|
air peerId relayId peers =
|
||||||
let
|
let
|
||||||
@ -28,4 +29,3 @@ air peerId relayId peers =
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
clientIdSet <| relayIdSet <| peersSet <| airScript
|
clientIdSet <| relayIdSet <| peersSet <| airScript
|
||||||
|
|
||||||
|
@ -1,34 +1,40 @@
|
|||||||
module Services.Model exposing (..)
|
module Services.Model exposing (..)
|
||||||
|
|
||||||
|
|
||||||
type alias Signature =
|
type alias Signature =
|
||||||
{ arguments : List (List String)
|
{ arguments : List (List String)
|
||||||
, name : String
|
, name : String
|
||||||
, output_types : List String
|
, output_types : List String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Record =
|
type alias Record =
|
||||||
{ fields : List (List String)
|
{ fields : List (List String)
|
||||||
, id : Int
|
, id : Int
|
||||||
, name : String
|
, name : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Interface =
|
type alias Interface =
|
||||||
{ function_signatures : List Signature
|
{ function_signatures : List Signature
|
||||||
, record_types : List Record
|
, record_types : List Record
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Service =
|
type alias Service =
|
||||||
{ service_id : String
|
{ service_id : String
|
||||||
, blueprint_id : String
|
, blueprint_id : String
|
||||||
, interface : Interface
|
, interface : Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias ServiceInfo =
|
type alias ServiceInfo =
|
||||||
{ name: String,
|
{ name : String
|
||||||
author: String,
|
, author : String
|
||||||
instanceNumber: Int
|
, instanceNumber : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ services : List ServiceInfo
|
{ services : List ServiceInfo
|
||||||
}
|
}
|
@ -5,18 +5,22 @@ import Palette exposing (classes)
|
|||||||
import Services.Model exposing (Model, ServiceInfo)
|
import Services.Model exposing (Model, ServiceInfo)
|
||||||
import Utils.Utils exposing (instancesText)
|
import Utils.Utils exposing (instancesText)
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
servicesView = List.map viewService model.services
|
servicesView =
|
||||||
|
List.map viewService model.services
|
||||||
in
|
in
|
||||||
Html.div [ classes "cf ph2-ns" ] servicesView
|
Html.div [ classes "cf ph2-ns" ] servicesView
|
||||||
|
|
||||||
|
|
||||||
viewService : ServiceInfo -> Html msg
|
viewService : ServiceInfo -> Html msg
|
||||||
viewService service =
|
viewService service =
|
||||||
Html.div [ classes "fl w-third-ns pa2" ]
|
Html.div [ classes "fl w-third-ns pa2" ]
|
||||||
[ Html.div [ classes "fl w-100 br2 ba solid ma2 pa3" ]
|
[ Html.div [ classes "fl w-100 br2 ba solid ma2 pa3" ]
|
||||||
[ Html.div [ classes "w-100 mb2 b" ] [ Html.text service.name ]
|
[ Html.div [ classes "w-100 mb2 b" ] [ Html.text service.name ]
|
||||||
, Html.div [ classes "w-100 mb4" ] [ Html.text ("By " ++ service.author) ]
|
, Html.div [ classes "w-100 mb4" ] [ Html.text ("By " ++ service.author) ]
|
||||||
, Html.div [classes "w-100"] [instancesText service.instanceNumber]]
|
, Html.div [ classes "w-100" ] [ instancesText service.instanceNumber ]
|
||||||
|
]
|
||||||
]
|
]
|
@ -29,11 +29,12 @@ import Route
|
|||||||
import Services.Air
|
import Services.Air
|
||||||
import Url
|
import Url
|
||||||
|
|
||||||
|
|
||||||
maybeValueToString : Maybe Value -> String
|
maybeValueToString : Maybe Value -> String
|
||||||
maybeValueToString mv =
|
maybeValueToString mv =
|
||||||
case mv of
|
case mv of
|
||||||
Just v ->
|
Just v ->
|
||||||
case (decodeValue string v) of
|
case decodeValue string v of
|
||||||
Ok value ->
|
Ok value ->
|
||||||
value
|
value
|
||||||
|
|
||||||
@ -43,31 +44,39 @@ maybeValueToString mv =
|
|||||||
Nothing ->
|
Nothing ->
|
||||||
""
|
""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- list of lists of strings in json to list of strings from first element if it is an array
|
-- list of lists of strings in json to list of strings from first element if it is an array
|
||||||
|
|
||||||
|
|
||||||
maybeValueToListString : Maybe Value -> List String
|
maybeValueToListString : Maybe Value -> List String
|
||||||
maybeValueToListString mv =
|
maybeValueToListString mv =
|
||||||
case mv of
|
case mv of
|
||||||
Just v ->
|
Just v ->
|
||||||
case (decodeValue (list (list string)) v) of
|
case decodeValue (list (list string)) v of
|
||||||
Ok value ->
|
Ok value ->
|
||||||
Maybe.withDefault [] (List.head value)
|
Maybe.withDefault [] (List.head value)
|
||||||
|
|
||||||
Err error ->
|
Err error ->
|
||||||
let
|
let
|
||||||
_ = Debug.log "error" error
|
_ =
|
||||||
|
Debug.log "error" error
|
||||||
in
|
in
|
||||||
case (decodeValue (list string) v) of
|
case decodeValue (list string) v of
|
||||||
Ok value ->
|
Ok value ->
|
||||||
value
|
value
|
||||||
|
|
||||||
Err err ->
|
Err err ->
|
||||||
let
|
let
|
||||||
_ = Debug.log "err" err
|
_ =
|
||||||
|
Debug.log "err" err
|
||||||
in
|
in
|
||||||
[ "error" ]
|
[ "error" ]
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
@ -95,37 +104,60 @@ update msg model =
|
|||||||
AquamarineEvent { name, peer, peers, services, modules } ->
|
AquamarineEvent { name, peer, peers, services, modules } ->
|
||||||
case name of
|
case name of
|
||||||
"peers_discovered" ->
|
"peers_discovered" ->
|
||||||
-- TODO call different function to parse args and change model
|
|
||||||
let
|
let
|
||||||
peersMap = List.map (\p -> Tuple.pair p emptyPeerData) (withDefault [] peers)
|
peersMap =
|
||||||
newDict = Dict.fromList (peersMap)
|
List.map (\p -> Tuple.pair p emptyPeerData) (withDefault [] peers)
|
||||||
updatedDict = Dict.union model.discoveredPeers newDict
|
|
||||||
|
newDict =
|
||||||
|
Dict.fromList peersMap
|
||||||
|
|
||||||
|
updatedDict =
|
||||||
|
Dict.union model.discoveredPeers newDict
|
||||||
in
|
in
|
||||||
-- TODO get data from args, propagate
|
|
||||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||||
|
|
||||||
"services_discovered" ->
|
"services_discovered" ->
|
||||||
let
|
let
|
||||||
newServices = Maybe.withDefault [] services
|
newServices =
|
||||||
empty = emptyPeerData
|
Maybe.withDefault [] services
|
||||||
up = (\old -> Just (Maybe.withDefault {empty | services = newServices} (Maybe.map (\o -> {o | services = newServices}) old)))
|
|
||||||
updatedDict = Dict.update peer up model.discoveredPeers
|
empty =
|
||||||
_ = Debug.log "discovered" updatedDict
|
emptyPeerData
|
||||||
|
|
||||||
|
up =
|
||||||
|
\old -> Just (Maybe.withDefault { empty | services = newServices } (Maybe.map (\o -> { o | services = newServices }) old))
|
||||||
|
|
||||||
|
updatedDict =
|
||||||
|
Dict.update peer up model.discoveredPeers
|
||||||
|
|
||||||
|
_ =
|
||||||
|
Debug.log "discovered" updatedDict
|
||||||
in
|
in
|
||||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||||
|
|
||||||
"modules_discovered" ->
|
"modules_discovered" ->
|
||||||
let
|
let
|
||||||
newModules = Maybe.withDefault [] modules
|
newModules =
|
||||||
empty = emptyPeerData
|
Maybe.withDefault [] modules
|
||||||
up = (\old -> Just (Maybe.withDefault {empty | modules = newModules} (Maybe.map (\o -> {o | modules = newModules}) old)))
|
|
||||||
updatedDict = Dict.update peer up model.discoveredPeers
|
empty =
|
||||||
_ = Debug.log "discovered" updatedDict
|
emptyPeerData
|
||||||
|
|
||||||
|
up =
|
||||||
|
\old -> Just (Maybe.withDefault { empty | modules = newModules } (Maybe.map (\o -> { o | modules = newModules }) old))
|
||||||
|
|
||||||
|
updatedDict =
|
||||||
|
Dict.update peer up model.discoveredPeers
|
||||||
|
|
||||||
|
_ =
|
||||||
|
Debug.log "discovered" updatedDict
|
||||||
in
|
in
|
||||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
let
|
let
|
||||||
_ = Debug.log "event in ELM" name
|
_ =
|
||||||
|
Debug.log "event in ELM" name
|
||||||
in
|
in
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@ module Utils.Utils exposing (..)
|
|||||||
|
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
|
|
||||||
|
|
||||||
instancesText : Int -> Html msg
|
instancesText : Int -> Html msg
|
||||||
instancesText num =
|
instancesText num =
|
||||||
let
|
let
|
||||||
strNum = String.fromInt num
|
strNum =
|
||||||
|
String.fromInt num
|
||||||
in
|
in
|
||||||
if num == 1 then
|
if num == 1 then
|
||||||
Html.text (strNum ++ " instance")
|
Html.text (strNum ++ " instance")
|
||||||
|
|
||||||
else
|
else
|
||||||
Html.text (strNum ++ " instances")
|
Html.text (strNum ++ " instances")
|
||||||
|
19
src/View.elm
19
src/View.elm
@ -39,15 +39,19 @@ title _ =
|
|||||||
body : Model -> Html Msg
|
body : Model -> Html Msg
|
||||||
body model =
|
body model =
|
||||||
let
|
let
|
||||||
a = 1
|
a =
|
||||||
url = model.url
|
1
|
||||||
newUrl = { url | path = "/hub"}
|
|
||||||
|
url =
|
||||||
|
model.url
|
||||||
|
|
||||||
|
newUrl =
|
||||||
|
{ url | path = "/hub" }
|
||||||
in
|
in
|
||||||
layout <|
|
layout <|
|
||||||
List.concat
|
List.concat
|
||||||
[
|
[ [ header [ classes "w-100 bt bb b--black-10" ] [ routeView (Page "hub") ] ]
|
||||||
[ header [ classes "w-100 bt bb b--black-10" ] [ routeView (Page "hub") ] ] ++
|
++ [ header [ classes "w-100 bt bb b--black-10", onClick Click ] [ text "GET SERVICES" ] ]
|
||||||
[ header [ classes "w-100 bt bb b--black-10", onClick Click ] [ text "GET SERVICES" ] ]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -55,8 +59,7 @@ layout : List (Html Msg) -> Html Msg
|
|||||||
layout elms =
|
layout elms =
|
||||||
div [ classes "mw9 center w-70" ]
|
div [ classes "mw9 center w-70" ]
|
||||||
[ div [ classes "fl w-100 pa2" ]
|
[ div [ classes "fl w-100 pa2" ]
|
||||||
([
|
([]
|
||||||
]
|
|
||||||
++ elms
|
++ elms
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user