mirror of
https://github.com/fluencelabs/dashboard
synced 2025-03-28 02:41:04 +00:00
update main model schema
This commit is contained in:
parent
9102ed6282
commit
6dbc8d6ea9
1
elm.json
1
elm.json
@ -22,6 +22,7 @@
|
|||||||
"elm-community/graph": "6.0.0",
|
"elm-community/graph": "6.0.0",
|
||||||
"elm-community/intdict": "3.0.0",
|
"elm-community/intdict": "3.0.0",
|
||||||
"elm-community/list-extra": "8.2.4",
|
"elm-community/list-extra": "8.2.4",
|
||||||
|
"elm-community/maybe-extra": "5.2.0",
|
||||||
"ivadzy/bbase64": "1.1.1",
|
"ivadzy/bbase64": "1.1.1",
|
||||||
"lukewestby/elm-string-interpolate": "1.0.4",
|
"lukewestby/elm-string-interpolate": "1.0.4",
|
||||||
"mpizenberg/elm-pointer-events": "4.0.2",
|
"mpizenberg/elm-pointer-events": "4.0.2",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module Instances.View exposing (..)
|
module Instances.View exposing (..)
|
||||||
|
|
||||||
|
import Blueprints.Model exposing (Blueprint)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Html exposing (Html, a, div, table, tbody, td, text, th, thead, tr)
|
import Html exposing (Html, a, div, table, tbody, td, text, th, thead, tr)
|
||||||
import Html.Attributes exposing (attribute)
|
import Html.Attributes exposing (attribute)
|
||||||
@ -10,11 +11,11 @@ import Palette exposing (classes)
|
|||||||
import Services.Model exposing (Service)
|
import Services.Model exposing (Service)
|
||||||
|
|
||||||
|
|
||||||
toInstance : String -> Identify -> Dict String String -> Service -> Instance
|
toInstance : String -> Identify -> Dict String Blueprint -> Service -> Instance
|
||||||
toInstance peerId identify blueprints service =
|
toInstance peerId identify blueprints service =
|
||||||
let
|
let
|
||||||
name =
|
name =
|
||||||
blueprints |> Dict.get service.blueprint_id |> Maybe.withDefault "unknown"
|
blueprints |> Dict.get service.blueprint_id |> Maybe.map .name |> Maybe.withDefault "unknown"
|
||||||
|
|
||||||
ip =
|
ip =
|
||||||
List.head identify.external_addresses |> Maybe.map (String.split "/") |> Maybe.map (List.drop 2) |> Maybe.andThen List.head |> Maybe.withDefault "unknown"
|
List.head identify.external_addresses |> Maybe.map (String.split "/") |> Maybe.map (List.drop 2) |> Maybe.andThen List.head |> Maybe.withDefault "unknown"
|
||||||
@ -25,18 +26,12 @@ toInstance peerId identify blueprints service =
|
|||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
bps =
|
|
||||||
Dict.values model.discoveredPeers |> List.map (\data -> data.blueprints |> List.map (\b -> ( b.id, b.name )))
|
|
||||||
|
|
||||||
bpsDict =
|
|
||||||
List.concat bps |> Dict.fromList
|
|
||||||
|
|
||||||
instances =
|
instances =
|
||||||
Dict.toList model.discoveredPeers
|
Dict.toList model.discoveredPeers
|
||||||
|> List.map
|
|> List.map
|
||||||
(\( peer, data ) ->
|
(\( peer, data ) ->
|
||||||
data.services
|
data.services
|
||||||
|> List.map (toInstance peer data.identify bpsDict)
|
|> List.map (toInstance peer data.identify model.blueprints)
|
||||||
)
|
)
|
||||||
|> List.concat
|
|> List.concat
|
||||||
in
|
in
|
||||||
|
@ -55,6 +55,8 @@ init flags url key =
|
|||||||
, key = key
|
, key = key
|
||||||
, page = r
|
, page = r
|
||||||
, discoveredPeers = Dict.empty
|
, discoveredPeers = Dict.empty
|
||||||
|
, modules = Dict.empty
|
||||||
|
, blueprints = Dict.empty
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
( emptyModel, Route.routeCommand emptyModel r )
|
( emptyModel, Route.routeCommand emptyModel r )
|
||||||
|
@ -35,8 +35,8 @@ type Route
|
|||||||
type alias PeerData =
|
type alias PeerData =
|
||||||
{ identify : Identify
|
{ identify : Identify
|
||||||
, services : List Service
|
, services : List Service
|
||||||
, modules : List Module
|
, modules : List String
|
||||||
, blueprints : List Blueprint
|
, blueprints : List String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,4 +52,6 @@ type alias Model =
|
|||||||
, url : Url.Url
|
, url : Url.Url
|
||||||
, page : Route
|
, page : Route
|
||||||
, discoveredPeers : Dict String PeerData
|
, discoveredPeers : Dict String PeerData
|
||||||
|
, modules : Dict String Module
|
||||||
|
, blueprints : Dict String Blueprint
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ module Modules.View exposing (..)
|
|||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Html exposing (Html, div, p, span, text)
|
import Html exposing (Html, div, p, span, text)
|
||||||
import Html.Attributes exposing (attribute)
|
import Html.Attributes exposing (attribute)
|
||||||
|
import Maybe.Extra
|
||||||
import Model exposing (Model, PeerData)
|
import Model exposing (Model, PeerData)
|
||||||
import Modules.Model exposing (Module, ModuleShortInfo)
|
import Modules.Model exposing (Module, ModuleShortInfo)
|
||||||
import Palette exposing (classes)
|
import Palette exposing (classes)
|
||||||
@ -11,20 +12,20 @@ import Utils.Utils exposing (instancesText)
|
|||||||
|
|
||||||
getModuleShortInfo : Model -> List ModuleShortInfo
|
getModuleShortInfo : Model -> List ModuleShortInfo
|
||||||
getModuleShortInfo model =
|
getModuleShortInfo model =
|
||||||
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\( moduleName, ( moduleInfo, peers ) ) -> { moduleInfo = moduleInfo, instanceNumber = List.length peers })
|
getAllModules model.modules model.discoveredPeers |> Dict.toList |> List.map (\( moduleName, ( moduleInfo, peers ) ) -> { moduleInfo = moduleInfo, instanceNumber = List.length peers })
|
||||||
|
|
||||||
|
|
||||||
getAllModules : Dict String PeerData -> Dict String ( Module, List String )
|
getAllModules : Dict String Module -> Dict String PeerData -> Dict String ( Module, List String )
|
||||||
getAllModules peerData =
|
getAllModules modules peerData =
|
||||||
let
|
let
|
||||||
peerDatas =
|
peerDatas =
|
||||||
Dict.toList peerData
|
Dict.toList peerData
|
||||||
|
|
||||||
allModules =
|
allModulesByPeers =
|
||||||
peerDatas |> List.map (\( peer, pd ) -> pd.modules |> List.map (\ms -> ( peer, ms ))) |> List.concat
|
peerDatas |> List.map (\( peer, pd ) -> pd.modules |> List.map (\ms -> ( peer, ms ))) |> List.concat
|
||||||
|
|
||||||
peersByModuleName =
|
peersByModuleName =
|
||||||
allModules |> List.foldr updateDict Dict.empty
|
allModulesByPeers |> List.foldr (updateDict modules) Dict.empty
|
||||||
in
|
in
|
||||||
peersByModuleName
|
peersByModuleName
|
||||||
|
|
||||||
@ -33,23 +34,25 @@ getAllModules peerData =
|
|||||||
-- group by module name and append peers
|
-- group by module name and append peers
|
||||||
|
|
||||||
|
|
||||||
updateDict : ( String, Module ) -> Dict String ( Module, List String ) -> Dict String ( Module, List String )
|
updateDict : Dict String Module -> ( String, String ) -> Dict String ( Module, List String ) -> Dict String ( Module, List String )
|
||||||
updateDict ( peer, moduleInfo ) dict =
|
updateDict modules ( peer, moduleName ) dict =
|
||||||
dict
|
dict
|
||||||
|> Dict.update moduleInfo.name
|
|> Dict.update moduleName
|
||||||
(\oldM ->
|
(\oldM ->
|
||||||
oldM
|
Maybe.Extra.or
|
||||||
|> Maybe.map (\( info, peers ) -> ( info, List.append [ peer ] peers ))
|
(oldM |> Maybe.map (\( info, peers ) -> ( info, List.append [ peer ] peers )))
|
||||||
|> Maybe.withDefault ( moduleInfo, [ peer ] )
|
(Dict.get moduleName modules |> Maybe.map (\m -> ( m, [ peer ] )))
|
||||||
|> Just
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view modules =
|
view modules =
|
||||||
let
|
let
|
||||||
|
info =
|
||||||
|
getModuleShortInfo modules
|
||||||
|
|
||||||
modulesView =
|
modulesView =
|
||||||
List.map viewService (getModuleShortInfo modules)
|
List.map viewService info
|
||||||
in
|
in
|
||||||
div [ classes "cf ph2-ns" ] modulesView
|
div [ classes "cf ph2-ns" ] modulesView
|
||||||
|
|
||||||
|
@ -39,14 +39,11 @@ modelToServiceInfo model id =
|
|||||||
services =
|
services =
|
||||||
datas |> List.map (\( peer, data ) -> data.services |> List.map (\s -> ( peer, s ))) |> List.concat
|
datas |> List.map (\( peer, data ) -> data.services |> List.map (\s -> ( peer, s ))) |> List.concat
|
||||||
|
|
||||||
blueprints =
|
|
||||||
datas |> List.map (\( _, data ) -> data.blueprints) |> List.concat |> List.map (\bp -> ( bp.id, bp.name )) |> Dict.fromList
|
|
||||||
|
|
||||||
service =
|
service =
|
||||||
services |> List.Extra.find (\( _, s ) -> s.service_id == id)
|
services |> List.Extra.find (\( _, s ) -> s.service_id == id)
|
||||||
|
|
||||||
name =
|
name =
|
||||||
service |> Maybe.andThen (\( _, s ) -> blueprints |> Dict.get s.blueprint_id) |> Maybe.withDefault "unknown"
|
service |> Maybe.andThen (\( _, s ) -> model.blueprints |> Dict.get s.blueprint_id |> Maybe.map .name) |> Maybe.withDefault "unknown"
|
||||||
|
|
||||||
info =
|
info =
|
||||||
service
|
service
|
||||||
@ -66,14 +63,14 @@ modelToServiceInfo model id =
|
|||||||
|
|
||||||
|
|
||||||
viewInfo : ServiceInfo -> Html msg
|
viewInfo : ServiceInfo -> Html msg
|
||||||
viewInfo moduleInfo =
|
viewInfo serviceInfo =
|
||||||
article [ classes "cf" ]
|
article [ classes "cf" ]
|
||||||
[ div [ classes "fl w-30 gray mv1" ] [ text "AUTHOR" ]
|
[ div [ classes "fl w-30 gray mv1" ] [ text "AUTHOR" ]
|
||||||
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black b" ] [ text moduleInfo.author ], span [ classes "fl w-100 black" ] [ text moduleInfo.authorPeerId ] ]
|
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black b" ] [ text serviceInfo.author ], span [ classes "fl w-100 black" ] [ text serviceInfo.authorPeerId ] ]
|
||||||
, div [ classes "fl w-30 gray mv1" ] [ text "DESCRIPTION" ]
|
, div [ classes "fl w-30 gray mv1" ] [ text "DESCRIPTION" ]
|
||||||
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] [ text moduleInfo.description ] ]
|
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] [ text serviceInfo.description ] ]
|
||||||
, div [ classes "fl w-30 gray mv1" ] [ text "INTERFACE" ]
|
, div [ classes "fl w-30 gray mv1" ] [ text "INTERFACE" ]
|
||||||
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] (recordsView moduleInfo.service.interface.record_types ++ signaturesView moduleInfo.service.interface.function_signatures) ]
|
, div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] (recordsView serviceInfo.service.interface.record_types ++ signaturesView serviceInfo.service.interface.function_signatures) ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ view : Model -> Html msg
|
|||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
allBps =
|
allBps =
|
||||||
getBlueprintsToServices model.discoveredPeers
|
getBlueprintsToServices model.blueprints model.discoveredPeers
|
||||||
|
|
||||||
info =
|
info =
|
||||||
Dict.values allBps |> List.map (\( bp, servicesByPeers ) -> { name = bp.name, author = "Fluence Labs", instanceNumber = List.length (servicesByPeers |> List.map (\( _, s ) -> s) |> List.concat) })
|
Dict.values allBps |> List.map (\( bp, servicesByPeers ) -> { name = bp.name, author = "Fluence Labs", instanceNumber = List.length (servicesByPeers |> List.map (\( _, s ) -> s) |> List.concat) })
|
||||||
@ -40,14 +40,11 @@ viewService service =
|
|||||||
-- bpId peerId
|
-- bpId peerId
|
||||||
|
|
||||||
|
|
||||||
getBlueprintsToServices : Dict String PeerData -> Dict String ( Blueprint, List ( String, List Service ) )
|
getBlueprintsToServices : Dict String Blueprint -> Dict String PeerData -> Dict String ( Blueprint, List ( String, List Service ) )
|
||||||
getBlueprintsToServices peerData =
|
getBlueprintsToServices blueprints peerData =
|
||||||
let
|
let
|
||||||
peerDatas =
|
|
||||||
Dict.toList peerData
|
|
||||||
|
|
||||||
allBlueprints =
|
allBlueprints =
|
||||||
peerDatas |> List.map (\( _, pd ) -> pd.blueprints |> List.map (\bp -> bp)) |> List.concat
|
Dict.values blueprints
|
||||||
|
|
||||||
bpsToServices =
|
bpsToServices =
|
||||||
allBlueprints |> List.map (\bp -> ( bp.id, ( bp, getServicesByBlueprintId peerData bp.id ) )) |> Dict.fromList
|
allBlueprints |> List.map (\bp -> ( bp.id, ( bp, getServicesByBlueprintId peerData bp.id ) )) |> Dict.fromList
|
||||||
|
@ -89,22 +89,6 @@ update msg model =
|
|||||||
in
|
in
|
||||||
( updatedModel, Cmd.none )
|
( updatedModel, Cmd.none )
|
||||||
|
|
||||||
"modules_discovered" ->
|
|
||||||
let
|
|
||||||
newModules =
|
|
||||||
Maybe.withDefault [] modules
|
|
||||||
|
|
||||||
empty =
|
|
||||||
emptyPeerData
|
|
||||||
|
|
||||||
up =
|
|
||||||
\old -> Just (Maybe.withDefault { empty | modules = newModules } (Maybe.map (\o -> { o | modules = newModules }) old))
|
|
||||||
|
|
||||||
updatedDict =
|
|
||||||
Dict.update peer up model.discoveredPeers
|
|
||||||
in
|
|
||||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
let
|
let
|
||||||
_ =
|
_ =
|
||||||
@ -132,44 +116,22 @@ updateModel model peer identify services modules blueprints =
|
|||||||
data =
|
data =
|
||||||
Maybe.withDefault emptyPeerData (Dict.get peer model.discoveredPeers)
|
Maybe.withDefault emptyPeerData (Dict.get peer model.discoveredPeers)
|
||||||
|
|
||||||
|
moduleDict =
|
||||||
|
modules |> List.map (\m -> ( m.name, m )) |> Dict.fromList
|
||||||
|
|
||||||
|
blueprintDict =
|
||||||
|
blueprints |> List.map (\b -> ( b.name, b )) |> Dict.fromList
|
||||||
|
|
||||||
|
updatedModules =
|
||||||
|
Dict.union moduleDict model.modules
|
||||||
|
|
||||||
|
updatedBlueprints =
|
||||||
|
Dict.union blueprintDict model.blueprints
|
||||||
|
|
||||||
newData =
|
newData =
|
||||||
{ data | identify = identify, services = services, modules = modules, blueprints = blueprints }
|
{ data | identify = identify, services = services, modules = Dict.keys moduleDict, blueprints = Dict.keys blueprintDict }
|
||||||
|
|
||||||
updated =
|
updated =
|
||||||
Dict.insert peer newData model.discoveredPeers
|
Dict.insert peer newData model.discoveredPeers
|
||||||
in
|
in
|
||||||
{ model | discoveredPeers = updated }
|
{ model | discoveredPeers = updated, modules = updatedModules, blueprints = updatedBlueprints }
|
||||||
|
|
||||||
|
|
||||||
peersByModule : Dict String PeerData -> String -> List String
|
|
||||||
peersByModule peerData moduleId =
|
|
||||||
let
|
|
||||||
list =
|
|
||||||
Dict.toList peerData
|
|
||||||
|
|
||||||
found =
|
|
||||||
list |> List.filter (\( _, pd ) -> existsByModule moduleId pd.modules) |> List.map (\( peer, _ ) -> peer)
|
|
||||||
in
|
|
||||||
found
|
|
||||||
|
|
||||||
|
|
||||||
existsByModule : String -> List Module -> Bool
|
|
||||||
existsByModule moduleId modules =
|
|
||||||
modules |> List.any (\m -> m.name == moduleId)
|
|
||||||
|
|
||||||
|
|
||||||
peersByBlueprintId : Dict String PeerData -> String -> List String
|
|
||||||
peersByBlueprintId peerData blueprintId =
|
|
||||||
let
|
|
||||||
list =
|
|
||||||
Dict.toList peerData
|
|
||||||
|
|
||||||
found =
|
|
||||||
list |> List.filter (\( _, pd ) -> existsByBlueprintId blueprintId pd.blueprints) |> List.map (\( peer, _ ) -> peer)
|
|
||||||
in
|
|
||||||
found
|
|
||||||
|
|
||||||
|
|
||||||
existsByBlueprintId : String -> List Blueprint -> Bool
|
|
||||||
existsByBlueprintId id bps =
|
|
||||||
bps |> List.any (\b -> b.id == id)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user