Skip to content

Commit

Permalink
Merge pull request #732 from hmrc/PODS-10302
Browse files Browse the repository at this point in the history
PODS-10302 - Migrate /* main folder to Twirl - Part 3
  • Loading branch information
LauraToddCodes authored Jan 23, 2025
2 parents 0b34687 + 87d7be0 commit 654e9b5
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 327 deletions.
21 changes: 11 additions & 10 deletions app/controllers/NotSubmissionTimeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import config.FrontendAppConfig
import controllers.actions.{AllowAccessActionProviderForIdentifierRequest, IdentifierAction}
import models.CommonQuarters
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.Results.Ok
import play.api.mvc.{Action, AnyContent}
Expand All @@ -27,24 +28,24 @@ import renderer.Renderer
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import javax.inject.Inject
import scala.concurrent.ExecutionContext
import scala.concurrent.{ExecutionContext, Future}
import views.html.NotSubmissionTimeView

class NotSubmissionTimeController @Inject()(renderer: Renderer,
class NotSubmissionTimeController @Inject()(override val messagesApi: MessagesApi,
notSubmissionTimeView: NotSubmissionTimeView,
identify: IdentifierAction,
appConfig: FrontendAppConfig,
allowAccess: AllowAccessActionProviderForIdentifierRequest
)(implicit val executionContext: ExecutionContext) extends CommonQuarters {
)(implicit val executionContext: ExecutionContext)
extends CommonQuarters with I18nSupport {

def onPageLoad(srn: String, startDate: LocalDate): Action[AnyContent] = {
(identify andThen allowAccess(Some(srn))).async {
implicit request =>

val json = Json.obj(
"continueLink" -> appConfig.schemeDashboardUrl(request).format(srn),
"date" -> getNextQuarterDateAndFormat(startDate)
)

renderer.render("notSubmissionTime.njk", json).map(Ok(_))
Future.successful(Ok(notSubmissionTimeView(
appConfig.schemeDashboardUrl(request).format(srn),
getNextQuarterDateAndFormat(startDate)
)))
}
}

Expand Down
61 changes: 25 additions & 36 deletions app/controllers/PastAftReturnsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@ import models.AFTQuarter.formatForDisplayOneYear
import models.viewModels.PastAftReturnsViewModel
import models.{AFTOverview, PastAftReturnGroup, Quarters, ReportLink}
import play.api.i18n.I18nSupport
import play.api.libs.json.{JsObject, Json}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import renderer.Renderer
import services.SchemeService
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import uk.gov.hmrc.viewmodels.NunjucksSupport

import java.time.LocalDate
import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
import views.html.PastAFTReturnsView

class PastAftReturnsController @Inject()(aftConnector: AFTConnector,
allowAccess: AllowAccessActionProviderForIdentifierRequest,
val controllerComponents: MessagesControllerComponents,
identify: IdentifierAction,
renderer: Renderer,
pastAFTReturnsView: PastAFTReturnsView,
schemeService: SchemeService
)
(implicit ec: ExecutionContext) extends FrontendBaseController
with I18nSupport
with NunjucksSupport {
with I18nSupport {

def onPageLoad(srn: String, page: Int): Action[AnyContent] = (identify andThen allowAccess(Some(srn))).async {
implicit request =>
Expand All @@ -56,12 +53,28 @@ class PastAftReturnsController @Inject()(aftConnector: AFTConnector,

val groupedReturns = getGroupedReturns(srn, startDateRange, aftOverview)

val ctxValues = getCtx(groupedReturns, page, schemeName, srn)

renderer.render(
"past_aft_returns.njk",
ctx = ctxValues
).map(Ok(_))
val (pageNo, viewModel) = if (groupedReturns.size > 4) {
val splitReturns = groupedReturns.splitAt(4)
val firstPageReturns = splitReturns._1
val secondPageReturns = splitReturns._2

if (page == 2) {
(2, PastAftReturnsViewModel(secondPageReturns))
} else {
(1, PastAftReturnsViewModel(firstPageReturns))
}
} else {
(0, PastAftReturnsViewModel(groupedReturns))
}

Future.successful(Ok(pastAFTReturnsView(
schemeName,
viewModel,
pageNo,
controllers.routes.PastAftReturnsController.onPageLoad(srn, 1).url,
controllers.routes.PastAftReturnsController.onPageLoad(srn, 2).url,
controllers.routes.AFTOverviewController.onPageLoad(srn).url
)))
}
}
}
Expand All @@ -86,28 +99,4 @@ class PastAftReturnsController @Inject()(aftConnector: AFTConnector,
groupedReturns.filter(pastReturn => pastReturn.reports.nonEmpty)
}

private def getCtx(groupedReturns: List[PastAftReturnGroup], page: Int, schemeName: String, srn: String): JsObject = {
val (pageNo, viewModel) = if (groupedReturns.size > 4) {
val splitReturns = groupedReturns.splitAt(4)
val firstPageReturns = splitReturns._1
val secondPageReturns = splitReturns._2

if (page == 2) {
(2, PastAftReturnsViewModel(secondPageReturns))
} else {
(1, PastAftReturnsViewModel(firstPageReturns))
}
} else {
(0, PastAftReturnsViewModel(groupedReturns))
}

Json.obj(
"page" -> pageNo,
"schemeName" -> schemeName,
"returnLink" -> controllers.routes.AFTOverviewController.onPageLoad(srn).url,
"viewModel" -> viewModel,
"firstPageLink" -> controllers.routes.PastAftReturnsController.onPageLoad(srn, 1).url,
"secondPageLink" -> controllers.routes.PastAftReturnsController.onPageLoad(srn, 2).url
)
}
}
57 changes: 21 additions & 36 deletions app/controllers/QuartersController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,32 @@ import connectors.AFTConnector
import controllers.actions._
import forms.QuartersFormProvider
import models.LocalDateBinder._
import models.requests.IdentifierRequest
import models.{AFTQuarter, Draft, GenericViewModel, Quarters, SubmittedHint}
import models.{AFTQuarter, Draft, Quarters, SubmittedHint}
import play.api.data.Form
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import renderer.Renderer
import services.{QuartersService, SchemeService}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import uk.gov.hmrc.viewmodels.NunjucksSupport
import utils.TwirlMigration

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
import views.html.QuartersView

class QuartersController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
allowAccess: AllowAccessActionProviderForIdentifierRequest,
formProvider: QuartersFormProvider,
val controllerComponents: MessagesControllerComponents,
renderer: Renderer,
quartersView: QuartersView,
config: FrontendAppConfig,
schemeService: SchemeService,
aftConnector: AFTConnector,
quartersService: QuartersService
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport
with NunjucksSupport {
with I18nSupport {

private def form(year: String, quarters: Seq[AFTQuarter])(implicit messages: Messages): Form[AFTQuarter] =
formProvider(messages("quarters.error.required", year), quarters)
Expand All @@ -64,16 +61,14 @@ class QuartersController @Inject()(
if (displayQuarters.nonEmpty) {
val quarters = displayQuarters.map(_.quarter)

val json = Json.obj(
"srn" -> srn,
"startDate" -> None,
"form" -> form(year, quarters),
"radios" -> Quarters.radios(form(year, quarters), displayQuarters),
"viewModel" -> viewModel(srn, year, schemeDetails.schemeName),
"year" -> year
)

renderer.render(template = "quarters.njk", json).map(Ok(_))
Future.successful(Ok(quartersView(
year,
form(year, quarters),
TwirlMigration.toTwirlRadios(Quarters.radios(form(year, quarters), displayQuarters)),
routes.QuartersController.onSubmit(srn, year),
config.schemeDashboardUrl(request).format(srn),
schemeDetails.schemeName
)))
} else {
Future.successful(Redirect(controllers.routes.SessionExpiredController.onPageLoad))
}
Expand All @@ -91,15 +86,14 @@ class QuartersController @Inject()(
.bindFromRequest()
.fold(
formWithErrors => {
val json = Json.obj(
fields = "srn" -> srn,
"startDate" -> None,
"form" -> formWithErrors,
"radios" -> Quarters.radios(formWithErrors, displayQuarters),
"viewModel" -> viewModel(srn, year, schemeDetails.schemeName),
"year" -> year
)
renderer.render(template = "quarters.njk", json).map(BadRequest(_))
Future.successful(BadRequest(quartersView(
year,
formWithErrors,
TwirlMigration.toTwirlRadios(Quarters.radios(formWithErrors, displayQuarters)),
routes.QuartersController.onSubmit(srn, year),
config.schemeDashboardUrl(request).format(srn),
schemeDetails.schemeName
)))
},
value => {
val tpssReports = aftOverview.filter(_.periodStartDate == value.startDate).filter(_.tpssReportPresent)
Expand All @@ -122,7 +116,6 @@ class QuartersController @Inject()(
case Some(o) =>
Future.successful(Redirect(controllers.routes.AFTSummaryController.onPageLoad(srn, value.startDate, Draft, o.numberOfVersions)))
}

}
}
}
Expand All @@ -136,13 +129,5 @@ class QuartersController @Inject()(
}
}

private def viewModel(srn: String, year: String, schemeName: String)
(implicit request: IdentifierRequest[_]): GenericViewModel =
GenericViewModel(
submitUrl = routes.QuartersController.onSubmit(srn, year).url,
returnUrl = config.schemeDashboardUrl(request).format(srn),
schemeName = schemeName
)

case class InvalidValueSelected(details: String) extends Exception(s"The selected quarter did not match any quarters in the list of options: $details")
}
38 changes: 38 additions & 0 deletions app/views/NotSubmissionTimeView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@this(
layout: templates.Layout
)

@(continueLink: String, date: String)(implicit request: Request[_], messages: Messages)

@layout(messages("aft.notSubmissionTime.title")) {
<div>
<h1 class="govuk-heading-xl">
@messages("aft.notSubmissionTime.heading")
</h1>

<p class="govuk-body">@messages("aft.notSubmissionTime.p1", date)</p>

<p class="govuk-body">
<a href=@continueLink
class="govuk-link">
@messages("site.continue_to_scheme_overview")
</a>
</p>
</div>
}
Loading

0 comments on commit 654e9b5

Please sign in to comment.