list of actual modules with instance number

This commit is contained in:
DieMyst 2020-11-28 16:50:40 +03:00
parent 75b2a7b5fb
commit b13fca0b4f
8 changed files with 63 additions and 47 deletions

6
package-lock.json generated
View File

@ -5927,9 +5927,9 @@
"dev": true
},
"fluence": {
"version": "0.7.85",
"resolved": "https://registry.npmjs.org/fluence/-/fluence-0.7.85.tgz",
"integrity": "sha512-qN0mBYgF6Y09Z+qhxnfXyTqmgY++eyWYOUHsRtsmzdTWQuFhlgenLg3861tG9sGCaOUJTfSrrTcdYluC1bgrAw==",
"version": "0.7.86",
"resolved": "https://registry.npmjs.org/fluence/-/fluence-0.7.86.tgz",
"integrity": "sha512-h0RYWwSf56bxQpW+z3o0tHH7UCwYy3khhZGwkGyrP6rxD5YM55r/Xc+8n+OAgxVpBBcPxFUWuxblm+UH65cZvw==",
"requires": {
"@fluencelabs/aquamarine-stepper": "0.0.13",
"async": "3.2.0",

View File

@ -19,7 +19,7 @@
},
"homepage": "https://github.com/fluencelabs/fluence-admin#readme",
"dependencies": {
"fluence": "0.7.85",
"fluence": "0.7.86",
"tachyons": "^4.12.0"
},
"devDependencies": {

View File

@ -1,5 +0,0 @@
module HubPage.Model exposing (..)
type alias Model =
{}

View File

@ -1,9 +1,8 @@
module HubPage.View exposing (..)
import Html exposing (Html)
import HubPage.Model exposing (Model)
import HubPage.Msg exposing (Msg)
import Modules.Model exposing (ModuleShortInfo)
import Model exposing (Model)
import Modules.Model exposing (ModuleShortInfo, getModuleShortInfo)
import Modules.View
import Services.Model exposing (ServiceInfo)
import Services.View
@ -18,20 +17,9 @@ servicesExample =
]
modulesExample : List ModuleShortInfo
modulesExample =
[ { name = "sqlite3", instanceNumber = 2 }
, { name = "ipfs_adapter", instanceNumber = 3 }
, { name = "mariadb_adapter", instanceNumber = 5 }
, { name = "chat_history", instanceNumber = 1 }
, { name = "user_list", instanceNumber = 1 }
, { name = "basic_auth", instanceNumber = 0 }
]
view : Model -> Html msg
view model =
Html.div []
[ Services.View.view { services = servicesExample }
, Modules.View.view { modules = modulesExample }
, Modules.View.view (getModuleShortInfo model)
]

View File

@ -1,12 +1,26 @@
module Modules.Model exposing (..)
import Dict exposing (Dict)
import Model exposing (Model, PeerData)
type alias ModuleShortInfo =
{ name : String
, instanceNumber : Int
}
getModuleShortInfo : Model -> List ModuleShortInfo
getModuleShortInfo model =
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\(moduleName, peers) -> {name = moduleName, instanceNumber = List.length peers})
type alias Model =
{ modules : List ModuleShortInfo
}
getAllModules : Dict String PeerData -> Dict String (List String)
getAllModules peerData =
let
peerDatas = Dict.toList peerData
allModules = peerDatas |> List.map (\(peer, pd) -> pd.modules |> List.map (\ms -> (peer, ms))) |> List.concat
peersByModuleName = allModules |> List.foldr updateDict Dict.empty
in
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)

View File

@ -1,16 +1,16 @@
module Modules.View exposing (..)
import Html exposing (Html)
import Modules.Model exposing (Model, ModuleShortInfo)
import Modules.Model exposing (ModuleShortInfo)
import Palette exposing (classes)
import Utils.Utils exposing (instancesText)
view : Model -> Html msg
view model =
view : List ModuleShortInfo -> Html msg
view modules =
let
modulesView =
List.map viewService model.modules
List.map viewService modules
in
Html.div [ classes "cf ph2-ns" ] modulesView

View File

@ -29,9 +29,9 @@ routeView model route =
Page page ->
case page of
"" ->
HubPage.view {}
HubPage.view model
"hub" ->
HubPage.view {}
HubPage.view model
"module" ->
let

View File

@ -20,7 +20,7 @@ import AirScripts.GetAll
import Blueprints.Model exposing (Blueprint)
import Browser
import Browser.Navigation as Nav
import Dict
import Dict exposing (Dict)
import Json.Decode exposing (decodeValue, list, string)
import Json.Encode exposing (Value)
import List.Unique exposing (filterDuplicates)
@ -123,8 +123,12 @@ update msg model =
"all_info" ->
let
updated = Maybe.map4 (updateModel model peer) identify services modules blueprints
updatedModel = withDefault model updated
byBp = peersByBlueprintId model.discoveredPeers "623c6d14-2204-43c4-84d5-a237bcd19874"
_ = Debug.log "by blueprint id" byBp
in
( withDefault model updated, Cmd.none )
( updatedModel, Cmd.none )
"modules_discovered" ->
let
@ -171,21 +175,36 @@ updateModel model peer identify services modules blueprints =
in
{ model | discoveredPeers = updated }
getAllModules : Model -> List String
getAllModules model =
getServicesByBlueprintId : Dict String PeerData -> String -> List (String, Service)
getServicesByBlueprintId peerData bpId =
let
peerDatas = Dict.values model.discoveredPeers
allModules = peerDatas |> List.map (\pd -> pd.modules)
flatten = List.foldr (++) [] (allModules)
modulesUnique = filterDuplicates (flatten)
in
modulesUnique
list = Dict.toList peerData
found = list |> List.map (\(peer, pd) -> (peer, (filterServicesByBlueprintId bpId pd)))
filtered = found |> List.filter (\(peer, services) -> not (List.isEmpty services)) |> List.map (\(peer, services) -> services |> List.map (\s -> (peer, s)))
in
List.concat filtered
peersByBlueprintId : Model -> String -> List String
peersByBlueprintId model blueprintId =
filterServicesByBlueprintId : String -> PeerData -> List Service
filterServicesByBlueprintId blueprintId peerData =
peerData.services |> List.filter (\s -> s.blueprint_id == blueprintId)
peersByModule : Dict String PeerData -> String -> List String
peersByModule peerData moduleId =
let
list = Dict.toList model.discoveredPeers
found = list |> List.filter (\(peer, pd) -> existsByBlueprintId blueprintId pd.blueprints) |> List.map (\(peer, _) -> peer)
list = Dict.toList peerData
found = list |> List.filter (\(_, pd) -> existsByModule moduleId pd.modules) |> List.map (\(peer, _) -> peer)
in
found
existsByModule : String -> List String -> Bool
existsByModule moduleId modules =
modules |> List.any (\m -> m == 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