Show score and icon
This commit is contained in:
parent
4d9b403a68
commit
e932010e81
|
@ -25,7 +25,6 @@ page =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- VIEW
|
-- VIEW
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Pages.Top exposing (Model, Msg, Params, page)
|
module Pages.Top exposing (Model, Msg, Params, page)
|
||||||
|
|
||||||
import Html exposing (Html, button, div, h2, h5, img, text, ul, li, a)
|
import Html exposing (Html, button, div, h2, h5, img, text, ul, li, a, p, span)
|
||||||
import Html.Attributes exposing (src, style, class)
|
import Html.Attributes exposing (src, style, class, alt, href)
|
||||||
import Html.Events exposing (onClick)
|
import Html.Events exposing (onClick)
|
||||||
import Http
|
import Http
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
|
@ -30,6 +30,8 @@ type alias App =
|
||||||
, category : String
|
, category : String
|
||||||
, repository : Maybe String
|
, repository : Maybe String
|
||||||
, versions : Maybe (List String)
|
, versions : Maybe (List String)
|
||||||
|
, icon : Maybe String
|
||||||
|
, status : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +46,10 @@ init { params } =
|
||||||
( Loading, loadApps )
|
( Loading, loadApps )
|
||||||
|
|
||||||
|
|
||||||
|
default_image : String
|
||||||
|
default_image = "http://localhost:8000/logo.png"
|
||||||
|
|
||||||
|
|
||||||
-- UPDATE
|
-- UPDATE
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,26 +84,64 @@ subscriptions model =
|
||||||
|
|
||||||
view : Model -> Document Msg
|
view : Model -> Document Msg
|
||||||
view model =
|
view model =
|
||||||
{ title = "Examples.Cats"
|
{ title = "abra apps"
|
||||||
, body = [ body model ]
|
, body = [ body model ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
body : Model -> Html Msg
|
body : Model -> Html Msg
|
||||||
body model =
|
body model =
|
||||||
div []
|
div [ class "pt-3" ]
|
||||||
[ viewApps model
|
[ viewApps model
|
||||||
]
|
]
|
||||||
|
|
||||||
|
renderStatusBadge : App -> Html Msg
|
||||||
|
renderStatusBadge app =
|
||||||
|
let
|
||||||
|
status_class =
|
||||||
|
case app.status of
|
||||||
|
"1" ->
|
||||||
|
"badge-success"
|
||||||
|
"2" ->
|
||||||
|
"badge-info"
|
||||||
|
"3" ->
|
||||||
|
"badge-warning"
|
||||||
|
"4" ->
|
||||||
|
"badge-danger"
|
||||||
|
_ ->
|
||||||
|
"badge-dark"
|
||||||
|
in
|
||||||
|
span [ class ("card-link badge " ++ status_class) ]
|
||||||
|
[ text ("Score: " ++ app.status) ]
|
||||||
|
|
||||||
viewAppName : App -> Html Msg
|
viewAppName : App -> Html Msg
|
||||||
viewAppName app =
|
viewAppName app =
|
||||||
div [ class "col-4" ]
|
let
|
||||||
|
icon_url =
|
||||||
|
case app.icon of
|
||||||
|
Just "" ->
|
||||||
|
default_image
|
||||||
|
Just i ->
|
||||||
|
i
|
||||||
|
Nothing ->
|
||||||
|
default_image
|
||||||
|
repository_link =
|
||||||
|
case app.repository of
|
||||||
|
Just i ->
|
||||||
|
a [ class "card-link", href i ] [ text "Code" ]
|
||||||
|
Nothing ->
|
||||||
|
text ""
|
||||||
|
in
|
||||||
|
div [ class "col-4 mb-3" ]
|
||||||
[ div [ class "card" ]
|
[ div [ class "card" ]
|
||||||
[ div [ class "card-body" ]
|
[ img [ class "card-img-top", src icon_url, alt ("icon for " ++ app.name) ] []
|
||||||
[ h5 [ class "card-title" ] [ text app.name ]
|
|
||||||
, div [ class "card-body" ]
|
, div [ class "card-body" ]
|
||||||
[ text app.category
|
[ h5 [ class "card-title" ] [ text app.name ]
|
||||||
|
, repository_link
|
||||||
]
|
]
|
||||||
|
, div [ class "card-footer" ]
|
||||||
|
[ span [ class "card-link badge badge-secondary" ] [ text app.category ]
|
||||||
|
, renderStatusBadge app
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -120,8 +164,6 @@ viewApps model =
|
||||||
(List.map viewAppName (List.sortBy .name apps))
|
(List.map viewAppName (List.sortBy .name apps))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- HTTP
|
-- HTTP
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,15 +174,24 @@ loadApps =
|
||||||
, expect = Http.expectJson GotApps appListDecoder
|
, expect = Http.expectJson GotApps appListDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
featuresDecoder =
|
||||||
|
(Decode.oneOf
|
||||||
|
[ Decode.at [ "status" ] Decode.string
|
||||||
|
, Decode.succeed ""
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
appDecoder : Decode.Decoder App
|
appDecoder : Decode.Decoder App
|
||||||
appDecoder =
|
appDecoder =
|
||||||
Decode.map4
|
Decode.map6
|
||||||
App
|
App
|
||||||
(Decode.field "name" Decode.string)
|
(Decode.field "name" Decode.string)
|
||||||
(Decode.field "category" Decode.string)
|
(Decode.field "category" Decode.string)
|
||||||
|
(Decode.maybe (Decode.field "repository" Decode.string))
|
||||||
(Decode.succeed Nothing)
|
(Decode.succeed Nothing)
|
||||||
(Decode.succeed Nothing)
|
(Decode.maybe (Decode.field "icon" Decode.string))
|
||||||
|
(Decode.at [ "features" ] featuresDecoder)
|
||||||
|
|
||||||
appListDecoder : Decode.Decoder (List App)
|
appListDecoder : Decode.Decoder (List App)
|
||||||
appListDecoder =
|
appListDecoder =
|
||||||
|
|
|
@ -68,8 +68,8 @@ view :
|
||||||
view { page, toMsg } model =
|
view { page, toMsg } model =
|
||||||
{ title = page.title
|
{ title = page.title
|
||||||
, body =
|
, body =
|
||||||
[ div []
|
[ div [ class "bg-dark" ]
|
||||||
[ nav [ class "navbar navbar-expand-lg navbar-dark bg-dark" ]
|
[ nav [ class "navbar navbar-expand-lg navbar-dark bg-primary sticky-top" ]
|
||||||
[ a [ class "navbar-brand", href (Route.toString Route.Top) ] [ text "abra apps" ]
|
[ a [ class "navbar-brand", href (Route.toString Route.Top) ] [ text "abra apps" ]
|
||||||
, ul [ class "navbar-nav" ]
|
, ul [ class "navbar-nav" ]
|
||||||
[ li [ class "nav-tem" ] [ a [ class "nav-link", href (Route.toString Route.About) ] [ text "about" ] ]
|
[ li [ class "nav-tem" ] [ a [ class "nav-link", href (Route.toString Route.About) ] [ text "about" ] ]
|
||||||
|
|
Loading…
Reference in New Issue