Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PIL declarations to activity log #980

Merged
merged 1 commit into from Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pages/pil/dashboard/index.js
Expand Up @@ -6,6 +6,7 @@ const success = require('../../success');
const confirm = require('./routers/confirm');
const { hydrate, updateDataFromTask, redirectToTaskIfOpen } = require('../../common/middleware');
const { canUpdateModel, canTransferPil } = require('../../../lib/utils');
const content = require('./content');

module.exports = settings => {
const sendData = (req, params = {}) => {
Expand All @@ -14,7 +15,10 @@ module.exports = settings => {
const opts = {
method: 'PUT',
json: merge({
data: pick(req.model, 'procedures', 'notesCatD', 'notesCatF', 'species')
data: pick(req.model, 'procedures', 'notesCatD', 'notesCatF', 'species'),
meta: {
declaration: content.fields.declaration.label
}
}, params)
};

Expand Down
27 changes: 26 additions & 1 deletion pages/task/read/routers/confirm.js
@@ -1,7 +1,29 @@
const form = require('../../../common/routers/form');
const { Router } = require('express');
const { set, get, pick } = require('lodash');
const { render } = require('mustache');
const getSchema = require('../../schema/confirm');
const content = require('../content/confirm');

const requiresDeclaration = (task, values) => {
const model = task.data.model;
let action = task.data.action;
if (action === 'grant' && task.type === 'amendment') {
action = 'update';
}
return ['pil', 'trainingPil', 'project'].includes(model) && values.status === 'endorsed' && action !== 'review';
};

const trim = value => value.split('\n').map(s => s.trim()).join('\n').trim();

const getDeclarationText = (task, values) => {
const declaration = get(content, `declaration.${values.status}.${task.data.model}`);
const licenceHolder = get(task, 'data.modelData.profile') || get(task, 'data.modelData.licenceHolder');
return trim(render(declaration, {
name: `${get(licenceHolder, 'firstName')} ${get(licenceHolder, 'lastName')}`,
type: task.type
}));
};

module.exports = () => {
const app = Router();
Expand Down Expand Up @@ -46,7 +68,6 @@ module.exports = () => {

app.post('/', (req, res, next) => {
const values = req.session.form[`${req.task.id}`].values;

const opts = {
method: 'PUT',
headers: { 'Content-type': 'application/json' },
Expand All @@ -60,6 +81,10 @@ module.exports = () => {
}
};

if (requiresDeclaration(req.task, values)) {
opts.json.meta.declaration = getDeclarationText(req.task, values);
}

return req.api(`/tasks/${req.task.id}/status`, opts)
.then(response => {
req.session.success = { taskId: get(response, 'json.data.id') };
Expand Down
19 changes: 19 additions & 0 deletions pages/task/read/views/components/activity-log.jsx
Expand Up @@ -78,6 +78,24 @@ function DeadlineDetails({ item }) {
);
}

function ExtraPilMeta({ item }) {
const declaration = get(item, 'event.meta.payload.meta.declaration');

if (!declaration) {
return null;
}

return (
<div className="declaration">
<p>Declaration:</p>
<Inset>
<Markdown>{declaration}</Markdown>
</Inset>
</div>
);

}

function ExtraProjectMeta({ item, task }) {
const mostRecentActivity = item.id === task.activityLog[0].id;
const versionId = get(item, 'event.data.data.version');
Expand Down Expand Up @@ -135,6 +153,7 @@ function LogItem({ item, task }) {
<Action task={task} action={action} changedBy={item.changedBy} />
<InspectorRecommendation item={item} />
{ isExtension && <DeadlineDetails item={item} /> }
{ task.data.model === 'pil' && <ExtraPilMeta item={item} /> }
<Comment changedBy={item.changedBy} comment={item.comment} />
{ task.data.model === 'project' && <ExtraProjectMeta item={item} task={task} /> }
</div>
Expand Down