Skip to content

Commit

Permalink
Merge pull request #4253 from bbc/t1601-features-notification
Browse files Browse the repository at this point in the history
Addition of announcement/notification banner
  • Loading branch information
rebecca-thompson authored Apr 22, 2024
2 parents 95cdbd9 + 72378e7 commit 08f695c
Show file tree
Hide file tree
Showing 16 changed files with 520 additions and 1 deletion.
20 changes: 20 additions & 0 deletions common-lib/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ usageRightsConfigProvider = {
}
}

# -------------------------------------------------------------
# Announcements - notifications to be seen by users
# Format:
# [ (array)
# { (json object)
# announceId: (string) the unique id of the announcement - should be unique among all active announcements
# description: (string) the main text to display in the notification notification_banner
# endDate: (string, optional, format="yyyy-mm-dd") the date beyond which the announcement should not be seen, if not present set as today + 1 year
# url: (string, optional) a link to a page/document providing further details regarding announcement
# urlText: (string, optional) text to be included in a-tag hyperlink (will revert to default if not present)
# category: (string) the type of announcement - will control styling and display, Enum=announcement, information, warning, error, success
# lifespan: (string) the lifecycle behaviour Enum=transient (message disappears on any click etc),
# session (message must be acknowledged but action NOT stored in client cookie - used for current session messages)
# persistent (message must be acknowledged and action stored in client cookie - used for long running announcements)
# },
# ...
# ]
# -----------------------------------------------------------------
announcements = []

domainMetadata.specifications = []

