From a9cc00525f084b99f6dd412baf3eb293f9ba6b16 Mon Sep 17 00:00:00 2001 From: Pavel Murygin Date: Wed, 30 Jun 2021 20:45:46 +0300 Subject: [PATCH] Moar blueprints --- src/BlueprintPage/Model.elm | 17 ---- src/BlueprintPage/View.elm | 159 ------------------------------------ src/Model.elm | 4 +- src/Pages/BlueprintPage.elm | 114 ++++++++++++++++++++++++++ src/Route.elm | 13 ++- src/Utils/Html.elm | 10 +++ 6 files changed, 137 insertions(+), 180 deletions(-) delete mode 100644 src/BlueprintPage/Model.elm delete mode 100644 src/BlueprintPage/View.elm create mode 100644 src/Pages/BlueprintPage.elm create mode 100644 src/Utils/Html.elm diff --git a/src/BlueprintPage/Model.elm b/src/BlueprintPage/Model.elm deleted file mode 100644 index ed39587..0000000 --- a/src/BlueprintPage/Model.elm +++ /dev/null @@ -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 - } diff --git a/src/BlueprintPage/View.elm b/src/BlueprintPage/View.elm deleted file mode 100644 index 17041e0..0000000 --- a/src/BlueprintPage/View.elm +++ /dev/null @@ -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 - ) diff --git a/src/Model.elm b/src/Model.elm index 6d686b3..0fa8fc5 100644 --- a/src/Model.elm +++ b/src/Model.elm @@ -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 = diff --git a/src/Pages/BlueprintPage.elm b/src/Pages/BlueprintPage.elm new file mode 100644 index 0000000..7755adc --- /dev/null +++ b/src/Pages/BlueprintPage.elm @@ -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 + ) diff --git a/src/Route.elm b/src/Route.elm index 96b87a6..c95ebda 100644 --- a/src/Route.elm +++ b/src/Route.elm @@ -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 diff --git a/src/Utils/Html.elm b/src/Utils/Html.elm new file mode 100644 index 0000000..8ab006a --- /dev/null +++ b/src/Utils/Html.elm @@ -0,0 +1,10 @@ +module Utils.Html exposing (..) + + +textOrBsp : String -> String +textOrBsp text = + if text == "" then + String.fromChar (Char.fromCode 0xA0) + + else + text