services displayed everywhere

This commit is contained in:
Pavel Murygin 2021-06-30 23:59:37 +03:00
parent 1c2d0859af
commit 09182b51eb
4 changed files with 56 additions and 28 deletions

View File

@ -10,6 +10,7 @@ import List.Unique exposing (..)
import Maybe.Extra as Maybe import Maybe.Extra as Maybe
import Msg exposing (Msg(..)) import Msg exposing (Msg(..))
import Palette exposing (classes, darkRed, redFont) import Palette exposing (classes, darkRed, redFont)
import Services.ServiceRow
import Services.ServicesTable import Services.ServicesTable
import Utils.Html exposing (..) import Utils.Html exposing (..)
@ -43,21 +44,7 @@ fromCache cache id =
Dict.get id cache.servicesByBlueprintId Dict.get id cache.servicesByBlueprintId
|> Maybe.withDefault Array.empty |> Maybe.withDefault Array.empty
|> Array.toList |> Array.toList
|> List.map |> Services.ServicesTable.fromCache cache
(\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 = res =
Maybe.map Maybe.map

View File

@ -2,9 +2,13 @@ module Pages.Hub exposing (Model, fromCache, init, view)
import Blueprints.BlueprintsList import Blueprints.BlueprintsList
import Cache import Cache
import Dict
import Html exposing (Html, a, div, span, text) import Html exposing (Html, a, div, span, text)
import Html.Attributes exposing (attribute) import Html.Attributes exposing (attribute)
import Maybe.Extra as Maybe
import Palette exposing (classes, redFont) import Palette exposing (classes, redFont)
import Services.ServiceRow
import Services.ServicesTable
@ -15,14 +19,10 @@ type alias FmModel =
{} {}
type alias ServicesModel =
{}
type alias Model = type alias Model =
{ featuredBlueprints : Blueprints.BlueprintsList.Model { featuredBlueprints : Blueprints.BlueprintsList.Model
, featuredModules : FmModel , featuredModules : FmModel
, services : ServicesModel , services : Services.ServicesTable.Model
} }
@ -30,7 +30,7 @@ init : Model
init = init =
{ featuredBlueprints = [] { featuredBlueprints = []
, featuredModules = {} , featuredModules = {}
, services = {} , services = []
} }
@ -38,7 +38,10 @@ fromCache : Cache.Model -> Model
fromCache cache = fromCache cache =
{ featuredBlueprints = Blueprints.BlueprintsList.fromCache cache { featuredBlueprints = Blueprints.BlueprintsList.fromCache cache
, featuredModules = {} , featuredModules = {}
, services = {} , services =
cache.servicesById
|> Dict.keys
|> Services.ServicesTable.fromCache cache
} }
@ -56,9 +59,9 @@ view model =
, div [ classes "pt4 f3 fw5 pb4" ] [ text "Featured Modules" ] , div [ classes "pt4 f3 fw5 pb4" ] [ text "Featured Modules" ]
--, Modules.View.view model --, Modules.View.view model
, div [ classes "pt4 f3 fw5 pb4" ] [ text "Services" ] , div [ classes "pt4 f3 fw5 pb4" ]
[ text "Services" ]
--, Tuple.second (Instances.View.view model (\_ -> True)) , Services.ServicesTable.view model.services
] ]

View File

@ -1,6 +1,7 @@
module Services.ServiceRow exposing (Model, view) module Services.ServiceRow exposing (Model, fromCache, view)
import Cache exposing (BlueprintId) import Cache exposing (BlueprintId, ServiceId)
import Dict exposing (Dict)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Palette exposing (classes, shortHashRaw) import Palette exposing (classes, shortHashRaw)
@ -19,6 +20,30 @@ type alias Model =
} }
fromCache : Cache.Model -> ServiceId -> Maybe Model
fromCache cache id =
let
srv =
Dict.get id cache.servicesById
bp =
srv |> Maybe.andThen (\x -> Dict.get x.blueprintId cache.blueprintsById)
res =
srv
|> Maybe.map
(\x ->
{ blueprintName = bp |> Maybe.map .name |> Maybe.withDefault ""
, blueprintId = bp |> Maybe.map .id |> Maybe.withDefault ""
, serviceId = id
, peerId = "peerId"
, ip = "id"
}
)
in
res
-- view -- view

View File

@ -1,8 +1,10 @@
module Services.ServicesTable exposing (Model, view) module Services.ServicesTable exposing (Model, fromCache, view)
import Cache exposing (ServiceId) import Cache exposing (ServiceId)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Maybe.Extra as Maybe
import Msg exposing (Msg(..))
import Palette exposing (classes) import Palette exposing (classes)
import Services.ServiceRow import Services.ServiceRow
@ -15,6 +17,17 @@ type alias Model =
List Services.ServiceRow.Model List Services.ServiceRow.Model
fromCache : Cache.Model -> List ServiceId -> Model
fromCache cache services =
services
|> List.map (Services.ServiceRow.fromCache cache)
|> Maybe.values
-- view
view : Model -> Html msg view : Model -> Html msg
view model = view model =
div [ classes "pa1 bg-white br3 overflow-auto" ] div [ classes "pa1 bg-white br3 overflow-auto" ]