2020-11-25 05:20:20 +03:00
|
|
|
module Modules.View exposing (..)
|
|
|
|
|
2020-11-28 17:59:09 +03:00
|
|
|
import Dict exposing (Dict)
|
2020-11-30 14:31:03 +03:00
|
|
|
import Html exposing (Html, div, p, span, text)
|
2020-11-30 19:56:11 +03:00
|
|
|
import Html.Attributes exposing (attribute)
|
2020-11-28 17:59:09 +03:00
|
|
|
import Model exposing (Model, PeerData)
|
2020-11-28 16:50:40 +03:00
|
|
|
import Modules.Model exposing (ModuleShortInfo)
|
2020-11-25 05:20:20 +03:00
|
|
|
import Palette exposing (classes)
|
|
|
|
import Utils.Utils exposing (instancesText)
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-11-30 14:31:03 +03:00
|
|
|
|
2020-11-28 17:59:09 +03:00
|
|
|
getModuleShortInfo : Model -> List ModuleShortInfo
|
|
|
|
getModuleShortInfo model =
|
2020-11-30 14:31:03 +03:00
|
|
|
getAllModules model.discoveredPeers |> Dict.toList |> List.map (\( moduleName, peers ) -> { name = moduleName, instanceNumber = List.length peers })
|
|
|
|
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-11-28 17:59:09 +03:00
|
|
|
getAllModules : Dict String PeerData -> Dict String (List String)
|
|
|
|
getAllModules peerData =
|
|
|
|
let
|
2020-11-30 14:31:03 +03:00
|
|
|
peerDatas =
|
|
|
|
Dict.toList peerData
|
|
|
|
|
|
|
|
allModules =
|
|
|
|
peerDatas |> List.map (\( peer, pd ) -> pd.modules |> List.map (\ms -> ( peer, ms ))) |> List.concat
|
|
|
|
|
|
|
|
peersByModuleName =
|
|
|
|
allModules |> List.foldr updateDict Dict.empty
|
2020-11-28 17:59:09 +03:00
|
|
|
in
|
2020-11-30 14:31:03 +03:00
|
|
|
peersByModuleName
|
|
|
|
|
2020-11-28 17:59:09 +03:00
|
|
|
|
2020-11-30 14:31:03 +03:00
|
|
|
updateDict : ( String, String ) -> Dict String (List String) -> Dict String (List String)
|
|
|
|
updateDict ( peer, moduleName ) dict =
|
|
|
|
dict |> Dict.update moduleName (\oldM -> oldM |> Maybe.map (List.append [ peer ]) |> Maybe.withDefault [ peer ] |> Just)
|
2020-11-28 17:59:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
view : Model -> Html msg
|
2020-11-28 16:50:40 +03:00
|
|
|
view modules =
|
2020-11-25 05:20:20 +03:00
|
|
|
let
|
2020-11-25 19:51:53 +03:00
|
|
|
modulesView =
|
2020-11-28 17:59:09 +03:00
|
|
|
List.map viewService (getModuleShortInfo modules)
|
2020-11-25 05:20:20 +03:00
|
|
|
in
|
2020-11-30 14:31:03 +03:00
|
|
|
div [ classes "cf ph2-ns" ] modulesView
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
|
2020-11-25 22:11:11 +03:00
|
|
|
viewService : ModuleShortInfo -> Html msg
|
2020-11-25 05:20:20 +03:00
|
|
|
viewService service =
|
2020-11-30 14:31:03 +03:00
|
|
|
div [ classes "fl w-third-ns pa2" ]
|
2020-11-30 19:56:11 +03:00
|
|
|
[ div [ attribute "href" "#", classes "fl w-100 link dim black mw5 dt hide-child ba b-black pa4 br2 solid" ]
|
2020-11-30 14:31:03 +03:00
|
|
|
[ p [ classes "tl di" ] [ span [ classes "b pl2" ] [ text service.name ], span [ classes "di fr pr2" ] [ instancesText service.instanceNumber ] ]
|
2020-11-25 19:51:53 +03:00
|
|
|
]
|
|
|
|
]
|