Introduce real dates instead of using strings.

This commit is contained in:
Vidir Valberg Gudmundsson 2017-07-17 21:48:56 +02:00
parent 733c36d00c
commit 540c8c1156
9 changed files with 105 additions and 73 deletions

View File

@ -14,7 +14,8 @@
"elm-lang/navigation": "2.1.0 <= v < 3.0.0",
"elm-lang/websocket": "1.0.2 <= v < 2.0.0",
"evancz/elm-markdown": "3.0.2 <= v < 4.0.0",
"evancz/url-parser": "2.0.1 <= v < 3.0.0"
"evancz/url-parser": "2.0.1 <= v < 3.0.0",
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}

View File

@ -9,6 +9,12 @@ import Models exposing (Day, Speaker, Event, EventInstance, EventLocation, Event
import Json.Decode exposing (int, string, float, list, bool, dict, Decoder)
import Json.Decode.Pipeline exposing (decode, required, optional, hardcoded)
import Date exposing (Month(..))
-- External modules
import Date.Extra as Date
-- DECODERS
@ -29,7 +35,7 @@ dayDecoder : Decoder Day
dayDecoder =
decode Day
|> required "day_name" string
|> required "iso" string
|> required "iso" dateDecoder
|> required "repr" string
@ -48,6 +54,19 @@ eventDecoder =
|> required "speakers" (list speakerDecoder)
dateDecoder =
let
unpacked x =
case Date.fromIsoString x of
Just value ->
value
Nothing ->
Date.fromParts 1970 Jan 1 0 0 0 0
in
Json.Decode.map unpacked string
eventInstanceDecoder : Decoder EventInstance
eventInstanceDecoder =
decode EventInstance
@ -59,8 +78,8 @@ eventInstanceDecoder =
|> required "event_type" string
|> required "bg-color" string
|> required "fg-color" string
|> required "from" string
|> required "to" string
|> required "from" dateDecoder
|> required "to" dateDecoder
|> required "timeslots" float
|> required "location" string
|> required "location_icon" string
@ -85,7 +104,7 @@ eventTypeDecoder =
|> required "light_text" bool
initDataDecoder : Decoder (Flags -> Day -> Filter -> Route -> Model)
initDataDecoder : Decoder (Flags -> Maybe Day -> Filter -> Route -> Model)
initDataDecoder =
decode Model
|> required "days" (list dayDecoder)

View File

@ -38,7 +38,7 @@ init flags location =
Filter [] []
initModel =
(Model [] [] [] [] [] flags allDaysDay emptyFilter currentRoute)
(Model [] [] [] [] [] flags Nothing emptyFilter currentRoute)
-- To ensure we load data on right momens we call update with the
-- OnLocationChange message which is in charge of all that

View File

@ -1,9 +1,11 @@
module Models exposing (..)
import Date exposing (Date, now)
type Route
= OverviewRoute
| DayRoute DayIso
| DayRoute String
| EventRoute EventSlug
| NotFoundRoute
@ -15,7 +17,7 @@ type alias Model =
, eventTypes : List EventType
, events : List Event
, flags : Flags
, activeDay : Day
, activeDay : Maybe Day
, filter : Filter
, route : Route
}
@ -27,13 +29,9 @@ type alias Filter =
}
type alias DayIso =
String
type alias Day =
{ day_name : String
, iso : DayIso
, date : Date
, repr : String
}
@ -60,8 +58,8 @@ type alias EventInstance =
, eventType : String
, backgroundColor : String
, forgroundColor : String
, from : String
, to : String
, from : Date
, to : Date
, timeslots : Float
, location : String
, locationIcon : String
@ -78,26 +76,6 @@ type alias Event =
}
emptyEventInstance : EventInstance
emptyEventInstance =
{ title = "This should not happen!"
, slug = "this-should-not-happen"
, id = 0
, url = ""
, eventSlug = ""
, eventType = ""
, backgroundColor = ""
, forgroundColor = ""
, from = ""
, to = ""
, timeslots = 0.0
, location = ""
, locationIcon = ""
, videoRecording = False
, videoUrl = ""
}
type alias EventLocation =
{ name : String
, slug : String
@ -119,8 +97,3 @@ type alias Flags =
, ics_button_href : String
, camp_slug : String
}
allDaysDay : Day
allDaysDay =
Day "All Days" "" ""

View File

