Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
teneightfive committed Jul 22, 2020
1 parent 5577201 commit 688aa7c
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 20 deletions.
34 changes: 32 additions & 2 deletions app/move/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module.exports = function view(req, res) {
assessment_answers: assessmentAnswers = [],
person_escort_record: personEscortRecord,
} = profile || {}
const personEscortRecordIsComplete = personEscortRecord?.status === 'complete'
const personEscortRecordIsEnabled = FEATURE_FLAGS.PERSON_ESCORT_RECORD
const personEscortRecordIsComplete =
personEscortRecord?.status !== 'in_progress'
const personEscortRecordUrl = `${originalUrl}/person-escort-record`
const showPersonEscortRecordBanner =
FEATURE_FLAGS.PERSON_ESCORT_RECORD &&
Expand All @@ -44,19 +46,47 @@ module.exports = function view(req, res) {
update: updateUrls,
}

const perMap = {
risk: 'risk-information',
health: 'health-information',
}

console.log(personEscortRecord)

const locals = {
move,
personEscortRecord,
personEscortRecordIsEnabled,
personEscortRecordIsComplete,
personEscortRecordUrl,
personEscortRecordtaskList,
showPersonEscortRecordBanner,
personEscortRecordTagList: presenters.frameworkFlagsToTagList(
personEscortRecord?.flags
),
moveSummary: presenters.moveToMetaListComponent(move, updateActions),
personalDetailsSummary: presenters.personToSummaryListComponent(person),
tagList: presenters.assessmentToTagList(assessmentAnswers),
assessment: presenters
.assessmentAnswersByCategory(assessmentAnswers)
.map(presenters.assessmentCategoryToPanelComponent),
.map(presenters.assessmentCategoryToPanelComponent)
.map(assessment => {
if (!personEscortRecord?.id) {
return {
...assessment,
current: assessment.panels,
isEditable: true,
}
}

return {
...assessment,
current: [],
previous: assessment.panels,
perSection: perMap[assessment.key],
isEditable: false,
}
}),
canCancelMove:
(userPermissions.includes('move:cancel') &&
move.status === 'requested' &&
Expand Down
74 changes: 61 additions & 13 deletions app/move/views/_includes/assessment.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,74 @@
}) }}
</h2>

{% for panel in assessmentCategory.panels %}
{% call appPanel(panel) %}
{{ appMetaList({
classes: "app-meta-list--divider",
items: panel.items
}) }}
{% endcall %}
{% else %}
{% if not personEscortRecordIsComplete and not assessmentCategory.isEditable %}
{{ appMessage({
classes: "app-message--muted govuk-!-margin-top-2",
allowDismiss: false,
content: {
text: t('assessment::no_items.text', {
context: assessmentCategory.key
})
text: "Person Escort Record " + assessmentCategory.key + " information must be completed to display this information"
}
}) }}
{% endfor %}
{% else %}
{% for panel in assessmentCategory.current %}
{% call appPanel(panel) %}
{{ appMetaList({
classes: "app-meta-list--divider",
items: panel.items
}) }}
{% endcall %}
{% else %}
{{ appMessage({
classes: "app-message--muted govuk-!-margin-top-2",
allowDismiss: false,
content: {
text: t('assessment::no_items.text', {
context: assessmentCategory.key
})
}
}) }}
{% endfor %}
{% endif %}

{% if assessmentCategory.previous | length %}
{% set html %}
{% for panel in assessmentCategory.panels %}
{% call appPanel(panel) %}
{{ appMetaList({
classes: "app-meta-list--divider",
items: panel.items
}) }}
{% endcall %}
{% endfor %}
{% endset %}

{{ govukDetails({
html: html,
classes: "govuk-!-font-size-16 govuk-!-margin-top-4",
summaryText: "View previous information"
}) }}
{% else %}
{# {% for panel in assessmentCategory.panels %}
{% call appPanel(panel) %}
{{ appMetaList({
classes: "app-meta-list--divider",
items: panel.items
}) }}
{% endcall %}
{% else %}
{{ appMessage({
classes: "app-message--muted govuk-!-margin-top-2",
allowDismiss: false,
content: {
text: t('assessment::no_items.text', {
context: assessmentCategory.key
})
}
}) }}
{% endfor %} #}
{% endif %}

{% if not personEscortRecord %}
{% if assessmentCategory.isEditable %}
{{ updateLink(updateLinks[assessmentCategory.key]) }}
{% endif %}
</section>
Expand Down
16 changes: 15 additions & 1 deletion app/move/views/view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,21 @@
}) }}
</span>

{% if tagList | length %}
{# TODO: Remove feature flag once PER feature is live #}
{% if personEscortRecordIsEnabled %}
<div class="govuk-!-margin-top-2">
{% if personEscortRecordTagList | length and personEscortRecordIsComplete %}
{% for tag in personEscortRecordTagList %}
{{ appTag(tag) }}
{% endfor %}
{% else %}
{{ govukInsetText({
classes: "govuk-inset-text--compact govuk-!-margin-0",
text: t("person-escort-record::flags.incomplete")
}) }}
{% endif %}
<div>
{% elif tagList | length %}
<div class="govuk-!-margin-top-2">
{% for tag in tagList %}
{{ appTag(tag) }}
Expand Down
7 changes: 7 additions & 0 deletions common/assets/scss/overrides/_govuk-frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
.govuk-hint * {
color: $govuk-secondary-text-colour;
}

.govuk-inset-text--compact {
@include govuk-font($size: 16);
border-left-width: 4px;
color: $govuk-secondary-text-colour;
padding: govuk-spacing(1) govuk-spacing(2);
}
4 changes: 4 additions & 0 deletions common/components/card/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ $_image-width: 80px;
padding-top: 0;
margin-top: -8px;
}

