add model for package and option result

This commit is contained in:
Rok Garbas 2020-03-31 05:22:27 +02:00
parent ea09e01c89
commit 7ba9487c30
Failed to generate hash of commit
2 changed files with 102 additions and 28 deletions

View file

@ -11,7 +11,8 @@
"elm/html": "1.0.0", "elm/html": "1.0.0",
"elm/http": "2.0.0", "elm/http": "2.0.0",
"elm/json": "1.1.3", "elm/json": "1.1.3",
"elm/url": "1.0.0" "elm/url": "1.0.0",
"krisajenkins/remotedata": "6.0.1"
}, },
"indirect": { "indirect": {
"elm/bytes": "1.0.8", "elm/bytes": "1.0.8",

View file

@ -1,27 +1,41 @@
port module Main exposing (main) module Main exposing (main)
import Browser exposing (UrlRequest(..)) import Browser exposing (UrlRequest(..))
import Browser.Navigation as Nav exposing (Key) import Browser.Navigation as Nav exposing (Key)
import Html exposing (..) import Html
import Html.Attributes exposing (..) exposing
import Html.Events exposing (onClick, onInput) ( Html
, button
, div
, h1
, header
, input
, li
, text
, ul
)
import Html.Attributes
exposing
( class
, type_
, value
)
import Html.Events
exposing
( onClick
, onInput
)
import Http exposing (Error(..)) import Http exposing (Error(..))
import Json.Decode as Decode
import Url exposing (Url) import Url exposing (Url)
import Url.Parser as UrlParser exposing ((</>), (<?>), Parser) import Url.Parser as UrlParser
exposing
( (<?>)
, Parser
)
import Url.Parser.Query as UrlParserQuery import Url.Parser.Query as UrlParserQuery
-- ---------------------------
-- PORTS
-- ---------------------------
port toJs : String -> Cmd msg
-- --------------------------- -- ---------------------------
-- MODEL -- MODEL
-- --------------------------- -- ---------------------------
@ -35,7 +49,7 @@ type alias Model =
type alias SearchModel = type alias SearchModel =
{ query : String { query : String
, results : List String , results : List SearchResult
} }
@ -43,12 +57,53 @@ type Page
= Search SearchModel = Search SearchModel
type SearchResult
= Package SearchResultPackage
| Option SearchResultOption
type alias SearchResultPackage =
{ attribute_name : String
, name : String
, version : String
, description : String
, longDescription : String
, license : List SearchResultPackageLicense
, position : String
, homepage : String
}
type alias SearchResultOption =
{ option_name : String
, description : String
, type_ : String
, default : String
, example : String
, source : String
}
type alias SearchResultPackageLicense =
{ fullName : String
, url : String
}
type alias SearchResultPackageMaintainer =
{ name : String
, email : String
, github : String
}
emptySearch : Page
emptySearch = emptySearch =
Search { query = "", results = [] } Search { query = "", results = [] }
init : Int -> Url -> Key -> ( Model, Cmd Msg ) init : Int -> Url -> Key -> ( Model, Cmd Msg )
init flags url key = init _ url key =
( { key = key ( { key = key
, page = UrlParser.parse urlParser url |> Maybe.withDefault emptySearch , page = UrlParser.parse urlParser url |> Maybe.withDefault emptySearch
} }
@ -102,7 +157,7 @@ type Msg
initPage : Page -> Cmd Msg initPage : Page -> Cmd Msg
initPage page = initPage page =
case page of case page of
Search model -> Search _ ->
Cmd.none Cmd.none
@ -116,9 +171,21 @@ update message model =
let let
newModel = newModel =
{ model | page = UrlParser.parse urlParser url |> Maybe.withDefault model.page } { model | page = UrlParser.parse urlParser url |> Maybe.withDefault model.page }
in
( { newModel packages =
| page = [ Package
{ attribute_name = "firefox"
, name = "firefox"
, version = "74.0"
, description = "A web browser built from Firefox source tree (with plugins: )"
, longDescription = ""
, license = [ { fullName = "Mozilla Public License 2.0", url = "http://spdx.org/licenses/MPL-2.0.html" } ]
, position = ""
, homepage = "http://www.mozilla.com/en-US/firefox/"
}
]
newPage =
case newModel.page of case newModel.page of
Search searchModel -> Search searchModel ->
Search Search
@ -128,10 +195,11 @@ update message model =
[] []
else else
[ "result1" ] packages
} }
} in
, initPage model.page ( { newModel | page = newPage }
, initPage newPage
) )
SearchPageInput query -> SearchPageInput query ->
@ -186,9 +254,14 @@ searchPage model =
] ]
searchPageResult : String -> Html Msg searchPageResult : SearchResult -> Html Msg
searchPageResult item = searchPageResult result =
li [] [ text item ] case result of
Package package ->
li [] [ text package.attribute_name ]
Option option ->
li [] [ text option.option_name ]