port forwarding is working
This commit is contained in:
parent
0829e0f03f
commit
7fadc22ce0
|
@ -23,9 +23,14 @@ serve:
|
|||
ifeq ($(DEBUG),1)
|
||||
elm-go src/Main.elm \
|
||||
--dir=../public \
|
||||
--start-page=index.html \
|
||||
--port=8000 \
|
||||
--start-page=../public/index.html \
|
||||
--host=localhost \
|
||||
-- --debug
|
||||
--proxy-prefix=/ \
|
||||
--proxy-host=http://localhost:8080 \
|
||||
-- \
|
||||
--debug \
|
||||
--output=../public/elm.min.js
|
||||
else ifeq ($(RELEASE),1)
|
||||
$(error Cannot use serve target with RELEASE=1)
|
||||
endif
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
module Page.Landing exposing
|
||||
( Model
|
||||
, Msg
|
||||
, view
|
||||
, init
|
||||
, update
|
||||
, subscriptions
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Element exposing (Element)
|
||||
import Websockets
|
||||
import Ports
|
||||
import Element.Background
|
||||
import Element.Input
|
||||
import EncodeDecode
|
||||
import Html.Attributes exposing (placeholder)
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import Html.Attributes exposing (placeholder)
|
||||
import Element.Input
|
||||
import Element.Background
|
||||
import Ports
|
||||
import Websockets
|
||||
|
||||
import EncodeDecode
|
||||
|
||||
type alias Model = {
|
||||
time : String,
|
||||
greetWidgetText : String,
|
||||
greeting : String
|
||||
type alias Model =
|
||||
{ time : String
|
||||
, greetWidgetText : String
|
||||
, greeting : String
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= DownMsg EncodeDecode.DownMsg
|
||||
| UpMsg EncodeDecode.LandingUpMsg
|
||||
|
@ -30,15 +32,17 @@ type Msg
|
|||
| GreetWidgetText String
|
||||
| NoOp
|
||||
|
||||
init : () -> (Model, Cmd Msg)
|
||||
init flags = (
|
||||
{ time = "time not yet set"
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
( { time = "time not yet set"
|
||||
, greetWidgetText = ""
|
||||
, greeting = ""
|
||||
},
|
||||
Cmd.none
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
Ports.socketOnEvent
|
||||
|
@ -48,45 +52,67 @@ subscriptions model =
|
|||
(\_ -> NoOp)
|
||||
(\message ->
|
||||
case Decode.decodeString EncodeDecode.downMsgDecoder message.data of
|
||||
Ok msg -> DownMsg msg
|
||||
Err err -> DecodeError err
|
||||
Ok msg ->
|
||||
DownMsg msg
|
||||
|
||||
Err err ->
|
||||
DecodeError err
|
||||
)
|
||||
(\_ -> NoOp)
|
||||
)
|
||||
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.TimeUpdate time)) ->
|
||||
( {model | time = time}, Cmd.none )
|
||||
DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) ->
|
||||
( {model | greeting = greeting}, Cmd.none)
|
||||
UpMsg upMsg ->
|
||||
let cmd = Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg
|
||||
in
|
||||
(model, cmd)
|
||||
( { model | time = time }, Cmd.none )
|
||||
|
||||
DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) ->
|
||||
( { model | greeting = greeting }, Cmd.none )
|
||||
|
||||
UpMsg upMsg ->
|
||||
let
|
||||
cmd =
|
||||
Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg
|
||||
in
|
||||
( model, cmd )
|
||||
|
||||
GreetWidgetText text ->
|
||||
( { model | greetWidgetText = text }, Cmd.none )
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
GreetWidgetText text -> ( {model | greetWidgetText = text}, Cmd.none )
|
||||
_ -> (model, Cmd.none)
|
||||
|
||||
greetWidget : Model -> Element Msg
|
||||
greetWidget model =
|
||||
let
|
||||
idleBlue = Element.rgb255 18 147 217
|
||||
focusBlue = Element.rgb255 18 125 184
|
||||
idleBlue =
|
||||
Element.rgb255 18 147 217
|
||||
|
||||
myButton = Element.Input.button
|
||||
focusBlue =
|
||||
Element.rgb255 18 125 184
|
||||
|
||||
myButton =
|
||||
Element.Input.button
|
||||
[ Element.Background.color idleBlue
|
||||
, Element.mouseOver [Element.Background.color focusBlue]
|
||||
, Element.mouseOver [ Element.Background.color focusBlue ]
|
||||
, Element.width (Element.fill |> Element.maximum 100)
|
||||
, Element.height (Element.fill |> Element.maximum 50)
|
||||
]
|
||||
{ onPress = Just <| UpMsg <| EncodeDecode.RequestGreet model.greetWidgetText
|
||||
, label = Element.text "Greet"
|
||||
}
|
||||
placeholder = case model.greetWidgetText of
|
||||
"" -> Just <| Element.Input.placeholder [] <| Element.text "Type Your Name"
|
||||
_ -> Just <| Element.Input.placeholder [] <| Element.text ""
|
||||
|
||||
placeholder =
|
||||
case model.greetWidgetText of
|
||||
"" ->
|
||||
Just <| Element.Input.placeholder [] <| Element.text "Type Your Name"
|
||||
|
||||
_ ->
|
||||
Just <| Element.Input.placeholder [] <| Element.text ""
|
||||
|
||||
textInput =
|
||||
Element.Input.text
|
||||
[ Element.width (Element.fill |> Element.maximum 400)
|
||||
|
@ -97,17 +123,20 @@ greetWidget model =
|
|||
, placeholder = placeholder
|
||||
, label = Element.Input.labelHidden "Enter your name"
|
||||
}
|
||||
nameInput = Element.row [] [ textInput , myButton]
|
||||
|
||||
nameInput =
|
||||
Element.row [] [ textInput, myButton ]
|
||||
in
|
||||
Element.column []
|
||||
[ nameInput
|
||||
, Element.text model.greeting
|
||||
]
|
||||
|
||||
|
||||
view : Model -> Element Msg
|
||||
view model =
|
||||
Element.column []
|
||||
[ Element.text "Landing"
|
||||
[ Element.text "Landing..."
|
||||
, Element.text <| "Current time is : " ++ model.time
|
||||
, greetWidget model
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue