Moar blueprints

This commit is contained in:
Pavel Murygin 2021-06-30 20:45:46 +03:00
parent 1f2357a7b2
commit a9cc00525f
6 changed files with 137 additions and 180 deletions

View File

@ -1,17 +0,0 @@
module BlueprintPage.Model exposing (..)
import Blueprints.Model exposing (Blueprint)
import Modules.Model exposing (Module)
type alias BlueprintViewInfo =
{ name : String
, id : String
, author : String
, authorPeerId : String
, description : String
, website : String
, blueprint : Blueprint
, modules : List Module
, openedModule : Maybe String
}

View File

@ -1,159 +0,0 @@
module BlueprintPage.View exposing (..)
import BlueprintPage.Model exposing (BlueprintViewInfo)
import Blueprints.Model exposing (Blueprint)
import Components.Spinner
import Dict exposing (Dict)
import Html exposing (Html, a, article, div, img, span, strong, text)
import Html.Attributes exposing (attribute)
import Html.Events exposing (onClick)
import Info exposing (getBlueprintDescription)
import Instances.View
import List.Unique exposing (..)
import Model exposing (Model)
import Modules.Model exposing (Module)
import Msg exposing (Msg(..))
import Palette exposing (classes, darkRed, redFont)
import Service.Model exposing (Interface)
view : Model -> String -> Html Msg
view model id =
let
blueprintInfo =
blueprintToInfo model id
in
case blueprintInfo of
Just bi ->
let
( instanceNum, instanceView ) =
Instances.View.view model (\service -> service.blueprint_id == id)
in
div [ classes "fl w-100" ]
[ div [ classes "fl w-100 pb4 pt4" ]
[ div [ redFont, classes "f1 fw4 pt3 pb2" ] [ text ("Blueprint: " ++ bi.name) ]
, span [ classes "fl w-100", darkRed ] [ text ("ID: " ++ bi.id) ]
]
, div [ classes "fl w-100 bg-white mt2 ph4 pt3 mb5 pb3 br3" ] [ viewInfo bi ]
, div [ classes "pt4 fw5 f3 pb4" ] [ text ("Services (" ++ String.fromInt instanceNum ++ ")") ]
, div [ classes "fl w-100 mt2 mb4 bg-white br3" ]
[ instanceView ]
]
Nothing ->
div [ classes "cf ph2-ns mt6" ]
Components.Spinner.view
blueprintToInfo : Model -> String -> Maybe BlueprintViewInfo
blueprintToInfo model id =
case Dict.get id model.blueprints of
Just bp ->
let
hashes =
bp.dependencies
|> List.map (\d -> String.split ":" d)
|> List.map (\p -> Maybe.withDefault [] (List.tail p))
|> List.map (\p -> Maybe.withDefault "" (List.head p))
modules =
bp.dependencies |> List.map (\d -> Dict.get d model.modules) |> List.filterMap identity
modulesByHash =
hashes |> List.map (\d -> Dict.get d model.modulesByHash) |> List.filterMap identity
m =
List.Unique.filterDuplicates (List.concat [ modules, modulesByHash ])
in
Just
{ name = bp.name
, id = id
, author = "Fluence Labs"
, authorPeerId = "fluence_labs_peer_id"
, description = getBlueprintDescription bp.name
, website = "https://github.com/fluencelabs/"
, blueprint = bp
, modules = m
, openedModule = model.toggledInterface
}
Nothing ->
Nothing
-- TODO:: do this for all possible places which could be empty
textOrBsp : String -> String
textOrBsp text =
if text == "" then
String.fromChar (Char.fromCode 0xA0)
else
text
viewInfo : BlueprintViewInfo -> Html Msg
viewInfo blueprintInfo =
let
checkToggle =
\id -> blueprintInfo.openedModule |> Maybe.map (\om -> om == id) |> Maybe.withDefault False
in
article [ classes "cf" ]
[ div [ classes "fl w-20-ns gray-font mv3" ] [ text "AUTHOR" ]
, div [ classes "fl w-80-ns mv3 lucida" ]
[ span [ classes "fl black b" ] [ text (textOrBsp blueprintInfo.author) ] ]
, div [ classes "fl w-20-ns gray-font mv3" ] [ text "DESCRIPTION" ]
, div [ classes "fl w-80-ns mv3 cf" ]
[ span [ classes "fl black lucida pv1" ] [ text (textOrBsp blueprintInfo.description) ] ]
, div [ classes "fl w-20-ns gray-font mv3" ] [ text "MODULES" ]
, div [ classes "fl w-80-ns mv3" ]
[ text
(textOrBsp
(String.join ", " (blueprintInfo.modules |> List.map (\m -> m.name)))
)
]
--(blueprintInfo.modules
-- |> List.map (\m -> viewToggledInterface (checkToggle m.name) m.name)
--)
]
alwaysPreventDefault : msg -> { message : msg, stopPropagation : Bool, preventDefault : Bool }
alwaysPreventDefault msg =
{ message = msg, stopPropagation = True, preventDefault = True }
--viewToggledInterface : Bool -> String -> Interface -> Html Msg
viewToggledInterface : Bool -> String -> Html Msg
viewToggledInterface isOpen name =
let
interfaceViewEl =
if isOpen then
--[ div [ classes "fl w-100 ph3" ] (interfaceView interface) ]
[]
else
[]
in
div []
([ div [ classes "fl w-100 light-shadow bg-near-white pa2 mv2 pointer", onClick (ToggleInterface name) ]
[ span [ classes "fl mh2 pv1 tldib v-mid dib v-mid" ] [ text name ]
--, a [ attribute "href" ("/module/" ++ name), classes "fl dib v-mid mt1" ] [ img [ attribute "src" "/images/link.svg" ] [] ]
--, div [ classes "fl o-40 f4 fr pr3 dib v-mid" ]
-- [ if isOpen then
-- text "▲"
--
-- else
-- text "▼"
-- ]
]
]
--++ interfaceViewEl
)

