Look up README using default_branch, + website
This commit is contained in:
parent
b570602aa2
commit
f30f25160e
5
elm.json
5
elm.json
|
@ -13,13 +13,16 @@
|
||||||
"elm/json": "1.1.3",
|
"elm/json": "1.1.3",
|
||||||
"elm/regex": "1.0.0",
|
"elm/regex": "1.0.0",
|
||||||
"elm/url": "1.0.0",
|
"elm/url": "1.0.0",
|
||||||
|
"elm-community/json-extra": "4.3.0",
|
||||||
"pablohirafuji/elm-markdown": "2.0.5"
|
"pablohirafuji/elm-markdown": "2.0.5"
|
||||||
},
|
},
|
||||||
"indirect": {
|
"indirect": {
|
||||||
"elm/bytes": "1.0.8",
|
"elm/bytes": "1.0.8",
|
||||||
"elm/file": "1.0.5",
|
"elm/file": "1.0.5",
|
||||||
|
"elm/parser": "1.1.0",
|
||||||
"elm/time": "1.0.0",
|
"elm/time": "1.0.0",
|
||||||
"elm/virtual-dom": "1.0.2"
|
"elm/virtual-dom": "1.0.2",
|
||||||
|
"rtfeldman/elm-iso8601-date-strings": "1.1.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test-dependencies": {
|
"test-dependencies": {
|
||||||
|
|
|
@ -7,7 +7,9 @@ import Html.Events exposing (onClick)
|
||||||
import Http
|
import Http
|
||||||
import Markdown
|
import Markdown
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
|
import Json.Decode.Extra as Decode exposing (andMap)
|
||||||
import Spa.Document exposing (Document)
|
import Spa.Document exposing (Document)
|
||||||
|
import Spa.Generated.Route as Route
|
||||||
import Spa.Page as Page exposing (Page)
|
import Spa.Page as Page exposing (Page)
|
||||||
import Spa.Url as Url exposing (Url)
|
import Spa.Url as Url exposing (Url)
|
||||||
|
|
||||||
|
@ -35,6 +37,9 @@ type alias App =
|
||||||
, versions : Maybe (List String)
|
, versions : Maybe (List String)
|
||||||
, icon : Maybe String
|
, icon : Maybe String
|
||||||
, status : String
|
, status : String
|
||||||
|
, slug : String
|
||||||
|
, default_branch : String
|
||||||
|
, website : Maybe String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +58,7 @@ type Status
|
||||||
|
|
||||||
init : Url Params -> ( Model, Cmd Msg )
|
init : Url Params -> ( Model, Cmd Msg )
|
||||||
init url =
|
init url =
|
||||||
( { url = url, status = Loading, readme = "" }, loadData )
|
( { url = url, status = Loading, readme = "" }, loadApp )
|
||||||
|
|
||||||
|
|
||||||
default_image : String
|
default_image : String
|
||||||
|
@ -74,20 +79,20 @@ update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
MorePlease ->
|
MorePlease ->
|
||||||
( { model | status = Loading }, loadData )
|
( { model | status = Loading }, loadApp )
|
||||||
|
|
||||||
GotApps result ->
|
GotApps result ->
|
||||||
case result of
|
case result of
|
||||||
Ok apps ->
|
Ok apps ->
|
||||||
let
|
let
|
||||||
-- TODO better way of getting a single app?
|
-- TODO better way of getting a single app?
|
||||||
apps_filtered = List.filter (\app -> app.name == model.url.params.app) apps
|
apps_filtered = List.filter (\app -> app.slug == model.url.params.app) apps
|
||||||
in
|
in
|
||||||
case List.head apps_filtered of
|
case List.head apps_filtered of
|
||||||
Nothing ->
|
Nothing ->
|
||||||
( { model | status = Failure }, Cmd.none )
|
( { model | status = Failure }, Cmd.none )
|
||||||
Just item ->
|
Just item ->
|
||||||
( { model | status = Success (item) }, Cmd.none )
|
( { model | status = Success (item) }, loadREADME item)
|
||||||
|
|
||||||
Err _ ->
|
Err _ ->
|
||||||
( { model | status = Failure }, Cmd.none )
|
( { model | status = Failure }, Cmd.none )
|
||||||
|
@ -194,17 +199,30 @@ viewApp app readme =
|
||||||
, text "code" ]
|
, text "code" ]
|
||||||
Nothing ->
|
Nothing ->
|
||||||
text ""
|
text ""
|
||||||
|
website_link =
|
||||||
|
case app.website of
|
||||||
|
Just link ->
|
||||||
|
case link of
|
||||||
|
"" ->
|
||||||
|
text ""
|
||||||
|
_ ->
|
||||||
|
a [ class "card-link", href link ]
|
||||||
|
[ i [ class "fas fa-home" ] []
|
||||||
|
, text "homepage" ]
|
||||||
|
Nothing ->
|
||||||
|
text ""
|
||||||
in
|
in
|
||||||
div [ class "col-md-6 col-sm-10 mb-3 offset-md-3 offset-sm-1" ]
|
div [ class "col-md-6 col-sm-10 mb-3 offset-md-3 offset-sm-1" ]
|
||||||
[ div [ class "card" ]
|
[ div [ class "card" ]
|
||||||
[ div [ class "card-header" ]
|
[ div [ class "card-header" ]
|
||||||
[ span [ class "card-link badge badge-secondary" ] [ text app.category ]
|
[ a
|
||||||
|
[ class "btn btn-sm border border-secondary card-link"
|
||||||
|
, href (Route.toString Route.Top)]
|
||||||
|
[ text "← back" ]
|
||||||
|
, span [ class "card-link badge badge-secondary" ] [ text app.category ]
|
||||||
, viewStatusBadge app
|
, viewStatusBadge app
|
||||||
, repository_link
|
, repository_link
|
||||||
, a [ class "card-link", href "http://example.com" ]
|
, website_link
|
||||||
[ i [ class "fas fa-home" ] []
|
|
||||||
, text "homepage" ]
|
|
||||||
-- FIXME: add actual homepage link to apps.json and render here
|
|
||||||
]
|
]
|
||||||
, img [ class "card-img-top", src icon_url, alt ("icon for " ++ app.name) ] []
|
, img [ class "card-img-top", src icon_url, alt ("icon for " ++ app.name) ] []
|
||||||
, div [ class "card-body" ]
|
, div [ class "card-body" ]
|
||||||
|
@ -219,19 +237,32 @@ viewApp app readme =
|
||||||
-- HTTP
|
-- HTTP
|
||||||
|
|
||||||
|
|
||||||
loadData : Cmd Msg
|
loadApp : Cmd Msg
|
||||||
loadData =
|
loadApp =
|
||||||
-- fetch app JSON and README in parallel
|
-- fetch app JSON and README in parallel
|
||||||
Cmd.batch
|
Http.get
|
||||||
[ Http.get
|
-- FIXME: change to absolute URL, if this works?
|
||||||
-- FIXME: change to absolute URL, if this works?
|
{ url = "http://localhost:8000/abra-apps-list.json"
|
||||||
{ url = "http://localhost:8000/abra-apps-list.json"
|
, expect = Http.expectJson GotApps appListDecoder }
|
||||||
, expect = Http.expectJson GotApps appListDecoder }
|
|
||||||
, Http.get
|
|
||||||
-- FIXME add branch name to apps.json, load actual README
|
loadREADME : App -> Cmd Msg
|
||||||
{ url = "http://localhost:1234/coop-cloud/adapt_authoring/raw/branch/main/README.md"
|
loadREADME app =
|
||||||
, expect = Http.expectString GotText }
|
let
|
||||||
]
|
repository_link =
|
||||||
|
case app.repository of
|
||||||
|
Just link ->
|
||||||
|
a [ class "card-link", href link ]
|
||||||
|
[ i [ class "fab fa-git-alt" ] []
|
||||||
|
, text "code" ]
|
||||||
|
Nothing ->
|
||||||
|
text ""
|
||||||
|
in
|
||||||
|
Http.get
|
||||||
|
-- FIXME add branch name to apps.json, load actual README
|
||||||
|
{ url = "http://localhost:1234/coop-cloud/" ++ app.slug ++ "/raw/branch/" ++ app.default_branch ++ "/README.md"
|
||||||
|
, expect = Http.expectString GotText }
|
||||||
|
|
||||||
|
|
||||||
featuresDecoder =
|
featuresDecoder =
|
||||||
-- get features.status if it's there
|
-- get features.status if it's there
|
||||||
|
@ -244,14 +275,16 @@ featuresDecoder =
|
||||||
|
|
||||||
appDecoder : Decode.Decoder App
|
appDecoder : Decode.Decoder App
|
||||||
appDecoder =
|
appDecoder =
|
||||||
Decode.map6
|
Decode.succeed App
|
||||||
App
|
|> andMap (Decode.field "name" Decode.string)
|
||||||
(Decode.field "name" Decode.string)
|
|> andMap (Decode.field "category" Decode.string)
|
||||||
(Decode.field "category" Decode.string)
|
|> andMap (Decode.maybe (Decode.field "repository" Decode.string))
|
||||||
(Decode.maybe (Decode.field "repository" Decode.string))
|
|> andMap (Decode.succeed Nothing)
|
||||||
(Decode.succeed Nothing)
|
|> andMap (Decode.maybe (Decode.field "icon" Decode.string))
|
||||||
(Decode.maybe (Decode.field "icon" Decode.string))
|
|> andMap (Decode.at [ "features" ] featuresDecoder)
|
||||||
(Decode.at [ "features" ] featuresDecoder)
|
|> andMap (Decode.field "slug" Decode.string)
|
||||||
|
|> andMap (Decode.field "default_branch" Decode.string)
|
||||||
|
|> andMap (Decode.maybe (Decode.field "website" Decode.string))
|
||||||
|
|
||||||
|
|
||||||
appListDecoder : Decode.Decoder (List App)
|
appListDecoder : Decode.Decoder (List App)
|
||||||
|
|
|
@ -33,6 +33,8 @@ type alias App =
|
||||||
, versions : Maybe (List String)
|
, versions : Maybe (List String)
|
||||||
, icon : Maybe String
|
, icon : Maybe String
|
||||||
, status : String
|
, status : String
|
||||||
|
, slug : String
|
||||||
|
, website : Maybe String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,9 +113,16 @@ viewStatusBadge app =
|
||||||
"badge-danger"
|
"badge-danger"
|
||||||
_ ->
|
_ ->
|
||||||
"badge-dark"
|
"badge-dark"
|
||||||
|
status_score =
|
||||||
|
case app.status of
|
||||||
|
"" ->
|
||||||
|
"?"
|
||||||
|
score ->
|
||||||
|
score
|
||||||
|
|
||||||
in
|
in
|
||||||
span [ class ("card-link badge " ++ status_class) ]
|
span [ class ("card-link badge " ++ status_class) ]
|
||||||
[ text ("Score: " ++ app.status) ]
|
[ text ("Score: " ++ status_score) ]
|
||||||
|
|
||||||
viewApp : App -> Html Msg
|
viewApp : App -> Html Msg
|
||||||
viewApp app =
|
viewApp app =
|
||||||
|
@ -136,7 +145,19 @@ viewApp app =
|
||||||
]
|
]
|
||||||
Nothing ->
|
Nothing ->
|
||||||
text ""
|
text ""
|
||||||
app_href = Route.toString <| Route.App_String { app = app.name }
|
website_link =
|
||||||
|
case app.website of
|
||||||
|
Just link ->
|
||||||
|
case link of
|
||||||
|
"" ->
|
||||||
|
text ""
|
||||||
|
_ ->
|
||||||
|
a [ class "card-link", href link ]
|
||||||
|
[ i [ class "fas fa-home" ] []
|
||||||
|
, text "homepage" ]
|
||||||
|
Nothing ->
|
||||||
|
text ""
|
||||||
|
app_href = Route.toString <| Route.App_String { app = app.slug }
|
||||||
in
|
in
|
||||||
div [ class "col-4 mb-3" ]
|
div [ class "col-4 mb-3" ]
|
||||||
[ div [ class "card" ]
|
[ div [ class "card" ]
|
||||||
|
@ -145,9 +166,7 @@ viewApp app =
|
||||||
[ h5 [ class "card-title" ]
|
[ h5 [ class "card-title" ]
|
||||||
[ a [ href app_href ] [ text app.name ] ]
|
[ a [ href app_href ] [ text app.name ] ]
|
||||||
, repository_link
|
, repository_link
|
||||||
, a [ class "card-link", href "http://example.com" ]
|
, website_link
|
||||||
[ i [ class "fas fa-home" ] []
|
|
||||||
, text "homepage" ]
|
|
||||||
, a [ class "card-link", href app_href ]
|
, a [ class "card-link", href app_href ]
|
||||||
[ i [ class "fas fa-book" ] []
|
[ i [ class "fas fa-book" ] []
|
||||||
, text "docs" ]
|
, text "docs" ]
|
||||||
|
@ -174,7 +193,7 @@ viewApps model =
|
||||||
Success apps ->
|
Success apps ->
|
||||||
div []
|
div []
|
||||||
[ div [ class "row" ]
|
[ div [ class "row" ]
|
||||||
(List.map viewApp (List.sortBy .name apps))
|
(List.map viewApp (List.sortBy (String.toLower << .name) apps))
|
||||||
]
|
]
|
||||||
|
|
||||||
-- HTTP
|
-- HTTP
|
||||||
|
@ -197,7 +216,7 @@ featuresDecoder =
|
||||||
|
|
||||||
appDecoder : Decode.Decoder App
|
appDecoder : Decode.Decoder App
|
||||||
appDecoder =
|
appDecoder =
|
||||||
Decode.map6
|
Decode.map8
|
||||||
App
|
App
|
||||||
(Decode.field "name" Decode.string)
|
(Decode.field "name" Decode.string)
|
||||||
(Decode.field "category" Decode.string)
|
(Decode.field "category" Decode.string)
|
||||||
|
@ -205,6 +224,8 @@ appDecoder =
|
||||||
(Decode.succeed Nothing)
|
(Decode.succeed Nothing)
|
||||||
(Decode.maybe (Decode.field "icon" Decode.string))
|
(Decode.maybe (Decode.field "icon" Decode.string))
|
||||||
(Decode.at [ "features" ] featuresDecoder)
|
(Decode.at [ "features" ] featuresDecoder)
|
||||||
|
(Decode.field "slug" Decode.string)
|
||||||
|
(Decode.maybe (Decode.field "website" Decode.string))
|
||||||
|
|
||||||
appListDecoder : Decode.Decoder (List App)
|
appListDecoder : Decode.Decoder (List App)
|
||||||
appListDecoder =
|
appListDecoder =
|
||||||
|
|
Loading…
Reference in New Issue