Skip to content

Commit

Permalink
Merge pull request #476 from guardian/fp/show-missing-commissioned-le…
Browse files Browse the repository at this point in the history
…ngth-reason

Surface missingCommissionedLengthReason field
  • Loading branch information
Fweddi authored Nov 26, 2024
2 parents d9a3c13 + cde31f6 commit 0eaf661
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 24 deletions.
15 changes: 13 additions & 2 deletions app/controllers/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,23 @@ class Api(
APIAuthAction.async { request =>
ApiResponseFt[Long](for {
json <- readJsonFromRequestResponse(request.body)
status <- extractDataResponse[Option[Int]](json)
id <- stubsApi.updateContentCommissionedLength(stubId, status)
commissionedLength <- extractDataResponse[Option[Int]](json)
id <- stubsApi.updateContentCommissionedLength(stubId, commissionedLength)
} yield id
)}
}

def putStubMissingCommissionedLengthReason(stubId: Long) = {
APIAuthAction.async { request =>
ApiResponseFt[Long](for {
json <- readJsonFromRequestResponse(request.body)
missingCommissionedLengthReason <- extractDataResponse[Option[String]](json)
id <- stubsApi.updateContentMissingCommissionedLengthReason(stubId, missingCommissionedLengthReason)
} yield id
)
}
}

