Merge f8ccd9a993d977641fd370069d4070458bc75f16 into 2d1117eac2bd14930ede872549e3f59e3b3c8965
This commit is contained in:
commit
4a4a6f8ea2
@ -1,20 +1,18 @@
|
|||||||
|
import Browser exposing (element)
|
||||||
import Html exposing (Html, div, h1, input, text)
|
import Html exposing (Html, div, h1, input, text)
|
||||||
import Html.Attributes exposing (placeholder)
|
import Html.Attributes exposing (placeholder)
|
||||||
import Html.Events exposing (onInput)
|
import Html.Events exposing (onInput)
|
||||||
import Table
|
import Table
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main =
|
main =
|
||||||
Html.program
|
Browser.element
|
||||||
{ init = init presidents
|
{ init = (init presidents)
|
||||||
, update = update
|
, update = update
|
||||||
, view = view
|
, view = view
|
||||||
, subscriptions = \_ -> Sub.none
|
, subscriptions = \_ -> Sub.none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- MODEL
|
-- MODEL
|
||||||
|
|
||||||
|
|
||||||
@ -24,9 +22,10 @@ type alias Model =
|
|||||||
, query : String
|
, query : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type alias Flags = {}
|
||||||
|
|
||||||
init : List Person -> ( Model, Cmd Msg )
|
init : (List Person) -> Flags -> ( Model, Cmd Msg )
|
||||||
init people =
|
init people _ =
|
||||||
let
|
let
|
||||||
model =
|
model =
|
||||||
{ people = people
|
{ people = people
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
|
import Browser exposing ( element)
|
||||||
import Html exposing (Html, Attribute, div, h1, input, p, text)
|
import Html exposing (Html, Attribute, div, h1, input, p, text)
|
||||||
import Html.Attributes exposing (checked, style, type_)
|
import Html.Attributes exposing (checked, style, type_)
|
||||||
import Html.Events exposing (onClick)
|
import Html.Events exposing (onClick)
|
||||||
import Html.Lazy exposing (lazy)
|
import Html.Lazy exposing (lazy)
|
||||||
import Table exposing (defaultCustomizations)
|
import Table exposing (defaultCustomizations)
|
||||||
import Time exposing (Time)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main =
|
main =
|
||||||
Html.program
|
Browser.element
|
||||||
{ init = init missionSights
|
{ init = init missionSights
|
||||||
, update = update
|
, update = update
|
||||||
, view = view
|
, view = view
|
||||||
@ -25,9 +23,16 @@ type alias Model =
|
|||||||
, tableState : Table.State
|
, tableState : Table.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type alias TimeSpan =
|
||||||
|
{ hours: Float
|
||||||
|
, minutes: Float
|
||||||
|
}
|
||||||
|
|
||||||
init : List Sight -> ( Model, Cmd Msg )
|
type alias Flags = {}
|
||||||
init sights =
|
|
||||||
|
|
||||||
|
init : List Sight -> Flags -> ( Model, Cmd Msg )
|
||||||
|
init sights _ =
|
||||||
let
|
let
|
||||||
model =
|
model =
|
||||||
{ sights = sights
|
{ sights = sights
|
||||||
@ -91,31 +96,36 @@ viewSummary allSights =
|
|||||||
sights ->
|
sights ->
|
||||||
let
|
let
|
||||||
time =
|
time =
|
||||||
List.sum (List.map .time sights)
|
sumTimeSpan (List.map .time sights)
|
||||||
|
|
||||||
price =
|
price =
|
||||||
List.sum (List.map .price sights)
|
List.sum (List.map .price sights)
|
||||||
|
|
||||||
summary =
|
summary =
|
||||||
"That is " ++ timeToString time ++ " of fun, costing $" ++ toString price
|
"That is " ++ timeToString time ++ " of fun, costing $" ++ String.fromFloat price
|
||||||
in
|
in
|
||||||
p [] [ text summary ]
|
p [] [ text summary ]
|
||||||
|
|
||||||
|
sumTimeSpan : List TimeSpan -> TimeSpan
|
||||||
|
sumTimeSpan spans =
|
||||||
|
{ hours = List.sum (List.map (.hours) spans)
|
||||||
|
, minutes = List.sum (List.map (.minutes) spans)
|
||||||
|
}
|
||||||
|
|
||||||
timeToString : Time -> String
|
timeToString : TimeSpan -> String
|
||||||
timeToString time =
|
timeToString time =
|
||||||
let
|
let
|
||||||
hours =
|
hours =
|
||||||
case floor (Time.inHours time) of
|
case floor (time.hours) of
|
||||||
0 -> ""
|
0 -> ""
|
||||||
1 -> "1 hour"
|
1 -> "1 hour"
|
||||||
n -> toString n ++ " hours"
|
n -> String.fromInt n ++ " hours"
|
||||||
|
|
||||||
minutes =
|
minutes =
|
||||||
case rem (round (Time.inMinutes time)) 60 of
|
case modBy 60 (round (time.minutes)) of
|
||||||
0 -> ""
|
0 -> ""
|
||||||
1 -> "1 minute"
|
1 -> "1 minute"
|
||||||
n -> toString n ++ " minutes"
|
n -> String.fromInt n ++ " minutes"
|
||||||
in
|
in
|
||||||
hours ++ " " ++ minutes
|
hours ++ " " ++ minutes
|
||||||
|
|
||||||
@ -144,7 +154,7 @@ config =
|
|||||||
toRowAttrs : Sight -> List (Attribute Msg)
|
toRowAttrs : Sight -> List (Attribute Msg)
|
||||||
toRowAttrs sight =
|
toRowAttrs sight =
|
||||||
[ onClick (ToggleSelected sight.name)
|
[ onClick (ToggleSelected sight.name)
|
||||||
, style [ ("background", if sight.selected then "#CEFAF8" else "white") ]
|
, style "backgroundColor" (if sight.selected then "#CEFAF8" else "white")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -153,10 +163,9 @@ timeColumn =
|
|||||||
Table.customColumn
|
Table.customColumn
|
||||||
{ name = "Time"
|
{ name = "Time"
|
||||||
, viewData = timeToString << .time
|
, viewData = timeToString << .time
|
||||||
, sorter = Table.increasingOrDecreasingBy .time
|
, sorter = Table.unsortable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
checkboxColumn : Table.Column Sight Msg
|
checkboxColumn : Table.Column Sight Msg
|
||||||
checkboxColumn =
|
checkboxColumn =
|
||||||
Table.veryCustomColumn
|
Table.veryCustomColumn
|
||||||
@ -179,7 +188,7 @@ viewCheckbox {selected} =
|
|||||||
|
|
||||||
type alias Sight =
|
type alias Sight =
|
||||||
{ name : String
|
{ name : String
|
||||||
, time : Time
|
, time : TimeSpan
|
||||||
, price : Float
|
, price : Float
|
||||||
, rating : Float
|
, rating : Float
|
||||||
, selected : Bool
|
, selected : Bool
|
||||||
@ -188,12 +197,12 @@ type alias Sight =
|
|||||||
|
|
||||||
missionSights : List Sight
|
missionSights : List Sight
|
||||||
missionSights =
|
missionSights =
|
||||||
[ Sight "Eat a Burrito" (30 * Time.minute) 7 4.6 False
|
[ Sight "Eat a Burrito" ( TimeSpan 0 30 ) 7 4.6 False
|
||||||
, Sight "Buy drugs in Dolores park" Time.hour 20 4.8 False
|
, Sight "Buy drugs in Dolores park" ( TimeSpan 1 0 ) 20 4.8 False
|
||||||
, Sight "Armory Tour" (1.5 * Time.hour) 27 4.5 False
|
, Sight "Armory Tour" ( TimeSpan 1 30 ) 27 4.5 False
|
||||||
, Sight "Tartine Bakery" Time.hour 10 4.1 False
|
, Sight "Tartine Bakery" ( TimeSpan 1 0 ) 10 4.1 False
|
||||||
, Sight "Have Brunch" (2 * Time.hour) 25 4.2 False
|
, Sight "Have Brunch" ( TimeSpan 2 0 ) 25 4.2 False
|
||||||
, Sight "Get catcalled at BART" (5 * Time.minute) 0 1.6 False
|
, Sight "Get catcalled at BART" ( TimeSpan 0 5 ) 0 1.6 False
|
||||||
, Sight "Buy a painting at \"Stuff\"" (45 * Time.minute) 400 4.7 False
|
, Sight "Buy a painting at \"Stuff\"" ( TimeSpan 0 45 ) 400 4.7 False
|
||||||
, Sight "McDonalds at 24th" (20 * Time.minute) 5 2.8 False
|
, Sight "McDonalds at 24th" ( TimeSpan 0 20 ) 5 2.8 False
|
||||||
]
|
]
|
||||||
|
@ -23,17 +23,17 @@ Then navigate to `1-presidents.elm` or `2-travel.elm` from [localhost:8000](http
|
|||||||
To see the examples *with* CSS, run the following commands:
|
To see the examples *with* CSS, run the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/evancz/elm-sortable-table.git
|
git clone https://github.com/NoRedInk/elm-sortable-table.git
|
||||||
cd elm-sortable-table
|
cd elm-sortable-table
|
||||||
cd examples
|
cd examples
|
||||||
elm-make 1-presidents.elm --yes --output=elm.js
|
elm make 1-presidents.elm --output=elm.js
|
||||||
elm-reactor
|
elm-reactor
|
||||||
```
|
```
|
||||||
|
|
||||||
Then open [localhost:8000/index.html](http://localhost:8000/index.html) in your browser. That HTML file loads in some CSS and whatever code is in `elm.js`. So if you want to see the second example with CSS, you can compile it like this:
|
Then open [localhost:8000/index.html](http://localhost:8000/index.html) in your browser. That HTML file loads in some CSS and whatever code is in `elm.js`. So if you want to see the second example with CSS, you can compile it like this:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
elm-make 2-travel.elm --yes --output=elm.js
|
elm make 2-travel.elm --output=elm.js
|
||||||
```
|
```
|
||||||
|
|
||||||
As you make changes, you will want to recompile the Elm code with `elm-make`.
|
As you make changes, you will want to recompile the Elm code with `elm-make`.
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.1",
|
|
||||||
"summary": "helpful summary of your project, less than 80 characters",
|
|
||||||
"repository": "https://github.com/user/project.git",
|
|
||||||
"license": "BSD3",
|
|
||||||
"source-directories": [
|
|
||||||
"."
|
|
||||||
],
|
|
||||||
"exposed-modules": [],
|
|
||||||
"dependencies": {
|
|
||||||
"elm-lang/core": "5.0.0 <= v < 6.0.0",
|
|
||||||
"elm-lang/html": "2.0.0 <= v < 3.0.0",
|
|
||||||
"evancz/elm-sortable-table": "1.0.1 <= v < 2.0.0"
|
|
||||||
},
|
|
||||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
|
||||||
}
|
|
5855
examples/elm.js
Normal file
5855
examples/elm.js
Normal file
File diff suppressed because it is too large
Load Diff
25
examples/elm.json
Normal file
25
examples/elm.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"type": "application",
|
||||||
|
"source-directories": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"elm-version": "0.19.0",
|
||||||
|
"dependencies": {
|
||||||
|
"direct": {
|
||||||
|
"NoRedInk/elm-sortable-table": "1.0.0",
|
||||||
|
"elm/browser": "1.0.1",
|
||||||
|
"elm/core": "1.0.2",
|
||||||
|
"elm/html": "1.0.0",
|
||||||
|
"elm/time": "1.0.0"
|
||||||
|
},
|
||||||
|
"indirect": {
|
||||||
|
"elm/json": "1.1.2",
|
||||||
|
"elm/url": "1.0.0",
|
||||||
|
"elm/virtual-dom": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test-dependencies": {
|
||||||
|
"direct": {},
|
||||||
|
"indirect": {}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,12 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript">Elm.Main.fullscreen();</script>
|
<div id="elm-mount"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
Elm.Main.init({
|
||||||
|
node: document.getElementById('elm-mount')
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user