diff --git a/src/Pages/BlueprintPage.elm b/src/Pages/BlueprintPage.elm index 26439c7..364ad7a 100644 --- a/src/Pages/BlueprintPage.elm +++ b/src/Pages/BlueprintPage.elm @@ -1,16 +1,16 @@ module Pages.BlueprintPage exposing (Model, fromCache, view) +import Array exposing (Array) import Cache exposing (BlueprintId) import Dict exposing (Dict) -import Html exposing (Html, a, article, div, img, span, strong, text) -import Html.Attributes exposing (attribute) +import Html exposing (Html, article, div, span, text) import Html.Events exposing (onClick) import Info exposing (..) import List.Unique exposing (..) -import Modules.Model exposing (Module) +import Maybe.Extra as Maybe import Msg exposing (Msg(..)) import Palette exposing (classes, darkRed, redFont) -import Service.Model exposing (Interface) +import Services.ServicesTable import Utils.Html exposing (..) @@ -28,6 +28,7 @@ type alias Model = -- , blueprint : Blueprint , moduleNames : List String + , services : Services.ServicesTable.Model , openedModule : Maybe String } @@ -38,6 +39,26 @@ fromCache cache id = bp = Dict.get id cache.blueprintsById + services = + Dict.get id cache.servicesByBlueprintId + |> Maybe.withDefault Array.empty + |> Array.toList + |> List.map + (\mbSrvId -> + Dict.get mbSrvId cache.servicesById + |> Maybe.map + (\srv -> + { -- name = "srv.name" + blueprintName = bp |> Maybe.map .name |> Maybe.withDefault "" + , blueprintId = id + , serviceId = srv.id + , peerId = "peerId" + , ip = "id" + } + ) + ) + |> Maybe.values + res = Maybe.map (\x -> @@ -50,6 +71,7 @@ fromCache cache id = -- , blueprint = "Blueprint" , moduleNames = [] + , services = services , openedModule = Nothing } ) @@ -64,6 +86,12 @@ fromCache cache id = view : Model -> Html Msg view model = + let + instancesCount = + model.services + |> List.length + |> String.fromInt + in div [ classes "fl w-100" ] [ div [ classes "fl w-100 pb4 pt4" ] [ div [ redFont, classes "f1 fw4 pt3 pb2" ] [ text ("Blueprint: " ++ model.name) ] @@ -92,13 +120,10 @@ view model = ] , div [ classes "pt4 fw5 f3 pb4" ] [ text - ("Services (" - ++ -- String.fromInt instanceNum ++ - ")" - ) + ("Services (" ++ instancesCount ++ ")") ] , div [ classes "fl w-100 mt2 mb4 bg-white br3" ] - [--instanceView + [ Services.ServicesTable.view model.services ] ] diff --git a/src/Services/ServiceRow.elm b/src/Services/ServiceRow.elm new file mode 100644 index 0000000..a6ed8cf --- /dev/null +++ b/src/Services/ServiceRow.elm @@ -0,0 +1,33 @@ +module Services.ServiceRow exposing (Model, view) + +import Cache exposing (BlueprintId) +import Html exposing (..) +import Html.Attributes exposing (..) +import Palette exposing (classes, shortHashRaw) + + + +-- module + + +type alias Model = + { blueprintName : String + , blueprintId : BlueprintId + , serviceId : String + , peerId : String + , ip : String + } + + + +-- view + + +view : Model -> Html msg +view model = + tr [ classes "table-red-row" ] + [ td [ classes "ph3" ] [ p [ classes "ws-normal" ] [ a [ attribute "href" ("/blueprint/" ++ model.blueprintId), classes "black" ] [ text model.blueprintName ] ] ] + , td [ classes "ph3" ] [ p [ classes "ws-normal" ] [ text model.serviceId ] ] + , td [ classes "ph3 dn dtc-ns" ] [ p [ classes "ws-normal" ] [ text (shortHashRaw 8 model.peerId) ] ] + , td [ classes "ph3 dn dtc-ns" ] [ p [ classes "ws-normal" ] [ text model.ip ] ] + ] diff --git a/src/Services/ServicesTable.elm b/src/Services/ServicesTable.elm new file mode 100644 index 0000000..bb5ba75 --- /dev/null +++ b/src/Services/ServicesTable.elm @@ -0,0 +1,34 @@ +module Services.ServicesTable exposing (Model, view) + +import Cache exposing (ServiceId) +import Html exposing (..) +import Html.Attributes exposing (..) +import Palette exposing (classes) +import Services.ServiceRow + + + +-- model + + +type alias Model = + List Services.ServiceRow.Model + + +view : Model -> Html msg +view model = + div [ classes "pa1 bg-white br3 overflow-auto" ] + [ div [ classes "mw8-ns pa2 " ] + [ table [ classes "f6 w-100 center ws-normal-ns", attribute "cellspacing" "0" ] + [ thead [] + [ tr [ classes "" ] + [ th [ classes "fw5 tl pa3 gray-font" ] [ text "BLUEPRINT" ] + , th [ classes "fw5 tl pa3 gray-font" ] [ text "SERVICE ID" ] + , th [ classes "fw5 tl pa3 gray-font dn dtc-ns" ] [ text "NODE" ] + , th [ classes "fw5 tl pa3 gray-font dn dtc-ns" ] [ text "MULTIADDR" ] + ] + ] + , tbody [ classes "lucida" ] (model |> List.map Services.ServiceRow.view) + ] + ] + ]