diff --git a/src/controllers/datasetController.js b/src/controllers/datasetController.js index 3b8c9bcd..a90f2d0c 100644 --- a/src/controllers/datasetController.js +++ b/src/controllers/datasetController.js @@ -11,16 +11,29 @@ class DatasetController extends PageController { // const dataset = req.sessionModel.get('data-subject') // const options = datasetOptions[dataset] - const options = [dataSubjects['Article 4'].dataSets[0], dataSubjects['Conservation area'].dataSets[0]] - - if (options) { - this.availableDatasets = options.filter(option => option.available) - req.form.options.datasetItems = options - super.get(req, res, next) - } else { - // skip to next step of form wizard - this.successHandler(req, res, next) + // the options should be all the datasets that are available + + const availableDataSubjects = Object.values(dataSubjects).filter(dataSubject => dataSubject.available) + const dataSets = Object.values(availableDataSubjects).map(dataSubject => dataSubject.dataSets).flat() + const availableDatasets = dataSets.filter(dataSet => dataSet.available) + + req.form.options.datasetItems = availableDatasets + super.get(req, res, next) + } + + // we shouldn't need this here but as we dont currently set the datasubject, we need to do so here + post (req, res, next) { + const dataset = req.body.dataset + // set the data-subject based on the dataset selected + let dataSubject = '' + for (const [key, value] of Object.entries(dataSubjects)) { + if (value.dataSets.find(dataSet => dataSet.value === dataset)) { + dataSubject = key + break + } } + req.body['data-subject'] = dataSubject + super.post(req, res, next) } } diff --git a/src/controllers/uploadController.js b/src/controllers/uploadController.js index 298cf2d9..d73c210a 100644 --- a/src/controllers/uploadController.js +++ b/src/controllers/uploadController.js @@ -37,7 +37,7 @@ class UploadController extends PageController { originalname: req.file.originalname, dataset: req.sessionModel.get('dataset'), dataSubject: req.sessionModel.get('data-subject'), - organisation: 'local-authority-eng:CAT', // ToDo: this needs to be dynamic, not collected in the prototype, should it be? + // organisation: 'local-authority-eng:CAT', // ToDo: this needs to be dynamic, not collected in the prototype, should it be? sessionId: await hash(req.sessionID), ipAddress: await hash(req.ip) }) diff --git a/src/routes/form-wizard/steps.js b/src/routes/form-wizard/steps.js index 79abdee7..dc88f649 100644 --- a/src/routes/form-wizard/steps.js +++ b/src/routes/form-wizard/steps.js @@ -26,7 +26,7 @@ export default { '/dataset': { ...baseSettings, controller: datasetController, - fields: ['dataset'], + fields: ['dataset', 'data-subject'], next: 'upload', backLink: './' }, diff --git a/src/utils/utils.js b/src/utils/utils.js index 44e8c01b..97e907cb 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -6,7 +6,7 @@ export const severityLevels = { } export const dataSubjects = { - 'Article 4': { + 'article-4-direction': { available: true, dataSets: [ { @@ -15,13 +15,13 @@ export const dataSubjects = { available: true }, { - value: 'article-4-direction area', + value: 'article-4-direction-area', text: 'Article 4 direction area dataset', available: false } ] }, - 'Conservation area': { + 'conservation-area': { available: true, dataSets: [ { @@ -36,8 +36,8 @@ export const dataSubjects = { } ] }, - 'Tree preservation order': { - available: false, + 'tree-preservation-order': { + available: true, dataSets: [ { value: 'tree-preservation-order', @@ -47,7 +47,7 @@ export const dataSubjects = { { value: 'tree-preservation-zone', text: 'Tree preservation zone dataset', - available: false + available: true }, { value: 'tree', @@ -56,8 +56,24 @@ export const dataSubjects = { } ] }, - 'Listed building': { - available: false, - dataSets: [] + 'listed-building': { + available: true, + dataSets: [ + { + value: 'listed-building', + text: 'Listed building', + available: false + }, + { + value: 'listed-building-outline', + text: 'Listed building outline', + available: true + }, + { + value: 'listed-building-grade', + text: 'Listed building grade', + available: false + } + ] } }