73 lines
2.4 KiB
Elm
Raw Normal View History

module Services.View exposing (..)
2020-11-28 17:59:09 +03:00
import Blueprints.Model exposing (Blueprint)
import Dict exposing (Dict)
2020-11-30 14:31:03 +03:00
import Html exposing (Html, div, text)
2020-11-30 19:56:11 +03:00
import Html.Attributes exposing (attribute)
2020-11-28 17:59:09 +03:00
import Model exposing (Model, PeerData)
import Palette exposing (classes)
2020-11-28 17:59:09 +03:00
import Services.Model exposing (Service, ServiceInfo)
import Utils.Utils exposing (instancesText)
2020-11-25 19:51:53 +03:00
view : Model -> Html msg
view model =
let
2020-11-30 14:31:03 +03:00
allBps =
2020-12-01 14:51:12 +03:00
getBlueprintsToServices model.blueprints model.discoveredPeers
2020-11-30 14:31:03 +03:00
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
in
2020-11-30 19:56:11 +03:00
div [ classes "cf ph1-ns" ] servicesView
2020-11-25 19:51:53 +03:00
2020-11-25 16:27:26 +03:00
viewService : ServiceInfo -> Html msg
viewService service =
2020-11-30 14:31:03 +03:00
div [ classes "fl w-third-ns pa2" ]
2020-11-30 19:56:11 +03:00
[ div [ attribute "href" "#", classes "fl w-100 link dim black mw5 dt hide-child ba b-black pa4 br2 solid" ]
2020-11-30 14:31:03 +03:00
[ div [ classes "w-100 mb2 b" ] [ text service.name ]
, div [ classes "w-100 mb4" ] [ text ("By " ++ service.author) ]
, div [ classes "w-100" ] [ instancesText service.instanceNumber ]
2020-11-25 19:51:53 +03:00
]
]
2020-11-28 17:59:09 +03:00
2020-11-30 14:31:03 +03:00
2020-11-28 17:59:09 +03:00
-- bpId peerId
2020-11-30 14:31:03 +03:00
2020-12-01 14:51:12 +03:00
getBlueprintsToServices : Dict String Blueprint -> Dict String PeerData -> Dict String ( Blueprint, List ( String, List Service ) )
getBlueprintsToServices blueprints peerData =
2020-11-28 17:59:09 +03:00
let
2020-11-30 14:31:03 +03:00
allBlueprints =
2020-12-01 14:51:12 +03:00
Dict.values blueprints
2020-11-28 17:59:09 +03:00
2020-11-30 14:31:03 +03:00
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 )
2020-11-28 17:59:09 +03:00
getServicesByBlueprintId peerData bpId =
let
2020-11-30 14:31:03 +03:00
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
2020-11-28 17:59:09 +03:00
filterServicesByBlueprintId : String -> PeerData -> List Service
filterServicesByBlueprintId blueprintId peerData =
peerData.services |> List.filter (\s -> s.blueprint_id == blueprintId)