diff --git a/package-lock.json b/package-lock.json index 95a5720..5e950f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 31286fa..28e7dcb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/HubPage/Model.elm b/src/HubPage/Model.elm deleted file mode 100644 index d1c4f50..0000000 --- a/src/HubPage/Model.elm +++ /dev/null @@ -1,5 +0,0 @@ -module HubPage.Model exposing (..) - - -type alias Model = - {} diff --git a/src/HubPage/View.elm b/src/HubPage/View.elm index 15ea065..a707542 100644 --- a/src/HubPage/View.elm +++ b/src/HubPage/View.elm @@ -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) ] diff --git a/src/Modules/Model.elm b/src/Modules/Model.elm index 213da48..c329ec6 100644 --- a/src/Modules/Model.elm +++ b/src/Modules/Model.elm @@ -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) diff --git a/src/Modules/View.elm b/src/Modules/View.elm index e9fac6e..fe005df 100644 --- a/src/Modules/View.elm +++ b/src/Modules/View.elm @@ -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 diff --git a/src/Route.elm b/src/Route.elm index c7c100b..2873ac6 100644 --- a/src/Route.elm +++ b/src/Route.elm @@ -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 diff --git a/src/Update.elm b/src/Update.elm index e0531f1..7079dea 100644 --- a/src/Update.elm +++ b/src/Update.elm @@ -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