Skip to content

Commit

Permalink
Added spares
Browse files Browse the repository at this point in the history
  • Loading branch information
rapind committed Oct 5, 2023
1 parent e34735b commit 685162c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// section: "leagues", // OPTIONAL. Can be "leagues", "competition", or "products". Will default to "leagues" if omitted or an invalid value is passed.
registration: true, // OPTIONAL. Set to false if you don't want prices and the add to cart / register / waitlist buttons to show up.
// eventId: 3742, // OPTIONAL. If you only want to show one specific event, enter it's ID here.
// excludeEventSections: ["details", "registrations"], // OPTIONAL. Event sections you don't want to show up. Possible values: "details", "registrations", "draws", "stages", "teams", "reports"
// excludeEventSections: ["details", "registrations", "spares"], // OPTIONAL. Event sections you don't want to show up. Possible values: "details", "registrations", "spares", "draws", "stages", "teams", "reports"
// defaultEventSection: "draws", // OPTIONAL. If you want a default event section other than the details view. Possible values: "registrations", "spares", "draws", "stages", "teams", "reports"
// theme: { // OPTIONAL. You can customize the colors used.
// primary: "#ed1940", // OPTIONAL. The primary color in hexadecimal (important buttons / links / backgrounds). Default is red: #ed1940
Expand Down
2 changes: 1 addition & 1 deletion prod.min.js

Large diffs are not rendered by default.

109 changes: 87 additions & 22 deletions src/Results.elm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Route
type NestedEventRoute
= DetailsRoute
| RegistrationsRoute
| SparesRoute
| DrawsRoute
| DrawRoute Int
| GameRoute String
Expand Down Expand Up @@ -181,6 +182,7 @@ type alias Event =
, sheetNames : List String
, teams : List Team
, registrations : List Registration
, spares : List Spare
, stages : List Stage
, draws : List Draw
}
Expand Down Expand Up @@ -248,6 +250,12 @@ type alias Registration =
}


type alias Spare =
{ name : String
, positions : List String
}


type alias Lineup =
{ first : Maybe String
, second : Maybe String
Expand Down Expand Up @@ -479,6 +487,12 @@ decodeEvent =
_ ->
Decode.succeed EventStateComplete
)

decodeSpare : Decoder Spare
decodeSpare =
Decode.succeed Spare
|> required "name" string
|> required "positions" (list string)
in
Decode.succeed Event
|> required "id" int
Expand Down Expand Up @@ -507,6 +521,7 @@ decodeEvent =
|> optional "sheet_names" (list string) []
|> optional "teams" (list decodeTeam) []
|> optional "registrations" (list decodeRegistration) []
|> optional "spares" (list decodeSpare) []
|> optional "stages" (list decodeStage) []
|> optional "draws" (list decodeDraw) []

Expand Down Expand Up @@ -786,30 +801,10 @@ matchRoute defaultEventSection =
matchNestedEventRoute : Maybe String -> Parser (NestedEventRoute -> a) a
matchNestedEventRoute defaultEventSection =
Url.Parser.oneOf
-- [ Url.Parser.map
-- (case defaultEventSection of
-- Just "registrations" ->
-- RegistrationsRoute
--
-- Just "draws" ->
-- DrawsRoute
--
-- Just "stages" ->
-- StagesRoute
--
-- Just "teams" ->
-- TeamsRoute
--
-- Just "reports" ->
-- ReportsRoute
--
-- _ ->
-- DetailsRoute
-- )
-- Url.Parser.top
[ Url.Parser.map DetailsRoute Url.Parser.top
, Url.Parser.map DetailsRoute (Url.Parser.s "details")
, Url.Parser.map RegistrationsRoute (Url.Parser.s "registrations")
, Url.Parser.map SparesRoute (Url.Parser.s "spares")
, Url.Parser.map DrawsRoute (Url.Parser.s "draws")
, Url.Parser.map StagesRoute (Url.Parser.s "stages")
, Url.Parser.map TeamsRoute (Url.Parser.s "teams")
Expand Down Expand Up @@ -1304,6 +1299,9 @@ eventSections excludeEventSections event =
hasRegistrations =
not (List.isEmpty event.registrations)

hasSpares =
not (List.isEmpty event.spares)

hasDraws =
not (List.isEmpty event.draws)

Expand All @@ -1323,6 +1321,9 @@ eventSections excludeEventSections event =
"registrations" ->
hasRegistrations

"spares" ->
hasSpares

"draws" ->
hasDraws

Expand All @@ -1339,7 +1340,7 @@ eventSections excludeEventSections event =
_ ->
True
in
[ "details", "registrations", "draws", "stages", "teams", "reports" ]
[ "details", "registrations", "spares", "draws", "stages", "teams", "reports" ]
|> List.filter included
|> List.filter hasData

Expand All @@ -1353,6 +1354,9 @@ eventSectionForRoute route =
RegistrationsRoute ->
"registrations"

SparesRoute ->
"spares"

DrawsRoute ->
"draws"

Expand Down Expand Up @@ -2505,6 +2509,9 @@ viewEvent theme translations { flags, device, scoringHilight, fullScreen } neste
RegistrationsRoute ->
viewRegistrations theme translations event.registrations

SparesRoute ->
viewSpares theme translations event.spares

DrawsRoute ->
viewDraws theme translations scoringHilight event

Expand Down Expand Up @@ -2787,6 +2794,64 @@ viewRegistrations theme translations registrations =
)


viewSpares : Theme -> List Translation -> List Spare -> Element Msg
viewSpares theme translations spares =
let
tableHeader content =
el
[ Font.bold
, Border.widthEach { bottom = 1, left = 0, right = 0, top = 0 }
, Border.color theme.grey
, El.padding 12
]
(text (translate translations content))

tableCell i content =
el
[ El.padding 12
, Background.color
(if modBy 2 i == 0 then
theme.greyLight

else
theme.transparent
)
]
(text content)

nameColumn =
{ header = tableHeader "curler"
, width = El.fill
, view = \i spare -> tableCell i spare.name
}

positionsColumn =
{ header = tableHeader "position"
, width = El.fill
, view =
\i spare ->
tableCell i
(if List.isEmpty spare.positions then
"-"

else
List.map (\pos -> translate translations pos) spare.positions
|> String.join ", "
)
}
in
el [ El.width El.fill, El.htmlAttribute (class "cio__event_spares") ]
(if List.isEmpty spares then
El.paragraph [] [ text (translate translations "no_spares") ]

else
El.indexedTable [ El.htmlAttribute (class "cio__event_spares_table") ]
{ data = spares
, columns = [ nameColumn, positionsColumn ]
}
)


viewDraws : Theme -> List Translation -> Maybe ScoringHilight -> Event -> Element Msg
viewDraws theme translations scoringHilight event =
let
Expand Down

0 comments on commit 685162c

Please sign in to comment.