Skip to content

Commit

Permalink
Merge pull request #34 from Marvell-Consulting/SW-128
Browse files Browse the repository at this point in the history
SW-128: Metadata - Dataset Summary
  • Loading branch information
wheelsandcogs authored Nov 5, 2024
2 parents b4a8195 + a64c026 commit eb1f2a9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 4 deletions.
29 changes: 28 additions & 1 deletion src/controllers/publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';

import { generateViewErrors } from '../utils/generate-view-errors';
import { hasError, titleValidator } from '../validators';
import { descriptionValidator, hasError, titleValidator } from '../validators';
import { ViewError } from '../dtos/view-error';
import { logger } from '../utils/logger';
import { ViewDTO, ViewErrDTO } from '../dtos/view-dto';
Expand Down Expand Up @@ -215,3 +215,30 @@ export const changeData = async (req: Request, res: Response, next: NextFunction
}
res.render('publish/change-data');
};

export const provideSummary = async (req: Request, res: Response, next: NextFunction) => {
let errors: ViewErrDTO | undefined;
const dataset = singleLangDataset(res.locals.dataset, req.language);
let description = dataset?.datasetInfo?.description;

if (req.method === 'POST') {
try {
const descriptionError = await hasError(descriptionValidator(), req);
if (descriptionError) {
res.status(400);
throw new Error('errors.description.missing');
}

description = req.body.description;

await req.swapi.updateDatasetInfo(dataset.id, { description, language: req.language });
res.redirect(req.buildUrl(`/publish/${dataset.id}/tasklist`, req.language));
return;
} catch (err) {
const error: ViewError = { field: 'title', tag: { name: 'errors.title.missing' } };
errors = generateViewErrors(undefined, 400, [error]);
}
}

res.render('publish/summary', { description, errors });
};
7 changes: 7 additions & 0 deletions src/middleware/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
"descriptive": "It should be short, descriptive and unique",
"language": "This should be entered in the language in which you're viewing this service."
},
"summary": {
"heading": "What is the summary of the dataset?",
"explain": "In short, simple sentences explain:",
"explain_1": "what this dataset is about and what it shows",
"explain_2": "the dataset's dimensions and why they've been used, if needed",
"language": "This should be entered in the language in which you're viewing this service."
},
"upload": {
"title": "Upload the data table",
"note": "The file should be in a CSV format"
Expand Down
6 changes: 5 additions & 1 deletion src/routes/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
sources,
taskList,
changeData,
redirectToTasklist
redirectToTasklist,
provideSummary
} from '../controllers/publish';

export const publish = Router();
Expand Down Expand Up @@ -40,3 +41,6 @@ publish.get('/:datasetId/tasklist', fetchDataset, taskList);

publish.get('/:datasetId/change', fetchDataset, changeData);
publish.post('/:datasetId/change', fetchDataset, upload.none(), changeData);

publish.get('/:datasetId/summary', fetchDataset, provideSummary);
publish.post('/:datasetId/summary', fetchDataset, upload.none(), provideSummary);
1 change: 1 addition & 0 deletions src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const revisionIdValidator = () => param('revisionId').trim().notEmpty().i
export const importIdValidator = () => param('importId').trim().notEmpty().isUUID(4);

export const titleValidator = () => body('title').trim().notEmpty();
export const descriptionValidator = () => body('description').trim().notEmpty();
44 changes: 44 additions & 0 deletions src/views/publish/summary.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%- include("../partials/header"); %>
<div class="govuk-width-container app-width-container">
<!-- <a href="#" class="govuk-back-link">Back</a> -->
<main class="govuk-main-wrapper" id="main-content" role="main">

<div class="top-links">
<div class="govuk-width-container">
<a href="javascript:history.back()" class="govuk-back-link"><%= t('buttons.back') %></a>
<a href="<%= buildUrl(`/publish/${locals.datasetId}/tasklist`, i18n.language) %>" class="govuk-link return-link"><%= t('publish.header.overview') %></a>
</div>
</div>

<div class="govuk-width-container">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl"><%= t('publish.summary.heading') %></h1>

<%- include("../partials/error-handler"); %>

<p class="govuk-body"><%= t('publish.summary.explain') %></p>

<ul class="govuk-list govuk-list--bullet">
<li><%= t('publish.summary.explain_1') %></li>
<li><%= t('publish.summary.explain_2') %></li>
</ul>

<div class="govuk-hint">
<%= t('publish.summary.language') %>
</div>

<form enctype="multipart/form-data" method="post">
<div class="govuk-form-group">
<textarea class="govuk-textarea" id="description" name="description" rows="4"><%= locals.description %></textarea>
</div>
<button type="submit" class="govuk-button" data-module="govuk-button"><%= t('buttons.continue') %></button>
<a class="govuk-button govuk-button--secondary" href="javascript:history.back()"><%= t('buttons.cancel')%></a>
</form>
</div>
</div>
</div>
</main>
</div>

<%- include("../partials/footer"); %>
5 changes: 3 additions & 2 deletions src/views/publish/title.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
<div class="govuk-form-group">
<input class="govuk-input" id="title" name="title" type="text" value="<%= locals.title %>">
</div>
<p class="govuk-body"><button type="submit" class="govuk-button" data-module="govuk-button">
<button type="submit" class="govuk-button" data-module="govuk-button">
<%= t('buttons.continue') %>
</button> <a class="govuk-button govuk-button--secondary" href="<%= locals.backButtonLink %>"><%= t('buttons.cancel')%></a></p>
</button>
<a class="govuk-button govuk-button--secondary" href="javascript:history.back()"><%= t('buttons.cancel')%></a>
</form>
</main>
</div>
Expand Down

0 comments on commit eb1f2a9

Please sign in to comment.