metadata.templates = []
Expand Down
7 changes: 7 additions & 0 deletions kahuna/app/controllers/KahunaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class KahunaController(
val domainMetadataSpecs: String = Json.toJson(config.domainMetadataSpecs).toString()
val fieldAliases: String = Json.toJson(config.fieldAliasConfigs).toString()
val metadataTemplates: String = Json.toJson(config.metadataTemplates).toString()
val announcements: String = Json.toJson(config.announcements).toString()
val returnUri = config.rootUri + okPath
val costFilterLabel = config.costFilterLabel.getOrElse("Free to use only")
val costFilterChargeable = config.costFilterChargeable.getOrElse(false)
Expand All @@ -68,6 +69,7 @@ class KahunaController(
scriptsToLoad,
domainMetadataSpecs,
metadataTemplates,
announcements,
additionalNavigationLinks,
costFilterLabel,
costFilterChargeable,
Expand All @@ -81,6 +83,11 @@ class KahunaController(
Ok(views.html.quotas(config.mediaApiUri))
}

def notifications = authentication { req =>
val announcements: String = Json.toJson(config.announcements).toString()
Ok(announcements)
}

def ok = Action { implicit request =>
Ok("ok")
}
Expand Down
67 changes: 67 additions & 0 deletions kahuna/app/lib/AnnouncementsConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package lib

import play.api.ConfigLoader
import play.api.libs.json._
import scala.collection.JavaConverters._
import scala.util.{Try, Success, Failure}
import java.time.{LocalDate, Period}

case class Announcement(
announceId: String,
description: String,
endDate: LocalDate,
url: String,
urlText: String,
category: String,
lifespan: String
)

object Announcement {

val announceCategory = Set("announcement", "information", "warning", "error", "success")
val announceLifespan = Set("transient", "session", "persistent")

implicit val writes: Writes[Announcement] = Json.writes[Announcement]

implicit val configLoader: ConfigLoader[Seq[Announcement]] = {
ConfigLoader(_.getConfigList).map(
_.asScala.map(config => {

val endDate = if (config.hasPath("endDate")) {
val dte = Try(LocalDate.parse(config.getString("endDate")))
dte match {
case Success(value) => value
case Failure(_) => LocalDate.now().plus(Period.ofYears(1))
}
} else {
LocalDate.now().plus(Period.ofYears(1))
}

val announceUrl = if (config.hasPath("url")) {
config.getString("url")
} else ""

val urlText = if (config.hasPath("urlText")) {
config.getString("urlText")
} else ""

val category = if (announceCategory.contains(config.getString("category"))) {
config.getString("category")
} else "announcement" // the expected category applicationConf announcements

val lifespan = if (announceLifespan.contains(config.getString("lifespan"))) {
config.getString("lifespan")
} else "persistent" // the expected lifespan for applicationConf announcements

Announcement(config.getString("announceId"),
config.getString("description"),
endDate,
announceUrl,
urlText,
category,
lifespan
)
}))
}

}
2 changes: 2 additions & 0 deletions kahuna/app/lib/KahunaConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class KahunaConfig(resources: GridConfigResources) extends CommonConfig(resource

val metadataTemplates: Seq[MetadataTemplate] = configuration.get[Seq[MetadataTemplate]]("metadata.templates")

val announcements: Seq[Announcement] = configuration.getOptional[Seq[Announcement]]("announcements").getOrElse(Seq.empty)

//BBC custom warning text
val warningTextHeader: String = configuration.getOptional[String]("warningText.header")
.getOrElse("This image can be used, but has warnings:")
Expand Down
3 changes: 3 additions & 0 deletions kahuna/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
scriptsToLoad: List[ScriptToLoad],
domainMetadataSpecs: String,
metadataTemplates: String,
announcements: String,
additionalNavigationLinks: String,
costFilterLabel: String,
costFilterChargeable: Boolean,
Expand Down Expand Up @@ -77,6 +78,7 @@
telemetryUri: '@kahunaConfig.telemetryUri.getOrElse("")',
defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages,
shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket,
announcements: @Html(announcements),
}
</script>

Expand All @@ -86,6 +88,7 @@

<div ui-view></div>
<ui-global-errors></ui-global-errors>
<ui-notifications></ui-notifications>

<script src="@routes.Assets.versioned("dist/build.js")"></script>

Expand Down
1 change: 1 addition & 0 deletions kahuna/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GET /images/$id<[0-9a-z]+>/crop controllers.KahunaControll
GET /search controllers.KahunaController.index(ignored="")
GET /upload controllers.KahunaController.index(ignored="")
GET /quotas controllers.KahunaController.quotas
GET /notifications controllers.KahunaController.notifications

# Empty page to return to the same domain as the app
GET /ok controllers.KahunaController.ok
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.outer-notifications {
width: 100%;
}

.notification-container {
width: 100%;
display: flex;
border-bottom: 1px solid black;
}

.notification-container-last {
width: 100%;
display: flex;
}

.notification-start {
flex: 0 0 initial;
display: flex;
align-items: center;
margin-top: 6px;
padding: 8px 16px 8px 24px;
justify-content: center;
}

.notification-start-icon {
text-align: center;
}

.notification {
flex: 1;
display: flex;
align-items: center;
padding: 8px 0px 8px 0px;
min-height: 28px;
}

.notification-end {
flex: 0 0 initial;
display: flex;
align-items: center;
padding: 8px 24px 8px 24px;
}

.notification-url {
color: black;
border-bottom: 1px solid black;
font-weight: 500;
}

.notification-url:hover {
color: black;
font-weight: 500;
}

.notification-button {
width: 80px;
padding: 8px 0 0 0;
text-align: center;
}

.notification-button:hover {
cursor: pointer;
}

.notification-announcement {
background: #A8CFFF;
color: black;
stroke: #A8CFFF;
}

.notification-information {
background: #A8CFFF;
color: black;
stroke: #A8CFFF;
}

.notification-warning {
background: #FEDB8B;
color: black;
stroke: #FEDB8B;
}

.notification-error {
background: #EEBFBE;
color: black;
stroke: #EEBFBE;
}

.notification-success {
background: #6FE290;
color: black;
stroke: black;
}
Loading

0 comments on commit 08f695c

Please sign in to comment.