mirror of
https://github.com/fluencelabs/dashboard
synced 2025-04-01 20:31:07 +00:00
get actual services by blueprints
This commit is contained in:
parent
b13fca0b4f
commit
5146543311
@ -2,24 +2,12 @@ module HubPage.View exposing (..)
|
|||||||
|
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Model exposing (Model)
|
import Model exposing (Model)
|
||||||
import Modules.Model exposing (ModuleShortInfo, getModuleShortInfo)
|
|
||||||
import Modules.View
|
import Modules.View
|
||||||
import Services.Model exposing (ServiceInfo)
|
|
||||||
import Services.View
|
import Services.View
|
||||||
|
|
||||||
|
|
||||||
servicesExample : List ServiceInfo
|
|
||||||
servicesExample =
|
|
||||||
[ { name = "SQLite", author = "Company Inc", instanceNumber = 2 }
|
|
||||||
, { name = "Redis", author = "Roga Kopita", instanceNumber = 3 }
|
|
||||||
, { name = "Chat", author = "Fluence Labs", instanceNumber = 5 }
|
|
||||||
, { name = "Imagemagick", author = "Magic Corp", instanceNumber = 0 }
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html msg
|
view : Model -> Html msg
|
||||||
view model =
|
view model =
|
||||||
Html.div []
|
Html.div []
|
||||||
[ Services.View.view { services = servicesExample }
|
[ Services.View.view model
|
||||||
, Modules.View.view (getModuleShortInfo model)
|
, Modules.View.view model
|
||||||
]
|
]
|
||||||
|
@ -1,26 +1,7 @@
|
|||||||
module Modules.Model exposing (..)
|
module Modules.Model exposing (..)
|
||||||
|
|
||||||
|
|
||||||
import Dict exposing (Dict)
|
|
||||||
import Model exposing (Model, PeerData)
|
|
||||||
type alias ModuleShortInfo =
|
type alias ModuleShortInfo =
|
||||||
{ name : String
|
{ name : String
|
||||||
, instanceNumber : Int
|
, instanceNumber : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleShortInfo : Model -> List ModuleShortInfo
|
|
||||||
getModuleShortInfo model =
|
|
||||||
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\(moduleName, peers) -> {name = moduleName, instanceNumber = List.length peers})
|
|
||||||
|
|
||||||
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)
|
|
@ -1,16 +1,35 @@
|
|||||||
module Modules.View exposing (..)
|
module Modules.View exposing (..)
|
||||||
|
|
||||||
|
import Dict exposing (Dict)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
|
import Model exposing (Model, PeerData)
|
||||||
import Modules.Model exposing (ModuleShortInfo)
|
import Modules.Model exposing (ModuleShortInfo)
|
||||||
import Palette exposing (classes)
|
import Palette exposing (classes)
|
||||||
import Utils.Utils exposing (instancesText)
|
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})
|
||||||
|
|
||||||
view : List ModuleShortInfo -> Html msg
|
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 : Model -> Html msg
|
||||||
view modules =
|
view modules =
|
||||||
let
|
let
|
||||||
modulesView =
|
modulesView =
|
||||||
List.map viewService modules
|
List.map viewService (getModuleShortInfo modules)
|
||||||
in
|
in
|
||||||
Html.div [ classes "cf ph2-ns" ] modulesView
|
Html.div [ classes "cf ph2-ns" ] modulesView
|
||||||
|
|
||||||
|
@ -34,7 +34,3 @@ type alias ServiceInfo =
|
|||||||
, instanceNumber : Int
|
, instanceNumber : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
|
||||||
{ services : List ServiceInfo
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
module Services.View exposing (..)
|
module Services.View exposing (..)
|
||||||
|
|
||||||
|
import Blueprints.Model exposing (Blueprint)
|
||||||
|
import Dict exposing (Dict)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
|
import Model exposing (Model, PeerData)
|
||||||
import Palette exposing (classes)
|
import Palette exposing (classes)
|
||||||
import Services.Model exposing (Model, ServiceInfo)
|
import Services.Model exposing (Service, 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
|
||||||
|
allBps = getBlueprintsToServices model.discoveredPeers
|
||||||
|
info = (Dict.values allBps) |> List.map (\(bp, servicesByPeers) -> {name = bp.name, author = "Fluence Labs", instanceNumber = List.length (servicesByPeers |> List.map(\(_, s) -> s) |> List.concat)})
|
||||||
servicesView =
|
servicesView =
|
||||||
List.map viewService model.services
|
List.map viewService info
|
||||||
in
|
in
|
||||||
Html.div [ classes "cf ph2-ns" ] servicesView
|
Html.div [ classes "cf ph2-ns" ] servicesView
|
||||||
|
|
||||||
@ -24,3 +29,26 @@ viewService service =
|
|||||||
, Html.div [ classes "w-100" ] [ instancesText service.instanceNumber ]
|
, Html.div [ classes "w-100" ] [ instancesText service.instanceNumber ]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- bpId peerId
|
||||||
|
getBlueprintsToServices : Dict String PeerData -> Dict String (Blueprint, (List (String, List Service)))
|
||||||
|
getBlueprintsToServices peerData =
|
||||||
|
let
|
||||||
|
peerDatas = Dict.toList peerData
|
||||||
|
allBlueprints = peerDatas |> List.map (\(_, pd) -> pd.blueprints |> List.map (\bp -> bp)) |> List.concat
|
||||||
|
bpsToServices = allBlueprints |> List.map (\bp -> (bp.id, (bp, getServicesByBlueprintId peerData bp.id))) |> Dict.fromList
|
||||||
|
in
|
||||||
|
bpsToServices
|
||||||
|
|
||||||
|
getServicesByBlueprintId : Dict String PeerData -> String -> List (String, List Service)
|
||||||
|
getServicesByBlueprintId peerData bpId =
|
||||||
|
let
|
||||||
|
list = Dict.toList peerData
|
||||||
|
found = list |> List.map (\(peer, pd) -> (peer, (filterServicesByBlueprintId bpId pd)))
|
||||||
|
filtered = found |> List.filter (\(_, services) -> not (List.isEmpty services))
|
||||||
|
in
|
||||||
|
filtered
|
||||||
|
|
||||||
|
filterServicesByBlueprintId : String -> PeerData -> List Service
|
||||||
|
filterServicesByBlueprintId blueprintId peerData =
|
||||||
|
peerData.services |> List.filter (\s -> s.blueprint_id == blueprintId)
|
||||||
|
@ -23,7 +23,6 @@ import Browser.Navigation as Nav
|
|||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Json.Decode exposing (decodeValue, list, string)
|
import Json.Decode exposing (decodeValue, list, string)
|
||||||
import Json.Encode exposing (Value)
|
import Json.Encode exposing (Value)
|
||||||
import List.Unique exposing (filterDuplicates)
|
|
||||||
import Maybe exposing (withDefault)
|
import Maybe exposing (withDefault)
|
||||||
import Model exposing (Model, PeerData, emptyPeerData)
|
import Model exposing (Model, PeerData, emptyPeerData)
|
||||||
import Msg exposing (..)
|
import Msg exposing (..)
|
||||||
@ -175,19 +174,6 @@ updateModel model peer identify services modules blueprints =
|
|||||||
in
|
in
|
||||||
{ model | discoveredPeers = updated }
|
{ model | discoveredPeers = updated }
|
||||||
|
|
||||||
getServicesByBlueprintId : Dict String PeerData -> String -> List (String, Service)
|
|
||||||
getServicesByBlueprintId peerData bpId =
|
|
||||||
let
|
|
||||||
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
|
|
||||||
|
|
||||||
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 : Dict String PeerData -> String -> List String
|
||||||
peersByModule peerData moduleId =
|
peersByModule peerData moduleId =
|
||||||
let
|
let
|
||||||
|
Loading…
x
Reference in New Issue
Block a user