Skip to content

Commit

Permalink
Merge pull request #508 from guardian/sponsorship-packages
Browse files Browse the repository at this point in the history
Sponsorship packages
  • Loading branch information
davidfurey authored Mar 8, 2024
2 parents 615583c + 645b544 commit 392920b
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 15 deletions.
10 changes: 9 additions & 1 deletion app/model/Sponsorship.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import play.api.Logging
import play.api.libs.json._
import play.api.libs.functional.syntax._
import repositories.{SectionRepository, TagRepository, TagLookupCache}
import com.gu.tagmanagement.{Sponsorship => ThriftSponsorship, SponsorshipTargeting => ThriftSponsorshipTargeting, SponsorshipType}
import com.gu.tagmanagement.{Sponsorship => ThriftSponsorship, SponsorshipTargeting => ThriftSponsorshipTargeting, SponsorshipType, SponsorshipPackage}

import scala.util.control.NonFatal

Expand All @@ -32,6 +32,7 @@ case class Sponsorship (
validTo: Option[DateTime],
status: String,
sponsorshipType: String,
sponsorshipPackage: Option[String],
sponsorName: String,
sponsorLogo: Image,
highContrastSponsorLogo: Option[Image],
Expand All @@ -44,9 +45,14 @@ case class Sponsorship (

def toItem = Item.fromJSON(Json.toJson(this).toString())

private def sponsorshipPackageAsThrift(s: String) = SponsorshipPackage.valueOf(
s.replace("-", "") // convert us-exclusive to usexclusive
)

def asThrift: ThriftSponsorship = ThriftSponsorship(
id = id,
sponsorshipType = SponsorshipType.valueOf(sponsorshipType).get,
sponsorshipPackage = sponsorshipPackage.flatMap(sponsorshipPackageAsThrift),
sponsorName = sponsorName,
sponsorLogo = sponsorLogo.asThrift,
highContrastSponsorLogo = highContrastSponsorLogo.map(_.asThrift),
Expand Down Expand Up @@ -81,6 +87,7 @@ case class DenormalisedSponsorship (
validTo: Option[DateTime],
status: String,
sponsorshipType: String,
sponsorshipPackage: Option[String],
sponsorName: String,
sponsorLogo: Image,
highContrastSponsorLogo: Option[Image],
Expand All @@ -101,6 +108,7 @@ object DenormalisedSponsorship {
validTo = s.validTo,
status = s.status,
sponsorshipType = s.sponsorshipType,
sponsorshipPackage = s.sponsorshipPackage,
sponsorName = s.sponsorName,
sponsorLogo = s.sponsorLogo,
highContrastSponsorLogo = s.highContrastSponsorLogo,
Expand Down
3 changes: 3 additions & 0 deletions app/model/command/CreateSponsorshipCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ case class CreateSponsorshipCommand(
validFrom: Option[DateTime],
validTo: Option[DateTime],
sponsorshipType: String,
sponsorshipPackage: Option[String],
sponsorName: String,
sponsorLogo: Image,
highContrastSponsorLogo: Option[Image],
Expand All @@ -38,6 +39,7 @@ case class CreateSponsorshipCommand(
validTo = validTo,
status = status,
sponsorshipType = sponsorshipType,
sponsorshipPackage = sponsorshipPackage,
sponsorName = sponsorName,
sponsorLogo = sponsorLogo,
highContrastSponsorLogo = highContrastSponsorLogo,
Expand Down Expand Up @@ -76,6 +78,7 @@ object CreateSponsorshipCommand{
(JsPath \ "validFrom").formatNullable[DateTime] and
(JsPath \ "validTo").formatNullable[DateTime] and
(JsPath \ "sponsorshipType").format[String] and
(JsPath \ "sponsorshipPackage").formatNullable[String] and
(JsPath \ "sponsorName").format[String] and
(JsPath \ "sponsorLogo").format[Image] and
(JsPath \ "highContrastSponsorLogo").formatNullable[Image] and
Expand Down
1 change: 1 addition & 0 deletions app/model/command/CreateTagCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ case class InlinePaidContentSponsorshipCommand(
validTo = validTo,
status = status,
sponsorshipType = "paidContent",
sponsorshipPackage = None,
sponsorName = sponsorName,
sponsorLogo = sponsorLogo,
highContrastSponsorLogo = highContrastSponsorLogo,
Expand Down
3 changes: 3 additions & 0 deletions app/model/command/UpdateSponsorshipCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ case class UpdateSponsorshipCommand(
validFrom: Option[DateTime],
validTo: Option[DateTime],
sponsorshipType: String,
sponsorshipPackage: Option[String],
sponsorName: String,
sponsorLogo: Image,
highContrastSponsorLogo: Option[Image],
Expand All @@ -39,6 +40,7 @@ case class UpdateSponsorshipCommand(
validTo = validTo,
status = status,
sponsorshipType = sponsorshipType,
sponsorshipPackage = sponsorshipPackage,
sponsorName = sponsorName,
sponsorLogo = sponsorLogo,
highContrastSponsorLogo = highContrastSponsorLogo,
Expand Down Expand Up @@ -104,6 +106,7 @@ object UpdateSponsorshipCommand{
(JsPath \ "validFrom").formatNullable[DateTime] and
(JsPath \ "validTo").formatNullable[DateTime] and
(JsPath \ "sponsorshipType").format[String] and
(JsPath \ "sponsorshipPackage").formatNullable[String] and
(JsPath \ "sponsorName").format[String] and
(JsPath \ "sponsorLogo").format[Image] and
(JsPath \ "highContrastSponsorLogo").formatNullable[Image] and
Expand Down
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ version := "1.0"

lazy val scalaVer = "2.12.16"

resolvers ++= Resolver.sonatypeOssRepos("releases")

scalacOptions ++= Seq(
"-target:jvm-1.8",
"-encoding", "UTF-8",
Expand All @@ -31,7 +33,7 @@ lazy val dependencies = Seq(
"com.squareup.okhttp3" % "okhttp" % "4.9.2",
"com.google.guava" % "guava" % "18.0",
"com.gu" %% "content-api-client-default" % "17.24.1",
"com.gu" %% "tags-thrift-schema" % "2.8.1",
"com.gu" %% "tags-thrift-schema" % "2.8.3",
"net.logstash.logback" % "logstash-logback-encoder" % "7.2",
"org.slf4j" % "slf4j-api" % "1.7.12",
"org.slf4j" % "jcl-over-slf4j" % "1.7.12",
Expand Down
4 changes: 2 additions & 2 deletions public/components/Sponsorship/Create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import SponsorshipTypeEdit from '../SponsorshipEdit/SponsorshipTypeEdit.react';
import SponsorshipPackageEdit from '../SponsorshipEdit/SponsorshipPackageEdit.react';
import SponsorEdit from '../SponsorshipEdit/SponsorEdit.react';
import ValidityEdit from '../SponsorshipEdit/ValidityEdit.react';
import TargetingEdit from '../SponsorshipEdit/TargetingEdit.react';
Expand Down Expand Up @@ -64,8 +65,7 @@ class SponsorshipCreate extends React.Component {
return (
<div className="sponsorship-edit">
<div className="sponsorship-edit__column--sidebar">
<SponsorshipTypeEdit sponsorship={this.props.sponsorship} updateSponsorship={this.props.sponsorshipActions.updateSponsorship}/>
<SponsorEdit sponsorship={this.props.sponsorship} updateSponsorship={this.props.sponsorshipActions.updateSponsorship}/>
<SponsorEdit sponsorship={this.props.sponsorship} updateSponsorship={this.props.sponsorshipActions.updateSponsorship} creating={true} />
</div>
<div className="sponsorship-edit__column">
<ValidityEdit sponsorship={this.props.sponsorship} updateSponsorship={this.updateSponsorshipAndCheckClashes.bind(this)} />
Expand Down
10 changes: 9 additions & 1 deletion public/components/SponsorshipEdit/SponsorEdit.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import SponsorLogo from './SponsorLogo.react';
import {PAID_HOSTEDCONTENT_TYPE} from '../../constants/paidContentTagTypes';
import ReactTooltip from 'react-tooltip';
import { Required } from './Required.react';
import SponsorshipPackageEdit from "./SponsorshipPackageEdit.react";
import SponsorshipTypeEdit from "./SponsorshipTypeEdit.react";

const imageRules = `
<p style="text-align:left; margin-left: -10px">This image should:</p>
Expand Down Expand Up @@ -57,7 +59,12 @@ export default class SponsorEdit extends React.Component {
const logoWidth = this.props.paidContentTagType === PAID_HOSTEDCONTENT_TYPE.value ? false : 280;
const logoHeight = this.props.paidContentTagType === PAID_HOSTEDCONTENT_TYPE.value ? false : 180;

return (
return (<>
<div className="tag-edit__input-group">
<label className="tag-edit__input-group__header">Sponsorship</label>
{ <SponsorshipTypeEdit sponsorship={this.props.sponsorship} updateSponsorship={this.props.updateSponsorship} editable={!!this.props.creating}/> }
{ this.props.sponsorship.sponsorshipType == "sponsored" ? <SponsorshipPackageEdit sponsorship={this.props.sponsorship} updateSponsorship={this.props.updateSponsorship}/> : null }
</div>
<div className="tag-edit__input-group">
<ReactTooltip html={true}/>
<label className="tag-edit__input-group__header">Sponsor</label>
Expand Down Expand Up @@ -93,6 +100,7 @@ export default class SponsorEdit extends React.Component {
</div>

</div>
</>
);

}
Expand Down
2 changes: 1 addition & 1 deletion public/components/SponsorshipEdit/SponsorLogo.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const dropzoneStyles = {
padding: "10px"
}

export default class SponsorEdit extends React.Component {
export default class SponsorLogo extends React.Component {

constructor(props) {
super(props);
Expand Down
33 changes: 33 additions & 0 deletions public/components/SponsorshipEdit/SponsorshipPackageEdit.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';

export default class SponsorshipPackageEdit extends React.Component {

constructor(props) {
super(props);
}

updateType(e) {
this.props.updateSponsorship(Object.assign({}, this.props.sponsorship, {
sponsorshipPackage: e.target.value
}));
}


render () {

if (!this.props.sponsorship) {
return false;
}

return (
<div className="tag-edit__field">
<label className="tag-edit__label">Package</label>
<select value={this.props.sponsorship.sponsorshipPackage || "default"} onChange={this.updateType.bind(this)}>
<option value="default">default</option>
<option value="us">Advertising partner (US only)</option>
<option value="us-exclusive">Exclusive advertising partner (US only)</option>
</select>
</div>
);
}
}
18 changes: 9 additions & 9 deletions public/components/SponsorshipEdit/SponsorshipTypeEdit.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export default class SponsorEdit extends React.Component {
export default class SponsorshipTypeEdit extends React.Component {

constructor(props) {
super(props);
Expand All @@ -20,14 +20,14 @@ export default class SponsorEdit extends React.Component {
}

return (
<div className="tag-edit__input-group">
<label className="tag-edit__input-group__header">Sponsorship type</label>
<div className="tag-edit__field">
<select value={this.props.sponsorship.sponsorshipType} onChange={this.updateType.bind(this)}>
<option value="sponsored">sponsored</option>
<option value="foundation">foundation</option>
</select>
</div>
<div className="tag-edit__field">
{ this.props.editable ? <>
<label className="tag-edit__label">Type</label>
<select value={this.props.sponsorship.sponsorshipType} onChange={this.updateType.bind(this)}>
<option value="sponsored">sponsored</option>
<option value="foundation">foundation</option>
</select>
</> : this.props.sponsorship.sponsorshipType }
</div>
);
}
Expand Down

0 comments on commit 392920b

Please sign in to comment.