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)
|
2019-08-09 18:22:27 +02:00
|
|
|
import Html exposing (Html, fieldset, input, label)
|
|
|
|
import Html.Attributes exposing (for, id, 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
|
|
|
|
|
|
|
|
2019-08-09 18:22:27 +02:00
|
|
|
myStyle : List (Html.Attribute msg) -> List (Html.Attribute msg)
|
2019-07-27 16:24:13 +02:00
|
|
|
myStyle =
|
2019-08-09 18:22:27 +02:00
|
|
|
List.append [ style "width" "100%" ]
|
2019-07-27 16:24:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
view : Model -> Html Msg
|
|
|
|
view state =
|
2019-08-09 18:22:27 +02:00
|
|
|
fieldset []
|
|
|
|
[ label [ for "url" ] []
|
|
|
|
, input (myStyle [ id "url", placeholder "GitHub/GitLab/Bitbucket URL", value state.url, onInput UrlChange ])
|
2019-07-28 21:42:49 +02:00
|
|
|
[]
|
2019-08-09 18:22:27 +02:00
|
|
|
, label [ for "output" ] []
|
|
|
|
, input (myStyle [ id "output", 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
|
|
|
|
}
|