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/navigation": "2.1.0 <= v < 3.0.0",
"elm-lang/websocket": "1.0.2 <= v < 2.0.0", "elm-lang/websocket": "1.0.2 <= v < 2.0.0",
"evancz/elm-markdown": "3.0.2 <= v < 4.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" "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 exposing (int, string, float, list, bool, dict, Decoder)
import Json.Decode.Pipeline exposing (decode, required, optional, hardcoded) import Json.Decode.Pipeline exposing (decode, required, optional, hardcoded)
import Date exposing (Month(..))
-- External modules
import Date.Extra as Date
-- DECODERS -- DECODERS
@ -29,7 +35,7 @@ dayDecoder : Decoder Day
dayDecoder = dayDecoder =
decode Day decode Day
|> required "day_name" string |> required "day_name" string
|> required "iso" string |> required "iso" dateDecoder
|> required "repr" string |> required "repr" string
@ -48,6 +54,19 @@ eventDecoder =
|> required "speakers" (list speakerDecoder) |> 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 : Decoder EventInstance
eventInstanceDecoder = eventInstanceDecoder =
decode EventInstance decode EventInstance
@ -59,8 +78,8 @@ eventInstanceDecoder =
|> required "event_type" string |> required "event_type" string
|> required "bg-color" string |> required "bg-color" string
|> required "fg-color" string |> required "fg-color" string
|> required "from" string |> required "from" dateDecoder
|> required "to" string |> required "to" dateDecoder
|> required "timeslots" float |> required "timeslots" float
|> required "location" string |> required "location" string
|> required "location_icon" string |> required "location_icon" string
@ -85,7 +104,7 @@ eventTypeDecoder =
|> required "light_text" bool |> required "light_text" bool
initDataDecoder : Decoder (Flags -> Day -> Filter -> Route -> Model) initDataDecoder : Decoder (Flags -> Maybe Day -> Filter -> Route -> Model)
initDataDecoder = initDataDecoder =
decode Model decode Model
|> required "days" (list dayDecoder) |> required "days" (list dayDecoder)

View file

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

View file

@ -1,9 +1,11 @@
module Models exposing (..) module Models exposing (..)
import Date exposing (Date, now)
type Route type Route
= OverviewRoute = OverviewRoute
| DayRoute DayIso | DayRoute String
| EventRoute EventSlug | EventRoute EventSlug
| NotFoundRoute | NotFoundRoute
@ -15,7 +17,7 @@ type alias Model =
, eventTypes : List EventType , eventTypes : List EventType
, events : List Event , events : List Event
, flags : Flags , flags : Flags
, activeDay : Day , activeDay : Maybe Day
, filter : Filter , filter : Filter
, route : Route , route : Route
} }
@ -27,13 +29,9 @@ type alias Filter =
} }
type alias DayIso =
String
type alias Day = type alias Day =
{ day_name : String { day_name : String
, iso : DayIso , date : Date
, repr : String , repr : String
} }
@ -60,8 +58,8 @@ type alias EventInstance =
, eventType : String , eventType : String
, backgroundColor : String , backgroundColor : String
, forgroundColor : String , forgroundColor : String
, from : String , from : Date
, to : String , to : Date
, timeslots : Float , timeslots : Float
, location : String , location : String
, locationIcon : 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 = type alias EventLocation =
{ name : String { name : String
, slug : String , slug : String
@ -119,8 +97,3 @@ type alias Flags =
, ics_button_href : String , ics_button_href : String
, camp_slug : String , camp_slug : String
} }
allDaysDay : Day
allDaysDay =
Day "All Days" "" ""

View file

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

View file

@ -11,34 +11,57 @@ import Messages exposing (Msg(..))
import Html exposing (Html, text, a, div) import Html exposing (Html, text, a, div)
import Html.Attributes exposing (class, classList, href, id) import Html.Attributes exposing (class, classList, href, id)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Date.Extra as Date
dayPicker : Model -> Html Msg dayPicker : Model -> Html Msg
dayPicker model = dayPicker model =
div [ class "row" ] let
[ div [ id "schedule-days", class "btn-group" ] isAllDaysActive =
(List.map (\day -> dayButton day model.activeDay) (allDaysDay :: model.days)) case model.activeDay of
] Just activeDay ->
False
Nothing ->
dayButton : Day -> Day -> Html Msg True
dayButton day activeDay = in
a div [ class "row" ]
[ classList [ div [ id "schedule-days", class "btn-group" ]
[ ( "btn", True ) ([ a
, ( "btn-default", day /= activeDay ) [ classList
, ( "btn-primary", day == activeDay ) [ ( "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 dayButton : Day -> Maybe Day -> Html Msg
) dayButton day activeDay =
] let
[ text day.day_name 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 -- Local modules
import Messages exposing (Msg(..)) import Messages exposing (Msg(..))
import Models exposing (Model, DayIso) import Models exposing (Model)
import Views.FilterView exposing (filterSidebar) import Views.FilterView exposing (filterSidebar)
-- External modules -- 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 = dayView dayIso model =
div [] div []
[ filterSidebar model [ 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 exposing (Html, text, div, ul, li, span, i, h4, a, p, hr)
import Html.Attributes exposing (class, classList, href) import Html.Attributes exposing (class, classList, href)
import Markdown import Markdown
import Date.Extra as Date
eventDetailView : EventSlug -> Model -> Html Msg eventDetailView : EventSlug -> Model -> Html Msg
@ -74,5 +75,9 @@ eventInstancesList eventSlug eventInstances =
eventInstanceItem : EventInstance -> Html Msg eventInstanceItem : EventInstance -> Html Msg
eventInstanceItem eventInstance = eventInstanceItem eventInstance =
li [] 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 exposing (Html, text, div, ul, li, span, i, h4, p, small, a)
import Html.Lazy exposing (lazy, lazy2) import Html.Lazy exposing (lazy, lazy2)
import Html.Attributes exposing (class, classList, href, style) import Html.Attributes exposing (class, classList, href, style)
import Date.Extra as Date exposing (Interval(..), equalBy)
scheduleOverviewView : Model -> Html Msg scheduleOverviewView : Model -> Html Msg
@ -50,7 +51,8 @@ dayRowView day model =
filteredEventInstances = filteredEventInstances =
List.filter List.filter
(\eventInstance -> (\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.location locations
&& List.member eventInstance.eventType types && List.member eventInstance.eventType types
) )
@ -75,7 +77,12 @@ dayEventInstanceView eventInstance =
] ]
] ]
[ small [] [ 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 ) ] ] [] , i [ classList [ ( "fa", True ), ( "fa-" ++ eventInstance.locationIcon, True ), ( "pull-right", True ) ] ] []
, p , p
[] []