templates, view for services and modules, air for services and modules

This commit is contained in:
DieMyst 2020-11-25 05:20:20 +03:00
parent 10afac025e
commit 84b5a10a04
33 changed files with 2023 additions and 17155 deletions

18858
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"start": "webpack-serve --open",
"pack": "webpack"
"pack": "webpack",
"dev": "parcel index.html"
},
"repository": {
"type": "git",
@ -18,7 +19,7 @@
},
"homepage": "https://github.com/fluencelabs/fluence-admin#readme",
"dependencies": {
"fluence": "0.7.80",
"fluence": "0.7.81",
"tachyons": "^4.12.0"
},
"devDependencies": {
@ -31,6 +32,7 @@
"elm-webpack-loader": "6.0.1",
"html-webpack-plugin": "^4.4.1",
"http-server": "^0.12.3",
"parcel-bundler": "^1.12.4",
"replace-in-file": "^6.0.0",
"source-map-loader": "1.1.2",
"style-loader": "^0.23.1",

5
src/HubPage/Model.elm Normal file
View File

@ -0,0 +1,5 @@
module HubPage.Model exposing (..)
type alias Model =
{
}

3
src/HubPage/Msg.elm Normal file
View File

@ -0,0 +1,3 @@
module HubPage.Msg exposing (..)
type Msg = NoOp

1
src/HubPage/Update.elm Normal file
View File

@ -0,0 +1 @@
module HubPage.Update exposing (..)

33
src/HubPage/View.elm Normal file
View File

@ -0,0 +1,33 @@
module HubPage.View exposing (..)
import Html exposing (Html)
import HubPage.Model exposing (Model)
import HubPage.Msg exposing (Msg)
import Modules.Model exposing (Module)
import Modules.View
import Services.Model exposing (Service)
import Services.View
servicesExample : List Service
servicesExample =
[ { name = "SQLite", author = "Company Inc", instanceNumber = 2 }
, { name = "Redis", author = "Roga Kopita", instanceNumber = 3 }
, { name = "Chat", author = "Fluence Labs", instanceNumber = 5 }
, { name = "Imagemagick", author = "Magic Corp", instanceNumber = 0 }
]
modulesExample : List Module
modulesExample =
[ { name = "sqlite3", instanceNumber = 2 }
, { name = "ipfs_adapter", instanceNumber = 3 }
, { name = "mariadb_adapter", instanceNumber = 5 }
, { name = "chat_history", instanceNumber = 1 }
, { name = "user_list", instanceNumber = 1 }
, { name = "basic_auth", instanceNumber = 0 }
]
view : Model -> Html msg
view model = Html.div []
[ Services.View.view {services = servicesExample}
, Modules.View.view {modules = modulesExample }
]

10
src/Instances/Model.elm Normal file
View File

@ -0,0 +1,10 @@
module Instances.Model exposing (..)
type alias Instance =
{
}
type alias Model =
{
}

3
src/Instances/Msg.elm Normal file
View File

@ -0,0 +1,3 @@
module Instances.Msg exposing (..)
type Msg = NoOp

1
src/Instances/Update.elm Normal file
View File

@ -0,0 +1 @@
module Instances.Update exposing (..)

1
src/Instances/View.elm Normal file
View File

@ -0,0 +1 @@
module Instances.View exposing (..)

1
src/ModulePage/Model.elm Normal file
View File

@ -0,0 +1 @@
module ModulePage.Model exposing (..)

1
src/ModulePage/Msg.elm Normal file
View File

@ -0,0 +1 @@
module ModulePage.Msg exposing (..)

View File

@ -0,0 +1 @@
module ModulePage.Update exposing (..)

1
src/ModulePage/View.elm Normal file
View File

@ -0,0 +1 @@
module ModulePage.View exposing (..)

31
src/Modules/Air.elm Normal file
View File

@ -0,0 +1,31 @@
module Modules.Air exposing (..)
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode exposing (list, string)
air : String -> String -> List String -> Air
air peerId relayId peers =
let
clientIdSet =
set "clientId" <| string peerId
relayIdSet =
set "relayId" <| string relayId
peersSet =
set "peers" <| list string peers
airScript =
seq
(callBI "relayId" ( "op", "identity" ) [ ] Nothing)
(fold "peers" "p" <|
par
(seq
(callBI "p" ( "srv", "get_modules" ) [ ] (Just "modules[]"))
(relayEvent "modules_discovered" [ "p", "modules" ])
)
(next "p")
)
in
clientIdSet <| relayIdSet <| peersSet <| airScript

10
src/Modules/Model.elm Normal file
View File

@ -0,0 +1,10 @@
module Modules.Model exposing (..)
type alias Module =
{ name: String
, instanceNumber: Int
}
type alias Model =
{ modules : List Module
}

1
src/Modules/Msg.elm Normal file
View File

@ -0,0 +1 @@
module Modules.Msg exposing (..)

1
src/Modules/Update.elm Normal file
View File

@ -0,0 +1 @@
module Modules.Update exposing (..)

20
src/Modules/View.elm Normal file
View File

@ -0,0 +1,20 @@
module Modules.View exposing (..)
import Html exposing (Html)
import Modules.Model exposing (Model, Module)
import Palette exposing (classes)
import Utils.Utils exposing (instancesText)
view : Model -> Html msg
view model =
let
modulesView = List.map viewService model.modules
in
Html.div [classes "cf ph2-ns"] modulesView
viewService : Module -> Html msg
viewService service =
Html.div [classes "fl w-third-ns pa2"]
[ Html.div [classes "fl w-100 br2 ba solid pa2 mh2"]
[ Html.p [classes "tl di"] [Html.span [classes "b pl2"] [Html.text service.name], Html.span [classes "di fr pr2"] [instancesText service.instanceNumber]]
]
]

View File

@ -1,6 +1,8 @@
module Route exposing (..)
import Air exposing (call, callBI, fold, next, par, relayEvent, seq, set)
import Html exposing (Html)
import HubPage.View as HubPage
import Json.Encode as Encode
import Model exposing (Model, Route(..))
import Port exposing (sendAir)
@ -18,12 +20,26 @@ routeParser =
parse url =
Maybe.withDefault (Page "") <| Url.Parser.parse routeParser url
routeView : Route -> Html msg
routeView route =
case route of
Page page ->
case page of
"hub" ->
HubPage.view {}
_ ->
Html.text ("undefined page: " ++ page)
Peer peer ->
Html.text peer
routeCommand : Model -> Route -> Cmd msg
routeCommand m r =
case r of
Page _ ->
Page s ->
let
_ = Debug.log "page" s
clientId =
set "clientId" <| Encode.string m.peerId

View File

@ -0,0 +1 @@
module ServicePage.Model exposing (..)

1
src/ServicePage/Msg.elm Normal file
View File

@ -0,0 +1 @@
module ServicePage.Msg exposing (..)

View File

@ -0,0 +1 @@
module ServicePage.Update exposing (..)

1
src/ServicePage/View.elm Normal file
View File

@ -0,0 +1 @@
module ServicePage.View exposing (..)

31
src/Services/Air.elm Normal file
View File

@ -0,0 +1,31 @@
module Services.Air exposing (..)
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode exposing (list, string)
air : String -> String -> List String -> Air
air peerId relayId peers =
let
clientIdSet =
set "clientId" <| string peerId
relayIdSet =
set "relayId" <| string relayId
peersSet =
set "peers" <| list string peers
airScript =
seq
(callBI "relayId" ( "op", "identity" ) [ ] Nothing)
(fold "peers" "p" <|
par
(seq
(callBI "p" ( "srv", "get_interfaces" ) [ ] (Just "interfaces[]"))
(relayEvent "interfaces_discovered" [ "p", "interfaces" ])
)
(next "p")
)
in
clientIdSet <| relayIdSet <| peersSet <| airScript

11
src/Services/Model.elm Normal file
View File

@ -0,0 +1,11 @@
module Services.Model exposing (..)
type alias Service =
{ name: String,
author: String,
instanceNumber: Int
}
type alias Model =
{ services : List Service
}

1
src/Services/Msg.elm Normal file
View File

@ -0,0 +1 @@
module Services.Msg exposing (..)

1
src/Services/Update.elm Normal file
View File

@ -0,0 +1 @@
module Services.Update exposing (..)

22
src/Services/View.elm Normal file
View File

@ -0,0 +1,22 @@
module Services.View exposing (..)
import Html exposing (Html)
import Palette exposing (classes)
import Services.Model exposing (Model, Service)
import Utils.Utils exposing (instancesText)
view : Model -> Html msg
view model =
let
servicesView = List.map viewService model.services
in
Html.div [classes "cf ph2-ns"] servicesView
viewService : Service -> Html msg
viewService service =
Html.div [classes "fl w-third-ns pa2"]
[ Html.div [classes "fl w-100 br2 ba solid ma2 pa3"]
[ Html.div [classes "w-100 mb2 b"] [Html.text service.name]
, Html.div [classes "w-100 mb4"] [Html.text ("By " ++ service.author)]
, Html.div [classes "w-100"] [instancesText service.instanceNumber]]
]

View File

@ -20,12 +20,53 @@ import Air
import Browser
import Browser.Navigation as Nav
import Dict
import Json.Decode exposing (decodeValue, list, string)
import Json.Encode exposing (Value)
import Model exposing (Model)
import Msg exposing (..)
import Port exposing (sendAir)
import Route
import Services.Air
import Url
maybeValueToString : Maybe Value -> String
maybeValueToString mv =
case mv of
Just v ->
case (decodeValue string v) of
Ok value ->
value
Err error ->
"error"
Nothing ->
""
-- list of lists of strings in json to list of strings from first element if it is an array
maybeValueToListString : Maybe Value -> List String
maybeValueToListString mv =
case mv of
Just v ->
case (decodeValue (list (list string)) v) of
Ok value ->
Maybe.withDefault [] (List.head value)
Err error ->
let
_ = Debug.log "error" error
in
case (decodeValue (list string) v) of
Ok value ->
value
Err err ->
let
_ = Debug.log "err" err
in
["error"]
Nothing ->
[]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
@ -56,19 +97,20 @@ update msg model =
"peers_discovered" ->
-- TODO call different function to parse args and change model
let
b =
Debug.log "args" args
peer =
maybeValueToString (List.head args)
up p =
case p of
Nothing ->
Just { interfaces = [] }
peers = maybeValueToListString (List.head (List.drop 1 args))
Just x ->
Just x
b = Debug.log "peer" peer
c = Debug.log "peers" peers
peersMap = List.map (\p -> Tuple.pair p { interfaces = [] }) peers
newDict = Dict.fromList (peersMap)
updatedDict = Dict.union model.discoveredPeers newDict
in
-- TODO get data from args, propagate
( { model | discoveredPeers = Dict.update "abc" up model.discoveredPeers }, Cmd.none )
( { model | discoveredPeers = updatedDict }, Cmd.none )
_ ->
let
@ -79,7 +121,7 @@ update msg model =
Click ->
( model
, sendAir <| Air.event "hello" []
, sendAir (Services.Air.air model.peerId model.relayId (Dict.keys model.discoveredPeers))
)
RelayChanged relayId ->

13
src/Utils/Utils.elm Normal file
View File

@ -0,0 +1,13 @@
module Utils.Utils exposing (..)
import Html exposing (Html)
instancesText : Int -> Html msg
instancesText num =
let
strNum = String.fromInt num
in
if num == 1 then
Html.text (strNum ++ "instance")
else
Html.text (strNum ++ "instances")

View File

@ -16,13 +16,14 @@ limitations under the License.
-}
import Browser exposing (Document)
import Browser exposing (Document, UrlRequest(..))
import Html exposing (Html, div, header, text)
import Html.Attributes exposing (class, classList)
import Html.Events exposing (onClick)
import Model exposing (Model)
import Model exposing (Model, Route(..))
import Msg exposing (..)
import Palette exposing (classes)
import Route exposing (routeView)
view : Model -> Document Msg
@ -37,17 +38,24 @@ title _ =
body : Model -> Html Msg
body model =
layout <|
List.concat
[-- TODO render the view according to model.page
]
let
a = 1
url = model.url
newUrl = { url | path = "/hub"}
in
layout <|
List.concat
[
[ header [ classes "w-100 bt bb b--black-10" ] [ routeView (Page "hub") ] ] ++
[ header [ classes "w-100 bt bb b--black-10", onClick Click ] [ text "Fluence Network Dashboard" ] ]
]
layout : List (Html Msg) -> Html Msg
layout elms =
div [ classes "mw9 center" ]
div [ classes "mw9 center w-70" ]
[ div [ classes "fl w-100 pa2" ]
([ header [ classes "w-100 bt bb b--black-10", onClick Click ] [ text "Fluence Network Dashboard" ]
([
]
++ elms
)

View File

@ -12,6 +12,9 @@ module.exports = {
contentBase: './bundle',
hot: false,
inline: false,
historyApiFallback:{
index:'index.html'
},
},
devtool: "eval-source-map",
module: {