2019-07-29 23:17:41 +02:00
|
|
|
module Main exposing
|
|
|
|
( Model
|
|
|
|
, Msg(..)
|
|
|
|
, init
|
|
|
|
, main
|
|
|
|
, update
|
|
|
|
, view
|
|
|
|
)
|
2019-07-27 16:24:13 +02:00
|
|
|
|
|
|
|
import Browser
|
2019-08-09 17:54:24 +02:00
|
|
|
import Data exposing (Url, hostname, toUrl)
|
|
|
|
import Html exposing (Html, div, input)
|
|
|
|
import Html.Attributes exposing (placeholder, readonly, style, value)
|
2019-07-27 16:24:13 +02:00
|
|
|
import Html.Events exposing (onInput)
|
|
|
|
import Parse exposing (parseUrl)
|
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= UrlChange String
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ url : String
|
|
|
|
, parsed : Maybe Url
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : Model
|
|
|
|
init =
|
|
|
|
{ url = ""
|
|
|
|
, parsed = Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> Model -> Model
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
UrlChange newUrl ->
|
|
|
|
{ state | url = newUrl, parsed = parseUrl newUrl }
|
|
|
|
|
|
|
|
|
|
|
|
displayMUrl : Maybe Url -> String
|
|
|
|
displayMUrl mUrl =
|
|
|
|
mUrl
|
|
|
|
|> Maybe.map toUrl
|
2019-07-28 21:42:49 +02:00
|
|
|
|> Maybe.withDefault (hostname ++ "<service>/<user>/<repo>/<gitref>/<file>")
|
2019-07-27 16:24:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
myStyle : List (Html.Attribute msg)
|
|
|
|
myStyle =
|
|
|
|
[ style "width" "100%" ]
|
|
|
|
|
|
|
|
|
|
|
|
myStyle2 : List (Html.Attribute msg) -> List (Html.Attribute msg)
|
|
|
|
myStyle2 =
|
|
|
|
List.append myStyle
|
|
|
|
|
|
|
|
|
|
|
|
view : Model -> Html Msg
|
|
|
|
view state =
|
2019-08-09 17:54:24 +02:00
|
|
|
div myStyle
|
2019-07-29 21:16:33 +02:00
|
|
|
[ input (myStyle2 [ placeholder "GitHub/GitLab/Bitbucket URL", value state.url, onInput UrlChange ])
|
2019-07-28 21:42:49 +02:00
|
|
|
[]
|
2019-08-05 18:17:29 +02:00
|
|
|
, input (myStyle2 [ readonly True, value (displayMUrl state.parsed) ]) []
|
2019-07-27 16:24:13 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
main : Program () Model Msg
|
|
|
|
main =
|
2019-07-29 23:17:41 +02:00
|
|
|
Browser.sandbox
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
}
|