2020-12-01 17:47:52 +03:00
|
|
|
module Blueprints.View exposing (..)
|
2020-11-25 05:20:20 +03:00
|
|
|
|
2020-12-01 17:47:52 +03:00
|
|
|
import Blueprints.Model exposing (Blueprint, BlueprintInfo)
|
2020-11-28 17:59:09 +03:00
|
|
|
import Dict exposing (Dict)
|
2020-12-03 13:02:23 +03:00
|
|
|
import Html exposing (Html, a, div, span, 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)
|
2020-11-25 05:20:20 +03:00
|
|
|
import Palette exposing (classes)
|
2020-12-01 17:47:52 +03:00
|
|
|
import Service.Model exposing (Service)
|
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-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 =
|
2020-12-02 12:10:59 +03:00
|
|
|
Dict.values allBps
|
|
|
|
|> List.map
|
|
|
|
(\( bp, servicesByPeers ) ->
|
|
|
|
{ name = bp.name
|
|
|
|
, id = bp.id
|
|
|
|
, author = "Fluence Labs"
|
|
|
|
, instanceNumber = List.length (servicesByPeers |> List.map (\( _, s ) -> s) |> List.concat)
|
|
|
|
}
|
|
|
|
)
|
2020-11-30 14:31:03 +03:00
|
|
|
|
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-12-03 11:32:26 +03:00
|
|
|
div [ classes "cf" ] servicesView
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
|
2020-12-01 17:47:52 +03:00
|
|
|
viewService : BlueprintInfo -> Html msg
|
|
|
|
viewService blueprint =
|
2020-12-03 13:02:23 +03:00
|
|
|
div [ classes "fl w-third-ns pr3 lucida" ]
|
2020-12-03 15:45:37 +03:00
|
|
|
[ a [ attribute "href" ("/blueprint/" ++ blueprint.id), classes "fl w-100 bg-white black mw6 mr3 mb3 ph4 hide-child pa2 br3 element-box ba b--white bw1 no-underline" ]
|
2020-12-03 13:02:23 +03:00
|
|
|
[ div [ classes "w-100 mb3 pt1 b" ] [ text blueprint.name ]
|
|
|
|
, div [ classes "w-100 mb4" ] [ text "By ", span [classes "b"] [text blueprint.author] ]
|
|
|
|
, div [ classes "w-100 mt1" ] [ instancesText blueprint.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)
|