get list of instance info

This commit is contained in:
DieMyst 2020-11-30 15:09:25 +03:00
parent 47a8de2482
commit a9c739c0b1

View File

@ -1,21 +1,40 @@
module Instances.View exposing (..)
import Dict exposing (Dict)
import Html exposing (Html, div, table, tbody, td, text, th, thead, tr)
import Html.Attributes exposing (attribute)
import Instances.Model exposing (Instance)
import Model exposing (Model)
import Nodes.Model exposing (Identify)
import Palette exposing (classes)
import Services.Model exposing (Service)
toInstance : String -> Identify -> Dict String String -> Service -> Instance
toInstance peerId identify blueprints service =
let
name =
blueprints |> Dict.get service.blueprint_id |> Maybe.withDefault "unknown"
ip =
List.head identify.external_addresses |> Maybe.withDefault "unknown"
in
{ name = name, instance = service.service_id, peerId = peerId, ip = ip }
view : Model -> Html msg
view model =
let
bps =
Dict.values model.discoveredPeers |> List.map (\data -> data.blueprints |> List.map (\b -> ( b.id, b.name )))
bpsDict =
List.concat bps |> Dict.fromList
instances =
[ { name = "SQLite", instance = "efrer3434g", peerId = "kljn35kfj4n5kjgn4k5jgn45kj", ip = "123.123.123.123" }
, { name = "SQLite", instance = "efrer3434g", peerId = "kljn35kfj4n5kjgn4k5jgn45kj", ip = "123.123.123.123" }
, { name = "SQLite", instance = "efrer3434g", peerId = "kljn35kfj4n5kjgn4k5jgn45kj", ip = "123.123.123.123" }
, { name = "SQLite", instance = "efrer3434g", peerId = "kljn35kfj4n5kjgn4k5jgn45kj", ip = "123.123.123.123" }
]
Dict.toList model.discoveredPeers
|> List.map (\( peer, data ) -> data.services
|> List.map (toInstance peer data.identify bpsDict))
|> List.concat
in
viewTable instances