2020-11-25 05:20:20 +03:00
|
|
|
module Services.View exposing (..)
|
|
|
|
|
2020-11-28 17:59:09 +03:00
|
|
|
import Blueprints.Model exposing (Blueprint)
|
|
|
|
import Dict exposing (Dict)
|
2020-11-25 05:20:20 +03:00
|
|
|
import Html exposing (Html)
|
2020-11-28 17:59:09 +03:00
|
|
|
import Model exposing (Model, PeerData)
|
2020-11-25 05:20:20 +03:00
|
|
|
import Palette exposing (classes)
|
2020-11-28 17:59:09 +03:00
|
|
|
import Services.Model exposing (Service, ServiceInfo)
|
2020-11-25 05:20:20 +03:00
|
|
|
import Utils.Utils exposing (instancesText)
|
|
|
|
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
view : Model -> Html msg
|
|
|
|
view model =
|
|
|
|
let
|
2020-11-28 17:59:09 +03:00
|
|
|
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)})
|
2020-11-25 19:51:53 +03:00
|
|
|
servicesView =
|
2020-11-28 17:59:09 +03:00
|
|
|
List.map viewService info
|
2020-11-25 05:20:20 +03:00
|
|
|
in
|
2020-11-25 19:51:53 +03:00
|
|
|
Html.div [ classes "cf ph2-ns" ] servicesView
|
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
|
2020-11-25 16:27:26 +03:00
|
|
|
viewService : ServiceInfo -> Html msg
|
2020-11-25 05:20:20 +03:00
|
|
|
viewService service =
|
2020-11-25 19:51:53 +03:00
|
|
|
Html.div [ classes "fl w-third-ns pa2" ]
|
|
|
|
[ Html.div [ classes "fl w-100 br2 ba solid ma2 pa3" ]
|
|
|
|
[ Html.div [ classes "w-100 mb2 b" ] [ Html.text service.name ]
|
|
|
|
, Html.div [ classes "w-100 mb4" ] [ Html.text ("By " ++ service.author) ]
|
|
|
|
, Html.div [ classes "w-100" ] [ instancesText service.instanceNumber ]
|
|
|
|
]
|
|
|
|
]
|
2020-11-28 17:59:09 +03:00
|
|
|
|
|
|
|
-- 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)
|