mirror of
https://github.com/fluencelabs/dashboard
synced 2025-03-16 13:30:48 +00:00
update module schema
This commit is contained in:
parent
b028804ea1
commit
9102ed6282
@ -3,6 +3,7 @@ module AirScripts.DiscoverPeers exposing (..)
|
||||
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
air : String -> String -> Air
|
||||
air peerId relayId =
|
||||
let
|
||||
@ -27,4 +28,4 @@ air peerId relayId =
|
||||
)
|
||||
)
|
||||
in
|
||||
(relayIdSet <| clientIdSet <| airScript)
|
||||
relayIdSet <| clientIdSet <| airScript
|
||||
|
@ -66,7 +66,7 @@ viewInstance : Instance -> Html msg
|
||||
viewInstance instance =
|
||||
tr [ classes "stripe-dark" ]
|
||||
[ td [ classes "pa3" ] [ text instance.name ]
|
||||
, td [ ] [ a [attribute "href" ("/service/" ++ instance.instance), classes "pa3 link dim hide-child"] [text instance.instance] ]
|
||||
, td [] [ a [ attribute "href" ("/service/" ++ instance.instance), classes "pa3 link dim hide-child" ] [ text instance.instance ] ]
|
||||
, td [ classes "pa3" ] [ text instance.peerId ]
|
||||
, td [ classes "pa3" ] [ text instance.ip ]
|
||||
]
|
||||
|
@ -19,6 +19,7 @@ limitations under the License.
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Browser.Navigation as Nav
|
||||
import Dict exposing (Dict)
|
||||
import Modules.Model exposing (Module)
|
||||
import Nodes.Model exposing (Identify, emptyIdentify)
|
||||
import Services.Model exposing (Service)
|
||||
import Url
|
||||
@ -34,7 +35,7 @@ type Route
|
||||
type alias PeerData =
|
||||
{ identify : Identify
|
||||
, services : List Service
|
||||
, modules : List String
|
||||
, modules : List Module
|
||||
, blueprints : List Blueprint
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,15 @@
|
||||
module Modules.Model exposing (..)
|
||||
|
||||
import Services.Model exposing (Interface)
|
||||
|
||||
|
||||
type alias Module =
|
||||
{ name : String
|
||||
, interface : Interface
|
||||
}
|
||||
|
||||
|
||||
type alias ModuleShortInfo =
|
||||
{ name : String
|
||||
{ moduleInfo : Module
|
||||
, instanceNumber : Int
|
||||
}
|
||||
|
@ -4,17 +4,17 @@ import Dict exposing (Dict)
|
||||
import Html exposing (Html, div, p, span, text)
|
||||
import Html.Attributes exposing (attribute)
|
||||
import Model exposing (Model, PeerData)
|
||||
import Modules.Model exposing (ModuleShortInfo)
|
||||
import Modules.Model exposing (Module, ModuleShortInfo)
|
||||
import Palette exposing (classes)
|
||||
import Utils.Utils exposing (instancesText)
|
||||
|
||||
|
||||
getModuleShortInfo : Model -> List ModuleShortInfo
|
||||
getModuleShortInfo model =
|
||||
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\( moduleName, peers ) -> { name = moduleName, instanceNumber = List.length peers })
|
||||
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\( moduleName, ( moduleInfo, peers ) ) -> { moduleInfo = moduleInfo, instanceNumber = List.length peers })
|
||||
|
||||
|
||||
getAllModules : Dict String PeerData -> Dict String (List String)
|
||||
getAllModules : Dict String PeerData -> Dict String ( Module, List String )
|
||||
getAllModules peerData =
|
||||
let
|
||||
peerDatas =
|
||||
@ -29,9 +29,20 @@ getAllModules peerData =
|
||||
peersByModuleName
|
||||
|
||||
|
||||
updateDict : ( String, String ) -> Dict String (List String) -> Dict String (List String)
|
||||
updateDict ( peer, moduleName ) dict =
|
||||
dict |> Dict.update moduleName (\oldM -> oldM |> Maybe.map (List.append [ peer ]) |> Maybe.withDefault [ peer ] |> Just)
|
||||
|
||||
-- group by module name and append peers
|
||||
|
||||
|
||||
updateDict : ( String, Module ) -> Dict String ( Module, List String ) -> Dict String ( Module, List String )
|
||||
updateDict ( peer, moduleInfo ) dict =
|
||||
dict
|
||||
|> Dict.update moduleInfo.name
|
||||
(\oldM ->
|
||||
oldM
|
||||
|> Maybe.map (\( info, peers ) -> ( info, List.append [ peer ] peers ))
|
||||
|> Maybe.withDefault ( moduleInfo, [ peer ] )
|
||||
|> Just
|
||||
)
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
@ -44,9 +55,9 @@ view modules =
|
||||
|
||||
|
||||
viewService : ModuleShortInfo -> Html msg
|
||||
viewService service =
|
||||
viewService moduleInfo =
|
||||
div [ classes "fl w-third-ns pa2" ]
|
||||
[ div [ attribute "href" "#", classes "fl w-100 link dim black mw5 dt hide-child ba b-black pa4 br2 solid" ]
|
||||
[ p [ classes "tl di" ] [ span [ classes "b pl2" ] [ text service.name ], span [ classes "di fr pr2" ] [ instancesText service.instanceNumber ] ]
|
||||
[ p [ classes "tl di" ] [ span [ classes "b pl2" ] [ text moduleInfo.moduleInfo.name ], span [ classes "di fr pr2" ] [ instancesText moduleInfo.instanceNumber ] ]
|
||||
]
|
||||
]
|
||||
|
@ -4,6 +4,7 @@ import Air exposing (Air(..))
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Dict exposing (Dict)
|
||||
import Json.Encode exposing (Value)
|
||||
import Modules.Model exposing (Module)
|
||||
import Nodes.Model exposing (Identify)
|
||||
import Services.Model exposing (Service)
|
||||
|
||||
@ -13,7 +14,7 @@ type alias SendParticle =
|
||||
|
||||
|
||||
type alias ReceiveEvent =
|
||||
{ name : String, peer : String, peers : Maybe (List String), identify : Maybe Identify, services : Maybe (List Service), modules : Maybe (List String), blueprints : Maybe (List Blueprint) }
|
||||
{ name : String, peer : String, peers : Maybe (List String), identify : Maybe Identify, services : Maybe (List Service), modules : Maybe (List Module), blueprints : Maybe (List Blueprint) }
|
||||
|
||||
|
||||
port sendParticle : SendParticle -> Cmd msg
|
||||
|
@ -26,7 +26,8 @@ parse url =
|
||||
routeView : Model -> Route -> Html msg
|
||||
routeView model route =
|
||||
let
|
||||
_ = Debug.log "page" route
|
||||
_ =
|
||||
Debug.log "page" route
|
||||
in
|
||||
case route of
|
||||
Page page ->
|
||||
@ -57,10 +58,10 @@ routeCommand m r =
|
||||
sendAir (DiscoverPeers.air m.peerId m.relayId)
|
||||
|
||||
Peer _ ->
|
||||
Cmd.none
|
||||
sendAir (DiscoverPeers.air m.peerId m.relayId)
|
||||
|
||||
Service string ->
|
||||
Cmd.none
|
||||
sendAir (DiscoverPeers.air m.peerId m.relayId)
|
||||
|
||||
Module string ->
|
||||
Cmd.none
|
||||
sendAir (DiscoverPeers.air m.peerId m.relayId)
|
||||
|
@ -23,6 +23,7 @@ import Browser.Navigation as Nav
|
||||
import Dict exposing (Dict)
|
||||
import Maybe exposing (withDefault)
|
||||
import Model exposing (Model, PeerData, emptyPeerData)
|
||||
import Modules.Model exposing (Module)
|
||||
import Msg exposing (..)
|
||||
import Nodes.Model exposing (Identify)
|
||||
import Port exposing (sendAir)
|
||||
@ -67,8 +68,16 @@ update msg model =
|
||||
|
||||
updatedDict =
|
||||
Dict.union model.discoveredPeers newDict
|
||||
|
||||
emptyPeers =
|
||||
Dict.toList updatedDict
|
||||
|> List.filter (\( p, data ) -> List.isEmpty data.identify.external_addresses)
|
||||
|> List.map Tuple.first
|
||||
|
||||
_ =
|
||||
Debug.log "empty peers" (List.length emptyPeers)
|
||||
in
|
||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||
( { model | discoveredPeers = updatedDict }, sendAir (AirScripts.GetAll.air model.peerId model.relayId emptyPeers) )
|
||||
|
||||
"all_info" ->
|
||||
let
|
||||
@ -77,12 +86,6 @@ update msg model =
|
||||
|
||||
updatedModel =
|
||||
withDefault model updated
|
||||
|
||||
byBp =
|
||||
peersByBlueprintId model.discoveredPeers "623c6d14-2204-43c4-84d5-a237bcd19874"
|
||||
|
||||
_ =
|
||||
Debug.log "by blueprint id" byBp
|
||||
in
|
||||
( updatedModel, Cmd.none )
|
||||
|
||||
@ -123,7 +126,7 @@ update msg model =
|
||||
( { model | relayId = relayId }, Cmd.none )
|
||||
|
||||
|
||||
updateModel : Model -> String -> Identify -> List Service -> List String -> List Blueprint -> Model
|
||||
updateModel : Model -> String -> Identify -> List Service -> List Module -> List Blueprint -> Model
|
||||
updateModel model peer identify services modules blueprints =
|
||||
let
|
||||
data =
|
||||
@ -150,9 +153,9 @@ peersByModule peerData moduleId =
|
||||
found
|
||||
|
||||
|
||||
existsByModule : String -> List String -> Bool
|
||||
existsByModule : String -> List Module -> Bool
|
||||
existsByModule moduleId modules =
|
||||
modules |> List.any (\m -> m == moduleId)
|
||||
modules |> List.any (\m -> m.name == moduleId)
|
||||
|
||||
|
||||
peersByBlueprintId : Dict String PeerData -> String -> List String
|
||||
|
Loading…
x
Reference in New Issue
Block a user