@ -2,7 +2,7 @@ module Update exposing (update)
-- Local modules
import Models exposing (Model, Route(OverviewRoute, EventRoute), emptyEventInstance, allDaysDay, Filter)
import Models exposing (Model, Route(OverviewRoute, EventRoute), Filter)
import Messages exposing (Msg(..))
import Decoders exposing (webSocketActionDecoder, initDataDecoder, eventDecoder)
import Routing exposing (parseLocation)
@ -31,7 +31,7 @@ update msg model =
Ok m ->
let
newModel_ =
m model.flags allDaysDay (Filter [] []) model.route
m model.flags Nothing (Filter [] []) model.route
in
{ model
| days = newModel_.days
@ -60,7 +60,7 @@ update msg model =
newModel ! []
MakeActiveday day ->
{ model | activeDay = day } ! []
{ model | activeDay = Just day } ! []
ToggleEventTypeFilter eventType ->
let

View File

@ -11,34 +11,57 @@ import Messages exposing (Msg(..))
import Html exposing (Html, text, a, div)
import Html.Attributes exposing (class, classList, href, id)
import Html.Events exposing (onClick)
import Date.Extra as Date
dayPicker : Model -> Html Msg
dayPicker model =
div [ class "row" ]
[ div [ id "schedule-days", class "btn-group" ]
(List.map (\day -> dayButton day model.activeDay) (allDaysDay :: model.days))
]
let
isAllDaysActive =
case model.activeDay of
Just activeDay ->
False
dayButton : Day -> Day -> Html Msg
dayButton day activeDay =
a
[ classList
[ ( "btn", True )
, ( "btn-default", day /= activeDay )
, ( "btn-primary", day == activeDay )
Nothing ->
True
in
div [ class "row" ]
[ div [ id "schedule-days", class "btn-group" ]
([ a
[ classList
[ ( "btn", True )
, ( "btn-default", not isAllDaysActive )
, ( "btn-primary", isAllDaysActive )
]
, href ("#")
]
[ text "All Days"
]
]
++ (List.map (\day -> dayButton day model.activeDay) model.days)
)
]
, onClick (MakeActiveday day)
, href
("#"
++ case day.iso of
"" ->
""
iso ->
"day/" ++ iso
)
]
[ text day.day_name
]
dayButton : Day -> Maybe Day -> Html Msg
dayButton day activeDay =
let
isActive =
case activeDay of
Just activeDay ->
day == activeDay
Nothing ->
False
in
a
[ classList
[ ( "btn", True )
, ( "btn-default", not isActive )
, ( "btn-primary", isActive )
]
, href ("#day/" ++ (Date.toFormattedString "y-M-d" day.date))
, onClick (MakeActiveday day)
]
[ text day.day_name
]

View File

@ -3,17 +3,21 @@ module Views.DayView exposing (dayView)
-- Local modules
import Messages exposing (Msg(..))
import Models exposing (Model, DayIso)
import Models exposing (Model)
import Views.FilterView exposing (filterSidebar)
-- External modules
import Html exposing (Html, text, div, ul, li, span, i, h4)
import Html exposing (Html, text, div, ul, li, span, i, h4, table)
dayView : DayIso -> Model -> Html Msg
-- Something about having a column per location!!
dayView : String -> Model -> Html Msg
dayView dayIso model =
div []
[ filterSidebar model
, table [] []
]

View File

@ -11,6 +11,7 @@ import Models exposing (..)
import Html exposing (Html, text, div, ul, li, span, i, h4, a, p, hr)
import Html.Attributes exposing (class, classList, href)
import Markdown
import Date.Extra as Date
eventDetailView : EventSlug -> Model -> Html Msg
@ -74,5 +75,9 @@ eventInstancesList eventSlug eventInstances =
eventInstanceItem : EventInstance -> Html Msg
eventInstanceItem eventInstance =
li []
[ text (eventInstance.from ++ " to " ++ eventInstance.to)
[ text
((Date.toFormattedString "y-MM-dd HH:mm" eventInstance.from)
++ " to "
++ (Date.toFormattedString "y-MM-d HH:mm" eventInstance.to)
)
]

View File

@ -12,6 +12,7 @@ import Views.FilterView exposing (filterSidebar)
import Html exposing (Html, text, div, ul, li, span, i, h4, p, small, a)
import Html.Lazy exposing (lazy, lazy2)
import Html.Attributes exposing (class, classList, href, style)
import Date.Extra as Date exposing (Interval(..), equalBy)
scheduleOverviewView : Model -> Html Msg
@ -50,7 +51,8 @@ dayRowView day model =
filteredEventInstances =
List.filter
(\eventInstance ->
((String.slice 0 10 eventInstance.from) == day.iso)
(Date.equalBy Month eventInstance.from day.date)
&& (Date.equalBy Date.Day eventInstance.from day.date)
&& List.member eventInstance.location locations
&& List.member eventInstance.eventType types
)
@ -75,7 +77,12 @@ dayEventInstanceView eventInstance =
]
]
[ small []
[ text ((String.slice 11 16 eventInstance.from) ++ " - " ++ (String.slice 11 16 eventInstance.to)) ]
[ text
((Date.toFormattedString "H:m" eventInstance.from)
++ " - "
++ (Date.toFormattedString "H:m" eventInstance.to)
)
]
, i [ classList [ ( "fa", True ), ( "fa-" ++ eventInstance.locationIcon, True ), ( "pull-right", True ) ] ] []
, p
[]