diff --git a/src/Instances/View.elm b/src/Instances/View.elm index 6c8802e..9eb2b94 100644 --- a/src/Instances/View.elm +++ b/src/Instances/View.elm @@ -15,6 +15,7 @@ toInstance peerId identify blueprints service = let name = blueprints |> Dict.get service.blueprint_id |> Maybe.withDefault "unknown" + ip = List.head identify.external_addresses |> Maybe.withDefault "unknown" in @@ -32,9 +33,12 @@ view model = instances = Dict.toList model.discoveredPeers - |> List.map (\( peer, data ) -> data.services - |> List.map (toInstance peer data.identify bpsDict)) - |> List.concat + |> List.map + (\( peer, data ) -> + data.services + |> List.map (toInstance peer data.identify bpsDict) + ) + |> List.concat in viewTable instances @@ -42,7 +46,7 @@ view model = viewTable : List Instance -> Html msg viewTable instances = div [ classes "pa4" ] - [ div [ classes "overflow-auto" ] + [ div [ classes "" ] [ table [ classes "f6 w-100 mw8 center", attribute "cellspacing" "0" ] [ thead [] [ tr [ classes "stripe-dark" ] diff --git a/src/ModulePage/Model.elm b/src/ModulePage/Model.elm deleted file mode 100644 index 4c83582..0000000 --- a/src/ModulePage/Model.elm +++ /dev/null @@ -1,14 +0,0 @@ -module ModulePage.Model exposing (..) - -import Services.Model exposing (Service) - - -type alias ModuleInfo = - { name : String - , id : String - , author : String - , authorPeerId : String - , description : String - , website : String - , service : Service - } diff --git a/src/ModulePage/View.elm b/src/ModulePage/View.elm deleted file mode 100644 index 0e8f3ac..0000000 --- a/src/ModulePage/View.elm +++ /dev/null @@ -1,68 +0,0 @@ -module ModulePage.View exposing (..) - -import Html exposing (Html, article, div, span, text) -import ModulePage.Model exposing (ModuleInfo) -import Palette exposing (classes) -import Services.Model exposing (Record, Signature) -import String.Interpolate exposing (interpolate) - - -view : ModuleInfo -> Html msg -view moduleInfo = - div [ classes "cf ph2-ns" ] - [ span [ classes "fl w-100 f1 lh-title dark-red" ] [ text ("Module: " ++ moduleInfo.name) ] - , span [ classes "fl w-100 light-red" ] [ text moduleInfo.id ] - , viewInfo moduleInfo - ] - - -viewInfo : ModuleInfo -> Html msg -viewInfo moduleInfo = - article [ classes "cf" ] - [ div [ classes "fl w-30 gray mv1" ] [ text "AUTHOR" ] - , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black b" ] [ text moduleInfo.author ], span [ classes "fl w-100 black" ] [ text moduleInfo.authorPeerId ] ] - , div [ classes "fl w-30 gray mv1" ] [ text "DESCRIPTION" ] - , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] [ text moduleInfo.description ] ] - , div [ classes "fl w-30 gray mv1" ] [ text "INTERFACE" ] - , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] (recordsView moduleInfo.service.interface.record_types ++ signaturesView moduleInfo.service.interface.function_signatures) ] - ] - - -recordsView : List Record -> List (Html msg) -recordsView record = - List.map recordView record - - -recordView : Record -> Html msg -recordView record = - div [ classes "i" ] - ([ span [ classes "fl w-100 mt2" ] [ text (record.name ++ " {") ] ] - ++ fieldsView record.fields - ++ [ span [ classes "fl w-100 mb2" ] [ text "}" ] ] - ) - - -fieldsView : List (List String) -> List (Html msg) -fieldsView fields = - fields |> List.map (\f -> span [ classes "fl w-100 ml2" ] [ text (String.join ": " f) ]) - - -signaturesView : List Signature -> List (Html msg) -signaturesView signatures = - List.map signatureView signatures - - -signatureView : Signature -> Html msg -signatureView signature = - div [ classes "i fl w-100 mv2" ] - [ text (interpolate "fn {0}({1}) -> {2}" [ signature.name, argumentsToString signature.arguments, outputToString signature.output_types ]) ] - - -argumentsToString : List (List String) -> String -argumentsToString arguments = - String.join ", " (arguments |> List.map (String.join ": ")) - - -outputToString : List String -> String -outputToString output = - output |> List.head |> Maybe.withDefault "void" diff --git a/src/Route.elm b/src/Route.elm index bd28a39..3fc5631 100644 --- a/src/Route.elm +++ b/src/Route.elm @@ -2,12 +2,12 @@ module Route exposing (..) import Air exposing (callBI, fold, next, par, relayEvent, seq, set) import Dict -import Html exposing (Html) +import Html exposing (Html, text) import HubPage.View as HubPage import Json.Encode as Encode import Model exposing (Model, Route(..)) -import ModulePage.View as ModulePage import Port exposing (sendAir) +import ServicePage.View as ServicePage import Url.Parser exposing ((), Parser, map, oneOf, s, string) @@ -37,39 +37,16 @@ routeView model route = HubPage.view model _ -> - Html.text ("undefined page: " ++ page) + text ("undefined page: " ++ page) Peer peer -> - Html.text peer + text peer Service serviceId -> - Html.text serviceId + ServicePage.view model serviceId Module moduleName -> - let - up = - \( pid, p ) -> Maybe.map (\a -> Tuple.pair pid a) (List.head (List.drop 0 p.services)) - - el = - List.head (List.drop 2 (Dict.toList model.discoveredPeers)) - in - case Maybe.andThen up el of - Just ( peerId, service ) -> - let - example = - { name = moduleName - , id = service.service_id - , author = "Fluence Labs" - , authorPeerId = peerId - , description = "Cool service" - , website = "https://github.com/fluencelabs/chat" - , service = service - } - in - ModulePage.view example - - Nothing -> - Html.text moduleName + text moduleName getPeers : Model -> Cmd msg diff --git a/src/ServicePage/Model.elm b/src/ServicePage/Model.elm index 2b7bdfd..d680516 100644 --- a/src/ServicePage/Model.elm +++ b/src/ServicePage/Model.elm @@ -1 +1,14 @@ module ServicePage.Model exposing (..) + +import Services.Model exposing (Service) + + +type alias ServiceInfo = + { name : String + , id : String + , author : String + , authorPeerId : String + , description : String + , website : String + , service : Service + } diff --git a/src/ServicePage/View.elm b/src/ServicePage/View.elm index b38f39b..84b6ac8 100644 --- a/src/ServicePage/View.elm +++ b/src/ServicePage/View.elm @@ -1 +1,117 @@ module ServicePage.View exposing (..) + +import Dict +import Html exposing (Html, article, div, span, text) +import List.Extra +import Model exposing (Model) +import Palette exposing (classes) +import ServicePage.Model exposing (ServiceInfo) +import Services.Model exposing (Record, Signature) +import String.Interpolate exposing (interpolate) + + +view : Model -> String -> Html msg +view model id = + let + moduleInfo = + modelToServiceInfo model id + in + case moduleInfo of + Just mi -> + div [ classes "cf ph2-ns" ] + [ span [ classes "fl w-100 f1 lh-title dark-red" ] [ text ("Module: " ++ mi.name) ] + , span [ classes "fl w-100 light-red" ] [ text mi.id ] + , viewInfo mi + ] + + Nothing -> + div [ classes "cf ph2-ns" ] + [ span [ classes "fl w-100 f1 lh-title dark-red" ] [ text "Module not found" ] + ] + + +modelToServiceInfo : Model -> String -> Maybe ServiceInfo +modelToServiceInfo model id = + let + datas = + Dict.toList model.discoveredPeers + + services = + datas |> List.map (\( peer, data ) -> data.services |> List.map (\s -> ( peer, s ))) |> List.concat + + blueprints = + datas |> List.map (\( _, data ) -> data.blueprints) |> List.concat |> List.map (\bp -> ( bp.id, bp.name )) |> Dict.fromList + + service = + services |> List.Extra.find (\( _, s ) -> s.service_id == id) + + name = + service |> Maybe.andThen (\( _, s ) -> blueprints |> Dict.get s.blueprint_id) |> Maybe.withDefault "unknown" + + info = + service + |> Maybe.map + (\( p, s ) -> + { name = name + , id = id + , author = "Fluence Labs" + , authorPeerId = p + , description = "Cool service" + , website = "https://github.com/fluencelabs/chat" + , service = s + } + ) + in + info + + +viewInfo : ServiceInfo -> Html msg +viewInfo moduleInfo = + article [ classes "cf" ] + [ div [ classes "fl w-30 gray mv1" ] [ text "AUTHOR" ] + , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black b" ] [ text moduleInfo.author ], span [ classes "fl w-100 black" ] [ text moduleInfo.authorPeerId ] ] + , div [ classes "fl w-30 gray mv1" ] [ text "DESCRIPTION" ] + , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] [ text moduleInfo.description ] ] + , div [ classes "fl w-30 gray mv1" ] [ text "INTERFACE" ] + , div [ classes "fl w-70 mv1" ] [ span [ classes "fl w-100 black" ] (recordsView moduleInfo.service.interface.record_types ++ signaturesView moduleInfo.service.interface.function_signatures) ] + ] + + +recordsView : List Record -> List (Html msg) +recordsView record = + List.map recordView record + + +recordView : Record -> Html msg +recordView record = + div [ classes "i" ] + ([ span [ classes "fl w-100 mt2" ] [ text (record.name ++ " {") ] ] + ++ fieldsView record.fields + ++ [ span [ classes "fl w-100 mb2" ] [ text "}" ] ] + ) + + +fieldsView : List (List String) -> List (Html msg) +fieldsView fields = + fields |> List.map (\f -> span [ classes "fl w-100 ml2" ] [ text (String.join ": " f) ]) + + +signaturesView : List Signature -> List (Html msg) +signaturesView signatures = + List.map signatureView signatures + + +signatureView : Signature -> Html msg +signatureView signature = + div [ classes "i fl w-100 mv2" ] + [ text (interpolate "fn {0}({1}) -> {2}" [ signature.name, argumentsToString signature.arguments, outputToString signature.output_types ]) ] + + +argumentsToString : List (List String) -> String +argumentsToString arguments = + String.join ", " (arguments |> List.map (String.join ": ")) + + +outputToString : List String -> String +outputToString output = + output |> List.head |> Maybe.withDefault "void"