def putStubStatusByComposerId(composerId: String) = {
APIAuthAction.async { request =>
ApiResponseFt[String](for {
Expand Down
7 changes: 7 additions & 0 deletions common-lib/src/main/scala/com/gu/workflow/api/StubAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ class StubAPI(
item <- extractDataResponse[Long](json)
} yield item

def updateContentMissingCommissionedLengthReason(stubId: Long, missingCommissionedLengthReason: Option[String]): ApiResponseFt[Long] =
for {
res <- ApiResponseFt.Async.Right(putRequest(s"stubs/$stubId/missingCommissionedLengthReason", missingCommissionedLengthReason.asJson))
json <- parseBody(res.body)
item <- extractDataResponse[Long](json)
} yield item

def updateContentStatusByComposerId(composerId: String, status: String): ApiResponseFt[String] =
for {
res <- ApiResponseFt.Async.Right(putRequest(s"content/$composerId/status", status.asJson))
Expand Down
1 change: 1 addition & 0 deletions common-lib/src/main/scala/models/Stub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ case class ExternalData(
hasMainMedia: Option[Boolean] = None,
commentable: Option[Boolean] = None,
commissionedLength: Option[Int] = None,
missingCommissionedLengthReason: Option[String] = None,
actualPublicationId: Option[Long] = None,
actualBookId: Option[Long] = None,
actualBookSectionId: Option[Long] = None,
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ PUT /api/stubs/:stubId/plannedBookSectionId controllers.Api.putSt
PUT /api/stubs/:stubId/plannedNewspaperPageNumber controllers.Api.putStubPlannedNewspaperPageNumber(stubId: Long)
PUT /api/stubs/:stubId/plannedNewspaperPublicationDate controllers.Api.putStubPlannedNewspaperPublicationDate(stubId: Long)
PUT /api/stubs/:stubId/rightsReviewed controllers.Api.putStubRightsReviewed(stubId: Long)
PUT /api/stubs/:stubId/commissionedLength controllers.Api.putStubCommissionedLength(stubId: Long)
PUT /api/stubs/:stubId/missingCommissionedLengthReason controllers.Api.putStubMissingCommissionedLengthReason(stubId: Long)
DELETE /api/stubs/:stubId controllers.Api.deleteStub(stubId: Long)

GET /api/statuses controllers.Api.statusus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
wf-editable-input-type="number"
ng-model="contentItem.commissionedLength"
wf-editable-on-update="updateCommissionedLength(newValue)"
wf-editable-maxlength="5">{{contentItem.commissionedLength || "Add" }}
wf-editable-maxlength="5">{{contentItem.commissionedLength || formatReason(contentItem.missingCommissionedLengthReason) || "Add" }}
</wf-editable>
</li>
<li class="drawer__item">
Expand Down
47 changes: 38 additions & 9 deletions public/components/content-list-drawer/content-list-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,49 @@ export function wfContentListDrawer($rootScope, config, $timeout, $window, conte
};

$scope.updateCommissionedLength = function (newValue) {
// Don't allow commissioned length to be unset
if(newValue === "") return;
if ($scope.contentItem.missingCommissionedLengthReason !== null && $scope.contentItem.missingCommissionedLengthReason !== undefined) {
// workflow stub
updateField("missingCommissionedLengthReason", null);
// composer preview
wfComposerService.deleteField(
$scope.contentItem.composerId,
"missingCommissionedLengthReason",
false
);
// composer live
wfComposerService.deleteField(
$scope.contentItem.composerId,
"missingCommissionedLengthReason",
true
);
}
// workflow stub
updateField("commissionedLength", newValue);
if (newValue === "") {
return wfComposerService.deleteField(
// composer preview
wfComposerService.updateField(
$scope.contentItem.composerId,
"commissionedLength"
);
}
return wfComposerService.updateField(
$scope.contentItem.composerId,
"commissionedLength",
newValue
"commissionedLength",
newValue
);
// composer live
wfComposerService.updateField(
$scope.contentItem.composerId,
"commissionedLength",
newValue,
true
);
};

$scope.formatReason = (missingCommissionedLengthReason) => {
const reasons = {
"BreakingNews": "Breaking News",
}

return reasons[missingCommissionedLengthReason] || missingCommissionedLengthReason;
}

/**
* Revert deadline to previous state
*/
Expand Down
9 changes: 9 additions & 0 deletions public/components/content-list-item/content-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function wfContentItemParser(config, wfFormatDateTime, statusLabels, sections) {
this.wordCount = item.wordCount;
this.printWordCount = item.printWordCount;
this.commissionedLength = item.commissionedLength;
this.missingCommissionedLengthReason = item.missingCommissionedLengthReason;

this.headline = item.headline;
this.standfirst = stripHtml(item.standfirst);
Expand Down Expand Up @@ -380,6 +381,14 @@ function wfCommissionedLengthCtrl ($scope) {
$scope.lengthStatus = "over";
}
});

$scope.formatReason = (missingCommissionedLengthReason) => {
const reasons = {
"BreakingNews": "Breaking News",
}

return reasons[missingCommissionedLengthReason] || missingCommissionedLengthReason;
}
}

export { wfContentListItem, wfContentItemParser, wfContentItemUpdateActionDirective, wfGetPriorityStringFilter, wfCommissionedLengthCtrl };
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
ng-attr-title="{{'Commissioned word count (' + lengthStatus + ' in comparison to web words)'}}">
<span ng-class="'content-list-item__field--commissionedLength-status-'+ lengthStatus"
ng-show="contentItem.contentType == 'article'">
{{ contentItem.commissionedLength }}
{{ contentItem.commissionedLength || formatReason(contentItem.missingCommissionedLengthReason) }}
</span>
</td>
21 changes: 11 additions & 10 deletions public/lib/column-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ const columnDefaults = [{
isNew: true,
isSortable: true,
sortField: ['statusInPrint']
},{
name: 'commissionedLength',
prettyName: 'Commissioned Length',
labelHTML: 'Commissioned Length',
colspan: 1,
title: '',
templateUrl: templateRoot + 'commissionedLength.html',
template: commissionedLengthTemplate,
active: true,
isSortable: true,
sortField: ['missingCommissionedLengthReason', 'commissionedLength']
},{
name: 'wordcount',
prettyName: 'Web wordcount',
Expand Down Expand Up @@ -347,16 +358,6 @@ const columnDefaults = [{
isSortable: true,
defaultSortOrder: ['asc', 'desc', 'asc'],
sortField: ['printLocationBookSection', 'printLocationPublicationDate', 'printLocationPageNumber']
},{
name: 'commissionedLength',
prettyName: 'Commissioned Length',
labelHTML: 'Commission',
colspan: 1,
title: '',
templateUrl: templateRoot + 'commissionedLength.html',
template: commissionedLengthTemplate,
active: true,
isSortable: true
},{
name: 'links',
prettyName: 'Open in...',
Expand Down
3 changes: 2 additions & 1 deletion public/lib/composer-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function wfComposerService($http, $q, config, $log, wfHttpSessionService, wfTele
revision: (d) => deepSearch(d, ['contentChangeDetails', 'data', 'revision']),
lastModified: (d) => new Date(deepSearch(d, ['contentChangeDetails', 'data', 'lastModified', 'date']) || undefined),
lastModifiedBy: (d) => deepSearch(d, ['contentChangeDetails', 'data', 'lastModified', 'user', 'firstName']) + ' ' + deepSearch(d, ['contentChangeDetails', 'data', 'lastModified', 'user', 'lastName']),
commissionedLength: (d) => deepSearch(d, ['preview', 'data', 'fields', 'commissionedLength', 'data']) || undefined
commissionedLength: (d) => deepSearch(d, ['preview', 'data', 'fields', 'commissionedLength', 'data']) || undefined,
missingCommissionedLengthReason: (d) => deepSearch(d, ['preview', 'data', 'fields', 'missingCommissionedLengthReason', 'data']) || undefined
};


Expand Down

0 comments on commit 0eaf661

Please sign in to comment.