Add a basic front end written in elm
This commit is contained in:
parent
34bac52943
commit
fcff89cccb
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
*.bak
|
||||
result
|
||||
.pls_cache
|
||||
elm-stuff
|
||||
|
27
elm.json
Normal file
27
elm.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.3"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.8",
|
||||
"elm/file": "1.0.5",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.3"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@
|
||||
in {
|
||||
pr-status = pkgs.perlPackages.buildPerlPackage {
|
||||
pname = "pr-status";
|
||||
version = "v0.0.1";
|
||||
version = "v0.0.2";
|
||||
src = ./.;
|
||||
buildInputs = with pkgs; [ makeWrapper ];
|
||||
propagatedBuildInputs = with pkgs.perlPackages; [
|
||||
@ -43,6 +43,11 @@
|
||||
forAllSystems (system: self.packages.${system}.pr-status);
|
||||
devShells = forAllSystems (system:
|
||||
let pkgs = nixpkgsFor.${system};
|
||||
npPackages = with pkgs; [
|
||||
elmPackages.elm
|
||||
elmPackages.elm-test
|
||||
elmPackages.elm-live
|
||||
];
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
shellHook = ''
|
||||
@ -57,7 +62,7 @@
|
||||
perl
|
||||
PerlCritic
|
||||
PerlTidy
|
||||
];
|
||||
] ++ npPackages;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
6544
pr-status.pl
6544
pr-status.pl
File diff suppressed because it is too large
Load Diff
204
src/Main.elm
Normal file
204
src/Main.elm
Normal file
@ -0,0 +1,204 @@
|
||||
module Main exposing (..)
|
||||
|
||||
import Browser
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (href, placeholder, style)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
import Json.Decode as Decode exposing (Decoder, field, int, list, map5, map6, string)
|
||||
|
||||
|
||||
type Status
|
||||
= Complete
|
||||
| Open
|
||||
|
||||
|
||||
type Msg
|
||||
= RunSearch
|
||||
| GotResult (Result Http.Error Model)
|
||||
| SetPR String
|
||||
|
||||
|
||||
type alias Branches =
|
||||
List String
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ pull_request : Int
|
||||
, release : String
|
||||
, status : Status
|
||||
, title : String
|
||||
, branches : Branches
|
||||
, error : String
|
||||
}
|
||||
|
||||
|
||||
main : Program () Model Msg
|
||||
main =
|
||||
Browser.element
|
||||
{ init = init
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = \_ -> Sub.none
|
||||
}
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
RunSearch ->
|
||||
( model, getResult model )
|
||||
|
||||
GotResult (Err _) ->
|
||||
( { model | error = "Can't load data!" }, Cmd.none )
|
||||
|
||||
GotResult (Ok pr) ->
|
||||
( pr, Cmd.none )
|
||||
|
||||
SetPR pr ->
|
||||
( { model
|
||||
| pull_request =
|
||||
case String.toInt pr of
|
||||
Just a ->
|
||||
a
|
||||
|
||||
Nothing ->
|
||||
0
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
initialModel : Model
|
||||
initialModel =
|
||||
{ pull_request = 0
|
||||
, release = ""
|
||||
, status = Open
|
||||
, title = ""
|
||||
, branches = []
|
||||
, error = ""
|
||||
}
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( initialModel, Cmd.none )
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ div []
|
||||
[ input [ placeholder "search...", onInput SetPR ] []
|
||||
, button [ onClick RunSearch ] [ text "Search" ]
|
||||
]
|
||||
, div []
|
||||
[ viewResult model ]
|
||||
]
|
||||
|
||||
|
||||
viewResult : Model -> Html Msg
|
||||
viewResult data =
|
||||
case data.title of
|
||||
"" ->
|
||||
text ""
|
||||
|
||||
_ ->
|
||||
let
|
||||
prStr =
|
||||
String.fromInt data.pull_request
|
||||
in
|
||||
table []
|
||||
[ tr []
|
||||
[ td [] [ b [] [ text "Title:" ] ]
|
||||
, td []
|
||||
[ a [ href ("https://github.com/NixOS/nixpkgs/pull/" ++ prStr) ]
|
||||
[ text data.title
|
||||
]
|
||||
]
|
||||
]
|
||||
, makeRow "Release:" data.release
|
||||
, makeRow "Status:"
|
||||
(case data.status of
|
||||
Complete ->
|
||||
"complete"
|
||||
|
||||
Open ->
|
||||
"open"
|
||||
)
|
||||
, viewBranches data.branches
|
||||
, case data.error of
|
||||
"" ->
|
||||
text ""
|
||||
|
||||
_ ->
|
||||
span [ style "color" "red" ] [ text data.error ]
|
||||
]
|
||||
|
||||
|
||||
viewBranches : List String -> Html Msg
|
||||
viewBranches blist =
|
||||
tr []
|
||||
[ td [] [ b [] [ text "Branches:" ] ]
|
||||
, td []
|
||||
[ ul []
|
||||
(List.map viewBranch blist)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
viewBranch : String -> Html Msg
|
||||
viewBranch branch =
|
||||
li [] [ text branch ]
|
||||
|
||||
|
||||
makeRow : String -> String -> Html Msg
|
||||
makeRow title data =
|
||||
tr []
|
||||
[ td [] [ b [] [ text title ] ]
|
||||
, td [] [ text data ]
|
||||
]
|
||||
|
||||
|
||||
getResult : Model -> Cmd Msg
|
||||
getResult model =
|
||||
Http.get
|
||||
{ url = "/" ++ String.fromInt model.pull_request
|
||||
, expect = Http.expectJson GotResult resultDecoder
|
||||
}
|
||||
|
||||
|
||||
resultDecoder : Decoder Model
|
||||
resultDecoder =
|
||||
map5
|
||||
(\pull_request release status title branches ->
|
||||
{ pull_request = pull_request
|
||||
, release = release
|
||||
, status = status
|
||||
, title = title
|
||||
, branches = branches
|
||||
, error = ""
|
||||
}
|
||||
)
|
||||
(field "pull_request" int)
|
||||
(field "release" string)
|
||||
(field "status" statusDecoder)
|
||||
(field "title" string)
|
||||
(field "branches" (list string))
|
||||
|
||||
|
||||
statusDecoder : Decoder Status
|
||||
statusDecoder =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
(\str ->
|
||||
case str of
|
||||
"complete" ->
|
||||
Decode.succeed Complete
|
||||
|
||||
"open" ->
|
||||
Decode.succeed Open
|
||||
|
||||
_ ->
|
||||
Decode.fail "invalid status"
|
||||
)
|
Loading…
Reference in New Issue
Block a user