Skip to content

Commit

Permalink
feat: euro 2024 header on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl committed Jun 13, 2024
1 parent 8206492 commit f9d3e78
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
61 changes: 46 additions & 15 deletions sport/app/football/controllers/LeagueTableController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import conf.switches.Switches
import feed.CompetitionsService
import model._
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import model.content.InteractiveAtom
import contentapi.ContentApiClient
import scala.concurrent.Future

case class TablesPage(
page: Page,
tables: Seq[Table],
urlBase: String,
filters: Map[String, Seq[CompetitionFilter]] = Map.empty,
comp: Option[Competition],
atom: Option[InteractiveAtom],
) {
lazy val singleCompetition = tables.size == 1
}

class LeagueTableController(
val competitionsService: CompetitionsService,
val controllerComponents: ControllerComponents,
val contentApiClient: ContentApiClient,
)(implicit context: ApplicationContext)
extends BaseController
with GuLogging
Expand Down Expand Up @@ -80,10 +85,12 @@ class LeagueTableController(

val htmlResponse =
() =>
football.views.html.tablesList.tablesPage(TablesPage(page, groups, "/football", filters(tableOrder), None))
football.views.html.tablesList
.tablesPage(TablesPage(page, groups, "/football", filters(tableOrder), None, None))
val jsonResponse =
() =>
football.views.html.tablesList.tablesPage(TablesPage(page, groups, "/football", filters(tableOrder), None))
football.views.html.tablesList
.tablesPage(TablesPage(page, groups, "/football", filters(tableOrder), None, None))
renderFormat(htmlResponse, jsonResponse, page, Switches.all)

}
Expand All @@ -104,18 +111,19 @@ class LeagueTableController(
val comps = competitionsService.competitions.filter(_.showInTeamsList).filter(_.hasTeams)

val htmlResponse =
() => football.views.html.teamlist(TablesPage(page, groups, "/football", filters(tableOrder), None), comps)
() =>
football.views.html.teamlist(TablesPage(page, groups, "/football", filters(tableOrder), None, None), comps)
val jsonResponse =
() =>
football.views.html.fragments
.teamlistBody(TablesPage(page, groups, "/football", filters(tableOrder), None), comps)
.teamlistBody(TablesPage(page, groups, "/football", filters(tableOrder), None, None), comps)
renderFormat(htmlResponse, jsonResponse, page, Switches.all)

}

def renderCompetitionJson(competition: String): Action[AnyContent] = renderCompetition(competition)
def renderCompetition(competition: String): Action[AnyContent] =
Action { implicit request =>
Action.async { implicit request =>
val table = loadTables
.find(_.competition.url.endsWith(s"/$competition"))
.orElse(loadTables.find(_.competition.id == competition))
Expand All @@ -127,13 +135,30 @@ class LeagueTableController(
s"${table.competition.fullName} table",
)

val futureAtom = if (Switches.Euro2024Header.isSwitchedOn && competition == "euro-2024") {
val id = "/atom/interactive/interactives/2023/01/euros-2024/tables-euros-2024-header"
val edition = Edition(request)
contentApiClient
.getResponse(contentApiClient.item(id, edition))
.map(_.interactive.map(InteractiveAtom.make(_)))
.recover { case _ => None }
} else Future.successful(None)

val smallTableGroup =
table.copy(groups = table.groups.map { group => group.copy(entries = group.entries.take(10)) }).groups(0)
val htmlResponse = () =>
football.views.html.tablesList
.tablesPage(
TablesPage(page, Seq(table), table.competition.url, filters(tableOrder), Some(table.competition)),
)
val htmlResponse = (atom: Option[InteractiveAtom]) =>
() =>
football.views.html.tablesList
.tablesPage(
TablesPage(
page,
Seq(table),
table.competition.url,
filters(tableOrder),
Some(table.competition),
atom,
),
)
val jsonResponse = () =>
football.views.html.tablesList.tablesComponent(
table.competition,
Expand All @@ -142,14 +167,13 @@ class LeagueTableController(
multiGroup = table.multiGroup,
)

renderFormat(htmlResponse, jsonResponse, page)

futureAtom.map(maybeAtom => renderFormat(htmlResponse(maybeAtom), jsonResponse, page))
}
.getOrElse(
if (request.isJson) {
Cached(60)(JsonNotFound())
Future.successful(Cached(60)(JsonNotFound()))
} else {
Redirect("/football/tables")
Future.successful(Redirect("/football/tables"))
},
)
}
Expand Down Expand Up @@ -181,7 +205,14 @@ class LeagueTableController(
val htmlResponse = () =>
football.views.html.tablesList
.tablesPage(
TablesPage(page, Seq(groupTable), table.competition.url, filters(tableOrder), Some(table.competition)),
TablesPage(
page,
Seq(groupTable),
table.competition.url,
filters(tableOrder),
Some(table.competition),
None,
),
)
val jsonResponse = () =>
football.views.html.tablesList.tablesComponent(
Expand Down
5 changes: 5 additions & 0 deletions sport/app/football/views/tablesList/tablesPage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<div class="l-side-margins">
<article id="article" class="content content--article tonal tonal--tone-news" itemprop="mainContentOfPage" itemtype="http://schema.org/Article" role="main">
<div class="content__main tonal__main">
@page.atom.map{ atom =>
<div class="gs-container">
@views.html.fragments.atoms.interactive(atom, shouldFence = false)
</div>
}
<div class="gs-container">
<div class="content__main-column">
<@if(!page.singleCompetition){h1}else{h2} class="hide-on-mobile-if-localnav content__inline-section page-heading--football">
Expand Down

0 comments on commit f9d3e78

Please sign in to comment.