diff --git a/app/controllers/Api.scala b/app/controllers/Api.scala index bb935a174..9440a87b0 100644 --- a/app/controllers/Api.scala +++ b/app/controllers/Api.scala @@ -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 { diff --git a/common-lib/src/main/scala/com/gu/workflow/api/StubAPI.scala b/common-lib/src/main/scala/com/gu/workflow/api/StubAPI.scala index af877dbad..f6ea336c4 100644 --- a/common-lib/src/main/scala/com/gu/workflow/api/StubAPI.scala +++ b/common-lib/src/main/scala/com/gu/workflow/api/StubAPI.scala @@ -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)) diff --git a/common-lib/src/main/scala/models/Stub.scala b/common-lib/src/main/scala/models/Stub.scala index 81b126fa0..4d595f448 100644 --- a/common-lib/src/main/scala/models/Stub.scala +++ b/common-lib/src/main/scala/models/Stub.scala @@ -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, diff --git a/conf/routes b/conf/routes index ba8c01237..b5868b551 100644 --- a/conf/routes +++ b/conf/routes @@ -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 diff --git a/public/components/content-list-drawer/content-list-drawer.html b/public/components/content-list-drawer/content-list-drawer.html index 96e242d42..cc6a0dc70 100644 --- a/public/components/content-list-drawer/content-list-drawer.html +++ b/public/components/content-list-drawer/content-list-drawer.html @@ -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" }}
  • diff --git a/public/components/content-list-drawer/content-list-drawer.js b/public/components/content-list-drawer/content-list-drawer.js index f6028a117..75dff4ad8 100644 --- a/public/components/content-list-drawer/content-list-drawer.js +++ b/public/components/content-list-drawer/content-list-drawer.js @@ -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 */ diff --git a/public/components/content-list-item/content-list-item.js b/public/components/content-list-item/content-list-item.js index ba79da303..3562ad436 100644 --- a/public/components/content-list-item/content-list-item.js +++ b/public/components/content-list-item/content-list-item.js @@ -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); @@ -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 }; diff --git a/public/components/content-list-item/templates/commissionedLength.html b/public/components/content-list-item/templates/commissionedLength.html index e16ac311c..c6a2cd016 100644 --- a/public/components/content-list-item/templates/commissionedLength.html +++ b/public/components/content-list-item/templates/commissionedLength.html @@ -3,6 +3,6 @@ ng-attr-title="{{'Commissioned word count (' + lengthStatus + ' in comparison to web words)'}}"> - {{ contentItem.commissionedLength }} + {{ contentItem.commissionedLength || formatReason(contentItem.missingCommissionedLengthReason) }} diff --git a/public/lib/column-defaults.js b/public/lib/column-defaults.js index 09a5c6892..170ce5b7a 100644 --- a/public/lib/column-defaults.js +++ b/public/lib/column-defaults.js @@ -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', @@ -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...', diff --git a/public/lib/composer-service.js b/public/lib/composer-service.js index 3db5788ff..937be6641 100644 --- a/public/lib/composer-service.js +++ b/public/lib/composer-service.js @@ -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 };