Skip to content

Commit

Permalink
use maxitemstodisplay to set flex story limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges-GNM committed Jan 8, 2025
1 parent 944edd9 commit 5633883
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/StoriesVisibleController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StoriesVisibleController(
def storiesVisible(containerType: String) =
AccessAPIAuthAction(parse.json[StoriesVisibleRequest]) { implicit request =>
val storiesVisible =
containerService.getStoriesVisible(containerType, request.body.stories)
containerService.getStoriesVisible(containerType, request.body.stories, collectionConfigJson = null)

logger.info(
s"got stories-visible=$storiesVisible for containerType=$containerType"
Expand Down
5 changes: 3 additions & 2 deletions app/services/CollectionService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ object CollectionService {
config: ConfigJson,
containerService: ContainerService
): Option[StoriesVisibleByStage] = {
val cConfigJson = config.collections.get(collectionId).get
val stages =
CollectionService.getStoriesForCollectionStages(collectionId, collection)
config.collections.get(collectionId).flatMap(_.`type`) match {
case Some(cType) =>
Some(
StoriesVisibleByStage(
containerService.getStoriesVisible(cType, stages._1),
containerService.getStoriesVisible(cType, stages._2)
containerService.getStoriesVisible(cType, stages._1, cConfigJson),
containerService.getStoriesVisible(cType, stages._2, cConfigJson)
)
)
case None => None
Expand Down
5 changes: 3 additions & 2 deletions app/services/ContainerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services

import play.api.libs.json.{Json, OFormat}
import slices._
import com.gu.facia.client.models.CollectionConfigJson

case class StoriesVisibleResponse(
desktop: Option[Int],
Expand All @@ -14,7 +15,7 @@ object StoriesVisibleResponse {
}

class ContainerService(val containers: Containers) {
def getStoriesVisible(containerType: String, stories: Seq[Story]) = {
def getStoriesVisible(containerType: String, stories: Seq[Story], collectionConfigJson: CollectionConfigJson) = {
val numberOfStories = stories.length
containers.all.get(containerType) map {
case Fixed(container) =>
Expand Down Expand Up @@ -48,7 +49,7 @@ class ContainerService(val containers: Containers) {
)

case Flexible(container) =>
val numberVisible = container.storiesVisible(stories)
val numberVisible = container.storiesVisible(stories, collectionConfigJson: CollectionConfigJson)
StoriesVisibleResponse(
Some(numberVisible),
Some(numberVisible)
Expand Down
14 changes: 10 additions & 4 deletions app/slices/FlexibleContainer.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package slices
import com.gu.facia.client.models.CollectionConfigJson

trait FlexibleContainer {
def storiesVisible(stories: Seq[Story]): Int
def storiesVisible(stories: Seq[Story], collectionConfigJson: CollectionConfigJson): Int
}

object FlexibleGeneral extends FlexibleContainer {
def storiesVisible(stories: Seq[Story]): Int = {
def storiesVisible(stories: Seq[Story], collectionConfigJson: CollectionConfigJson): Int = {
val byGroup = Story.segmentByGroup(stories)
val splash = byGroup.getOrElse(3, Seq.empty) ++
byGroup.getOrElse(2, Seq.empty) ++
byGroup.getOrElse(1, Seq.empty)
val numOfSplash = splash.size min 1
val numOfStandard = stories.size - numOfSplash
val defaultStandardStoryLimit = 8

numOfSplash + (numOfStandard min 8)
val standardStoryLimit = collectionConfigJson.displayHints
.flatMap(_.maxItemsToDisplay)
.getOrElse(defaultStandardStoryLimit)

numOfSplash + (numOfStandard min standardStoryLimit)
}
}

object FlexibleSpecial extends FlexibleContainer {
def storiesVisible(stories: Seq[Story]): Int = {
def storiesVisible(stories: Seq[Story], collectionConfigJson: CollectionConfigJson): Int = {
val byGroup = Story.segmentByGroup(stories)
val snap = byGroup.getOrElse(3, Seq.empty) ++
byGroup.getOrElse(2, Seq.empty) ++
Expand Down
6 changes: 6 additions & 0 deletions public/src/js/widgets/columns/fronts-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@
<label>Groups</label>
<span class="cnf-form__value" data-bind="text: meta.groups"></span>
<!-- /ko -->

<!-- ko if: meta.type() === "flexible/general"-->
<label for="flexGenStoryLimit">flexGenStoryAmount</label>
<input id="flexGenStoryLimit" type="number" data-bind="value: meta.displayHints.maxItemsToDisplay" placeholder="6">
<!-- /ko -->

<label for="userVisibility">User visibility</label>
<select id="userVisibility" data-bind="
optionsCaption: 'Select user visibility',
Expand Down

0 comments on commit 5633883

Please sign in to comment.