.govuk-inset-text {
margin: govuk-spacing(3) 0 0;
}
}

.app-card--compact {
Expand Down
5 changes: 5 additions & 0 deletions common/components/card/template.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% from "tag/macro.njk" import appTag %}
{% from "moj/components/badge/macro.njk" import mojBadge %}
{% from "govuk/components/inset-text/macro.njk" import govukInsetText %}

{% set headingLevel = params.headingLevel if params.headingLevel else 2 %}

Expand Down Expand Up @@ -61,5 +62,9 @@
{% endfor %}
</ul>
{% endif %}

{% if params.message %}
{{ govukInsetText(params.message) }}
{% endif %}
</div>
</div>
24 changes: 24 additions & 0 deletions common/components/tag/_tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,27 @@ a.app-tag {
border-color: govuk-colour("red");
}
}

.app-tag--warning {
background-color: govuk-colour("yellow");
color: govuk-colour("black");

&:focus {
background-color: govuk-colour("yellow");
color: govuk-colour("black");
}

@include govuk-media-query($media-type: print) {
border-color: govuk-colour("yellow");
}
}

a.app-tag--warning {
&:active,
&:link,
&:hover,
&:visited,
&:focus {
color: govuk-colour("black");
}
}
22 changes: 22 additions & 0 deletions common/lib/api-client/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module.exports = {
'profile',
'profile.documents',
'profile.person_escort_record',
'profile.person_escort_record.responses',
// 'profile.person_escort_record.flags',
'profile.person',
'profile.person.ethnicity',
'profile.person.gender',
Expand Down Expand Up @@ -385,6 +387,10 @@ module.exports = {
jsonApi: 'hasMany',
type: 'framework_responses',
},
flags: {
jsonApi: 'hasMany',
type: 'framework_flags',
},
},
options: {
defaultInclude: [
Expand All @@ -393,6 +399,7 @@ module.exports = {
'framework',
'responses',
'responses.question',
'flags',
],
},
},
Expand All @@ -406,6 +413,17 @@ module.exports = {
},
},
},
framework_flag: {
fields: {
name: '',
flag_type: '',
question_value: '',
// question: {
// jsonApi: 'hasOne',
// type: 'framework_questions',
// },
},
},
framework_question: {
fields: {
key: '',
Expand All @@ -431,6 +449,10 @@ module.exports = {
jsonApi: 'hasOne',
type: 'framework_questions',
},
flags: {
jsonApi: 'hasMany',
type: 'framework_flags',
},
},
options: {
defaultInclude: ['person_escort_record', 'question'],
Expand Down
22 changes: 22 additions & 0 deletions common/presenters/framework-flags-to-tag-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { sortBy, uniqBy, kebabCase } = require('lodash')

const { TAG_CATEGORY_WHITELIST } = require('../../config')

function frameworkFlagsToTagList(flags, hrefPrefix = '') {
const tags = uniqBy(flags, 'name')
.filter(({ flag_type: category }) => TAG_CATEGORY_WHITELIST[category])
.map(({ flag_type: category, name }) => {
const whitelisted = TAG_CATEGORY_WHITELIST[category]

return {
text: name,
href: `${hrefPrefix}#${kebabCase(name)}`,
classes: whitelisted ? whitelisted.tagClass : 'app-tag--inactive',
sortOrder: whitelisted ? whitelisted.sortOrder : null,
}
})

return sortBy(tags, ['sortOrder', 'text'])
}

module.exports = frameworkFlagsToTagList
2 changes: 2 additions & 0 deletions common/presenters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const assessmentToTagList = require('./assessment-to-tag-list')
const courtCaseToCardComponent = require('./court-case-to-card-component')
const courtHearingToSummaryListComponent = require('./court-hearing-to-summary-list-component')
const frameworkFieldToSummaryListRow = require('./framework-field-summary-list-row')
const frameworkFlagsToTagList = require('./framework-flags-to-tag-list')
const frameworkStepToSummary = require('./framework-step-to-summary')
const frameworkToTaskListComponent = require('./framework-to-task-list-component')
const moveToCardComponent = require('./move-to-card-component')
Expand All @@ -34,6 +35,7 @@ module.exports = {
courtCaseToCardComponent,
courtHearingToSummaryListComponent,
frameworkFieldToSummaryListRow,
frameworkFlagsToTagList,
frameworkStepToSummary,
frameworkToTaskListComponent,
moveToCardComponent,
Expand Down
19 changes: 16 additions & 3 deletions common/presenters/profile-to-card-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const i18n = require('../../config/i18n')
const filters = require('../../config/nunjucks/filters')

const assessmentToTagList = require('./assessment-to-tag-list')
const frameworkFlagsToTagList = require('./framework-flags-to-tag-list')

function profileToCardComponent({
showImage = true,
Expand All @@ -12,7 +13,12 @@ function profileToCardComponent({
} = {}) {
return function item(profile) {
profile = profile || {}
const { href, assessment_answers: assessmentAnswers, person = {} } = profile
const {
href,
assessment_answers: assessmentAnswers,
person = {},
person_escort_record: personEscortRecord,
} = profile
const {
id,
gender,
Expand Down Expand Up @@ -54,8 +60,15 @@ function profileToCardComponent({
}

if (showTags) {
card.tags = {
items: assessmentToTagList(assessmentAnswers, href),
if (personEscortRecord?.status === 'in_progress') {
card.message = {
classes: 'govuk-inset-text--compact',
text: i18n.t('person-escort-record::flags.incomplete'),
}
} else {
card.tags = {
items: frameworkFlagsToTagList(personEscortRecord.flags, href),
}
}
}

Expand Down
Loading

0 comments on commit 688aa7c

Please sign in to comment.