View File

@ -22,6 +22,7 @@ import Cache
import Dict exposing (Dict)
import Modules.Model exposing (Module)
import Nodes.Model exposing (Identify, emptyIdentify)
import Pages.BlueprintPage
import Pages.Hub
import Service.Model exposing (Service)
import Url
@ -35,7 +36,8 @@ type Route
type alias PageModel =
{ hub : Pages.Hub.Model }
{ hub : Pages.Hub.Model
}
type alias PeerData =

114
src/Pages/BlueprintPage.elm Normal file
View File

@ -0,0 +1,114 @@
module Pages.BlueprintPage exposing (Model, fromCache, view)
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.Events exposing (onClick)
import Info exposing (..)
import List.Unique exposing (..)
import Modules.Model exposing (Module)
import Msg exposing (Msg(..))
import Palette exposing (classes, darkRed, redFont)
import Service.Model exposing (Interface)
import Utils.Html exposing (..)
-- model
type alias Model =
{ name : String
, id : String
, author : String
, authorPeerId : String
, description : String
, website : String
-- , blueprint : Blueprint
, moduleNames : List String
, openedModule : Maybe String
}
fromCache : Cache.Model -> BlueprintId -> Maybe Model
fromCache cache id =
let
bp =
Dict.get id cache.blueprintsById
res =
Maybe.map
(\x ->
{ name = x.name
, id = x.id
, author = "Fluence Labs"
, authorPeerId = "fluence_labs_peer_id"
, description = getBlueprintDescription x.id
, website = "https://github.com/fluencelabs/"
-- , blueprint = "Blueprint"
, moduleNames = []
, openedModule = Nothing
}
)
bp
in
res
-- view
view : Model -> Html Msg
view model =
article [ classes "cf" ]
[ div [ classes "fl w-20-ns gray-font mv3" ] [ text "AUTHOR" ]
, div [ classes "fl w-80-ns mv3 lucida" ]
[ span [ classes "fl black b" ] [ text (textOrBsp model.author) ] ]
, div [ classes "fl w-20-ns gray-font mv3" ] [ text "DESCRIPTION" ]
, div [ classes "fl w-80-ns mv3 cf" ]
[ span [ classes "fl black lucida pv1" ] [ text (textOrBsp model.description) ] ]
, div [ classes "fl w-20-ns gray-font mv3" ] [ text "MODULES" ]
, div [ classes "fl w-80-ns mv3" ]
[ text
(textOrBsp
(String.join ", " model.moduleNames)
)
]
--(blueprintInfo.modules
-- |> List.map (\m -> viewToggledInterface (checkToggle m.name) m.name)
--)
]
viewToggledInterface : Bool -> String -> Html Msg
viewToggledInterface isOpen name =
let
interfaceViewEl =
if isOpen then
--[ div [ classes "fl w-100 ph3" ] (interfaceView interface) ]
[]
else
[]
in
div []
([ div [ classes "fl w-100 light-shadow bg-near-white pa2 mv2 pointer", onClick (ToggleInterface name) ]
[ span [ classes "fl mh2 pv1 tldib v-mid dib v-mid" ] [ text name ]
--, a [ attribute "href" ("/module/" ++ name), classes "fl dib v-mid mt1" ] [ img [ attribute "src" "/images/link.svg" ] [] ]
--, div [ classes "fl o-40 f4 fr pr3 dib v-mid" ]
-- [ if isOpen then
-- text "▲"
--
-- else
-- text "▼"
-- ]
]
]
--++ interfaceViewEl
)

View File

@ -1,12 +1,13 @@
module Route exposing (..)
import BlueprintPage.View as BlueprintPage
import Components.Spinner
import Dict exposing (Dict)
import Html exposing (Html, text)
import Html exposing (Html, div, text)
import Model exposing (Model, Route(..))
import ModulePage.View as ModulePage
import Msg exposing (Msg)
import NodePage.View as NodePage
import Pages.BlueprintPage
import Pages.Hub as HubPage
import Port exposing (getAll)
import Url.Parser exposing ((</>), Parser, map, oneOf, s, string)
@ -51,7 +52,13 @@ routeView model route =
text peer
Blueprint id ->
BlueprintPage.view model id
case Pages.BlueprintPage.fromCache model.cache id of
Just m ->
Pages.BlueprintPage.view m
Nothing ->
div []
Components.Spinner.view
Module moduleName ->
ModulePage.view model moduleName

10
src/Utils/Html.elm Normal file
View File

@ -0,0 +1,10 @@
module Utils.Html exposing (..)
textOrBsp : String -> String
textOrBsp text =
if text == "" then
String.fromChar (Char.fromCode 0xA0)
else
text