mirror of
https://github.com/fluencelabs/dashboard
synced 2025-05-28 15:11:30 +00:00
Storing modules
This commit is contained in:
parent
df2a4e119f
commit
8c0cf877b2
@ -12,11 +12,9 @@ type alias ModuleConfigDto =
|
||||
{ name : String
|
||||
}
|
||||
|
||||
|
||||
type alias ModuleDto =
|
||||
{ name : String
|
||||
, hash : String
|
||||
, config : ModuleConfigDto
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +33,7 @@ type alias PeerDto =
|
||||
{ peerId : String
|
||||
, identify : Maybe IdentifyDto
|
||||
, services : Maybe (List ServiceDto)
|
||||
|
||||
--, modules : Maybe (List ModuleDto)
|
||||
, modules : Maybe (List ModuleDto)
|
||||
, blueprints : Maybe (List BlueprintDto)
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
module Cache exposing (..)
|
||||
|
||||
import AquaPorts.CollectPeerInfo exposing (BlueprintDto, PeerDto, ServiceDto)
|
||||
import AquaPorts.CollectPeerInfo exposing (BlueprintDto, ModuleDto, PeerDto, ServiceDto)
|
||||
import AquaPorts.CollectServiceInterface exposing (ServiceInterfaceDto)
|
||||
import Array exposing (Array)
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Dict exposing (Dict)
|
||||
import Dict exposing (Dict, values)
|
||||
import Dict.Extra as Dict
|
||||
import Html exposing (b)
|
||||
import Set exposing (Set)
|
||||
|
||||
|
||||
|
||||
@ -33,17 +35,32 @@ extractHash str =
|
||||
|> Maybe.withDefault ""
|
||||
|
||||
|
||||
type alias Module =
|
||||
{ hash : Hash
|
||||
, name : String
|
||||
, interfaces : Maybe (List Never)
|
||||
}
|
||||
|
||||
|
||||
moduleFromDto : ModuleDto -> Module
|
||||
moduleFromDto dto =
|
||||
{ name = dto.name
|
||||
, hash = dto.hash
|
||||
, interfaces = Nothing
|
||||
}
|
||||
|
||||
|
||||
type alias Blueprint =
|
||||
{ id : BlueprintId
|
||||
, name : String
|
||||
, dependencies : Array Hash
|
||||
, dependencies : Set Hash
|
||||
}
|
||||
|
||||
|
||||
blueprintFromDto : BlueprintDto -> Blueprint
|
||||
blueprintFromDto bp =
|
||||
{ id = bp.id
|
||||
, dependencies = bp.dependencies |> List.map extractHash |> Array.fromList
|
||||
, dependencies = bp.dependencies |> List.map extractHash |> Set.fromList
|
||||
, name = bp.name
|
||||
}
|
||||
|
||||
@ -87,6 +104,8 @@ firstExternalAddress node =
|
||||
type alias Model =
|
||||
{ blueprintsById : Dict BlueprintId Blueprint
|
||||
, servicesById : Dict ServiceId Service
|
||||
, modulesByHash : Dict Hash Module
|
||||
, blueprintsByModuleHash : Dict Hash (Array BlueprintId)
|
||||
, servicesByBlueprintId : Dict BlueprintId (Array ServiceId)
|
||||
, nodeByServiceId : Dict ServiceId PeerId
|
||||
, nodeByBlueprintId : Dict BlueprintId PeerId
|
||||
@ -98,6 +117,8 @@ init : Model
|
||||
init =
|
||||
{ blueprintsById = Dict.empty
|
||||
, servicesById = Dict.empty
|
||||
, modulesByHash = Dict.empty
|
||||
, blueprintsByModuleHash = Dict.empty
|
||||
, servicesByBlueprintId = Dict.empty
|
||||
, nodeByServiceId = Dict.empty
|
||||
, nodeByBlueprintId = Dict.empty
|
||||
@ -121,7 +142,7 @@ type Msg
|
||||
update : Model -> Msg -> Model
|
||||
update model msg =
|
||||
case msg of
|
||||
CollectPeerInfo { peerId, blueprints, services, identify } ->
|
||||
CollectPeerInfo { peerId, blueprints, services, identify, modules } ->
|
||||
let
|
||||
newBlueprints =
|
||||
blueprints |> Maybe.withDefault [] |> List.map blueprintFromDto |> Dict.fromListBy (\x -> x.id)
|
||||
@ -129,6 +150,9 @@ update model msg =
|
||||
newServices =
|
||||
services |> Maybe.withDefault [] |> List.map serviceFromDto |> Dict.fromListBy (\x -> x.id)
|
||||
|
||||
newModules =
|
||||
modules |> Maybe.withDefault [] |> List.map moduleFromDto |> Dict.fromListBy (\x -> x.hash)
|
||||
|
||||
resultBlueprints =
|
||||
Dict.union newBlueprints model.blueprintsById
|
||||
|
||||
@ -153,11 +177,28 @@ update model msg =
|
||||
, services = Dict.keys newServices |> Array.fromList
|
||||
, blueprints = Dict.keys newBlueprints |> Array.fromList
|
||||
}
|
||||
|
||||
bpMyModuleHash =
|
||||
Dict.values resultBlueprints
|
||||
|> List.foldl
|
||||
(\bp ->
|
||||
\acc ->
|
||||
bp.dependencies
|
||||
|> Set.foldl
|
||||
(\hash ->
|
||||
Dict.insertDedupe (\l1 -> \l2 -> l1 ++ l2) hash [ bp.id ]
|
||||
)
|
||||
acc
|
||||
)
|
||||
Dict.empty
|
||||
|> Dict.map (\k -> \v -> Array.fromList v)
|
||||
in
|
||||
{ model
|
||||
| blueprintsById = resultBlueprints
|
||||
, servicesById = resultServices
|
||||
, servicesByBlueprintId = resultServicesByBlueprintId
|
||||
, modulesByHash = Dict.union model.modulesByHash newModules
|
||||
, blueprintsByModuleHash = bpMyModuleHash
|
||||
, nodes = Dict.insert newNode.peerId newNode model.nodes
|
||||
, nodeByServiceId = Dict.union model.nodeByServiceId (Dict.map (\x -> \_ -> peerId) newServices)
|
||||
, nodeByBlueprintId = Dict.union model.nodeByBlueprintId (Dict.map (\x -> \_ -> peerId) newBlueprints)
|
||||
|
40
src/Modules/ModuleTile.elm
Normal file
40
src/Modules/ModuleTile.elm
Normal file
@ -0,0 +1,40 @@
|
||||
module Modules.ModuleTile exposing (Model, view)
|
||||
|
||||
import Html exposing (Html, a, div, p, text)
|
||||
import Html.Attributes exposing (attribute)
|
||||
import Palette exposing (classes)
|
||||
|
||||
|
||||
|
||||
-- model
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ hash : String
|
||||
, name : String
|
||||
, numberOfUsages : Int
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- view
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
view model =
|
||||
let
|
||||
usages =
|
||||
[ text <| "in " ++ String.fromInt model.numberOfUsages ++ " blueprints" ]
|
||||
in
|
||||
div [ classes "fl w-100 w-third-ns pr3" ]
|
||||
[ a
|
||||
[ attribute "href" ("/module/" ++ model.name)
|
||||
, classes "fl w-100 bg-white black mw6 mr2 mb3 hide-child pa2 element-box ba b--white pl3"
|
||||
]
|
||||
[ p [ classes "tl di" ]
|
||||
[ div [ classes "fl b w-100 mb1 fw5 overflow-hidden" ]
|
||||
[ text model.name ]
|
||||
, div [ classes "fl w-100 mt1 lucida gray-font2" ] usages
|
||||
]
|
||||
]
|
||||
]
|
52
src/Modules/ModulesList.elm
Normal file
52
src/Modules/ModulesList.elm
Normal file
@ -0,0 +1,52 @@
|
||||
module Modules.ModulesList exposing (..)
|
||||
|
||||
import Array exposing (Array)
|
||||
import Cache
|
||||
import Components.Spinner
|
||||
import Dict
|
||||
import Html exposing (Html, div)
|
||||
import Modules.ModuleTile
|
||||
import Palette exposing (classes)
|
||||
import Set
|
||||
|
||||
|
||||
|
||||
-- model
|
||||
|
||||
|
||||
type alias Model =
|
||||
List Modules.ModuleTile.Model
|
||||
|
||||
|
||||
fromCache : Cache.Model -> Model
|
||||
fromCache cache =
|
||||
let
|
||||
numberOfUsages id =
|
||||
Dict.get id cache.blueprintsByModuleHash |> Maybe.withDefault Array.empty |> Array.length
|
||||
in
|
||||
cache.modulesByHash
|
||||
|> Dict.values
|
||||
|> List.map
|
||||
(\x ->
|
||||
{ hash = x.hash
|
||||
, name = x.name
|
||||
, numberOfUsages = numberOfUsages x.hash
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
-- view
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
view model =
|
||||
let
|
||||
finalView =
|
||||
if List.isEmpty model then
|
||||
Components.Spinner.view
|
||||
|
||||
else
|
||||
List.map Modules.ModuleTile.view model
|
||||
in
|
||||
div [ classes "cf" ] finalView
|
@ -6,6 +6,7 @@ import Dict
|
||||
import Html exposing (Html, a, div, span, text)
|
||||
import Html.Attributes exposing (attribute)
|
||||
import Maybe.Extra as Maybe
|
||||
import Modules.ModulesList
|
||||
import Palette exposing (classes, redFont)
|
||||
import Services.ServiceRow
|
||||
import Services.ServicesTable
|
||||
@ -21,7 +22,7 @@ type alias FmModel =
|
||||
|
||||
type alias Model =
|
||||
{ featuredBlueprints : Blueprints.BlueprintsList.Model
|
||||
, featuredModules : FmModel
|
||||
, featuredModules : Modules.ModulesList.Model
|
||||
, services : Services.ServicesTable.Model
|
||||
}
|
||||
|
||||
@ -29,7 +30,7 @@ type alias Model =
|
||||
init : Model
|
||||
init =
|
||||
{ featuredBlueprints = []
|
||||
, featuredModules = {}
|
||||
, featuredModules = []
|
||||
, services = []
|
||||
}
|
||||
|
||||
@ -37,7 +38,7 @@ init =
|
||||
fromCache : Cache.Model -> Model
|
||||
fromCache cache =
|
||||
{ featuredBlueprints = Blueprints.BlueprintsList.fromCache cache
|
||||
, featuredModules = {}
|
||||
, featuredModules = Modules.ModulesList.fromCache cache
|
||||
, services =
|
||||
cache.servicesById
|
||||
|> Dict.keys
|
||||
@ -57,8 +58,7 @@ view model =
|
||||
, div [ classes "pt4 f3 fw5 pb4" ] [ text "Featured Service Blueprints" ]
|
||||
, Blueprints.BlueprintsList.view model.featuredBlueprints
|
||||
, div [ classes "pt4 f3 fw5 pb4" ] [ text "Featured Modules" ]
|
||||
|
||||
--, Modules.View.view model
|
||||
, Modules.ModulesList.view model.featuredModules
|
||||
, div [ classes "pt4 f3 fw5 pb4" ]
|
||||
[ text "Services" ]
|
||||
, Services.ServicesTable.view model.services
|
||||
|
29
src/Pages/ModulePage.elm
Normal file
29
src/Pages/ModulePage.elm
Normal file
@ -0,0 +1,29 @@
|
||||
module Pages.ModulePage exposing (Model, view)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Html exposing (Html, a, article, div, span, text)
|
||||
import Html.Attributes exposing (attribute, property)
|
||||
import Palette exposing (classes, redFont)
|
||||
|
||||
|
||||
|
||||
-- model
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ name : String
|
||||
, id : String
|
||||
, author : String
|
||||
, authorPeerId : String
|
||||
, description : String
|
||||
, website : String
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- view
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
view model =
|
||||
div [] []
|
Loading…
x
Reference in New Issue
Block a user