Skip to content

Commit

Permalink
API-6928 - Update breadcrumbs throughout documentation (#451)
Browse files Browse the repository at this point in the history
also changed it to no longer ignore the first crumb
  • Loading branch information
Tobias1087 authored May 4, 2023
1 parent 1f0e4b3 commit d79a0f2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ class ApiDocumentationController @Inject() (
)(implicit val ec: ExecutionContext,
appConfig: ApplicationConfig,
mat: Materializer
) extends FrontendController(mcc) with HeaderNavigation with PageAttributesHelper with HomeCrumb with ApplicationLogger {
) extends FrontendController(mcc) with HeaderNavigation with PageAttributesHelper with HomeCrumb with DocumentationCrumb with ApplicationLogger {

private lazy val cacheControlHeaders = "cache-control" -> "no-cache,no-store,max-age=0"
private lazy val apiDocCrumb = Crumb("API Documentation", routes.ApiDocumentationController.apiIndexPage(None, None, None).url)

def apiIndexPage(service: Option[String], version: Option[String], filter: Option[String]): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
def pageAttributes(title: String = "API Documentation") =
PageAttributes(title, breadcrumbs = Breadcrumbs(apiDocCrumb, homeCrumb), headerLinks = navLinks, sidebarLinks = navigationService.sidebarNavigation())
PageAttributes(title, breadcrumbs = Breadcrumbs(documentationCrumb, homeCrumb), headerLinks = navLinks, sidebarLinks = navigationService.sidebarNavigation())

val params = for (a <- service; b <- version) yield (a, b)

Expand Down Expand Up @@ -165,12 +165,8 @@ class ApiDocumentationController @Inject() (
)(implicit request: Request[AnyContent],
messagesProvider: MessagesProvider
): Future[Result] = {
def makePageAttributes(apiDefinition: ExtendedAPIDefinition, selectedVersion: ExtendedAPIVersion, sidebarLinks: Seq[SidebarLink]): PageAttributes = {
def makePageAttributes(apiDefinition: ExtendedAPIDefinition, sidebarLinks: Seq[SidebarLink]) = {
val breadcrumbs = Breadcrumbs(
Crumb(
makeBreadcrumbName(apiDefinition, selectedVersion),
routes.ApiDocumentationController.renderApiDocumentation(service, selectedVersion.version, None).url
),
apiDocCrumb,
homeCrumb
)
Expand All @@ -192,7 +188,7 @@ class ApiDocumentationController @Inject() (
val apiDefinition = api.userAccessibleApiDefinition

Future.successful(Ok(retiredVersionJumpView(
makePageAttributes(apiDefinition, selectedVersion, navigationService.sidebarNavigation()),
makePageAttributes(apiDefinition, navigationService.sidebarNavigation()),
apiDefinition
)))
}
Expand All @@ -204,7 +200,7 @@ class ApiDocumentationController @Inject() (
messagesProvider: MessagesProvider
): Future[Result] = {
def renderRamlSpec(apiSpecification: ApiSpecification): Future[Result] = {
val attrs = makePageAttributes(api, selectedVersion, navigationService.apiSidebarNavigation2(service, selectedVersion, apiSpecification))
val attrs = makePageAttributes(api, navigationService.apiSidebarNavigation2(service, selectedVersion, apiSpecification))
val viewModel = ViewModel(apiSpecification)
successful(Ok(serviceDocumentationView(attrs, api, selectedVersion, viewModel, developerId.isDefined)).withHeaders(cacheControlHeaders))
}
Expand Down Expand Up @@ -236,7 +232,7 @@ class ApiDocumentationController @Inject() (
fraudPrevention <- withDefaultForService("fraud-prevention.md", "Fraud Prevention")
versioning <- withDefaultForService("versioning.md", "Versioning")
markdownBlocks = List(overview, errors, testing) ++ (if (requiredFraudPrevention) List(fraudPrevention) else List()) ++ List(versioning)
attrs = makePageAttributes(api, selectedVersion, navigationService.openApiSidebarNavigation(service, selectedVersion, markdownBlocks))
attrs = makePageAttributes(api, navigationService.openApiSidebarNavigation(service, selectedVersion, markdownBlocks))

} yield Ok(parentPage(attrs, markdownBlocks, api.name, api, selectedVersion, developerId.isDefined)).withHeaders(cacheControlHeaders)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,82 +40,32 @@ class AuthorisationController @Inject() (
credentialsView: CredentialsView
)(implicit ec: ExecutionContext,
applicationConfig: ApplicationConfig
) extends FrontendController(mcc) with HeaderNavigation with PageAttributesHelper with HomeCrumb
) extends FrontendController(mcc) with HeaderNavigation with PageAttributesHelper with BaseCrumbs
with ApplicationLogger {

private lazy val authCrumb = Crumb("Authorisation", routes.AuthorisationController.authorisationPage().url)

def authorisationPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
Future.successful(Ok(authorisationView(pageAttributes("Authorisation", routes.AuthorisationController.authorisationPage().url, navLinks))))
Future.successful(Ok(authorisationView(pageAttributes("Authorisation", navLinks, baseCrumbs))))
}

def authorisation2SVPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val breadcrumbs = Breadcrumbs(
Crumb("2-step verification", routes.AuthorisationController.authorisation2SVPage().url),
authCrumb,
homeCrumb
)
Future.successful(Ok(authorisation2SVView(pageAttributes(
"2-step verification",
routes.AuthorisationController.authorisation2SVPage().url,
navLinks,
Some(breadcrumbs)
))))
Future.successful(Ok(authorisation2SVView(pageAttributes("2-step verification", navLinks, basePlus(authCrumb)))))
}

def authorisationCredentialsPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val breadcrumbs = Breadcrumbs(
Crumb("Credentials", routes.AuthorisationController.authorisationCredentialsPage().url),
authCrumb,
homeCrumb
)
Future.successful(Ok(credentialsView(pageAttributes(
"Credentials",
routes.AuthorisationController.authorisationCredentialsPage().url,
navLinks,
Some(breadcrumbs)
))))
Future.successful(Ok(credentialsView(pageAttributes("Credentials", navLinks, basePlus(authCrumb)))))
}

def authorisationOpenAccessEndpointsPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val breadcrumbs = Breadcrumbs(
Crumb("Open access endpoints", routes.AuthorisationController.authorisationOpenAccessEndpointsPage().url),
authCrumb,
homeCrumb
)
Future.successful(Ok(authorisationOpenAccessEndpointsView(pageAttributes(
"Open access endpoints",
routes.AuthorisationController.authorisationOpenAccessEndpointsPage().url,
navLinks,
Some(breadcrumbs)
))))
Future.successful(Ok(authorisationOpenAccessEndpointsView(pageAttributes("Open access endpoints", navLinks, basePlus(authCrumb)))))
}

def authorisationAppRestrictedEndpointsPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val breadcrumbs = Breadcrumbs(
Crumb("Application-restricted endpoints", routes.AuthorisationController.authorisationAppRestrictedEndpointsPage().url),
authCrumb,
homeCrumb
)
Future.successful(Ok(authorisationAppRestrictedEndpointsView(pageAttributes(
"Application-restricted endpoints",
routes.AuthorisationController.authorisationAppRestrictedEndpointsPage().url,
navLinks,
Some(breadcrumbs)
))))
Future.successful(Ok(authorisationAppRestrictedEndpointsView(pageAttributes("Application-restricted endpoints", navLinks, basePlus(authCrumb)))))
}

def authorisationUserRestrictedEndpointsPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val breadcrumbs = Breadcrumbs(
Crumb("User-restricted endpoints", routes.AuthorisationController.authorisationUserRestrictedEndpointsPage().url),
authCrumb,
homeCrumb
)
Future.successful(Ok(authorisationUserRestrictedEndpointsView(pageAttributes(
"User-restricted endpoints",
routes.AuthorisationController.authorisationUserRestrictedEndpointsPage().url,
navLinks,
Some(breadcrumbs)
))))
Future.successful(Ok(authorisationUserRestrictedEndpointsView(pageAttributes("User-restricted endpoints", navLinks, basePlus(authCrumb)))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class DocumentationController @Inject() (
) extends FrontendController(mcc)
with HeaderNavigation
with PageAttributesHelper
with HomeCrumb
with BaseCrumbs
with TermsCrumb
with ApplicationLogger {

def indexPage(): Action[AnyContent] = headerNavigation {
Expand All @@ -64,11 +65,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
tutorialsView(
pageAttributes(
"Tutorials",
routes.DocumentationController.tutorialsPage().url,
navLinks
)
pageAttributes("Tutorials", navLinks, baseCrumbs)
)
)
)
Expand All @@ -79,11 +76,7 @@ class DocumentationController @Inject() (
partialsService.termsOfUsePartial() map { termsOfUsePartial =>
Ok(
termsOfUseView(
pageAttributes(
"Terms Of Use",
routes.DocumentationController.termsOfUsePage().url,
navLinks
),
pageAttributes("Terms Of Use", navLinks, baseCrumbs),
termsOfUsePartial
)
)
Expand All @@ -95,7 +88,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
termsOfUseWhatYouCanExpectView(
pageAttributes("What you can expect from us", routes.DocumentationController.termsOfUseWhatYouCanExpectPage().url, navLinks)
pageAttributes("What you can expect from us", navLinks, basePlus(termsCrumb))
)
)
)
Expand All @@ -106,7 +99,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
termsOfUseNotMeetingView(
pageAttributes("Not meeting the terms of use", routes.DocumentationController.termsOfUseNotMeetingPage().url, navLinks)
pageAttributes("Not meeting the terms of use", navLinks, basePlus(termsCrumb))
)
)
)
Expand All @@ -117,11 +110,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
usingTheHubView(
pageAttributes(
"Using the Developer Hub",
routes.DocumentationController.usingTheHubPage().url,
navLinks
)
pageAttributes("Using the Developer Hub", navLinks)
)
)
)
Expand All @@ -134,7 +123,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
mtdIntroductionView(
pageAttributes("Making Tax Digital guides", introPageUrl, navLinks)
pageAttributes("Making Tax Digital guides", navLinks, baseCrumbs)
)
)
)
Expand All @@ -152,11 +141,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
referenceView(
pageAttributes(
"Reference guide",
routes.DocumentationController.referenceGuidePage().url,
navLinks
)
pageAttributes("Reference guide", navLinks)
)
)
)
Expand All @@ -167,11 +152,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
developmentPracticesView(
pageAttributes(
"Development practices",
routes.DocumentationController.developmentPracticesPage().url,
navLinks
)
pageAttributes("Development practices", navLinks)
)
)
)
Expand All @@ -191,11 +172,7 @@ class DocumentationController @Inject() (
Future.successful(
Ok(
namingGuidelinesView(
pageAttributes(
"Application naming guidelines",
routes.DocumentationController.nameGuidelinesPage().url,
navLinks
)
pageAttributes("Application naming guidelines", navLinks, baseCrumbs)
)
)
)
Expand All @@ -208,14 +185,32 @@ trait HomeCrumb {
Crumb("Home", routes.DocumentationController.indexPage().url)
}

trait DocumentationCrumb {

lazy val documentationCrumb =
Crumb("Documentation", routes.DocumentationController.usingTheHubPage().url)
}

trait TermsCrumb {
lazy val termsCrumb = Crumb("Terms of use", routes.DocumentationController.termsOfUsePage().url)
}

trait BaseCrumbs extends HomeCrumb with DocumentationCrumb {

lazy val baseCrumbs = Some(Breadcrumbs(documentationCrumb, homeCrumb))

def basePlus(crumb: Crumb): Option[Breadcrumbs] = {
Some(Breadcrumbs(crumb, documentationCrumb, homeCrumb))
}
}

trait PageAttributesHelper {
self: FrontendController with HomeCrumb =>

def navigationService: NavigationService

def pageAttributes(title: String, url: String, headerNavLinks: Seq[NavLink], customBreadcrumbs: Option[Breadcrumbs] = None) = {
val breadcrumbs =
customBreadcrumbs.getOrElse(Breadcrumbs(Crumb(title, url), homeCrumb))
def pageAttributes(title: String, headerNavLinks: Seq[NavLink], customBreadcrumbs: Option[Breadcrumbs] = None): PageAttributes = {
val breadcrumbs = customBreadcrumbs.getOrElse(Breadcrumbs(homeCrumb))
apidocumentation.models.PageAttributes(
title,
breadcrumbs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import uk.gov.hmrc.apidocumentation.config.ApplicationConfig
import uk.gov.hmrc.apidocumentation.services.NavigationService
import uk.gov.hmrc.apidocumentation.util.ApplicationLogger
import uk.gov.hmrc.apidocumentation.views.html._
import uk.gov.hmrc.apidocumentation.models._

@Singleton
class TestingPagesController @Inject() (
Expand All @@ -35,18 +36,21 @@ class TestingPagesController @Inject() (
testUsersDataStatefulBehaviourView: TestUsersDataStatefulBehaviourView
)(implicit ec: ExecutionContext,
applicationConfig: ApplicationConfig
) extends FrontendController(mcc) with HeaderNavigation with ApplicationLogger with PageAttributesHelper with HomeCrumb {
) extends FrontendController(mcc) with HeaderNavigation with ApplicationLogger with PageAttributesHelper with BaseCrumbs {

def testingPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
Future.successful(Ok(testingView(pageAttributes("Testing in the sandbox", routes.TestingPagesController.testingPage().url, navLinks))))
Future.successful(Ok(testingView(pageAttributes("Testing in the sandbox", navLinks, baseCrumbs))))
}

def testingStatefulBehaviourPage(): Action[AnyContent] = headerNavigation { _ => _ =>
Future.successful(MovedPermanently(routes.TestingPagesController.testUsersDataStatefulBehaviourPage().url))
}

def testUsersDataStatefulBehaviourPage(): Action[AnyContent] = headerNavigation { implicit request => navLinks =>
val testUsersDataStatefulBehaviourUrl = routes.TestingPagesController.testUsersDataStatefulBehaviourPage().url
Future.successful(Ok(testUsersDataStatefulBehaviourView(pageAttributes("Test users, test data and stateful behaviour", testUsersDataStatefulBehaviourUrl, navLinks))))
Future.successful(Ok(testUsersDataStatefulBehaviourView(pageAttributes(
"Test users, test data and stateful behaviour",
navLinks,
basePlus(Crumb("Testing in the sandbox", routes.TestingPagesController.testingPage().url))
))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*@
<div class="govuk-breadcrumbs">
<ol class="govuk-breadcrumbs__list">
@defining(crumbs.tail) { linkableCrumbs =>
@defining(crumbs) { linkableCrumbs =>
@linkableCrumbs.reverse.map { crumb =>
<li class="govuk-breadcrumbs__list-item">
<a class="govuk-breadcrumbs__link" href="@crumb.url">@crumb.name</a>
Expand Down

0 comments on commit d79a0f2

Please sign in to comment.