Detail pages are for events. We now also load event data when accessing a detailpage directly.
This commit is contained in:
parent
ebbbe90880
commit
23d94145b7
|
@ -29,7 +29,22 @@ main =
|
||||||
|
|
||||||
init : Flags -> Location -> ( Model, Cmd Msg )
|
init : Flags -> Location -> ( Model, Cmd Msg )
|
||||||
init flags location =
|
init flags location =
|
||||||
( Model [] [] [] [] [] flags allDaysDay (Filter [] []) (parseLocation location), sendInitMessage flags.camp_slug )
|
let
|
||||||
|
currentRoute =
|
||||||
|
parseLocation location
|
||||||
|
|
||||||
|
emptyFilter =
|
||||||
|
Filter [] []
|
||||||
|
|
||||||
|
initModel =
|
||||||
|
(Model [] [] [] [] [] flags allDaysDay emptyFilter currentRoute)
|
||||||
|
|
||||||
|
-- To ensure we load data on right momens we call update with the
|
||||||
|
-- OnLocationChange message which is in charge of all that
|
||||||
|
( model, cmd ) =
|
||||||
|
update (OnLocationChange location) initModel
|
||||||
|
in
|
||||||
|
model ! [ cmd ]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ module Models exposing (..)
|
||||||
type Route
|
type Route
|
||||||
= OverviewRoute
|
= OverviewRoute
|
||||||
| DayRoute DayIso
|
| DayRoute DayIso
|
||||||
| EventInstanceRoute EventInstanceSlug
|
| EventRoute EventSlug
|
||||||
| NotFoundRoute
|
| NotFoundRoute
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,27 +2,27 @@ module Routing exposing (..)
|
||||||
|
|
||||||
-- Local modules
|
-- Local modules
|
||||||
|
|
||||||
import Models exposing (DayIso, EventInstanceSlug, Route(..))
|
import Models exposing (Route(..))
|
||||||
|
|
||||||
|
|
||||||
-- External modules
|
-- External modules
|
||||||
|
|
||||||
import Navigation exposing (Location)
|
import Navigation exposing (Location)
|
||||||
import UrlParser exposing ((</>))
|
import UrlParser exposing (Parser, (</>), oneOf, map, top, s, string, parseHash)
|
||||||
|
|
||||||
|
|
||||||
matchers : UrlParser.Parser (Route -> a) a
|
matchers : Parser (Route -> a) a
|
||||||
matchers =
|
matchers =
|
||||||
UrlParser.oneOf
|
oneOf
|
||||||
[ UrlParser.map OverviewRoute UrlParser.top
|
[ map OverviewRoute top
|
||||||
, UrlParser.map DayRoute (UrlParser.s "day" </> UrlParser.string)
|
, map DayRoute (s "day" </> string)
|
||||||
, UrlParser.map EventInstanceRoute (UrlParser.s "event" </> UrlParser.string)
|
, map EventRoute (s "event" </> string)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
parseLocation : Location -> Route
|
parseLocation : Location -> Route
|
||||||
parseLocation location =
|
parseLocation location =
|
||||||
case UrlParser.parseHash matchers location of
|
case parseHash matchers location of
|
||||||
Just route ->
|
Just route ->
|
||||||
route
|
route
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@ module Update exposing (update)
|
||||||
|
|
||||||
-- Local modules
|
-- Local modules
|
||||||
|
|
||||||
import Models exposing (Model, Route(EventInstanceRoute), emptyEventInstance, allDaysDay, Filter)
|
import Models exposing (Model, Route(OverviewRoute, EventRoute), emptyEventInstance, allDaysDay, 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)
|
||||||
import WebSocketCalls exposing (sendGetEventContent)
|
import WebSocketCalls exposing (sendGetEventContent, sendInitMessage)
|
||||||
|
|
||||||
|
|
||||||
-- Core modules
|
-- Core modules
|
||||||
|
@ -29,7 +29,16 @@ update msg model =
|
||||||
"init" ->
|
"init" ->
|
||||||
case Json.Decode.decodeString initDataDecoder str of
|
case Json.Decode.decodeString initDataDecoder str of
|
||||||
Ok m ->
|
Ok m ->
|
||||||
|
let
|
||||||
|
newModel_ =
|
||||||
m model.flags allDaysDay (Filter [] []) model.route
|
m model.flags allDaysDay (Filter [] []) model.route
|
||||||
|
in
|
||||||
|
{ model
|
||||||
|
| days = newModel_.days
|
||||||
|
, eventInstances = newModel_.eventInstances
|
||||||
|
, eventLocations = newModel_.eventLocations
|
||||||
|
, eventTypes = newModel_.eventTypes
|
||||||
|
}
|
||||||
|
|
||||||
Err error ->
|
Err error ->
|
||||||
model
|
model
|
||||||
|
@ -88,21 +97,25 @@ update msg model =
|
||||||
OnLocationChange location ->
|
OnLocationChange location ->
|
||||||
let
|
let
|
||||||
newRoute =
|
newRoute =
|
||||||
parseLocation (Debug.log "location" location)
|
parseLocation location
|
||||||
|
|
||||||
onLoadCmd =
|
onLoadCmd =
|
||||||
case newRoute of
|
case newRoute of
|
||||||
EventInstanceRoute eventInstanceSlug ->
|
EventRoute eventSlug ->
|
||||||
let
|
case List.head (List.filter (\x -> x.slug == eventSlug) model.events) of
|
||||||
eventInstance =
|
Just event ->
|
||||||
case List.head (List.filter (\x -> x.slug == eventInstanceSlug) model.eventInstances) of
|
Cmd.none
|
||||||
Just eventInstance ->
|
|
||||||
eventInstance
|
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
emptyEventInstance
|
sendGetEventContent model.flags.camp_slug (Debug.log "eventSlug" eventSlug)
|
||||||
in
|
|
||||||
sendGetEventContent model.flags.camp_slug eventInstance.eventSlug
|
OverviewRoute ->
|
||||||
|
case List.head model.days of
|
||||||
|
Just day ->
|
||||||
|
Cmd.none
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
sendInitMessage model.flags.camp_slug
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Cmd.none
|
Cmd.none
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Models exposing (..)
|
||||||
import Messages exposing (Msg(..))
|
import Messages exposing (Msg(..))
|
||||||
import Views.DayPicker exposing (dayPicker)
|
import Views.DayPicker exposing (dayPicker)
|
||||||
import Views.DayView exposing (dayView)
|
import Views.DayView exposing (dayView)
|
||||||
import Views.EventDetail exposing (eventInstanceDetailView)
|
import Views.EventDetail exposing (eventDetailView)
|
||||||
import Views.ScheduleOverview exposing (scheduleOverviewView)
|
import Views.ScheduleOverview exposing (scheduleOverviewView)
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ view model =
|
||||||
DayRoute dayIso ->
|
DayRoute dayIso ->
|
||||||
dayView dayIso model
|
dayView dayIso model
|
||||||
|
|
||||||
EventInstanceRoute eventInstanceSlug ->
|
EventRoute eventSlug ->
|
||||||
eventInstanceDetailView eventInstanceSlug model
|
eventDetailView eventSlug model
|
||||||
|
|
||||||
NotFoundRoute ->
|
NotFoundRoute ->
|
||||||
div [] [ text "Not found!" ]
|
div [] [ text "Not found!" ]
|
||||||
|
|
|
@ -10,8 +10,6 @@ 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)
|
||||||
import Html.Attributes exposing (class, classList, href)
|
|
||||||
import Html.Events exposing (onClick)
|
|
||||||
|
|
||||||
|
|
||||||
dayView : DayIso -> Model -> Html Msg
|
dayView : DayIso -> Model -> Html Msg
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module Views.EventDetail exposing (eventInstanceDetailView)
|
module Views.EventDetail exposing (eventDetailView)
|
||||||
|
|
||||||
-- Local modules
|
-- Local modules
|
||||||
|
|
||||||
|
@ -13,19 +13,11 @@ import Html.Attributes exposing (class, classList, href)
|
||||||
import Markdown
|
import Markdown
|
||||||
|
|
||||||
|
|
||||||
eventInstanceDetailView : EventInstanceSlug -> Model -> Html Msg
|
eventDetailView : EventSlug -> Model -> Html Msg
|
||||||
eventInstanceDetailView eventInstanceSlug model =
|
eventDetailView eventSlug model =
|
||||||
let
|
let
|
||||||
eventInstance =
|
|
||||||
case List.head (List.filter (\e -> e.slug == eventInstanceSlug) model.eventInstances) of
|
|
||||||
Just eventInstance ->
|
|
||||||
eventInstance
|
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
emptyEventInstance
|
|
||||||
|
|
||||||
event =
|
event =
|
||||||
case List.head (List.filter (\e -> e.slug == eventInstance.eventSlug) model.events) of
|
case List.head (List.filter (\e -> e.slug == eventSlug) model.events) of
|
||||||
Just event ->
|
Just event ->
|
||||||
event
|
event
|
||||||
|
|
||||||
|
@ -37,7 +29,7 @@ eventInstanceDetailView eventInstanceSlug model =
|
||||||
[ a [ href "#" ]
|
[ a [ href "#" ]
|
||||||
[ text "Back"
|
[ text "Back"
|
||||||
]
|
]
|
||||||
, h4 [] [ text eventInstance.title ]
|
, h4 [] [ text event.title ]
|
||||||
, p [] [ Markdown.toHtml [] event.abstract ]
|
, p [] [ Markdown.toHtml [] event.abstract ]
|
||||||
, hr [] []
|
, hr [] []
|
||||||
, h4 [] [ text "TODO: Show all instances here!" ]
|
, h4 [] [ text "TODO: Show all instances here!" ]
|
||||||
|
|
|
@ -67,7 +67,7 @@ dayEventInstanceView : EventInstance -> Html Msg
|
||||||
dayEventInstanceView eventInstance =
|
dayEventInstanceView eventInstance =
|
||||||
a
|
a
|
||||||
[ class "event"
|
[ class "event"
|
||||||
, href ("#event/" ++ eventInstance.slug)
|
, href ("#event/" ++ eventInstance.eventSlug)
|
||||||
, style
|
, style
|
||||||
[ ( "background-color", eventInstance.backgroundColor )
|
[ ( "background-color", eventInstance.backgroundColor )
|
||||||
, ( "color", eventInstance.forgroundColor )
|
, ( "color", eventInstance.forgroundColor )
|
||||||
|
|
|
@ -127,11 +127,6 @@ urlpatterns = [
|
||||||
|
|
||||||
url(
|
url(
|
||||||
r'^program/', include([
|
r'^program/', include([
|
||||||
url(
|
|
||||||
r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})/$',
|
|
||||||
ScheduleView.as_view(),
|
|
||||||
name='schedule_day'
|
|
||||||
),
|
|
||||||
url(
|
url(
|
||||||
r'^$',
|
r'^$',
|
||||||
ScheduleView.as_view(),
|
ScheduleView.as_view(),
|
||||||
|
|
|
@ -41,7 +41,6 @@ class ScheduleConsumer(JsonWebsocketConsumer):
|
||||||
"action": "init",
|
"action": "init",
|
||||||
"event_locations": event_locations,
|
"event_locations": event_locations,
|
||||||
"event_types": event_types,
|
"event_types": event_types,
|
||||||
"accept": True,
|
|
||||||
"event_instances": event_instances,
|
"event_instances": event_instances,
|
||||||
"days": days,
|
"days": days,
|
||||||
}
|
}
|
||||||
|
@ -51,8 +50,6 @@ class ScheduleConsumer(JsonWebsocketConsumer):
|
||||||
if action == 'get_event_content':
|
if action == 'get_event_content':
|
||||||
camp_slug = content.get('camp_slug')
|
camp_slug = content.get('camp_slug')
|
||||||
event_slug = content.get('event_slug')
|
event_slug = content.get('event_slug')
|
||||||
print(camp_slug)
|
|
||||||
print(event_slug)
|
|
||||||
event = Event.objects.get(
|
event = Event.objects.get(
|
||||||
slug=event_slug,
|
slug=event_slug,
|
||||||
camp__slug=camp_slug
|
camp__slug=camp_slug
|
||||||
|
|
Loading…
Reference in a new issue