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